Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796400585; b=0nvvQU8QNRWw5OJOO5hXkXPEKx5K2QNZGABdVhTsfl79n5LcQJQ++fdpNJG02Nk9KvW0 xTSy19UbG4e3MM4SO6JTVz6m2hEopoDK5JFWkugt2OHxmMNbodaKtn3eWMCszZxcJCPD8 I5920uz5ksKCV/AgwNllbqmqSZ6/q2HrwvCvp/XMGBNZjLQEiC1QyiKuqkzs+oM2mzjs/ K9EXdjQsXmx5seT8WL2XufO6zFItEPs78xvCXQNob/6g+0YsFTYTB4xL71LIpyRwRK/AI hJunbMWnRF1ClN55cai/3XjpESvq5ku90bY9qCjjG0a2HaPWuZ+ORNyzay+1Msp8lWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400585; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=miLUXNbzfWSHNRhlRb1+MbLVtfekKAp79uHJCRjtkfc=; b=dpXe9pDhprigEQPKbPrRRt3fgvVIAW4Kpr51QmT2BIzf62idUl0u8e5+2xNnryO39qsL gzihKX8+KvxVEBAMslzIhu5FcIVFV9Dmw0tCNrF3mwKdsW+r+vDSHRcrTufhSqxxJo+qq 4I6mi3mxGAnjfmUvOMhc0lNzWSPbaPzufaxq49IIVjq1QKEVcPiyQ0upfTDOFOVKJPQfy Qe5uS0dSaC18Unzpwz+CTST/+SG5ZwtRepB2TwA2EWLN/JpiNKZJSZq2USmmNUYen3StB 2lENsptsrr9e5I5iKz+9YGgY7QCfBTrQyWn69YR3njJsS+bnkEpSubiL9ehQwZ3z6NA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Gz5o8g7R; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=rZCjUi8B; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C614606A322 for ; Fri, 4 Dec 2026 16:09:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4C614606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Gz5o8g7R; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=rZCjUi8B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796400585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=miLUXNbzfWSHNRhlRb1+MbLVtfekKAp79uHJCRjtkfc=; b=Gz5o8g7Rhjexi/8ceaAmsmzFUUtgV6Wfd8+ybKJAnu4BuJwUMCDnAb/9dQWyHaQIbVgPvC AygrT35lCtylUZqwxkDRK+fAJkYFgVMJo00L5+bMAz0km+x6iXbJgHykpmXi9G4eyg/DJH 12TCov5IMJCQ0X+c1S/9Ca78i+6IU5M= Received: from mail-dl1-f72.google.com (mail-dl1-f72.google.com [74.125.82.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-0wa3RJfIMKCXi4b5p6d0pw-1; Fri, 4 Dec 2026 16:09:42 +0000 X-MC-Unique: 0wa3RJfIMKCXi4b5p6d0pw-1 X-Mimecast-MFC-AGG-ID: 0wa3RJfIMKCXi4b5p6d0pw_1796400581 Received: by mail-dl1-f72.google.com with SMTP id a92af1059eb24-1b5d5f27b91so1718079c88.1 for ; Fri, 04 Dec 2026 08:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796400581; x=1797005381; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=miLUXNbzfWSHNRhlRb1+MbLVtfekKAp79uHJCRjtkfc=; b=rZCjUi8BSlvz/UEsEAg6dUh+RzspzluSgLxmfSasQZ7BAleASfdLneXel2dG1LgBQd ZAlP31hwLybV4wm6v7E0oB20xH9B3MT1VDosB59qk21tayP3yM9ByY0vv0Pi0MfsoEuS yqCcCkHeNHZtE969T/NuEMObvxtGSiy4eNjKX7ViqK1Qj/YMAQ6d9lID7zJjsmFRShCP e6ZQ3WZ/hNC9n4OVksiE4oBM6xRM/R0PExTdVuHKHtREcHfjiAt7J2cECuMaYSAgPeLX tvUe/rsAYWvtwTfKPPI/etiKGjYpwt06CWcvHM/VIDHOx+x8KJk+1EJSlUj70W3lQhPB ryHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796400581; x=1797005381; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=miLUXNbzfWSHNRhlRb1+MbLVtfekKAp79uHJCRjtkfc=; b=Vbrsg+zA5GCmv+H7F+C7K8voCn0u+Q2qHlpxmLmJVISiNAycTFcFa//Zv745qBDqiJ e98d+oh8VECLdr460u3TfKF3In7PSoIvcdhoaIuIPXE0j8yGRaAfAdB70XA2oWoFThFF m6noQkC6z2RzZoaOTog+EKTnne4xrCk/37vRgvUywdE+5pKPRSBHo0fqg0Zc5BctCC+C 4K882ZXR09UsY39Nq+Moz5WAQjgdnriVIq7DuA0n4DzN4P8t/IKWhx14LKjfP/joH1Yh jAdheDkfQI3AyCmAxivJsbMI/xOBPaJPV2Zn4UmHVKAlsebvtAm4AXsGr0lKQcaD08Ll sCAQ== X-Gm-Message-State: APuU4Z+/VXZWhMHUDAHf//gH6pwCE/0RvPWwyoY9FlI8xLauqiCzhirF Nyc9JWV6jO8mKClriuSPH6d//0AYYp9EQmNgOodrVF0BJnvB5YnoeYxeSnucvrx4agAvLaDaqvB 2MQQEmIgcT5Z+w3RYXb12t3e0e+u5DK7cWkKWR6SyzBTaNzdy3os0ywTbgbq9Yq0dCqMPI4TqvR TVtSyi5Y6IcatMTGfDPiVQduNWEePnlgE2vbG5gr+UeHGGeI4c4myd990= X-Gm-Gg: AZFdTZcbh9n2ZiylxJ1Lkk0ksWsXqZtkDbiREbOp2mywBdcyNwVjLVTDa46gym2mqLM HfH0Z5bjQCDzjMKFpmAXwJbpPgKnEDvnIUzoYyFa6Emevy3DMG3Uz7rtzgM7LZofnNipe6rGKF9 /nvPDwtxfHQyJYN/RalRFQ2kOsjWgN3vOI7Up94ug+LN3mhJnj45949ma88ecC2wDUPIJb3nUK2 a8qvT5hr+ukDqNoMVelb8ChAKoSj3lr70i+pxu5tHzvzM+SwZ06ElOgy+ONtimHVx3paHo3yTes NXZv2kKahyymqmJ1k34vcbv6vEa0/3fLCv3b5FTPAC1YtSTKeNC8w9apjYQI68O2X+KkR/kt3AQ XefkaO/Klx19F1huIafjoyNLSQ8g7Fd+OGHCUB+vYaFY3DFHi X-Received: by 2002:a05:701a:cc92:10b0:1a3:9936:d11e with SMTP id a92af1059eb24-1b5d725903emr2201730c88.41.1796400580572; Fri, 04 Dec 2026 08:09:40 -0800 (PST) X-Received: by 2002:a05:701a:cc92:10b0:1a3:9936:d11e with SMTP id a92af1059eb24-1b5d725903emr2201700c88.41.1796400579784; Fri, 04 Dec 2026 08:09:39 -0800 (PST) Received: from localhost ([2601:18a:8300:7a50:179c:d788:6b01:1c69]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d6455949sm8503589c88.9.2026.12.04.08.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 08:09:39 -0800 (PST) From: Sana Sharma To: linux-rt-users@vger.kernel.org Cc: jkacur@redhat.com, Sana Sharma Subject: [PATCH] Add integration tests for multi stressor support in stress-ng Date: Fri, 4 Dec 2026 11:09:27 -0500 Message-ID: <20261204160927.445935-1-sansshar@redhat.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-rt-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add integrations test that checked the single-stressor and multi-stressor support as well as the cpuset logic in this context. Assisted-by: Claude Opus 4.8 Signed-off-by: Sana Sharma --- tests/test_stressng.py | 310 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 301 insertions(+), 9 deletions(-) diff --git a/tests/test_stressng.py b/tests/test_stressng.py index e9c0701..fe06852 100644 --- a/tests/test_stressng.py +++ b/tests/test_stressng.py @@ -3,18 +3,21 @@ # Copyright 2026 Sana Sharma """ Unit tests for the new stressng input validation """ -import os import sys import shutil import tempfile import subprocess import unittest +from pathlib import Path +from types import SimpleNamespace from unittest.mock import patch, MagicMock -sys.path.insert(0,'.') +sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from rteval.modules.loads import stressng from rteval.rtevalConfig import rtevalConfig from rteval.Log import Log +RTEVAL_CMD = str(Path(__file__).resolve().parent.parent / 'rteval-cmd') + _TEST_TMPDIRS = [] @@ -52,6 +55,7 @@ def make_stressng(**opts): cfg.AppendConfig('stressng', section) return stressng.Stressng(cfg.GetSection('stressng'), Log()) + class TestGetValidStressors(unittest.TestCase): """Test suite for the function get_valid_stressors""" @@ -61,20 +65,21 @@ class TestGetValidStressors(unittest.TestCase): mock_run.return_value = MagicMock(stdout="cpu vm matrix\n") self.assertEqual(stressng.get_valid_stressors(), ['cpu', 'vm', 'matrix']) - @patch('rteval.modules.loads.stressng.subprocess.run', - side_effect=FileNotFoundError) - def test_not_installed_exits(self, _): + @patch('rteval.modules.loads.stressng.subprocess.run') + def test_not_installed_returns_empty(self, mock_run): """Test when stress-ng is not installed""" + mock_run.side_effect = FileNotFoundError('stress-ng') with self.assertRaises(SystemExit) as cm: stressng.get_valid_stressors() self.assertEqual(cm.exception.code, 1) - @patch('rteval.modules.loads.stressng.subprocess.run', - side_effect=subprocess.CalledProcessError(1, 'stress-ng')) - def test_query_failure_exits(self, _): + @patch('rteval.modules.loads.stressng.subprocess.run') + def test_query_failure_returns_empty(self, mock_run): """Test when the stress-ng query fails""" - with self.assertRaises(SystemExit): + mock_run.side_effect = subprocess.CalledProcessError(1, 'stress-ng') + with self.assertRaises(SystemExit) as cm: stressng.get_valid_stressors() + self.assertEqual(cm.exception.code, 1) class TestValidateStressor(unittest.TestCase): """Test suite for the function validate_stressor""" @@ -93,6 +98,293 @@ class TestValidateStressor(unittest.TestCase): stressng.validate_stressors('bogus') self.assertEqual(cm.exception.code, 1) +""" +Tests for the stress-ng stressor functionality. +""" + +class TestSingleStressor(unittest.TestCase): + """Test suite for single stressor case""" + + def tearDown(self): + _cleanup_test_tmpdirs() + + def test_no_stressor_single(self): + """Test that the single stressor argument with no stressors throws the correct error""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressor"], + capture_output=True, + text=True + ) + assert result.returncode != 0 + assert "usage: rteval-cmd" in result.stderr + assert "rteval-cmd: error: argument --stressng-stressor: expected one argument" in result.stderr + + def test_default_worker_single(self): + """Test that for the single stressor the undefined workers defaults to 0""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressor", "cpu", "-d", "5"], + capture_output=True, + text=True + ) + assert result.returncode == 0 + assert "stressng: stress-ng --cpu 0 --taskset" in result.stdout + + def test_set_worker_single(self): + """Test that single stressor with a set number of workers passes the number through""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressor", "cpu", "--stressng-workers", "3", "-d", "5"], + capture_output=True, + text=True + ) + assert result.returncode == 0 + assert "stressng: stress-ng --cpu 3 --taskset" in result.stdout + + def test_single_with_multi(self): + """Tests that passing multiple stressors with the single stressor argument exits with an error""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressor", "cpu,vm", "--stressng-workers", "3"], + capture_output=True, + text=True + ) + assert result.returncode != 0 + assert "Invalid stress-ng stressor: 'cpu,vm'" in result.stdout + assert "Run 'stress-ng --stressors' to see valid options" in result.stdout + + def test_invalid_stressor_single(self): + """Tests that an invalid stressor name with the single stressor argument exits with an error""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressor", "bogus"], + capture_output=True, + text=True + ) + assert result.returncode != 0 + assert "Invalid stress-ng stressor: 'bogus'" in result.stdout + assert "Run 'stress-ng --stressors' to see valid options" in result.stdout + + def test_multiple_singles_with_invalid(self): + """Tests that an invalid stressor among repeated single stressor arguments exits with an error""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressor", "cpu", "--stressng-stressor", "bogus"], + capture_output=True, + text=True + ) + assert result.returncode != 0 + assert "Invalid stress-ng stressor: 'bogus'" in result.stdout + assert "Run 'stress-ng --stressors' to see valid options" in result.stdout + + def test_multiple_singles(self): + """Tests that when multiple single stressors are passed with single arguments the code runs all the stressors""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressor", "cpu", "--stressng-stressor", "vm", "--stressng-workers", "3", "-d", "5"], + capture_output=True, + text=True + ) + assert result.returncode == 0 + assert "stressng: stress-ng --cpu 3 --vm 3 --taskset" in result.stdout + +class TestMultiStressor(unittest.TestCase): + + def tearDown(self): + _cleanup_test_tmpdirs() + + def test_no_stressor_multi(self): + """Tests that multi stressors with no stressor name leads to an error""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressors"], + capture_output=True, + text=True + ) + assert result.returncode != 0 + assert "usage: rteval-cmd" in result.stderr + assert "rteval-cmd: error: argument --stressng-stressors: expected one argument" in result.stderr + + def test_one_stressor_multi(self): + """Tests that multiple stressors with one stressor argument works""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressors", "cpu", "-d", "5"], + capture_output=True, + text=True + ) + assert result.returncode == 0 + assert "stressng: stress-ng --cpu 0 --taskset" in result.stdout + + def test_multi_stressor_default_workers(self): + """Tests that the default workers is 0""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressors", "cpu,vm", "-d", "5"], + capture_output=True, + text=True + ) + assert result.returncode == 0 + assert "stressng: stress-ng --cpu 0 --vm 0 --taskset" in result.stdout + + def test_multi_stressor_set_workers(self): + """Tests that multiple stressors with a set number of workers passes correctly""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressors", "cpu,vm", "--stressng-workers", "2", "-d", "5"], + capture_output=True, + text=True + ) + assert result.returncode == 0 + assert "stressng: stress-ng --cpu 2 --vm 2 --taskset" in result.stdout + + def test_invalid_stressor_multi(self): + """Tests that an invalid stressor name with the multi stressor argument exits with an error""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressors", "bogus"], + capture_output=True, + text=True + ) + assert result.returncode != 0 + assert "Invalid stress-ng stressor: 'bogus'" in result.stdout + assert "Run 'stress-ng --stressors' to see valid options" in result.stdout + + def test_mixed_valid_invalid_multi(self): + """Tests that a mix of valid and invalid stressors exits with an error naming only the invalid one""" + result = subprocess.run( + [RTEVAL_CMD, "--stressng-stressors", "cpu,bogus"], + capture_output=True, + text=True + ) + assert result.returncode != 0 + assert "Invalid stress-ng stressor: 'bogus'" in result.stdout + assert "Invalid stress-ng stressor: 'cpu,bogus'" not in result.stdout + assert "Run 'stress-ng --stressors' to see valid options" in result.stdout + +class TestWorkloadPrepareCpuset(unittest.TestCase): + """ + Integration tests for the cpuset/taskset logic in _WorkloadPrepare. + + Each scenario is exercised for both ways of configuring stressors. + Stressng.__init__() normalizes both forms to a validated list stored in + cfg.stressors (see TestDonotrun), so that is what _WorkloadPrepare() + always sees: + * single stressor form -> ['cpu'] (from --stressng-stressor cpu) + * multi stressor form -> ['cpu', 'vm'] (from --stressng-stressors cpu,vm) + """ + + # stressor configs covered by every cpuset scenario: (label, cfg.stressors, + # expected -- options that should land in args) + STRESSOR_FORMS = ( + ("single", ['cpu'], ['--cpu']), + ("multi", ['cpu', 'vm'], ['--cpu', '--vm']), + ) + + @staticmethod + def make_stressng(stressors, workers='0', timeout=None, cpulist=""): + """Build a Stressng instance without running the heavy __init__. + + Only the attributes read by _WorkloadPrepare() are populated. The + cfg.stressors attribute mirrors what __init__ would store: a + validated list of stressor names, for both the single- and + multi-stressor flags. + """ + inst = stressng.Stressng.__new__(stressng.Stressng) + inst.cfg = SimpleNamespace(stressors=stressors, workers=workers, + timeout=timeout) + inst.cpulist = cpulist + inst._logging = False + inst._log = MagicMock() + inst.args = None + return inst + + @staticmethod + def taskset_arg(args): + """Return the value following --taskset, or None if not present.""" + if '--taskset' not in args: + return None + return args[args.index('--taskset') + 1] + + @patch('rteval.modules.loads.stressng.get_valid_stressors', + return_value=['cpu', 'vm', 'matrix', 'io']) + @patch('rteval.modules.loads.stressng.os.open', return_value=42) + @patch('rteval.modules.loads.stressng.SysTopology') + def test_cpulist_restricts_taskset(self, mock_systop, _mock_open, _mock_valid): + """A cpulist keeps only its CPUs, intersected per node.""" + topo = mock_systop.return_value + topo.getnodes.return_value = [0, 1] + topo.getcpus.side_effect = lambda n: {0: [0, 1, 2, 3], + 1: [4, 5, 6, 7]}[n] + + for label, stressors, flags in self.STRESSOR_FORMS: + with self.subTest(form=label): + s = self.make_stressng(stressors=stressors, cpulist="0,1,4,5") + s._WorkloadPrepare() + + self.assertEqual(self.taskset_arg(s.args), "0,1,4,5") + for flag in flags: + self.assertIn(flag, s.args) + + @patch('rteval.modules.loads.stressng.get_valid_stressors', + return_value=['cpu', 'vm', 'matrix', 'io']) + @patch('rteval.modules.loads.stressng.os.open', return_value=42) + @patch('rteval.modules.loads.stressng.SysTopology') + def test_empty_node_is_dropped(self, mock_systop, _mock_open, _mock_valid): + """A node whose CPUs are all filtered out is removed from the taskset.""" + topo = mock_systop.return_value + topo.getnodes.return_value = [0, 1] + topo.getcpus.side_effect = lambda n: {0: [0, 1, 2, 3], + 1: [4, 5, 6, 7]}[n] + + # cpulist only matches CPUs on node 0, so node 1 has no usable CPUs + for label, stressors, flags in self.STRESSOR_FORMS: + with self.subTest(form=label): + s = self.make_stressng(stressors=stressors, cpulist="0,1") + s._WorkloadPrepare() + + self.assertEqual(self.taskset_arg(s.args), "0,1") + for flag in flags: + self.assertIn(flag, s.args) + + @patch('rteval.cpulist_utils.sysread', return_value="2-3") + @patch('rteval.cpulist_utils._isolated_file_exists', return_value=True) + @patch('rteval.modules.loads.stressng.get_valid_stressors', + return_value=['cpu', 'vm', 'matrix', 'io']) + @patch('rteval.modules.loads.stressng.os.open', return_value=42) + @patch('rteval.modules.loads.stressng.SysTopology') + def test_no_cpulist_excludes_isolated(self, mock_systop, _mock_open, + _mock_valid, _mock_isofile, _mock_sysread): + """Without a cpulist, isolated CPUs (2,3 here) are excluded.""" + topo = mock_systop.return_value + topo.getnodes.return_value = [0] + topo.getcpus.side_effect = lambda n: [0, 1, 2, 3] + + for label, stressors, flags in self.STRESSOR_FORMS: + with self.subTest(form=label): + s = self.make_stressng(stressors=stressors, cpulist="") + s._WorkloadPrepare() + + self.assertEqual(self.taskset_arg(s.args), "0,1") + for flag in flags: + self.assertIn(flag, s.args) + + @patch('rteval.modules.loads.stressng.get_valid_stressors', + return_value=['cpu', 'vm', 'matrix', 'io']) + @patch('rteval.modules.loads.stressng.os.open', return_value=42) + @patch('rteval.modules.loads.stressng.SysTopology') + def test_workers_and_timeout_appended(self, mock_systop, _mock_open, _mock_valid): + """Worker count and timeout are placed in args before --taskset.""" + topo = mock_systop.return_value + topo.getnodes.return_value = [0] + topo.getcpus.side_effect = lambda n: [0, 1] + + # single stressor: --cpu --timeout ... + s = self.make_stressng(stressors=['cpu'], workers='3', timeout='30', + cpulist="0,1") + s._WorkloadPrepare() + self.assertEqual(s.args[:5], + ['stress-ng', '--cpu', '3', '--timeout', '30']) + self.assertEqual(self.taskset_arg(s.args), "0,1") + + # multi stressor: each stressor gets the worker count, then --timeout + s = self.make_stressng(stressors=['cpu', 'vm'], workers='2', timeout='30', + cpulist="0,1") + s._WorkloadPrepare() + self.assertEqual(s.args[:7], + ['stress-ng', '--cpu', '2', '--vm', '2', + '--timeout', '30']) + self.assertEqual(self.taskset_arg(s.args), "0,1") + class TestDonotrun(unittest.TestCase): """Whether the module opts in/out of running via _donotrun. -- 2.56.1