AndroidTestRunner: use Qt::StringLiterals and some cosmetic changes

Cleanup the includes, and remove unused include dir in CMakeLists.txt.

Task-number: QTQAINFRA-5928
Change-Id: I477024291042042765b666bda882bab4a5f8313f
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Assam Boudjelthia 2023-11-26 00:34:51 +02:00
parent 10a706df27
commit 6a7f9d6b14

View File

@ -1,23 +1,21 @@
// Copyright (C) 2019 BogDan Vatra <bogdan@kde.org> // Copyright (C) 2019 BogDan Vatra <bogdan@kde.org>
// Copyright (C) 2022 The Qt Company Ltd. // Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QCoreApplication> #include <QtCore/QCoreApplication>
#include <QDir> #include <QtCore/QDeadlineTimer>
#include <QHash> #include <QtCore/QDir>
#include <QRegularExpression> #include <QtCore/QHash>
#include <QSystemSemaphore> #include <QtCore/QProcess>
#include <QXmlStreamReader> #include <QtCore/QProcessEnvironment>
#include <QtCore/QRegularExpression>
#include <QtCore/QSystemSemaphore>
#include <QtCore/QThread>
#include <QtCore/QXmlStreamReader>
#include <algorithm>
#include <functional>
#include <atomic> #include <atomic>
#include <csignal> #include <csignal>
#include <QtCore/QDeadlineTimer> #include <functional>
#include <QtCore/QThread>
#include <QtCore/QProcessEnvironment>
#include <QtCore/QProcess>
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
@ -29,12 +27,12 @@ static bool checkJunit(const QByteArray &data) {
if (!reader.isStartElement()) if (!reader.isStartElement())
continue; continue;
if (reader.name() == QStringLiteral("error")) if (reader.name() == "error"_L1)
return false; return false;
const QString type = reader.attributes().value(QStringLiteral("type")).toString(); const QString type = reader.attributes().value("type"_L1).toString();
if (reader.name() == QStringLiteral("failure")) { if (reader.name() == "failure"_L1) {
if (type == QStringLiteral("fail") || type == QStringLiteral("xpass")) if (type == "fail"_L1 || type == "xpass"_L1)
return false; return false;
} }
} }
@ -65,10 +63,10 @@ static bool checkXml(const QByteArray &data) {
QXmlStreamReader reader{data}; QXmlStreamReader reader{data};
while (!reader.atEnd()) { while (!reader.atEnd()) {
reader.readNext(); reader.readNext();
const QString type = reader.attributes().value(QStringLiteral("type")).toString(); const QString type = reader.attributes().value("type"_L1).toString();
const bool isIncident = (reader.name() == QStringLiteral("Incident")); const bool isIncident = (reader.name() == "Incident"_L1);
if (reader.isStartElement() && isIncident) { if (reader.isStartElement() && isIncident) {
if (type == QStringLiteral("fail") || type == QStringLiteral("xpass")) if (type == "fail"_L1 || type == "xpass"_L1)
return false; return false;
} }
} }
@ -112,7 +110,7 @@ struct Options
bool skipAddInstallRoot = false; bool skipAddInstallRoot = false;
int timeoutSecs = 600; // 10 minutes int timeoutSecs = 600; // 10 minutes
QString buildPath; QString buildPath;
QString adbCommand{QStringLiteral("adb")}; QString adbCommand{"adb"_L1};
QString makeCommand; QString makeCommand;
QString package; QString package;
QString activity; QString activity;
@ -125,14 +123,14 @@ struct Options
int pid = -1; int pid = -1;
bool showLogcatOutput = false; bool showLogcatOutput = false;
const QHash<QString, std::function<bool(const QByteArray &)>> checkFiles = { const QHash<QString, std::function<bool(const QByteArray &)>> checkFiles = {
{QStringLiteral("txt"), checkTxt}, {"txt"_L1, checkTxt},
{QStringLiteral("csv"), checkCsv}, {"csv"_L1, checkCsv},
{QStringLiteral("xml"), checkXml}, {"xml"_L1, checkXml},
{QStringLiteral("lightxml"), checkLightxml}, {"lightxml"_L1, checkLightxml},
{QStringLiteral("xunitxml"), checkJunit}, {"xunitxml"_L1, checkJunit},
{QStringLiteral("junitxml"), checkJunit}, {"junitxml"_L1, checkJunit},
{QStringLiteral("teamcity"), checkTeamcity}, {"teamcity"_L1, checkTeamcity},
{QStringLiteral("tap"), checkTap}, {"tap"_L1, checkTap},
}; };
}; };
@ -191,50 +189,50 @@ static bool parseOptions()
int i = 1; int i = 1;
for (; i < arguments.size(); ++i) { for (; i < arguments.size(); ++i) {
const QString &argument = arguments.at(i); const QString &argument = arguments.at(i);
if (argument.compare(QStringLiteral("--adb"), Qt::CaseInsensitive) == 0) { if (argument.compare("--adb"_L1, Qt::CaseInsensitive) == 0) {
if (i + 1 == arguments.size()) if (i + 1 == arguments.size())
g_options.helpRequested = true; g_options.helpRequested = true;
else else
g_options.adbCommand = arguments.at(++i); g_options.adbCommand = arguments.at(++i);
} else if (argument.compare(QStringLiteral("--path"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--path"_L1, Qt::CaseInsensitive) == 0) {
if (i + 1 == arguments.size()) if (i + 1 == arguments.size())
g_options.helpRequested = true; g_options.helpRequested = true;
else else
g_options.buildPath = arguments.at(++i); g_options.buildPath = arguments.at(++i);
} else if (argument.compare(QStringLiteral("--make"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--make"_L1, Qt::CaseInsensitive) == 0) {
if (i + 1 == arguments.size()) if (i + 1 == arguments.size())
g_options.helpRequested = true; g_options.helpRequested = true;
else else
g_options.makeCommand = arguments.at(++i); g_options.makeCommand = arguments.at(++i);
} else if (argument.compare(QStringLiteral("--apk"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--apk"_L1, Qt::CaseInsensitive) == 0) {
if (i + 1 == arguments.size()) if (i + 1 == arguments.size())
g_options.helpRequested = true; g_options.helpRequested = true;
else else
g_options.apkPath = arguments.at(++i); g_options.apkPath = arguments.at(++i);
} else if (argument.compare(QStringLiteral("--activity"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--activity"_L1, Qt::CaseInsensitive) == 0) {
if (i + 1 == arguments.size()) if (i + 1 == arguments.size())
g_options.helpRequested = true; g_options.helpRequested = true;
else else
g_options.activity = arguments.at(++i); g_options.activity = arguments.at(++i);
} else if (argument.compare(QStringLiteral("--skip-install-root"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--skip-install-root"_L1, Qt::CaseInsensitive) == 0) {
g_options.skipAddInstallRoot = true; g_options.skipAddInstallRoot = true;
} else if (argument.compare(QStringLiteral("--show-logcat"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--show-logcat"_L1, Qt::CaseInsensitive) == 0) {
g_options.showLogcatOutput = true; g_options.showLogcatOutput = true;
} else if (argument.compare("--ndk-stack"_L1, Qt::CaseInsensitive) == 0) { } else if (argument.compare("--ndk-stack"_L1, Qt::CaseInsensitive) == 0) {
if (i + 1 == arguments.size()) if (i + 1 == arguments.size())
g_options.helpRequested = true; g_options.helpRequested = true;
else else
g_options.ndkStackPath = arguments.at(++i); g_options.ndkStackPath = arguments.at(++i);
} else if (argument.compare(QStringLiteral("--timeout"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--timeout"_L1, Qt::CaseInsensitive) == 0) {
if (i + 1 == arguments.size()) if (i + 1 == arguments.size())
g_options.helpRequested = true; g_options.helpRequested = true;
else else
g_options.timeoutSecs = arguments.at(++i).toInt(); g_options.timeoutSecs = arguments.at(++i).toInt();
} else if (argument.compare(QStringLiteral("--help"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--help"_L1, Qt::CaseInsensitive) == 0) {
g_options.helpRequested = true; g_options.helpRequested = true;
} else if (argument.compare(QStringLiteral("--verbose"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--verbose"_L1, Qt::CaseInsensitive) == 0) {
g_options.verbose = true; g_options.verbose = true;
} else if (argument.compare(QStringLiteral("--"), Qt::CaseInsensitive) == 0) { } else if (argument.compare("--"_L1, Qt::CaseInsensitive) == 0) {
++i; ++i;
break; break;
} else { } else {
@ -249,7 +247,7 @@ static bool parseOptions()
QString serial = qEnvironmentVariable("ANDROID_DEVICE_SERIAL"); QString serial = qEnvironmentVariable("ANDROID_DEVICE_SERIAL");
if (!serial.isEmpty()) if (!serial.isEmpty())
g_options.adbCommand += QStringLiteral(" -s %1").arg(serial); g_options.adbCommand += " -s %1"_L1.arg(serial);
if (g_options.ndkStackPath.isEmpty()) { if (g_options.ndkStackPath.isEmpty()) {
const QString ndkPath = qEnvironmentVariable("ANDROID_NDK_ROOT"); const QString ndkPath = qEnvironmentVariable("ANDROID_NDK_ROOT");
@ -310,8 +308,8 @@ static QString packageNameFromAndroidManifest(const QString &androidManifestPath
QXmlStreamReader reader(&androidManifestXml); QXmlStreamReader reader(&androidManifestXml);
while (!reader.atEnd()) { while (!reader.atEnd()) {
reader.readNext(); reader.readNext();
if (reader.isStartElement() && reader.name() == QStringLiteral("manifest")) if (reader.isStartElement() && reader.name() == "manifest"_L1)
return reader.attributes().value(QStringLiteral("package")).toString(); return reader.attributes().value("package"_L1).toString();
} }
} }
return {}; return {};
@ -324,8 +322,8 @@ static QString activityFromAndroidManifest(const QString &androidManifestPath)
QXmlStreamReader reader(&androidManifestXml); QXmlStreamReader reader(&androidManifestXml);
while (!reader.atEnd()) { while (!reader.atEnd()) {
reader.readNext(); reader.readNext();
if (reader.isStartElement() && reader.name() == QStringLiteral("activity")) if (reader.isStartElement() && reader.name() == "activity"_L1)
return reader.attributes().value(QStringLiteral("android:name")).toString(); return reader.attributes().value("android:name"_L1).toString();
} }
} }
return {}; return {};
@ -334,26 +332,26 @@ static QString activityFromAndroidManifest(const QString &androidManifestPath)
static void setOutputFile(QString file, QString format) static void setOutputFile(QString file, QString format)
{ {
if (file.isEmpty()) if (file.isEmpty())
file = QStringLiteral("-"); file = "-"_L1;
if (format.isEmpty()) if (format.isEmpty())
format = QStringLiteral("txt"); format = "txt"_L1;
g_options.outFiles[format] = file; g_options.outFiles[format] = file;
} }
static bool parseTestArgs() static bool parseTestArgs()
{ {
QRegularExpression oldFormats{QStringLiteral("^-(txt|csv|xunitxml|junitxml|xml|lightxml|teamcity|tap)$")}; QRegularExpression oldFormats{"^-(txt|csv|xunitxml|junitxml|xml|lightxml|teamcity|tap)$"_L1};
QRegularExpression newLoggingFormat{QStringLiteral("^(.*),(txt|csv|xunitxml|junitxml|xml|lightxml|teamcity|tap)$")}; QRegularExpression newLoggingFormat{"^(.*),(txt|csv|xunitxml|junitxml|xml|lightxml|teamcity|tap)$"_L1};
QString file; QString file;
QString logType; QString logType;
QStringList unhandledArgs; QStringList unhandledArgs;
for (int i = 0; i < g_options.testArgsList.size(); ++i) { for (int i = 0; i < g_options.testArgsList.size(); ++i) {
const QString &arg = g_options.testArgsList[i].trimmed(); const QString &arg = g_options.testArgsList[i].trimmed();
if (arg == QStringLiteral("--")) if (arg == "--"_L1)
continue; continue;
if (arg == QStringLiteral("-o")) { if (arg == "-o"_L1) {
if (i >= g_options.testArgsList.size() - 1) if (i >= g_options.testArgsList.size() - 1)
return false; // missing file argument return false; // missing file argument
@ -692,7 +690,7 @@ int main(int argc, char *argv[])
if (!execCommand(g_options.makeCommand, nullptr, true)) { if (!execCommand(g_options.makeCommand, nullptr, true)) {
if (!g_options.skipAddInstallRoot) { if (!g_options.skipAddInstallRoot) {
// we need to run make INSTALL_ROOT=path install to install the application file(s) first // we need to run make INSTALL_ROOT=path install to install the application file(s) first
if (!execCommand(QStringLiteral("%1 INSTALL_ROOT=%2 install").arg(g_options.makeCommand, if (!execCommand("%1 INSTALL_ROOT=%2 install"_L1.arg(g_options.makeCommand,
QDir::toNativeSeparators(g_options.buildPath)), nullptr)) { QDir::toNativeSeparators(g_options.buildPath)), nullptr)) {
return 1; return 1;
} }
@ -719,7 +717,7 @@ int main(int argc, char *argv[])
if (!execAdbCommand(installArgs, nullptr)) if (!execAdbCommand(installArgs, nullptr))
return 1; return 1;
QString manifest = g_options.buildPath + QStringLiteral("/AndroidManifest.xml"); QString manifest = g_options.buildPath + "/AndroidManifest.xml"_L1;
g_options.package = packageNameFromAndroidManifest(manifest); g_options.package = packageNameFromAndroidManifest(manifest);
if (g_options.activity.isEmpty()) if (g_options.activity.isEmpty())
g_options.activity = activityFromAndroidManifest(manifest); g_options.activity = activityFromAndroidManifest(manifest);