diff options
author | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-02-17 16:32:46 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-02-17 16:20:07 +0000 |
commit | 6ca299379fc1afd95c93b0199bc2899a1d90391c (patch) | |
tree | 7bf52dd9bbb0cf29f4b36fe38ab6a03536c567dd /tests/fuzzy-test | |
parent | 3ff29a66b153c1a76d476ff91a26db931df5de89 (diff) |
fuzzy-tester: Add ability to forward job count to qbs.
Change-Id: I45f275b448bd5660488faeed524c16085d2fa303
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'tests/fuzzy-test')
-rw-r--r-- | tests/fuzzy-test/commandlineparser.cpp | 23 | ||||
-rw-r--r-- | tests/fuzzy-test/commandlineparser.h | 3 | ||||
-rw-r--r-- | tests/fuzzy-test/fuzzytester.cpp | 9 | ||||
-rw-r--r-- | tests/fuzzy-test/fuzzytester.h | 4 | ||||
-rw-r--r-- | tests/fuzzy-test/main.cpp | 17 |
5 files changed, 43 insertions, 13 deletions
diff --git a/tests/fuzzy-test/commandlineparser.cpp b/tests/fuzzy-test/commandlineparser.cpp index 8972e4f4d..9588c00ce 100644 --- a/tests/fuzzy-test/commandlineparser.cpp +++ b/tests/fuzzy-test/commandlineparser.cpp @@ -36,6 +36,7 @@ static QString profileOption() { return "--profile"; } static QString startCommitOption() { return "--start-commit"; } static QString maxDurationoption() { return "--max-duration"; } +static QString jobCountOption() { return "--jobs"; } CommandLineParser::CommandLineParser() { @@ -46,6 +47,7 @@ void CommandLineParser::parse(const QStringList &commandLine) m_profile.clear(); m_startCommit.clear(); m_maxDuration = 0; + m_jobCount = 0; m_commandLine = commandLine; Q_ASSERT(!m_commandLine.isEmpty()); m_command = m_commandLine.takeFirst(); @@ -55,6 +57,8 @@ void CommandLineParser::parse(const QStringList &commandLine) assignOptionArgument(arg, m_profile); else if (arg == startCommitOption()) assignOptionArgument(arg, m_startCommit); + else if (arg == jobCountOption()) + assignOptionArgument(arg, m_jobCount); else if (arg == maxDurationoption()) parseDuration(); else @@ -68,9 +72,10 @@ void CommandLineParser::parse(const QStringList &commandLine) QString CommandLineParser::usageString() const { - return QString::fromLocal8Bit("%1 %2 <profile> %3 <start commit> [%4 <duration>]") + return QString::fromLocal8Bit("%1 %2 <profile> %3 <start commit> [%4 <duration>] " + "[%5 <job count>]") .arg(QFileInfo(m_command).fileName(), profileOption(), startCommitOption(), - maxDurationoption()); + maxDurationoption(), jobCountOption()); } void CommandLineParser::assignOptionArgument(const QString &option, QString &argument) @@ -84,6 +89,18 @@ void CommandLineParser::assignOptionArgument(const QString &option, QString &arg } } +void CommandLineParser::assignOptionArgument(const QString &option, int &argument) +{ + QString numberString; + assignOptionArgument(option, numberString); + bool ok; + argument = numberString.toInt(&ok); + if (!ok || argument <= 0) { + throw ParseException(QString::fromLocal8Bit("Invalid argument '%1' for option '%2'.") + .arg(numberString, option)); + } +} + void CommandLineParser::parseDuration() { QString durationString; @@ -96,7 +113,7 @@ void CommandLineParser::parseDuration() choppedDurationString.chop(1); bool ok; m_maxDuration = choppedDurationString.toInt(&ok); - if (!ok) { + if (!ok || m_maxDuration <= 0) { throw ParseException(QString::fromLocal8Bit("Invalid duration argument '%1'.") .arg(durationString)); } diff --git a/tests/fuzzy-test/commandlineparser.h b/tests/fuzzy-test/commandlineparser.h index 31ea474e0..8682e9ef4 100644 --- a/tests/fuzzy-test/commandlineparser.h +++ b/tests/fuzzy-test/commandlineparser.h @@ -56,11 +56,13 @@ public: QString profile() const { return m_profile; } QString startCommit() const { return m_startCommit; } int maxDurationInMinutes() const { return m_maxDuration; } + int jobCount() const { return m_jobCount; } QString usageString() const; private: void assignOptionArgument(const QString &option, QString &argument); + void assignOptionArgument(const QString &option, int &argument); void parseDuration(); QStringList m_commandLine; @@ -68,6 +70,7 @@ private: QString m_profile; QString m_startCommit; int m_maxDuration; + int m_jobCount; }; #endif // Include guard. diff --git a/tests/fuzzy-test/fuzzytester.cpp b/tests/fuzzy-test/fuzzytester.cpp index 4aee4193b..07fd8ffff 100644 --- a/tests/fuzzy-test/fuzzytester.cpp +++ b/tests/fuzzy-test/fuzzytester.cpp @@ -42,9 +42,10 @@ FuzzyTester::FuzzyTester() } void FuzzyTester::runTest(const QString &profile, const QString &startCommit, - int maxDurationInMinutes) + int maxDurationInMinutes, int jobCount) { m_profile = profile; + m_jobCount = jobCount; runGit(QStringList() << "rev-parse" << "HEAD", &m_headCommit); qDebug("HEAD is %s", qPrintable(m_headCommit)); @@ -167,7 +168,11 @@ bool FuzzyTester::runQbs(const QString &buildDir, const QString &command, QStrin if (errorOutput) errorOutput->clear(); QProcess qbs; - qbs.start("qbs", QStringList(command) << "-qq" << "-d" << buildDir << ("profile:" + m_profile)); + QStringList commandLine = QStringList(command) << "-qq" << "-d" << buildDir; + if (m_jobCount != 0) + commandLine << "--jobs" << QString::number(m_jobCount); + commandLine << ("profile:" + m_profile); + qbs.start("qbs", commandLine); if (!qbs.waitForStarted()) throw TestError("Failed to start qbs. It is expected to be in the PATH."); if (!qbs.waitForFinished(-1) || qbs.exitCode() != 0) { diff --git a/tests/fuzzy-test/fuzzytester.h b/tests/fuzzy-test/fuzzytester.h index eb06dc470..4639e7394 100644 --- a/tests/fuzzy-test/fuzzytester.h +++ b/tests/fuzzy-test/fuzzytester.h @@ -55,7 +55,8 @@ class FuzzyTester public: FuzzyTester(); - void runTest(const QString &profile, const QString &startCommit, int maxDurationInMinutes); + void runTest(const QString &profile, const QString &startCommit, int maxDurationInMinutes, + int jobCount); private: void checkoutCommit(const QString &commit); @@ -70,6 +71,7 @@ private: static QString defaultBuildDir(); QString m_profile; + int m_jobCount; QString m_headCommit; }; diff --git a/tests/fuzzy-test/main.cpp b/tests/fuzzy-test/main.cpp index 818d87553..efc503d1f 100644 --- a/tests/fuzzy-test/main.cpp +++ b/tests/fuzzy-test/main.cpp @@ -37,8 +37,9 @@ #include <iostream> static bool parseCommandLine(const QStringList &commandLine, QString &profile, - QString &startCommi, int &maxDuration); -static bool runTest(const QString &profile, const QString &startCommit, int maxDuration); + QString &startCommi, int &maxDuration, int &jobCount); +static bool runTest(const QString &profile, const QString &startCommit, int maxDuration, + int jobCount); int main(int argc, char *argv[]) { @@ -47,16 +48,17 @@ int main(int argc, char *argv[]) QString profile; QString startCommit; int maxDuration; - if (!parseCommandLine(app.arguments(), profile, startCommit, maxDuration)) + int jobCount; + if (!parseCommandLine(app.arguments(), profile, startCommit, maxDuration, jobCount)) return EXIT_FAILURE; - if (!runTest(profile, startCommit, maxDuration)) + if (!runTest(profile, startCommit, maxDuration, jobCount)) return EXIT_FAILURE; std::cout << "Test finished successfully." << std::endl; return EXIT_SUCCESS; } bool parseCommandLine(const QStringList &commandLine, QString &profile, QString &startCommit, - int &maxDuration) + int &maxDuration, int &jobCount) { CommandLineParser cmdParser; try { @@ -69,13 +71,14 @@ bool parseCommandLine(const QStringList &commandLine, QString &profile, QString profile = cmdParser.profile(); startCommit = cmdParser.startCommit(); maxDuration = cmdParser.maxDurationInMinutes(); + jobCount = cmdParser.jobCount(); return true; } -bool runTest(const QString &profile, const QString &startCommit, int maxDuration) +bool runTest(const QString &profile, const QString &startCommit, int maxDuration, int jobCount) { try { - FuzzyTester().runTest(profile, startCommit, maxDuration); + FuzzyTester().runTest(profile, startCommit, maxDuration, jobCount); } catch (const TestError &e) { std::cerr << qPrintable(e.errorMessage) << std::endl; return false; |