Skip to content

Commit fc96658

Browse files
committed
init python running
1 parent fe0f7b5 commit fc96658

File tree

2 files changed

+110
-14
lines changed

2 files changed

+110
-14
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,25 @@ jobs:
105105
tar -xzvf ubuntu-gcc-install.tar.gz -C install
106106
- name: Run func tests (MPI, num_proc=1)
107107
run: |
108-
source scripts/run_mpi.sh
108+
python3 scripts/run_tests.py --running-type="processes"
109109
env:
110110
PROC_COUNT: 1
111111
OMP_NUM_THREADS: 3
112112
- name: Run func tests (MPI, num_proc=2)
113113
run: |
114-
source scripts/run_mpi.sh
114+
python3 scripts/run_tests.py --running-type="processes"
115115
env:
116116
PROC_COUNT: 2
117117
OMP_NUM_THREADS: 2
118118
- name: Run func tests (MPI, num_proc=3)
119119
run: |
120-
source scripts/run_mpi.sh
120+
python3 scripts/run_tests.py --running-type="processes"
121121
env:
122122
PROC_COUNT: 3
123123
OMP_NUM_THREADS: 1
124124
- name: Run func tests (MPI, num_proc=4)
125125
run: |
126-
source scripts/run_mpi.sh
126+
python3 scripts/run_tests.py --running-type="processes"
127127
env:
128128
PROC_COUNT: 4
129129
OMP_NUM_THREADS: 1
@@ -268,25 +268,25 @@ jobs:
268268
tar -xzvf ubuntu-clang-install.tar.gz -C install
269269
- name: Run func tests (MPI, num_proc=1)
270270
run: |
271-
source scripts/run_mpi.sh
271+
python3 scripts/run_tests.py --running-type="processes"
272272
env:
273273
PROC_COUNT: 1
274274
OMP_NUM_THREADS: 3
275275
- name: Run func tests (MPI, num_proc=2)
276276
run: |
277-
source scripts/run_mpi.sh
277+
python3 scripts/run_tests.py --running-type="processes"
278278
env:
279279
PROC_COUNT: 2
280280
OMP_NUM_THREADS: 2
281281
- name: Run func tests (MPI, num_proc=3)
282282
run: |
283-
source scripts/run_mpi.sh
283+
python3 scripts/run_tests.py --running-type="processes"
284284
env:
285285
PROC_COUNT: 3
286286
OMP_NUM_THREADS: 1
287287
- name: Run func tests (MPI, num_proc=4)
288288
run: |
289-
source scripts/run_mpi.sh
289+
python3 scripts/run_tests.py --running-type="processes"
290290
env:
291291
PROC_COUNT: 4
292292
OMP_NUM_THREADS: 1
@@ -434,7 +434,7 @@ jobs:
434434
tar -xzvf ubuntu-clang-sanitizer-install.tar.gz -C install
435435
- name: Run tests (MPI)
436436
run: |
437-
source scripts/run_mpi.sh "--oversubscribe"
437+
python3 scripts/run_tests.py --running-type="processes" --additional-mpi-args="--oversubscribe"
438438
env:
439439
PROC_COUNT: 2
440440
OMP_NUM_THREADS: 2
@@ -601,25 +601,25 @@ jobs:
601601
tar -xzvf macos-clang-sanitizer-install.tar.gz -C install
602602
- name: Run func tests (MPI, num_proc=1)
603603
run: |
604-
source scripts/run_mpi.sh
604+
python3 scripts/run_tests.py --running-type="processes"
605605
env:
606606
PROC_COUNT: 1
607607
OMP_NUM_THREADS: 3
608608
- name: Run func tests (MPI, num_proc=2)
609609
run: |
610-
source scripts/run_mpi.sh
610+
python3 scripts/run_tests.py --running-type="processes"
611611
env:
612612
PROC_COUNT: 2
613613
OMP_NUM_THREADS: 2
614614
- name: Run func tests (MPI, num_proc=3)
615615
run: |
616-
source scripts/run_mpi.sh
616+
python3 scripts/run_tests.py --running-type="processes"
617617
env:
618618
PROC_COUNT: 3
619619
OMP_NUM_THREADS: 1
620620
- name: Run func tests (MPI, num_proc=4)
621621
run: |
622-
source scripts/run_mpi.sh
622+
python3 scripts/run_tests.py --running-type="processes"
623623
env:
624624
PROC_COUNT: 4
625625
OMP_NUM_THREADS: 1
@@ -990,7 +990,7 @@ jobs:
990990
cmake --build build --parallel
991991
- name: Run tests (MPI)
992992
run: |
993-
source scripts/run_mpi.sh
993+
python3 scripts/run_tests.py --running-type="processes"
994994
env:
995995
PROC_COUNT: 2
996996
OMP_NUM_THREADS: 2

scripts/run_tests.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import os
2+
import subprocess
3+
import platform
4+
from pathlib import Path
5+
6+
def init_cmd_args():
7+
import argparse
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument(
10+
"--running-type",
11+
required=True,
12+
choices=["threads", "processes"],
13+
help="Specify the execution mode. Choose 'threads' for multithreading or 'processes' for multiprocessing."
14+
)
15+
parser.add_argument(
16+
"--additional-mpi-args",
17+
required=False,
18+
default="",
19+
help="Additional MPI arguments to pass to the mpirun command (optional)."
20+
)
21+
args = parser.parse_args()
22+
_args_dict = vars(args)
23+
return _args_dict
24+
25+
def get_project_path():
26+
script_path = Path(__file__).resolve() # Absolute path of the script
27+
script_dir = script_path.parent # Directory containing the script
28+
return script_dir.parent
29+
30+
def source_script(script_path):
31+
command = f"source {script_path} && env"
32+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
33+
if result.returncode == 0:
34+
# Parse the output environment variables
35+
env_vars = {}
36+
for line in result.stdout.splitlines():
37+
if '=' in line:
38+
key, value = line.split("=", 1)
39+
env_vars[key] = value
40+
return env_vars
41+
else:
42+
print(f"Failed to source script: {script_path}")
43+
return {}
44+
45+
def setup_env():
46+
ocv_script_path = "build/ppc_opencv/install/bin/setup_vars_opencv4.sh"
47+
if os.path.isfile(Path(get_project_path()) / ocv_script_path):
48+
_executable_path = Path(get_project_path()) / "build/bin"
49+
env_vars = source_script(Path(get_project_path()) / ocv_script_path)
50+
else:
51+
_executable_path = Path(get_project_path()) / "install/bin"
52+
env_vars = source_script(Path(_executable_path) / "setup_vars_opencv4.sh")
53+
54+
os.environ.update(env_vars)
55+
return _executable_path
56+
57+
def run_exec_file(command):
58+
result = subprocess.run(command, shell=True, env=os.environ)
59+
if result.returncode != 0:
60+
raise Exception(f"Subprocess return {result.returncode}.")
61+
62+
def get_common_gtest_settings():
63+
return "--gtest_also_run_disabled_tests --gtest_repeat=10 --gtest_recreate_environments_when_repeating --gtest_color=0"
64+
65+
def run_threads():
66+
print(123)
67+
68+
def run_common(install_bin_dir):
69+
valgrind_settings = "--error-exitcode=1 --leak-check=full --show-leak-kinds=all"
70+
71+
if platform.system() == "Linux" and not os.environ.get("ASAN_RUN"):
72+
run_exec_file(f"valgrind {valgrind_settings} {Path(install_bin_dir) / 'core_func_tests'}")
73+
run_exec_file(f"valgrind {valgrind_settings} {Path(install_bin_dir) / 'ref_func_tests'}")
74+
75+
run_exec_file(f"{Path(install_bin_dir) / 'core_func_tests'} {get_common_gtest_settings()}")
76+
run_exec_file(f"{Path(install_bin_dir) / 'ref_func_tests'} {get_common_gtest_settings()}")
77+
78+
def run_processes(install_bin_dir, additional_mpi_args):
79+
proc_count = os.environ.get("PROC_COUNT")
80+
if proc_count is None:
81+
raise EnvironmentError("Required environment variable 'PROC_COUNT' is not set.")
82+
83+
if not os.environ.get("ASAN_RUN"):
84+
run_exec_file(f"mpirun {additional_mpi_args} -np {proc_count} {Path(install_bin_dir) / 'all_func_tests'} {get_common_gtest_settings()}")
85+
run_exec_file(f"mpirun {additional_mpi_args} -np {proc_count} {Path(install_bin_dir) / 'mpi_func_tests'} {get_common_gtest_settings()}")
86+
87+
if __name__ == "__main__":
88+
args_dict = init_cmd_args()
89+
executable_path = setup_env()
90+
run_common(executable_path)
91+
if args_dict["running_type"] == "threads":
92+
run_threads()
93+
elif args_dict["running_type"] == "processes":
94+
run_processes(executable_path, args_dict["additional_mpi_args"])
95+
else:
96+
raise Exception("running-type is wrong!")

0 commit comments

Comments
 (0)