summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-07-14 19:58:08 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-07-16 12:18:13 +0900
commit03760eafab52ef75bc7716cd778f7455efeb35cc (patch)
treec6d1e1a40e810b61bcece205163af10b438c717b
parent94f492598a6402a0ad05bdb682769c63f8206e29 (diff)
downloadbuildstream-03760eafab52ef75bc7716cd778f7455efeb35cc.tar.gz
tests/frontend/show.py: Test proper resolution of max-jobs
This tests that the resolution of the `max-jobs` automatic variable is properly controlled by the new user configuration and command line option, including the default automatic '0' value. Regression test for #1033
-rw-r--r--tests/frontend/show.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/frontend/show.py b/tests/frontend/show.py
index 756fe1786..55691a5c6 100644
--- a/tests/frontend/show.py
+++ b/tests/frontend/show.py
@@ -465,3 +465,54 @@ def test_format_deps(cli, datafiles, dep_kind, expected_deps):
if result.output.strip() != expected:
raise AssertionError("Expected output:\n{}\nInstead received output:\n{}"
.format(expected, result.output))
+
+
+# This tests the resolved value of the 'max-jobs' variable,
+# ensuring at least that the variables are resolved according
+# to how the user has configured max-jobs
+#
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project'))
+@pytest.mark.parametrize("cli_value, config_value", [
+ (None, None),
+ (None, '16'),
+ ('16', None),
+ ('5', '16'),
+ ('0', '16'),
+ ('16', '0'),
+])
+def test_max_jobs(cli, datafiles, cli_value, config_value):
+ project = str(datafiles)
+ target = 'target.bst'
+
+ # Specify `--max-jobs` if this test sets it
+ args = []
+ if cli_value is not None:
+ args += ['--max-jobs', cli_value]
+ args += ['show', '--deps', 'none', '--format', '%{vars}', target]
+
+ # Specify `max-jobs` in user configuration if this test sets it
+ if config_value is not None:
+ cli.configure({
+ 'build': {
+ 'max-jobs': config_value
+ }
+ })
+
+ result = cli.run(project=project, silent=True, args=args)
+ result.assert_success()
+ loaded = _yaml.load_data(result.output)
+ loaded_value = loaded.get_int('max-jobs')
+
+ # We expect the value provided on the command line to take
+ # precedence over the configuration file value, if specified.
+ #
+ # If neither are specified then we expect the default
+ expected_value = cli_value or config_value or '0'
+
+ if expected_value == '0':
+ # If we are expecting the automatic behavior of using the maximum
+ # number of cores available, just check that it is a value > 0
+ assert loaded_value > 0, "Automatic setting of max-jobs didnt work"
+ else:
+ # Check that we got the explicitly set value
+ assert loaded_value == int(expected_value)