From dcefe98fbbc8782dce68ae2da1605e8afa5dccfc Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 18 Nov 2021 19:44:37 +0300 Subject: [PATCH] test.py: Add --cpus option The option accepts taskset-style cpulist and limits the launched tests respectively. When specified, the default number of jobs is adjusted accordingly, if --jobs is given it overrides this "default" as expected. Signed-off-by: Pavel Emelyanov --- test.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test.py b/test.py index 1e55e7663f..cf22e35c01 100755 --- a/test.py +++ b/test.py @@ -515,9 +515,14 @@ async def run_test(test, options, gentle_kill=False, env=dict()): log.flush(); test.time_start = time.time() test.time_end = 0 + + path = test.path + args = test.args + if options.cpus: + path = 'taskset' + args = [ '-c', options.cpus, test.path, *test.args ] process = await asyncio.create_subprocess_exec( - test.path, - *test.args, + path, *args, stderr=log, stdout=log, env=dict(os.environ, @@ -616,10 +621,16 @@ def parse_cmd_line(): help="Skip tests which match the provided pattern") parser.add_argument('--no-parallel-cases', dest="parallel_cases", action="store_false", default=True, help="Do not run individual test cases in parallel") + parser.add_argument('--cpus', action="store", + help="Run the tests on those CPUs only (in taskset acceptible format). Consider using --jobs too") args = parser.parse_args() if not args.jobs: - nr_cpus = multiprocessing.cpu_count() + if not args.cpus: + nr_cpus = multiprocessing.cpu_count() + else: + nr_cpus = int(subprocess.check_output(['taskset', '-c', args.cpus, 'python', '-c', 'import os; print(len(os.sched_getaffinity(0)))'])) + cpus_per_test_job = 1 sysmem = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') testmem = 6e9 if os.sysconf('SC_PAGE_SIZE') > 4096 else 2e9