def load_native(config: Mapping[str, Any]) -> None: runtime_exe_path = build_runtime(config, "exe") data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) plugin_paths = threading_map( lambda plugin_config: build_one_plugin(config, plugin_config), [ plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"] ], desc="Building plugins", ) command_str = config["loader"].get("command", "%a") main_cmd_lst = [str(runtime_exe_path), *map(str, plugin_paths)] command_lst_sbst = list( flatten1( replace_all( unflatten(shlex.split(command_str)), {("%a",): main_cmd_lst, ("%b",): [shlex.quote(shlex.join(main_cmd_lst))]}, ) ) ) subprocess_run( command_lst_sbst, env_override=dict(ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path)), )
def load_tests(config: Mapping[str, Any]) -> None: runtime_exe_path = build_runtime(config, "exe", test=True) data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) enable_offload_flag = config["enable_offload"] enable_alignment_flag = config["enable_alignment"] make(Path("common"), ["tests/run"]) plugin_paths = threading_map( lambda plugin_config: build_one_plugin( config, plugin_config, test=True), [ plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"] ], desc="Building plugins", ) subprocess_run( [ "catchsegv", "xvfb-run", str(runtime_exe_path), *map(str, plugin_paths) ], env_override=dict( ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path), ILLIXR_RUN_DURATION=str(config["action"].get( "ILLIXR_RUN_DURATION", 10)), ILLIXR_OFFLOAD_ENABLE=str(enable_offload_flag), ILLIXR_ALIGNMENT_ENABLE=str(enable_alignment_flag), ILLIXR_ENABLE_VERBOSE_ERRORS=str(config["enable_verbose_errors"]), KIMERA_ROOT=config["action"]["kimera_path"], ), check=True, )
def setup(self): requirements_file = Path(self.directory / "requirements.txt") if requirements_file.exists(): command = "pip install -r requirements.txt" # print(f"> {command}") subprocess_run(command, cwd=str(requirements_file.parent))
def load_native(config: Mapping[str, Any]) -> None: runtime_exe_path = build_runtime(config, "exe") data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) enable_offload_flag = config["enable_offload"] enable_alignment_flag = config["enable_alignment"] realsense_cam_string = config["realsense_cam"] plugin_paths = threading_map( lambda plugin_config: build_one_plugin(config, plugin_config), [plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"]], desc="Building plugins", ) actual_cmd_str = config["action"].get("command", "$cmd") illixr_cmd_list = [str(runtime_exe_path), *map(str, plugin_paths)] env_override = dict( ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path), ILLIXR_OFFLOAD_ENABLE=str(enable_offload_flag), ILLIXR_ALIGNMENT_ENABLE=str(enable_alignment_flag), ILLIXR_ENABLE_VERBOSE_ERRORS=str(config["enable_verbose_errors"]), ILLIXR_RUN_DURATION=str(config["action"].get("ILLIXR_RUN_DURATION", 60)), ILLIXR_ENABLE_PRE_SLEEP=str(config["enable_pre_sleep"]), KIMERA_ROOT=config["action"]["kimera_path"], AUDIO_ROOT=config["action"]["audio_path"], REALSENSE_CAM=str(realsense_cam_string), ) env_list = [f"{shlex.quote(var)}={shlex.quote(val)}" for var, val in env_override.items()] actual_cmd_list = list( flatten1( replace_all( unflatten(shlex.split(actual_cmd_str)), { ("$env_cmd",): [ "env", "-C", Path(".").resolve(), *env_list, *illixr_cmd_list, ], ("$cmd",): illixr_cmd_list, ("$quoted_cmd",): [shlex.quote(shlex.join(illixr_cmd_list))], ("$env",): env_list, }, ) ) ) log_stdout_str = config["action"].get("log_stdout", None) log_stdout_ctx = cast( ContextManager[Optional[BinaryIO]], (open(log_stdout_str, "wb") if (log_stdout_str is not None) else noop_context(None)), ) with log_stdout_ctx as log_stdout: subprocess_run( actual_cmd_list, env_override=env_override, stdout=log_stdout, check=True, )
def load_monado(config: Mapping[str, Any]) -> None: profile = config["profile"] cmake_profile = "Debug" if profile == "dbg" else "Release" openxr_app_config = config["loader"]["openxr_app"].get("config", {}) monado_config = config["loader"]["monado"].get("config", {}) runtime_path = pathify(config["runtime"]["path"], root_dir, cache_path, True, True) monado_path = pathify( config["loader"]["monado"]["path"], root_dir, cache_path, True, True ) openxr_app_path = pathify( config["loader"]["openxr_app"]["path"], root_dir, cache_path, True, True ) data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) cmake( monado_path, monado_path / "build", dict( CMAKE_BUILD_TYPE=cmake_profile, BUILD_WITH_LIBUDEV="0", BUILD_WITH_LIBUVC="0", BUILD_WITH_LIBUSB="0", BUILD_WITH_NS="0", BUILD_WITH_PSMV="0", BUILD_WITH_PSVR="0", BUILD_WITH_OPENHMD="0", BUILD_WITH_VIVE="0", ILLIXR_PATH=str(runtime_path), **monado_config, ), ) cmake( openxr_app_path, openxr_app_path / "build", dict(CMAKE_BUILD_TYPE=cmake_profile, **openxr_app_config), ) plugin_paths = threading_map( lambda plugin_config: build_one_plugin(config, plugin_config), [ plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"] ], desc="Building plugins", ) subprocess_run( [str(openxr_app_path / "build" / "./openxr-example")], env_override=dict( XR_RUNTIME_JSON=str(monado_path / "build" / "openxr_monado-dev.json"), ILLIXR_PATH=str(runtime_path / f"plugin.{profile}.so"), ILLIXR_COMP=":".join(map(str, plugin_paths)), ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path), ), )
def setup(self): arguments = "--batch-mode --update-snapshots --fail-never -DskipTests" command = f"mvn {arguments} clean install" stdout_ = open(self.output_folder / "exec_setup.out", "a") stderr_ = open(self.output_folder / "exec_setup.err", "a") # print(f"> {command}") subprocess_run(command, cwd=str(self.directory), stdout=stdout_, stderr=stderr_)
def run_tests(self, report_folder): command = f"mvn test --fail-never --batch-mode" # print(f"> {command}") stdout_ = open(self.output_folder / "exec_stress.out", "a") stderr_ = open(self.output_folder / "exec_stress.err", "a") subprocess_run(command, cwd=str(self.directory), stdout=stdout_, stderr=stderr_)
def load_tests(config: Mapping[str, Any]) -> None: runtime_exe_path = build_runtime(config, "exe", test=True) data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) enable_offload_flag = config["enable_offload"] enable_alignment_flag = config["enable_alignment"] env_override: Mapping[str, str] = dict(ILLIXR_INTEGRATION="yes") make(Path("common"), ["tests/run"], env_override=env_override) realsense_cam_string = config["realsense_cam"] plugin_paths = threading_map( lambda plugin_config: build_one_plugin( config, plugin_config, test=True), [ plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"] ], desc="Building plugins", ) ## If pre-sleep is enabled, the application will pause and wait for a gdb process. ## If enabled, disable 'catchsegv' so that gdb can catch segfaults. enable_pre_sleep: bool = config["enable_pre_sleep"] cmd_list_tail: List[str] = [ "xvfb-run", str(runtime_exe_path), *map(str, plugin_paths) ] cmd_list: List[str] = (["catchsegv"] if not enable_pre_sleep else list()) + cmd_list_tail subprocess_run( cmd_list, env_override=dict( ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path), ILLIXR_RUN_DURATION=str(config["action"].get( "ILLIXR_RUN_DURATION", 10)), ILLIXR_OFFLOAD_ENABLE=str(enable_offload_flag), ILLIXR_ALIGNMENT_ENABLE=str(enable_alignment_flag), ILLIXR_ENABLE_VERBOSE_ERRORS=str(config["enable_verbose_errors"]), ILLIXR_ENABLE_PRE_SLEEP=str(enable_pre_sleep), KIMERA_ROOT=config["action"]["kimera_path"], REALSENSE_CAM=str(realsense_cam_string), ), check=True, )
def load_tests(config: Mapping[str, Any]) -> None: runtime_exe_path = build_runtime(config, "exe", test=True) data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) make(Path("common"), ["tests/run"]) plugin_paths = threading_map( lambda plugin_config: build_one_plugin(config, plugin_config, test=True), [ plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"] ], desc="Building plugins", ) subprocess_run( ["xvfb-run", str(runtime_exe_path), *map(str, plugin_paths)], env_override=dict(ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path), ILLIXR_RUN_DURATION="10"), )
def make_docs(config: Mapping[str, Any]) -> None: dir_api = "site/api" dir_docs = "site/docs" cmd_doxygen = ["doxygen", "doxygen.conf"] cmd_mkdocs = ["python3", "-m", "mkdocs", "build"] if not os.path.exists(dir_api): os.makedirs(dir_api) if not os.path.exists(dir_docs): os.makedirs(dir_docs) subprocess_run( cmd_doxygen, check=True, capture_output=False, ) subprocess_run( cmd_mkdocs, check=True, capture_output=False, )
def make( path: Path, targets: List[str], var_dict: Optional[Mapping[str, str]] = None, parallelism: Optional[int] = None, ) -> None: if parallelism is None: parallelism = max(1, multiprocessing.cpu_count() // 2) var_dict_args = shlex.join( f"{key}={val}" for key, val in (var_dict if var_dict else {}).items() ) subprocess_run( ["make", "-j", str(parallelism), "-C", str(path), *targets, *var_dict_args], check=True, capture_output=True, )
def cmake( path: Path, build_path: Path, var_dict: Optional[Mapping[str, str]] = None ) -> None: parallelism = max(1, multiprocessing.cpu_count() // 2) var_args = [f"-D{key}={val}" for key, val in (var_dict if var_dict else {}).items()] build_path.mkdir(exist_ok=True) subprocess_run( [ "cmake", "-S", str(path), "-B", str(build_path), "-G", "Unix Makefiles", *var_args, ], check=True, capture_output=True, ) make(build_path, ["all"])
def load_monado(config: Mapping[str, Any]) -> None: profile = config["profile"] cmake_profile = "Debug" if profile == "dbg" else "Release" openxr_app_config = config["action"]["openxr_app"].get("config", {}) monado_config = config["action"]["monado"].get("config", {}) runtime_path = pathify(config["runtime"]["path"], root_dir, cache_path, True, True) monado_path = pathify(config["action"]["monado"]["path"], root_dir, cache_path, True, True) openxr_app_path = pathify(config["action"]["openxr_app"]["path"], root_dir, cache_path, True, True) data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) enable_offload_flag = config["enable_offload"] enable_alignment_flag = config["enable_alignment"] cmake( monado_path, monado_path / "build", dict( CMAKE_BUILD_TYPE=cmake_profile, BUILD_WITH_LIBUDEV="0", BUILD_WITH_LIBUVC="0", BUILD_WITH_LIBUSB="0", BUILD_WITH_NS="0", BUILD_WITH_PSMV="0", BUILD_WITH_PSVR="0", BUILD_WITH_OPENHMD="0", BUILD_WITH_VIVE="0", ILLIXR_PATH=str(runtime_path), **monado_config, ), ) cmake( openxr_app_path, openxr_app_path / "build", dict(CMAKE_BUILD_TYPE=cmake_profile, **openxr_app_config), ) build_runtime(config, "so") plugin_paths = threading_map( lambda plugin_config: build_one_plugin(config, plugin_config), [ plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"] ], desc="Building plugins", ) subprocess_run( [str(openxr_app_path / "build" / "./openxr-example")], env_override=dict( XR_RUNTIME_JSON=str(monado_path / "build" / "openxr_monado-dev.json"), ILLIXR_PATH=str(runtime_path / f"plugin.{profile}.so"), ILLIXR_COMP=":".join(map(str, plugin_paths)), ILLIXR_DATA=str(data_path), ILLIXR_DEMO_DATA=str(demo_data_path), ILLIXR_OFFLOAD_ENABLE=str(enable_offload_flag), ILLIXR_ALIGNMENT_ENABLE=str(enable_alignment_flag), ILLIXR_ENABLE_VERBOSE_ERRORS=str(config["enable_verbose_errors"]), KIMERA_ROOT=config["action"]["kimera_path"], ), check=True, )
def load_monado(config: Mapping[str, Any]) -> None: action_name = config["action"]["name"] profile = config["profile"] cmake_profile = "Debug" if profile == "dbg" else "RelWithDebInfo" runtime_path = pathify(config["runtime"]["path"], root_dir, cache_path, True, True) monado_config = config["action"]["monado"].get("config", {}) monado_path = pathify(config["action"]["monado"]["path"], root_dir, cache_path, True, True) data_path = pathify(config["data"], root_dir, cache_path, True, True) demo_data_path = pathify(config["demo_data"], root_dir, cache_path, True, True) enable_offload_flag = config["enable_offload"] enable_alignment_flag = config["enable_alignment"] realsense_cam_string = config["realsense_cam"] is_mainline: bool = bool(config["action"]["is_mainline"]) build_runtime(config, "so", is_mainline=is_mainline) def process_plugin(plugin_config: Mapping[str, Any]) -> Path: if is_mainline: plugin_config.update(ILLIXR_MONADO_MAINLINE="ON") return build_one_plugin(config, plugin_config) plugin_paths: List[Path] = threading_map( process_plugin, [plugin_config for plugin_group in config["plugin_groups"] for plugin_config in plugin_group["plugin_group"]], desc="Building plugins", ) plugin_paths_comp_arg: str = ':'.join(map(str, plugin_paths)) env_monado: Mapping[str, str] = dict( ILLIXR_DATA=str(data_path), ILLIXR_PATH=str(runtime_path / f"plugin.{profile}.so"), ILLIXR_COMP=plugin_paths_comp_arg, XR_RUNTIME_JSON=str(monado_path / "build" / "openxr_monado-dev.json"), ) ## For CMake monado_build_opts: Mapping[str, str] = dict( CMAKE_BUILD_TYPE=cmake_profile, ILLIXR_PATH=str(runtime_path), **monado_config, ) if is_mainline: monado_build_opts.update(ILLIXR_MONADO_MAINLINE="ON") ## Compile Monado cmake( monado_path, monado_path / "build", monado_build_opts, env_override=env_monado, ) if not "openxr_app" in config["action"]: raise RuntimeError(f"Missing 'openxr_app' property for action '{action_name}") openxr_app_obj : Mapping[str, Any] = config["action"]["openxr_app"] openxr_app_config : Mapping[str, str] = openxr_app_obj.get("config", {}) openxr_app_path : Optional[Path] # Forward declare type openxr_app_bin_path : Path # Forward declare type if "src_path" in openxr_app_obj["app"]: ## Pathify 'src_path' for compilation openxr_app_path = pathify(openxr_app_obj["app"]["src_path"], root_dir, cache_path, True , True) openxr_app_bin_path = openxr_app_path / openxr_app_obj["app"]["bin_subpath"] else: ## Get the full path to the 'app' binary openxr_app_path = None openxr_app_bin_path = pathify(openxr_app_obj["app"], root_dir, cache_path, True, True) ## Compile the OpenXR app if we received an 'app' with 'src_path' if openxr_app_path: cmake( openxr_app_path, openxr_app_path / "build", dict(CMAKE_BUILD_TYPE=cmake_profile, **openxr_app_config), ) if not openxr_app_bin_path.exists(): raise RuntimeError(f"{action_name} Failed to build openxr_app (mainline={is_mainline}, path={openxr_app_bin_path})") if is_mainline: monado_target_name : str = "monado-service" monado_target_dir : Path = monado_path / "build" / "src" / "xrt" / "targets" / "service" monado_target_path : Path = monado_target_dir / monado_target_name if not monado_target_path.exists(): raise RuntimeError(f"[{action_name}] Failed to build monado (mainline={is_mainline}, path={monado_target_path})") env_monado_service: Mapping[str, str] = dict(**os.environ, **env_monado) ## Open the Monado service application in the background monado_service_proc = subprocess.Popen([str(monado_target_path)], env=env_monado_service, stdin=PIPE, stdout=PIPE, stderr=PIPE) ## Give the Monado service some time to boot up and the user some time to initialize VIO time.sleep(5) subprocess_run( [str(openxr_app_bin_path)], env_override=dict( ILLIXR_DEMO_DATA=str(demo_data_path), ILLIXR_OFFLOAD_ENABLE=str(enable_offload_flag), ILLIXR_ALIGNMENT_ENABLE=str(enable_alignment_flag), ILLIXR_ENABLE_VERBOSE_ERRORS=str(config["enable_verbose_errors"]), ILLIXR_ENABLE_PRE_SLEEP=str(config["enable_pre_sleep"]), KIMERA_ROOT=config["action"]["kimera_path"], AUDIO_ROOT=config["action"]["audio_path"], REALSENSE_CAM=str(realsense_cam_string), **env_monado, ), check=True, ) if is_mainline: ## Close and clean up the Monado service application try: outs, errs = monado_service_proc.communicate(timeout=1) except subprocess.TimeoutExpired: monado_service_proc.kill() outs, errs = monado_service_proc.communicate() ## Clean up leftover socket. It can only either be in $XDG_RUNTIME_DIR or /tmp Path(env_monado_service['XDG_RUNTIME_DIR'] + "/monado_comp_ipc").unlink(missing_ok=True) Path("/tmp/monado_comp_ipc").unlink(missing_ok=True) print("\nstdout:\n") sys.stdout.buffer.write(outs) print("\nstderr:\n") sys.stderr.buffer.write(errs)
def run_tests(self, report_folder): report_file = report_folder / "TEST-pytest.xml" command = f"pytest --junitxml {report_file.absolute()}" # print(f"> {command}") subprocess_run(command, cwd=str(self.directory))