deviceshell: Fix racecondition and long running tests

When writing to stdout and stderr from two processes, their output could become
interleaved. To work around that, we write stdout and stderr to different files
and later combine them together in the shell script.

Since tst_deviceshell tests could run for a long time if /usr folder
is too big, added a check that first tests the runtime once.

Since we currently only support linux containers, limit the tests to
only run if the container platform is linux as well.

Change-Id: I4b313596cdf9acc839d54d7cc77c66fd53ac23bf
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-07-14 15:05:18 +02:00
parent 825a3a5e7e
commit 07cb8876db
3 changed files with 26 additions and 6 deletions

1
.gitignore vendored
View File

@@ -39,6 +39,7 @@ tags
ui_*.h ui_*.h
wrapper.bat wrapper.bat
wrapper.sh wrapper.sh
debug_toolchain.cmake
# qtcreator generated files # qtcreator generated files
*.creator.user* *.creator.user*

View File

@@ -62,8 +62,11 @@ finalOutput() {
local fileInputBuffer local fileInputBuffer
while read fileInputBuffer while read fileInputBuffer
do do
if test -f "$fileInputBuffer.err"; then
cat $fileInputBuffer.err
fi
cat $fileInputBuffer cat $fileInputBuffer
rm $fileInputBuffer rm -f $fileInputBuffer.err $fileInputBuffer
done done
} }
@@ -117,7 +120,7 @@ executeAndMark()
# Mark the app's output streams # Mark the app's output streams
readAndMark $PID 'O' < "$stdoutenc" >> $TMPFILE & readAndMark $PID 'O' < "$stdoutenc" >> $TMPFILE &
readAndMark $PID 'E' < "$stderrenc" >> $TMPFILE & readAndMark $PID 'E' < "$stderrenc" >> $TMPFILE.err &
# Start the app ... # Start the app ...
if [ -z "$INDATA" ] if [ -z "$INDATA" ]

View File

@@ -60,9 +60,10 @@ private:
bool testDocker(const FilePath &executable) bool testDocker(const FilePath &executable)
{ {
QtcProcess p; QtcProcess p;
p.setCommand({executable, {"info"}}); p.setCommand({executable, {"info", "--format", "{{.OSType}}"}});
p.runBlocking(); p.runBlocking();
return p.result() == ProcessResult::FinishedWithSuccess; const QString platform = p.cleanedStdOut().trimmed();
return p.result() == ProcessResult::FinishedWithSuccess && platform == "linux";
} }
class tst_DeviceShell : public QObject class tst_DeviceShell : public QObject
@@ -336,10 +337,25 @@ private slots:
QList<int> runs{1,2,3,4,5,6,7,8,9}; QList<int> runs{1,2,3,4,5,6,7,8,9};
QList<QByteArray> results = Utils::mapped<QList>(runs, [&shell](const int i) -> QByteArray{ int maxDepth = 4;
int numMs = 0;
while (true) {
QElapsedTimer t; QElapsedTimer t;
t.start(); t.start();
DeviceShell::RunResult result = shell.outputForRunInShell({"find", {"/usr", "-maxdepth", "4"}}); DeviceShell::RunResult result = shell.outputForRunInShell({"find", {"/usr", "-maxdepth", QString::number(maxDepth)}});
numMs = t.elapsed();
qDebug() << "adjusted maxDepth" << maxDepth << "took" << numMs << "ms";
if (numMs < 100 || maxDepth == 1) {
break;
}
maxDepth--;
}
QList<QByteArray> results = Utils::mapped<QList>(runs, [&shell, maxDepth](const int i) -> QByteArray{
QElapsedTimer t;
t.start();
DeviceShell::RunResult result = shell.outputForRunInShell({"find", {"/usr", "-maxdepth", QString::number(maxDepth)}});
qDebug() << i << "took" << t.elapsed() << "ms"; qDebug() << i << "took" << t.elapsed() << "ms";
return result.stdOut; return result.stdOut;
}); });