From ad592736108898c8ef72ebbdcdc5289d29f2410c Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Tue, 22 Oct 2024 19:17:16 -0700 Subject: [PATCH 1/4] Add LIT parameter `priority` To control test process priority. Defaults to `IDLE_PRIORITY_CLASS`. --- tests/utils/stl/test/params.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/utils/stl/test/params.py b/tests/utils/stl/test/params.py index 3df3e61e6c..579d17957f 100644 --- a/tests/utils/stl/test/params.py +++ b/tests/utils/stl/test/params.py @@ -36,6 +36,23 @@ def pretty(self, config, litParams): return 'exclude run.pl tags {}'.format(str(self._taglist)) +def be_nice(prio: str) -> list[ConfigAction]: + """ + Set the process priority to run tests with. + """ + try: + import psutil + priority_map = { + 'normal': psutil.NORMAL_PRIORITY_CLASS, + 'low': psutil.BELOW_NORMAL_PRIORITY_CLASS, + 'idle': psutil.IDLE_PRIORITY_CLASS, + } + psutil.Process().nice(priority_map[prio]) + except ImportError: + pass + return [] + + def getDefaultParameters(config, litConfig): DEFAULT_PARAMETERS = [ Parameter(name='long_tests', choices=[True, False], type=bool, default=True, @@ -47,6 +64,10 @@ def getDefaultParameters(config, litConfig): Parameter(name="notags", type=list, default=[], help="Comma-separated list of run.pl tags to exclude tests", actions=lambda tags: [AddRunPLNotags(tags)]), + Parameter(name="priority", choices=["idle", "low", "normal"], default="idle", type=str, + help='Process priority to run tests with: "idle" (the default), "low", or "normal". ' + + 'Module "psutil" must be installed for to have any effect.', + actions=lambda prio: be_nice(prio)), ] return DEFAULT_PARAMETERS From 4e1b75a1c74f197e71ab4eca32e3883a04103c2a Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Tue, 22 Oct 2024 19:21:55 -0700 Subject: [PATCH 2/4] Correct missing word in descriptive text --- tests/utils/stl/test/params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/stl/test/params.py b/tests/utils/stl/test/params.py index 579d17957f..59bbadfabc 100644 --- a/tests/utils/stl/test/params.py +++ b/tests/utils/stl/test/params.py @@ -66,7 +66,7 @@ def getDefaultParameters(config, litConfig): actions=lambda tags: [AddRunPLNotags(tags)]), Parameter(name="priority", choices=["idle", "low", "normal"], default="idle", type=str, help='Process priority to run tests with: "idle" (the default), "low", or "normal". ' + - 'Module "psutil" must be installed for to have any effect.', + 'Module "psutil" must be installed for this to have any effect.', actions=lambda prio: be_nice(prio)), ] From e82bca1f2f65fa859bc7838628da255aeff5f998 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Tue, 22 Oct 2024 19:35:46 -0700 Subject: [PATCH 3/4] Rename `be_nice` to `beNice` --- tests/utils/stl/test/params.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/stl/test/params.py b/tests/utils/stl/test/params.py index 59bbadfabc..9f5c146410 100644 --- a/tests/utils/stl/test/params.py +++ b/tests/utils/stl/test/params.py @@ -36,7 +36,7 @@ def pretty(self, config, litParams): return 'exclude run.pl tags {}'.format(str(self._taglist)) -def be_nice(prio: str) -> list[ConfigAction]: +def beNice(prio: str) -> list[ConfigAction]: """ Set the process priority to run tests with. """ @@ -67,7 +67,7 @@ def getDefaultParameters(config, litConfig): Parameter(name="priority", choices=["idle", "low", "normal"], default="idle", type=str, help='Process priority to run tests with: "idle" (the default), "low", or "normal". ' + 'Module "psutil" must be installed for this to have any effect.', - actions=lambda prio: be_nice(prio)), + actions=lambda prio: beNice(prio)), ] return DEFAULT_PARAMETERS From c134f496356bfdc4ebcf28d5037844c4d635e6e3 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 23 Oct 2024 07:02:44 -0700 Subject: [PATCH 4/4] Add a note to inform the user when psutil isn't installed. --- tests/utils/stl/test/params.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/utils/stl/test/params.py b/tests/utils/stl/test/params.py index 9f5c146410..d032839bea 100644 --- a/tests/utils/stl/test/params.py +++ b/tests/utils/stl/test/params.py @@ -49,7 +49,8 @@ def beNice(prio: str) -> list[ConfigAction]: } psutil.Process().nice(priority_map[prio]) except ImportError: - pass + import sys + print(f'NOTE: Module "psutil" is not installed, so the priority setting "{prio}" has no effect.', file=sys.stderr) return []