summaryrefslogtreecommitdiffstats
path: root/test/cpu_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpu_config.py')
-rw-r--r--test/cpu_config.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/cpu_config.py b/test/cpu_config.py
new file mode 100644
index 00000000000..b4e5d1ab767
--- /dev/null
+++ b/test/cpu_config.py
@@ -0,0 +1,21 @@
+import os
+import psutil
+
+available_cpus = psutil.Process().cpu_affinity()
+num_cpus = len(available_cpus)
+
+max_vpp_cpus = os.getenv("MAX_VPP_CPUS", "auto").lower()
+
+if max_vpp_cpus == "auto":
+ max_vpp_cpus = num_cpus
+else:
+ try:
+ max_vpp_cpus = int(max_vpp_cpus)
+ except ValueError as e:
+ raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
+ "values are a positive integer or 'auto'") from e
+ if max_vpp_cpus <= 0:
+ raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
+ "values are a positive integer or 'auto'")
+ if max_vpp_cpus > num_cpus:
+ max_vpp_cpus = num_cpus