|
1 | 1 | import os
|
| 2 | +import shlex |
2 | 3 | import subprocess
|
3 | 4 | import platform
|
4 | 5 | from pathlib import Path
|
@@ -62,55 +63,76 @@ def setup_env(self, ppc_env):
|
62 | 63 | self.work_dir = Path(self.__get_project_path()) / "build" / "bin"
|
63 | 64 |
|
64 | 65 | def __run_exec(self, command):
|
65 |
| - result = subprocess.run(command, shell=True, env=self.__ppc_env) |
| 66 | + result = subprocess.run(command, shell=False, env=self.__ppc_env) |
66 | 67 | if result.returncode != 0:
|
67 | 68 | raise Exception(f"Subprocess return {result.returncode}.")
|
68 | 69 |
|
69 | 70 | @staticmethod
|
70 | 71 | def __get_gtest_settings(repeats_count, type_task):
|
71 |
| - command = f"--gtest_repeat={repeats_count} " |
72 |
| - command += "--gtest_recreate_environments_when_repeating " |
73 |
| - command += "--gtest_color=0 " |
74 |
| - command += "--gtest_shuffle " |
75 |
| - command += f"--gtest_filter=\"*{type_task}*\" " |
| 72 | + command = [ |
| 73 | + f"--gtest_repeat={repeats_count}", |
| 74 | + "--gtest_recreate_environments_when_repeating", |
| 75 | + "--gtest_color=0", |
| 76 | + "--gtest_shuffle", |
| 77 | + f"--gtest_filter=*{type_task}*", |
| 78 | + ] |
76 | 79 | return command
|
77 | 80 |
|
78 | 81 | def run_threads(self):
|
79 | 82 | if platform.system() == "Linux" and not self.__ppc_env.get("PPC_ASAN_RUN"):
|
80 | 83 | for task_type in ["seq", "stl"]:
|
81 |
| - self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'ppc_func_tests'} " |
82 |
| - f"{self.__get_gtest_settings(1, '_' + task_type + '_')}") |
| 84 | + self.__run_exec( |
| 85 | + shlex.split(self.valgrind_cmd) |
| 86 | + + [str(self.work_dir / 'ppc_func_tests')] |
| 87 | + + self.__get_gtest_settings(1, '_' + task_type + '_') |
| 88 | + ) |
83 | 89 |
|
84 | 90 | for task_type in ["omp", "seq", "stl", "tbb"]:
|
85 |
| - self.__run_exec(f"{self.work_dir / 'ppc_func_tests'} {self.__get_gtest_settings(3, '_' + task_type + '_')}") |
| 91 | + self.__run_exec( |
| 92 | + [str(self.work_dir / 'ppc_func_tests')] + self.__get_gtest_settings(3, '_' + task_type + '_') |
| 93 | + ) |
86 | 94 |
|
87 | 95 | def run_core(self):
|
88 | 96 | if platform.system() == "Linux" and not self.__ppc_env.get("PPC_ASAN_RUN"):
|
89 |
| - self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'core_func_tests'} " |
90 |
| - f"{self.__get_gtest_settings(1, '*')} --gtest_filter=*:-*_disabled_valgrind") |
| 97 | + self.__run_exec( |
| 98 | + shlex.split(self.valgrind_cmd) |
| 99 | + + [str(self.work_dir / 'core_func_tests')] |
| 100 | + + self.__get_gtest_settings(1, '*') |
| 101 | + + ["--gtest_filter=*:-*_disabled_valgrind"] |
| 102 | + ) |
91 | 103 |
|
92 |
| - self.__run_exec(f"{self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(1, '*')}") |
| 104 | + self.__run_exec( |
| 105 | + [str(self.work_dir / 'core_func_tests')] + self.__get_gtest_settings(1, '*') |
| 106 | + ) |
93 | 107 |
|
94 | 108 | def run_processes(self, additional_mpi_args):
|
95 | 109 | ppc_num_proc = self.__ppc_env.get("PPC_NUM_PROC")
|
96 | 110 | if ppc_num_proc is None:
|
97 | 111 | raise EnvironmentError("Required environment variable 'PPC_NUM_PROC' is not set.")
|
98 | 112 |
|
99 |
| - mpi_running = f"{self.mpi_exec} {additional_mpi_args} -np {ppc_num_proc}" |
| 113 | + mpi_running = [self.mpi_exec] + shlex.split(additional_mpi_args) + ["-np", ppc_num_proc] |
100 | 114 | if not self.__ppc_env.get("PPC_ASAN_RUN"):
|
101 | 115 | for task_type in ["all", "mpi"]:
|
102 |
| - self.__run_exec(f"{mpi_running} {self.work_dir / 'ppc_func_tests'} " |
103 |
| - f"{self.__get_gtest_settings(10, '_' + task_type)}") |
| 116 | + self.__run_exec( |
| 117 | + mpi_running |
| 118 | + + [str(self.work_dir / 'ppc_func_tests')] |
| 119 | + + self.__get_gtest_settings(10, '_' + task_type) |
| 120 | + ) |
104 | 121 |
|
105 | 122 | def run_performance(self):
|
106 | 123 | if not self.__ppc_env.get("PPC_ASAN_RUN"):
|
107 |
| - mpi_running = f"{self.mpi_exec} -np {self.__ppc_num_proc}" |
| 124 | + mpi_running = [self.mpi_exec, "-np", self.__ppc_num_proc] |
108 | 125 | for task_type in ["all", "mpi"]:
|
109 |
| - self.__run_exec(f"{mpi_running} {self.work_dir / 'ppc_perf_tests'} " |
110 |
| - f"{self.__get_gtest_settings(1, '_' + task_type)}") |
| 126 | + self.__run_exec( |
| 127 | + mpi_running |
| 128 | + + [str(self.work_dir / 'ppc_perf_tests')] |
| 129 | + + self.__get_gtest_settings(1, '_' + task_type) |
| 130 | + ) |
111 | 131 |
|
112 | 132 | for task_type in ["omp", "seq", "stl", "tbb"]:
|
113 |
| - self.__run_exec(f"{self.work_dir / 'ppc_perf_tests'} {self.__get_gtest_settings(1, '_' + task_type)}") |
| 133 | + self.__run_exec( |
| 134 | + [str(self.work_dir / 'ppc_perf_tests')] + self.__get_gtest_settings(1, '_' + task_type) |
| 135 | + ) |
114 | 136 |
|
115 | 137 |
|
116 | 138 | if __name__ == "__main__":
|
|
0 commit comments