@@ -24,96 +24,97 @@ def init_cmd_args():
24
24
return _args_dict
25
25
26
26
27
- def get_project_path ():
28
- script_path = Path (__file__ ).resolve () # Absolute path of the script
29
- script_dir = script_path .parent # Directory containing the script
30
- return script_dir .parent
31
-
32
-
33
- def source_script (script_path ):
34
- command = f"bash -c 'source { script_path } && env'"
35
- result = subprocess .run (command , stdout = subprocess .PIPE , shell = True , text = True )
36
- if result .returncode == 0 :
37
- # Parse the output environment variables
38
- env_vars = {}
39
- for line in result .stdout .splitlines ():
40
- if '=' in line :
41
- key , value = line .split ("=" , 1 )
42
- env_vars [key ] = value
43
- return env_vars
44
- else :
45
- print (f"Failed to source script: { script_path } " )
46
- return {}
47
-
48
-
49
- def setup_env ():
50
- ocv_script_path = "build/ppc_opencv/install/bin/setup_vars_opencv4.sh"
51
- if os .path .isfile (Path (get_project_path ()) / ocv_script_path ):
52
- _executable_path = Path (get_project_path ()) / "build/bin"
53
- env_vars = source_script (Path (get_project_path ()) / ocv_script_path )
54
- else :
55
- _executable_path = Path (get_project_path ()) / "install/bin"
56
- env_vars = source_script (Path (_executable_path ) / "setup_vars_opencv4.sh" )
57
-
58
- os .environ .update (env_vars )
59
- return _executable_path
60
-
61
-
62
- def run_exec_file (command ):
63
- result = subprocess .run (command , shell = True , env = os .environ )
64
- if result .returncode != 0 :
65
- raise Exception (f"Subprocess return { result .returncode } ." )
66
-
67
-
68
- def get_common_gtest_settings (repeats_count ):
69
- command = "--gtest_also_run_disabled_tests "
70
- command += f"--gtest_repeat={ repeats_count } "
71
- command += "--gtest_recreate_environments_when_repeating "
72
- command += "--gtest_color=0 "
73
- return command
74
-
75
-
76
- def run_threads (install_bin_dir ):
77
- valgrind_running = "valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all"
78
- if platform .system () == "Linux" and not os .environ .get ("ASAN_RUN" ):
79
- run_exec_file (f"{ valgrind_running } { Path (install_bin_dir ) / 'seq_func_tests' } { get_common_gtest_settings (1 )} " )
80
- run_exec_file (f"{ valgrind_running } { Path (install_bin_dir ) / 'stl_func_tests' } { get_common_gtest_settings (1 )} " )
81
-
82
- run_exec_file (f"{ Path (install_bin_dir ) / 'omp_func_tests' } { get_common_gtest_settings (3 )} " )
83
- run_exec_file (f"{ Path (install_bin_dir ) / 'seq_func_tests' } { get_common_gtest_settings (3 )} " )
84
- run_exec_file (f"{ Path (install_bin_dir ) / 'stl_func_tests' } { get_common_gtest_settings (3 )} " )
85
- run_exec_file (f"{ Path (install_bin_dir ) / 'tbb_func_tests' } { get_common_gtest_settings (3 )} " )
86
-
87
-
88
- def run_core (install_bin_dir ):
89
- valgrind_running = "valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all"
90
-
91
- if platform .system () == "Linux" and not os .environ .get ("ASAN_RUN" ):
92
- run_exec_file (f"{ valgrind_running } { Path (install_bin_dir ) / 'core_func_tests' } { get_common_gtest_settings (1 )} " )
93
- run_exec_file (f"{ valgrind_running } { Path (install_bin_dir ) / 'ref_func_tests' } { get_common_gtest_settings (1 )} " )
94
-
95
- run_exec_file (f"{ Path (install_bin_dir ) / 'core_func_tests' } { get_common_gtest_settings (3 )} " )
96
- run_exec_file (f"{ Path (install_bin_dir ) / 'ref_func_tests' } { get_common_gtest_settings (3 )} " )
97
-
98
-
99
- def run_processes (install_bin_dir , additional_mpi_args ):
100
- proc_count = os .environ .get ("PROC_COUNT" )
101
- if proc_count is None :
102
- raise EnvironmentError ("Required environment variable 'PROC_COUNT' is not set." )
103
-
104
- mpi_running = f"mpirun { additional_mpi_args } -np { proc_count } "
105
- if not os .environ .get ("ASAN_RUN" ):
106
- run_exec_file (f"{ mpi_running } { Path (install_bin_dir ) / 'all_func_tests' } { get_common_gtest_settings (10 )} " )
107
- run_exec_file (f"{ mpi_running } { Path (install_bin_dir ) / 'mpi_func_tests' } { get_common_gtest_settings (10 )} " )
27
+ class PPCRunner :
28
+ def __init__ (self ):
29
+ self .work_dir = None
30
+ self .valgrind_cmd = "valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all"
31
+ self .ocv_script_name = "setup_vars_opencv4.sh"
32
+ self .ocv_script_path = "build/ppc_opencv/install/bin/" + self .ocv_script_name
33
+
34
+ def __get_project_path (self ):
35
+ script_path = Path (__file__ ).resolve () # Absolute path of the script
36
+ script_dir = script_path .parent # Directory containing the script
37
+ return script_dir .parent
38
+
39
+ @staticmethod
40
+ def __source_script (script_path ):
41
+ command = f"bash -c 'source { script_path } && env'"
42
+ result = subprocess .run (command , stdout = subprocess .PIPE , shell = True , text = True )
43
+ if result .returncode == 0 :
44
+ # Parse the output environment variables
45
+ env_vars = {}
46
+ for line in result .stdout .splitlines ():
47
+ if '=' in line :
48
+ key , value = line .split ("=" , 1 )
49
+ env_vars [key ] = value
50
+ return env_vars
51
+ else :
52
+ print (f"Failed to source script: { script_path } " )
53
+ return {}
54
+
55
+ def setup_env (self ):
56
+ if os .path .isfile (Path (self .__get_project_path ()) / self .ocv_script_path ):
57
+ _work_dir = Path (self .__get_project_path ()) / "build/bin"
58
+ env_vars = self .__source_script (Path (self .__get_project_path ()) / self .ocv_script_path )
59
+ else :
60
+ _work_dir = Path (self .__get_project_path ()) / "install/bin"
61
+ env_vars = self .__source_script (Path (_work_dir ) / self .ocv_script_name )
62
+
63
+ self .work_dir = Path (_work_dir )
64
+ os .environ .update (env_vars )
65
+
66
+ @staticmethod
67
+ def __run_exec (command ):
68
+ result = subprocess .run (command , shell = True , env = os .environ )
69
+ if result .returncode != 0 :
70
+ raise Exception (f"Subprocess return { result .returncode } ." )
71
+
72
+ @staticmethod
73
+ def __get_gtest_settings (repeats_count ):
74
+ command = "--gtest_also_run_disabled_tests "
75
+ command += f"--gtest_repeat={ repeats_count } "
76
+ command += "--gtest_recreate_environments_when_repeating "
77
+ command += "--gtest_color=0 "
78
+ return command
79
+
80
+ def run_threads (self ):
81
+ if platform .system () == "Linux" and not os .environ .get ("ASAN_RUN" ):
82
+ self .__run_exec (f"{ self .valgrind_cmd } { self .work_dir / 'seq_func_tests' } { self .__get_gtest_settings (1 )} " )
83
+ self .__run_exec (f"{ self .valgrind_cmd } { self .work_dir / 'stl_func_tests' } { self .__get_gtest_settings (1 )} " )
84
+
85
+ self .__run_exec (f"{ self .work_dir / 'omp_func_tests' } { self .__get_gtest_settings (3 )} " )
86
+ self .__run_exec (f"{ self .work_dir / 'seq_func_tests' } { self .__get_gtest_settings (3 )} " )
87
+ self .__run_exec (f"{ self .work_dir / 'stl_func_tests' } { self .__get_gtest_settings (3 )} " )
88
+ self .__run_exec (f"{ self .work_dir / 'tbb_func_tests' } { self .__get_gtest_settings (3 )} " )
89
+
90
+ def run_core (self ):
91
+ if platform .system () == "Linux" and not os .environ .get ("ASAN_RUN" ):
92
+ self .__run_exec (f"{ self .valgrind_cmd } { self .work_dir / 'core_func_tests' } { self .__get_gtest_settings (1 )} " )
93
+ self .__run_exec (f"{ self .valgrind_cmd } { self .work_dir / 'ref_func_tests' } { self .__get_gtest_settings (1 )} " )
94
+
95
+ self .__run_exec (f"{ self .work_dir / 'core_func_tests' } { self .__get_gtest_settings (3 )} " )
96
+ self .__run_exec (f"{ self .work_dir / 'ref_func_tests' } { self .__get_gtest_settings (3 )} " )
97
+
98
+ def run_processes (self , additional_mpi_args ):
99
+ proc_count = os .environ .get ("PROC_COUNT" )
100
+ if proc_count is None :
101
+ raise EnvironmentError ("Required environment variable 'PROC_COUNT' is not set." )
102
+
103
+ mpi_running = f"mpirun { additional_mpi_args } -np { proc_count } "
104
+ if not os .environ .get ("ASAN_RUN" ):
105
+ self .__run_exec (f"{ mpi_running } { self .work_dir / 'all_func_tests' } { self .__get_gtest_settings (10 )} " )
106
+ self .__run_exec (f"{ mpi_running } { self .work_dir / 'mpi_func_tests' } { self .__get_gtest_settings (10 )} " )
108
107
109
108
110
109
if __name__ == "__main__" :
111
110
args_dict = init_cmd_args ()
112
- executable_path = setup_env ()
113
- run_core (executable_path )
111
+
112
+ ppc_runner = PPCRunner ()
113
+ ppc_runner .setup_env ()
114
+ ppc_runner .run_core ()
114
115
if args_dict ["running_type" ] == "threads" :
115
- run_threads (executable_path )
116
+ ppc_runner . run_threads ()
116
117
elif args_dict ["running_type" ] == "processes" :
117
- run_processes (executable_path , args_dict ["additional_mpi_args" ])
118
+ ppc_runner . run_processes (args_dict ["additional_mpi_args" ])
118
119
else :
119
120
raise Exception ("running-type is wrong!" )
0 commit comments