Skip to content

Commit dd97d52

Browse files
authored
Add an option to customize build dir in run_tests.py script (#719)
1 parent 7365338 commit dd97d52

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

scripts/run_tests.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def init_cmd_args():
2929
type=int,
3030
help="List of process/thread counts to run sequentially",
3131
)
32+
parser.add_argument(
33+
"--build-dir",
34+
default="build",
35+
help=(
36+
"Path to the CMake build directory (or its 'bin' subdirectory). "
37+
"Relative paths are resolved from the project root. "
38+
"Default: 'build'."
39+
),
40+
)
3241
parser.add_argument(
3342
"--verbose", action="store_true", help="Print commands executed by the script"
3443
)
@@ -38,11 +47,12 @@ def init_cmd_args():
3847

3948

4049
class PPCRunner:
41-
def __init__(self, verbose=False):
50+
def __init__(self, build_dir="build", verbose=False):
4251
self.__ppc_num_threads = None
4352
self.__ppc_num_proc = None
4453
self.__ppc_env = None
4554
self.work_dir = None
55+
self.build_dir = build_dir
4656
self.verbose = verbose
4757

4858
self.valgrind_cmd = (
@@ -87,10 +97,22 @@ def setup_env(self, ppc_env):
8797
"Required environment variable 'PPC_NUM_PROC' is not set."
8898
)
8999

90-
if (Path(self.__get_project_path()) / "install").exists():
91-
self.work_dir = Path(self.__get_project_path()) / "install" / "bin"
92-
else:
93-
self.work_dir = Path(self.__get_project_path()) / "build" / "bin"
100+
project_path = Path(self.__get_project_path())
101+
install_bin_dir = project_path / "install" / "bin"
102+
if install_bin_dir.exists():
103+
self.work_dir = install_bin_dir
104+
return
105+
106+
build_dir = Path(self.build_dir)
107+
if not build_dir.is_absolute():
108+
build_dir = project_path / build_dir
109+
bin_dir = build_dir if build_dir.name == "bin" else build_dir / "bin"
110+
if not bin_dir.exists():
111+
raise FileNotFoundError(
112+
f"Test binaries directory not found: '{bin_dir}'. "
113+
"Build the project or pass a correct '--build-dir' (e.g. 'build', 'build_seq', or 'build/bin')."
114+
)
115+
self.work_dir = bin_dir
94116

95117
def __run_exec(self, command):
96118
if self.verbose:
@@ -246,7 +268,10 @@ def run_performance(self):
246268

247269

248270
def _execute(args_dict, env):
249-
runner = PPCRunner(verbose=args_dict.get("verbose", False))
271+
runner = PPCRunner(
272+
build_dir=args_dict.get("build_dir", "build"),
273+
verbose=args_dict.get("verbose", False),
274+
)
250275
runner.setup_env(env)
251276

252277
if args_dict["running_type"] in ["threads", "processes"]:

0 commit comments

Comments
 (0)