diff --git a/src/holoscan_cli/commands/test_cmd.py b/src/holoscan_cli/commands/test_cmd.py index 45396cc0..9a98aadb 100644 --- a/src/holoscan_cli/commands/test_cmd.py +++ b/src/holoscan_cli/commands/test_cmd.py @@ -61,7 +61,11 @@ def register_test_parser(cli, subparsers, *, container_build) -> argparse.Argume help="CTest options, " "example: --ctest-options='-DGPU_TYPE=rtx4090' --ctest-options='-DDEBUG_MODE=ON'", ) - parser.add_argument("--no-xvfb", action="store_true", help="Do not use xvfb") + parser.add_argument( + "--no-xvfb", + action="store_true", + help="Skip Xvfb detection and run tests directly", + ) parser.add_argument("--ctest-script", help="CTest script") parser.add_argument( "--local-sdk-root", @@ -158,8 +162,6 @@ def handle_test(cli, args: argparse.Namespace) -> None: if hasattr(args, "cuda") and args.cuda is not None: container.cuda_version = args.cuda - xvfb = "" if args.no_xvfb else "xvfb-run -a" - # TAG is used in CTest scripts by default if getattr(args, "build_name_suffix", None): tag = args.build_name_suffix @@ -173,7 +175,15 @@ def handle_test(cli, args: argparse.Namespace) -> None: ) tag = image_name.split(":")[-1] - ctest_cmd = f"{xvfb} ctest " + ctest = "ctest" + if not args.no_xvfb: + ctest = ( + "if command -v xvfb-run >/dev/null 2>&1; then ctest_cmd='xvfb-run -a ctest'; " + "else echo 'WARNING: xvfb-run is unavailable; running tests without a virtual " + "display. Install Xvfb, or rebuild with --extra-scripts xvfb if these tests need " + "one.' >&2; ctest_cmd='ctest'; fi; ${ctest_cmd}" + ) + ctest_cmd = f'{ctest} -DCTEST_SOURCE_DIRECTORY="$PWD" ' if args.project: project_metadata = container.project_metadata or {} project_name = project_metadata.get("project_name", args.project) diff --git a/src/holoscan_cli/testing/container.ctest b/src/holoscan_cli/testing/container.ctest index 6470326f..f8ce3713 100644 --- a/src/holoscan_cli/testing/container.ctest +++ b/src/holoscan_cli/testing/container.ctest @@ -72,7 +72,9 @@ if(NOT TAG) set(TAG latest) endif() -get_filename_component(CTEST_SOURCE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) +if(NOT CTEST_SOURCE_DIRECTORY) + get_filename_component(CTEST_SOURCE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) +endif() set(CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}/build-${PROJ_NAME}") if(NOT CTEST_SITE)