aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fuzzy-test/commandlineparser.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2015-02-17 11:14:10 +0100
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2015-02-17 10:27:03 +0000
commit3ff29a66b153c1a76d476ff91a26db931df5de89 (patch)
tree05bf2055128d5be42e2be70095e82fb3314e41d3 /tests/fuzzy-test/commandlineparser.cpp
parent78516687e1bd7aef305e31f4596750f081bbe641 (diff)
fuzzy tester: Allow to run for a given time span.
This is helpful e.g. for letting the tool run overnight. Change-Id: I03fc9942dff35b6f9c4f966ab6795fede49f0ee6 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'tests/fuzzy-test/commandlineparser.cpp')
-rw-r--r--tests/fuzzy-test/commandlineparser.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/fuzzy-test/commandlineparser.cpp b/tests/fuzzy-test/commandlineparser.cpp
index 199956226..8972e4f4d 100644
--- a/tests/fuzzy-test/commandlineparser.cpp
+++ b/tests/fuzzy-test/commandlineparser.cpp
@@ -31,8 +31,11 @@
#include <QFileInfo>
+#include <cctype>
+
static QString profileOption() { return "--profile"; }
static QString startCommitOption() { return "--start-commit"; }
+static QString maxDurationoption() { return "--max-duration"; }
CommandLineParser::CommandLineParser()
{
@@ -42,6 +45,7 @@ void CommandLineParser::parse(const QStringList &commandLine)
{
m_profile.clear();
m_startCommit.clear();
+ m_maxDuration = 0;
m_commandLine = commandLine;
Q_ASSERT(!m_commandLine.isEmpty());
m_command = m_commandLine.takeFirst();
@@ -51,6 +55,8 @@ void CommandLineParser::parse(const QStringList &commandLine)
assignOptionArgument(arg, m_profile);
else if (arg == startCommitOption())
assignOptionArgument(arg, m_startCommit);
+ else if (arg == maxDurationoption())
+ parseDuration();
else
throw ParseException(QString::fromLocal8Bit("Unknown parameter '%1'").arg(arg));
}
@@ -62,8 +68,9 @@ void CommandLineParser::parse(const QStringList &commandLine)
QString CommandLineParser::usageString() const
{
- return QString::fromLocal8Bit("%1 %2 <profile> %3 <start commit>")
- .arg(QFileInfo(m_command).fileName(), profileOption(), startCommitOption());
+ return QString::fromLocal8Bit("%1 %2 <profile> %3 <start commit> [%4 <duration>]")
+ .arg(QFileInfo(m_command).fileName(), profileOption(), startCommitOption(),
+ maxDurationoption());
}
void CommandLineParser::assignOptionArgument(const QString &option, QString &argument)
@@ -76,3 +83,31 @@ void CommandLineParser::assignOptionArgument(const QString &option, QString &arg
.arg(option));
}
}
+
+void CommandLineParser::parseDuration()
+{
+ QString durationString;
+ QString choppedDurationString;
+ assignOptionArgument(maxDurationoption(), durationString);
+ choppedDurationString = durationString;
+ const char suffix = durationString.at(durationString.count() - 1).toLatin1();
+ const bool hasSuffix = !std::isdigit(suffix);
+ if (hasSuffix)
+ choppedDurationString.chop(1);
+ bool ok;
+ m_maxDuration = choppedDurationString.toInt(&ok);
+ if (!ok) {
+ throw ParseException(QString::fromLocal8Bit("Invalid duration argument '%1'.")
+ .arg(durationString));
+ }
+ if (hasSuffix) {
+ switch (suffix) {
+ case 'm': break;
+ case 'd': m_maxDuration *= 24; // Fall-through.
+ case 'h': m_maxDuration *= 60; break;
+ default:
+ throw ParseException(QString::fromLocal8Bit("Invalid duration suffix '%1'.")
+ .arg(suffix));
+ }
+ }
+}