summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrady J. Garvin <bgarvin@cse.unl.edu>2021-01-30 10:01:54 -0600
committerBrady J. Garvin <bgarvin@cse.unl.edu>2021-01-30 10:11:57 -0600
commit2b8eef30e7192869bdb607fa0c0f9f856af94ace (patch)
treea8b8dc8e9426643e706fc31b5ad325418f27cea1
parent139c2cae66edcb7de4589fa61a4d7ee5527f4c23 (diff)
validate:launcher: Ensure a positive job count.
The default number of jobs to use is half of the available cores rounded down, but in situations where only one core is available (such as under some VMs), this means that `gst-validate-launcher` defaults to using zero jobs, a case that the test-running code is not prepared to handle. This change makes the code match the documentation for the `--jobs` option, guards against negative values both in the default setting and in argument parsing, and introduces some defensive programming to prevent other situations where the code might try to use zero jobs. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-devtools/-/merge_requests/154>
-rw-r--r--validate/launcher/apps/gstcheck.py1
-rw-r--r--validate/launcher/baseclasses.py3
-rw-r--r--validate/launcher/main.py13
3 files changed, 13 insertions, 4 deletions
diff --git a/validate/launcher/apps/gstcheck.py b/validate/launcher/apps/gstcheck.py
index 7cd5a94..8b29fb8 100644
--- a/validate/launcher/apps/gstcheck.py
+++ b/validate/launcher/apps/gstcheck.py
@@ -372,6 +372,7 @@ class GstCheckTestsManager(MesonTestsManager):
to_inspect.append(test)
if to_inspect:
+ assert self.options.num_jobs >= 0
executor = conc.ThreadPoolExecutor(
max_workers=self.options.num_jobs)
tmp = []
diff --git a/validate/launcher/baseclasses.py b/validate/launcher/baseclasses.py
index 67c4842..00832bc 100644
--- a/validate/launcher/baseclasses.py
+++ b/validate/launcher/baseclasses.py
@@ -2091,7 +2091,8 @@ class _TestsLauncher(Loggable):
else:
alone_tests.append(test)
- max_num_jobs = min(self.options.num_jobs, len(tests))
+ # use max to defend against the case where all tests are alone_tests
+ max_num_jobs = max(min(self.options.num_jobs, len(tests)), 1)
jobs_running = 0
if self.options.forever and len(tests) < self.options.num_jobs and len(tests):
diff --git a/validate/launcher/main.py b/validate/launcher/main.py
index 9214b80..745a774 100644
--- a/validate/launcher/main.py
+++ b/validate/launcher/main.py
@@ -181,6 +181,13 @@ class PrintUsage(argparse.Action):
parser.exit()
+def _positive_integer_type(value):
+ cast = int(value)
+ if cast <= 0:
+ raise argparse.ArgumentTypeError(f'`{value}\' is not a positive integer')
+ return cast
+
+
class LauncherConfig(Loggable):
def __init__(self):
@@ -210,7 +217,7 @@ class LauncherConfig(Loggable):
self.logsdir = None
self.privatedir = None
self.redirect_logs = False
- self.num_jobs = int(multiprocessing.cpu_count() / 2)
+ self.num_jobs = max(multiprocessing.cpu_count(), 1)
self.dest = None
self._using_default_paths = False
# paths passed with --media-path, and not defined by a testsuite
@@ -543,8 +550,8 @@ class LauncherConfig(Loggable):
help="Redirect logs to stdout.")
dir_group.add_argument("-j", "--jobs", dest="num_jobs",
help="Number of tests to execute simultaneously"
- " (Defaults to number of cores of the processor)",
- type=int)
+ " (Defaults to the number of cores of the processor)",
+ type=_positive_integer_type)
dir_group.add_argument("--ignore-numfailures", dest="ignore_numfailures",
help="Ignore the number of failed test in exit code",
default=False, action='store_true')