framework: add a --timeout parameter

Submitted by Dylan Baker on June 28, 2018, 8:45 p.m.

Details

Message ID 20180628204521.27922-1-dylan@pnwbakers.com
State New
Headers show
Series "framework: add a --timeout parameter" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Dylan Baker June 28, 2018, 8:45 p.m.
This allows an timeout (in integers) to be set for each test. If the
tests run over this alotted time they'll be killed and the status will
be set to timeout. This only work on Unix-like machines running with
python 3.x or with 2.7 and subprocess32 installed.

It can be made to work for windows, either by bumping the python version
or by writing some windows specific code for killing processes.

cc: jordan.l.justen@intel.com
cc: clayton.a.craft@intel.com

---
 framework/programs/run.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch hide | download patch | download mbox

diff --git a/framework/programs/run.py b/framework/programs/run.py
index afb7eb78d..337a49631 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -39,6 +39,7 @@  from framework import exceptions
 from framework import monitoring
 from framework import profile
 from framework.results import TimeAttribute
+from framework.test import base
 from . import parsers
 
 __all__ = ['run',
@@ -220,6 +221,13 @@  def _run_parser(input_):
                         dest="ignore_missing",
                         action="store_true",
                         help="missing tests are considered as 'notrun'")
+    parser.add_argument('--timeout',
+                        dest='timeout',
+                        action='store',
+                        type=int,
+                        default=None,
+                        metavar='<int>',
+                        help='Sets a timeout threshold for tests to run in.')
     parser.add_argument("test_profile",
                         metavar="<Profile path(s)>",
                         nargs='+',
@@ -247,6 +255,7 @@  def _create_metadata(args, name, forced_test_list):
         opts['platform'] = args.platform
     opts['forced_test_list'] = forced_test_list
     opts['ignore_missing'] = args.ignore_missing
+    opts['timeout'] = args.timeout
 
     metadata = {'options': opts}
     metadata['name'] = name
@@ -291,6 +300,7 @@  def run(input_):
 
     """
     args = _run_parser(input_)
+    base.Test.timeout = args.timeout
     _disable_windows_exception_messages()
 
     # If dmesg is requested we must have serial run, this is because dmesg
@@ -423,6 +433,7 @@  def resume(input_):
     core.get_config(args.config_file)
 
     options.OPTIONS.env['PIGLIT_PLATFORM'] = results.options['platform']
+    base.Test.timeout = results.options['timeout']
 
     results.options['env'] = core.collect_system_info()
     results.options['name'] = results.name

Comments

On 2018-06-28 13:45:21, Dylan Baker wrote:
> This allows an timeout (in integers) to be set for each test. If the
> tests run over this alotted time they'll be killed and the status will
> be set to timeout. This only work on Unix-like machines running with
> python 3.x or with 2.7 and subprocess32 installed.
> 
> It can be made to work for windows, either by bumping the python version
> or by writing some windows specific code for killing processes.
> 
> cc: jordan.l.justen@intel.com
> cc: clayton.a.craft@intel.com
> 
> ---
>  framework/programs/run.py | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/framework/programs/run.py b/framework/programs/run.py
> index afb7eb78d..337a49631 100644
> --- a/framework/programs/run.py
> +++ b/framework/programs/run.py
> @@ -39,6 +39,7 @@ from framework import exceptions
>  from framework import monitoring
>  from framework import profile
>  from framework.results import TimeAttribute
> +from framework.test import base
>  from . import parsers
>  
>  __all__ = ['run',
> @@ -220,6 +221,13 @@ def _run_parser(input_):
>                          dest="ignore_missing",
>                          action="store_true",
>                          help="missing tests are considered as 'notrun'")
> +    parser.add_argument('--timeout',
> +                        dest='timeout',
> +                        action='store',
> +                        type=int,
> +                        default=None,
> +                        metavar='<int>',
> +                        help='Sets a timeout threshold for tests to run in.')

Since the tests can override this, should we say a *default* timeout?
(And add default in subject?)

I think --timeout is good for the param. (And not --default-timeout)

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

>      parser.add_argument("test_profile",
>                          metavar="<Profile path(s)>",
>                          nargs='+',
> @@ -247,6 +255,7 @@ def _create_metadata(args, name, forced_test_list):
>          opts['platform'] = args.platform
>      opts['forced_test_list'] = forced_test_list
>      opts['ignore_missing'] = args.ignore_missing
> +    opts['timeout'] = args.timeout
>  
>      metadata = {'options': opts}
>      metadata['name'] = name
> @@ -291,6 +300,7 @@ def run(input_):
>  
>      """
>      args = _run_parser(input_)
> +    base.Test.timeout = args.timeout
>      _disable_windows_exception_messages()
>  
>      # If dmesg is requested we must have serial run, this is because dmesg
> @@ -423,6 +433,7 @@ def resume(input_):
>      core.get_config(args.config_file)
>  
>      options.OPTIONS.env['PIGLIT_PLATFORM'] = results.options['platform']
> +    base.Test.timeout = results.options['timeout']
>  
>      results.options['env'] = core.collect_system_info()
>      results.options['name'] = results.name
> -- 
> 2.18.0
>