Fix FileSystemAccessTest::testFileActions() flakiness

Always add " > /dev/null 2>&1" infix so that the
output of e.g. "rm" command, when failed, is redirected
to dev/null.

Enclose the input data in runInShell() with quotation
marks and escape all the characters in passed data
accordingly. Pass the "-e" option to echo in order to
turn on the escaping mode.

Add a new test for testCreateRemoteFile().

Change-Id: I7db07b57035242279cac7dd77a80ac6dd05bfb1f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-03-16 20:21:49 +01:00
parent de8a67a412
commit 481df466e2
3 changed files with 64 additions and 18 deletions

View File

@@ -231,11 +231,14 @@ public:
bool runInShell(const CommandLine &cmd, const QByteArray &data = {})
{
QTC_ASSERT(m_shell, return false);
const QByteArray prefix = !data.isEmpty() ? QByteArray("echo " + data + " | ")
: QByteArray("");
QTC_CHECK(m_shell->readAllStandardOutput().isNull()); // clean possible left-overs
m_shell->readAllStandardOutput(); // clean possible left-overs
m_shell->write(prefix + cmd.toUserOutput().toUtf8() + "\necho $?\n");
const QByteArray prefix = !data.isEmpty()
? QByteArray("echo '" + data.toBase64() + "' | base64 -d | ") : QByteArray("");
const QByteArray suffix = QByteArray(" > /dev/null 2>&1\necho $?\n");
const QByteArray command = prefix + cmd.toUserOutput().toUtf8() + suffix;
m_shell->write(command);
DEBUG("RUN1 " << cmd.toUserOutput());
m_shell->waitForReadyRead();
const QByteArray output = m_shell->readAllStandardOutput();
@@ -243,18 +246,19 @@ public:
bool ok = false;
const int result = output.toInt(&ok);
LOG("Run command in shell:" << cmd.toUserOutput() << "result: " << output << " ==>" << result);
return ok && result == 0;
QTC_ASSERT(ok, return false);
return !result;
}
QByteArray outputForRunInShell(const QString &cmd)
{
QTC_ASSERT(m_shell, return {});
QTC_CHECK(m_shell->readAllStandardOutput().isNull()); // clean possible left-overs
static int val = 0;
const QByteArray delim = QString::number(++val, 16).toUtf8();
DEBUG("RUN2 " << cmd);
m_shell->readAllStandardOutput(); // clean possible left-overs
const QByteArray marker = "___QTC___" + delim + "_OUTPUT_MARKER___";
DEBUG(" CMD: " << cmd.toUtf8() + "\necho " + marker + "\n");
m_shell->write(cmd.toUtf8() + "\necho " + marker + "\n");
@@ -784,9 +788,6 @@ QByteArray LinuxDevice::fileContents(const FilePath &filePath, qint64 limit, qin
bool LinuxDevice::writeFileContents(const FilePath &filePath, const QByteArray &data) const
{
QTC_ASSERT(handlesFile(filePath), return {});
// This following would be the generic Unix solution.
// But it doesn't pass input. FIXME: Why?
return d->runInShell({"dd", {"of=" + filePath.path()}}, data);
}