From f41599c8e9435f3dfec60b872c2b4ae31177efdd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 10 Oct 2020 17:22:46 +0300 Subject: Add support for test timeouts --- tests/test/script/runner/driver.cxx | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'tests/test/script/runner/driver.cxx') diff --git a/tests/test/script/runner/driver.cxx b/tests/test/script/runner/driver.cxx index d5a74a4..935541d 100644 --- a/tests/test/script/runner/driver.cxx +++ b/tests/test/script/runner/driver.cxx @@ -1,6 +1,13 @@ // file : tests/test/script/runner/driver.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file +#ifndef _WIN32 +# include // this_thread::sleep_for() +# include +#else +# include +#endif + #include // numeric_limits #include #include // abort() @@ -36,10 +43,10 @@ main (int argc, char* argv[]) // Usage: driver [-i ] (-o )* (-e )* (-f )* // (-d )* (-v )* [(-t (a|m|s|z)) | (-s )] // - // Execute actions specified by -i, -o, -e, -f, -d, and -v options in the - // order as they appear on the command line. After that terminate abnormally - // if -t option is provided, otherwise exit normally with the status - // specified by -s option (0 by default). + // Execute actions specified by -i, -o, -e, -f, -d, -v, and -l options in + // the order as they appear on the command line. After that terminate + // abnormally if -t option is provided, otherwise exit normally with the + // status specified by -s option (0 by default). // // -i // Forward stdin data to the standard stream denoted by the file @@ -62,6 +69,9 @@ main (int argc, char* argv[]) // If the specified variable is set the print its value to stdout and the // string '' otherwise. // + // -l + // Sleep the specified number of seconds. + // // -t // Abnormally terminate itself using one of the following methods: // @@ -144,6 +154,18 @@ main (int argc, char* argv[]) optional var (getenv (v)); cout << (var ? *var : "") << endl; } + else if (o == "-l") + { + size_t t (toi (v)); + + // MinGW GCC 4.9 doesn't implement this_thread so use Win32 Sleep(). + // +#ifndef _WIN32 + this_thread::sleep_for (chrono::seconds (t)); +#else + Sleep (static_cast (t * 1000)); +#endif + } else if (o == "-t") { assert (aterm == '\0' && !status); // Make sure exit method is not set. -- cgit v1.1