diff --git a/tests/utils/stl/test/params.py b/tests/utils/stl/test/params.py index 3df3e61e6ca..d032839beaf 100644 --- a/tests/utils/stl/test/params.py +++ b/tests/utils/stl/test/params.py @@ -36,6 +36,24 @@ def pretty(self, config, litParams): return 'exclude run.pl tags {}'.format(str(self._taglist)) +def beNice(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: + import sys + print(f'NOTE: Module "psutil" is not installed, so the priority setting "{prio}" has no effect.', file=sys.stderr) + return [] + + def getDefaultParameters(config, litConfig): DEFAULT_PARAMETERS = [ Parameter(name='long_tests', choices=[True, False], type=bool, default=True, @@ -47,6 +65,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 this to have any effect.', + actions=lambda prio: beNice(prio)), ] return DEFAULT_PARAMETERS