xref: /aosp_15_r20/external/pytorch/tools/code_coverage/package/tool/utils.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1import subprocess
2
3from ..util.setting import TestPlatform
4from ..util.utils import print_error
5
6
7def run_cpp_test(binary_file: str) -> None:
8    # cpp test binary
9    try:
10        subprocess.check_call(binary_file)
11    except subprocess.CalledProcessError:
12        print_error(f"Binary failed to run: {binary_file}")
13
14
15def get_tool_path_by_platform(platform: TestPlatform) -> str:
16    if platform == TestPlatform.FBCODE:
17        from caffe2.fb.code_coverage.tool.package.fbcode.utils import (  # type: ignore[import]
18            get_llvm_tool_path,
19        )
20
21        return get_llvm_tool_path()  # type: ignore[no-any-return]
22    else:
23        from ..oss.utils import get_llvm_tool_path  # type: ignore[no-redef]
24
25        return get_llvm_tool_path()  # type: ignore[no-any-return]
26