Add debug logging to macdeployqt test

Preparation for debugging failures in the 6.2 branch

Pick-to: 6.5 6.2
Task-number: QTBUG-112892
Change-Id: Ib6428fb86be834c84be361a848c0f1306bfc2637
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-05-04 13:25:40 +02:00
parent 61e0671681
commit da7b6cb83d

View File

@ -4,6 +4,8 @@
#include <QtCore>
#include <QtTest>
Q_LOGGING_CATEGORY(lcTests, "qt.tools.tests")
bool g_testDirectoryBuild = false; // toggle to keep build output for debugging.
QTemporaryDir *g_temporaryDirectory;
QString g_macdeployqtBinary;
@ -34,6 +36,24 @@ static bool runProcess(const QString &binary,
process.setProcessEnvironment(env);
if (!workingDir.isEmpty())
process.setWorkingDirectory(workingDir);
const auto outputReader = qScopeGuard([&] {
QByteArray standardOutput = process.readAllStandardOutput();
if (!standardOutput.trimmed().isEmpty())
qCDebug(lcTests).nospace() << "Standard output:\n" << qUtf8Printable(standardOutput.trimmed());
if (stdOut)
*stdOut = standardOutput;
QByteArray standardError = process.readAllStandardError();
if (!standardError.trimmed().isEmpty())
qCDebug(lcTests).nospace() << "Standard error:\n" << qUtf8Printable(standardError.trimmed());
if (stdErr)
*stdErr = standardError;
});
qCDebug(lcTests).noquote() << "Running" << binary
<< "with arguments" << arguments
<< "in" << workingDir;
process.start(binary, arguments, QIODevice::ReadOnly);
if (!process.waitForStarted()) {
*errorMessage = msgProcessError(process, "Failed to start");
@ -46,10 +66,7 @@ static bool runProcess(const QString &binary,
process.kill();
return false;
}
if (stdOut)
*stdOut = process.readAllStandardOutput();
if (stdErr)
*stdErr= process.readAllStandardError();
if (process.exitStatus() != QProcess::NormalExit) {
*errorMessage = msgProcessError(process, "Crashed");
return false;
@ -148,26 +165,11 @@ bool deploy(const QString &name, const QStringList &options, QString *errorMessa
QString bundle = name + ".app";
QString path = buildPath(name);
QStringList args = QStringList() << bundle << options;
if (lcTests().isDebugEnabled())
args << "-verbose=3";
return runProcess(g_macdeployqtBinary, args, errorMessage, path);
}
bool debugDeploy(const QString &name, const QStringList &options, QString *errorMessage)
{
QString bundle = name + ".app";
QString path = buildPath(name);
QStringList args = QStringList() << bundle << options << "-verbose=3";
QByteArray stdOut;
QByteArray stdErr;
bool exitOK = runProcess(g_macdeployqtBinary, args, errorMessage, path, QProcessEnvironment(),
10000, &stdOut, &stdErr);
qDebug() << "macdeployqt exit OK" << exitOK;
qDebug() << qPrintable(stdOut);
qDebug() << qPrintable(stdErr);
return exitOK;
}
bool run(const QString &name, QString *errorMessage)
{
QString path = buildPath(name);