From f750e58986fea69b7ca4d33be34989ed5886b7ce Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 5 Jun 2019 17:13:44 +0200 Subject: signaltest: Add duration command line argument Many of the test programs have the --loop argument for automatic stopping. The main problem with the --loop argument is how long is --loop 1000? To simplify automated tests introduce a --duration argument which allows to set the time how long a test should run. This allows the test suite to define the execution time and also the timeout which a normal human can understand. For example run the test for 10 minutes and timeout at 11 minutes: # timeout 11m signaltest -D 10m Signed-off-by: Daniel Wagner Signed-off-by: John Kacur --- src/signaltest/signaltest.8 | 5 +++++ src/signaltest/signaltest.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/signaltest/signaltest.8 b/src/signaltest/signaltest.8 index 634d392..bd6ffe5 100644 --- a/src/signaltest/signaltest.8 +++ b/src/signaltest/signaltest.8 @@ -13,6 +13,11 @@ starting with two dashes ('\-\-'). .B \-b, \-\-breaktrace=USEC Send break trace command when latency > USEC .TP +.B \-D, \-\-duration=TIME +Specify a length for the test run. +.br +Append 'm', 'h', or 'd' to specify minutes, hours or days. +.TP .B \-l, \-\-loops=LOOPS Number of loops: default=0 (endless) .TP diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c index 59f979e..a168191 100644 --- a/src/signaltest/signaltest.c +++ b/src/signaltest/signaltest.c @@ -208,6 +208,8 @@ static void display_help(void) "signaltest \n\n" "-b USEC --breaktrace=USEC send break trace command when latency > USEC\n" "-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n" + "-D --duration=TIME specify a length for the test run.\n" + " Append 'm', 'h', or 'd' to specify minutes, hours or days.\n" "-p PRIO --prio=PRIO priority of highest prio thread\n" "-q --quiet print a summary only on exit\n" "-t NUM --threads=NUM number of threads: default=2\n" @@ -221,6 +223,7 @@ static void display_help(void) static int priority; static int num_threads = 2; static int max_cycles; +static int duration; static int verbose; static int quiet; static int lockall = 0; @@ -235,6 +238,7 @@ static void process_options (int argc, char *argv[]) static struct option long_options[] = { {"breaktrace", required_argument, NULL, 'b'}, {"loops", required_argument, NULL, 'l'}, + {"duration", required_argument, NULL, 'D'}, {"priority", required_argument, NULL, 'p'}, {"quiet", no_argument, NULL, 'q'}, {"threads", required_argument, NULL, 't'}, @@ -243,13 +247,14 @@ static void process_options (int argc, char *argv[]) {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; - int c = getopt_long (argc, argv, "b:c:d:i:l:np:qrsmt:v", + int c = getopt_long (argc, argv, "b:c:d:i:l:D:np:qrsmt:v", long_options, &option_index); if (c == -1) break; switch (c) { case 'b': tracelimit = atoi(optarg); break; case 'l': max_cycles = atoi(optarg); break; + case 'D': duration = parse_time_string(optarg); break; case 'p': priority = atoi(optarg); break; case 'q': quiet = 1; break; case 't': num_threads = atoi(optarg); break; @@ -259,6 +264,9 @@ static void process_options (int argc, char *argv[]) } } + if (duration < 0) + error = 1; + if (priority < 0 || priority > 99) error = 1; @@ -340,6 +348,10 @@ int main(int argc, char **argv) signal(SIGINT, sighand); signal(SIGTERM, sighand); + signal(SIGALRM, sighand); + + if (duration) + alarm(duration); par = calloc(num_threads, sizeof(struct thread_param)); if (!par) -- cgit v1.2.3