diff --git a/.github/workflows/build-hw-reusable.yml b/.github/workflows/build-hw-reusable.yml index b8fc659b4d..77f696b958 100644 --- a/.github/workflows/build-hw-reusable.yml +++ b/.github/workflows/build-hw-reusable.yml @@ -82,6 +82,7 @@ jobs: -DUR_ENABLE_TRACING=ON -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON + -DUR_CONFORMANCE_TEST_LOADER=OFF -DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON -DUR_STATIC_LOADER=${{matrix.adapter.static_Loader}} -DUR_STATIC_ADAPTER_${{matrix.adapter.name}}=${{matrix.adapter.static_adapter}} diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f457e3e272..6763854c4c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -92,6 +92,7 @@ jobs: -DUR_BUILD_TESTS=ON -DUR_FORMAT_CPP_STYLE=OFF -DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++ + -DUR_CONFORMANCE_TEST_LOADER=OFF ${{matrix.libbacktrace}} ${{matrix.pool_tracking}} ${{matrix.latency_tracking}} @@ -259,6 +260,7 @@ jobs: -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_FORMAT_CPP_STYLE=OFF + -DUR_CONFORMANCE_TEST_LOADER=OFF ${{matrix.adapter.var}} - name: Build all diff --git a/.github/workflows/multi_device.yml b/.github/workflows/multi_device.yml index 438b90fa54..bbdd473b50 100644 --- a/.github/workflows/multi_device.yml +++ b/.github/workflows/multi_device.yml @@ -47,6 +47,7 @@ jobs: -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON + -DUR_CONFORMANCE_TEST_LOADER=OFF -DUR_TEST_DEVICES_COUNT=2 -DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++ -DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib diff --git a/CMakeLists.txt b/CMakeLists.txt index a908a22d80..ea2c6586d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ set(UR_CONFORMANCE_TARGET_TRIPLES "" CACHE STRING "List of sycl targets to build CTS device binaries for") set(UR_CONFORMANCE_AMD_ARCH "" CACHE STRING "AMD device target ID to build CTS binaries for") option(UR_CONFORMANCE_ENABLE_MATCH_FILES "Enable CTS match files" ON) +option(UR_CONFORMANCE_TEST_LOADER "Also test the loader in the conformance tests" ON) set(UR_ADAPTER_LEVEL_ZERO_SOURCE_DIR "" CACHE PATH "Path to external 'level_zero' adapter source dir") set(UR_ADAPTER_OPENCL_SOURCE_DIR "" CACHE PATH diff --git a/README.md b/README.md index 950edff70e..e37934fd26 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ List of options provided by CMake: | UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 | | UR_CONFORMANCE_AMD_ARCH | AMD device target ID to build CTS binaries for | string | `""` | | UR_CONFORMANCE_ENABLE_MATCH_FILES | Enable CTS match files | ON/OFF | ON | +| UR_CONFORMANCE_TEST_LOADER | Build and run "loader" tests for the CTS | ON/OFF | ON | | UR_BUILD_ADAPTER_L0 | Build the Level-Zero adapter | ON/OFF | OFF | | UR_BUILD_ADAPTER_OPENCL | Build the OpenCL adapter | ON/OFF | OFF | | UR_BUILD_ADAPTER_CUDA | Build the CUDA adapter | ON/OFF | OFF | diff --git a/scripts/core/INTRO.rst b/scripts/core/INTRO.rst index 687bb53595..d30bbbdfa3 100644 --- a/scripts/core/INTRO.rst +++ b/scripts/core/INTRO.rst @@ -404,6 +404,32 @@ Specific environment variables can be set to control the behavior of unified run This environment variable is default enabled on Linux, but default disabled on Windows. +CTS Environment Variables +------------------------- + +The following environment variables are used by the CTS runner and can be used to specify the platform that the test +framework should run on. This can be used during development and testing to run CTS tests in case multiple platforms +are available. If both filters are specified, then they both must match a platform for it to be selected. If there are +no valid platforms, then the tests will fail. Command line arguments take priority over these variables. + +.. envvar:: UR_CTS_ADAPTER_PLATFORM + + A specifier list in the form of `[(backend):](platform name)[;[(backend)]:(platform name)]...`. If a backend + specific specifier is present in the list and the test is running for that backend, the device with the given name + is chosen. Otherwise, it must match the name of the specifier from the list with no backend. Backend names are case- + insensitive. + + For example, if the test device has multiple platforms and you want to run tests on the "ABC Corp" backend when + testing OpenCL and "XYZ Org" when testing level zero, you'd use `OPENCL:ABC Corp;LEVEL_ZERO:XYZ Org`. This form is + useful when running the `build` target with a build with multiple backends. + + For testing only one platform, the backend can be omitted. For example, just `ABC Corp` is sufficient if the tests + are only going to be testing OpenCL. + +.. envvar:: UR_CTS_BACKEND + + A (case insensitive) backend to force the test to use. For example, `opencl`, `level_zero`, `hip` and so on. + Service identifiers --------------------- diff --git a/test/adapters/CMakeLists.txt b/test/adapters/CMakeLists.txt index 78f0306d7b..54f8f76a7b 100644 --- a/test/adapters/CMakeLists.txt +++ b/test/adapters/CMakeLists.txt @@ -63,7 +63,7 @@ function(add_adapter_memcheck_test name) add_test(NAME ${test_name} COMMAND ${CMAKE_COMMAND} -D TEST_FILE=valgrind - -D TEST_ARGS="--tool=memcheck --leak-check=full $ --devices_count=${UR_TEST_DEVICES_COUNT} --platforms_count=${UR_TEST_DEVICES_COUNT}" + -D TEST_ARGS="--tool=memcheck --leak-check=full $ --backend=${backend} --devices_count=${UR_TEST_DEVICES_COUNT} --platforms_count=${UR_TEST_DEVICES_COUNT}" -D MODE=stderr -D MATCH_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_memcheck.match -P ${PROJECT_SOURCE_DIR}/cmake/match.cmake diff --git a/test/conformance/CMakeLists.txt b/test/conformance/CMakeLists.txt index b45a3fc3da..4d62299ce3 100644 --- a/test/conformance/CMakeLists.txt +++ b/test/conformance/CMakeLists.txt @@ -9,45 +9,48 @@ set(UR_CONFORMANCE_DEVICE_BINARIES_DIR "${CMAKE_CURRENT_BINARY_DIR}/device_binaries" CACHE INTERNAL "Internal cache variable for device binaries directory") -function(add_test_adapter name adapter) - if(NOT "${ARGN}" STREQUAL "") - set(EXTRA_NAME "-${ARGN}") - endif() +function(add_test_adapter name adapter backend) set(TEST_TARGET_NAME test-${name}) - set(TEST_NAME ${name}-${adapter}${EXTRA_NAME}) + set(TEST_NAME ${name}-${adapter}) set(TEST_COMMAND - "${PROJECT_BINARY_DIR}/bin/${TEST_TARGET_NAME} --devices_count=${UR_TEST_DEVICES_COUNT} --platforms_count=${UR_TEST_PLATFORMS_COUNT}" + "${PROJECT_BINARY_DIR}/bin/${TEST_TARGET_NAME} --backend=${backend} --devices_count=${UR_TEST_DEVICES_COUNT} --platforms_count=${UR_TEST_PLATFORMS_COUNT}" ) - set(MATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${name}_${adapter}${EXTRA_NAME}.match") - - if(${UR_CONFORMANCE_ENABLE_MATCH_FILES} AND EXISTS ${MATCH_FILE}) - add_test(NAME ${TEST_NAME} - COMMAND ${CMAKE_COMMAND} - -D TEST_FILE=${Python3_EXECUTABLE} - -D TEST_ARGS="${UR_CONFORMANCE_TEST_DIR}/cts_exe.py --test_command ${TEST_COMMAND}" - -D MODE=stdout - -D MATCH_FILE=${MATCH_FILE} - -P ${PROJECT_SOURCE_DIR}/cmake/match.cmake - DEPENDS ${TEST_TARGET_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - else() - separate_arguments(TEST_COMMAND) - add_test(NAME ${TEST_NAME} - COMMAND ${TEST_COMMAND} - DEPENDS ${TEST_TARGET_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - endif() + set(MATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${name}_${adapter}.match") + + function(do_add_test tname env) + if(${UR_CONFORMANCE_ENABLE_MATCH_FILES} AND EXISTS ${MATCH_FILE}) + add_test(NAME ${tname} + COMMAND ${CMAKE_COMMAND} + -D TEST_FILE=${Python3_EXECUTABLE} + -D TEST_ARGS="${UR_CONFORMANCE_TEST_DIR}/cts_exe.py --test_command ${TEST_COMMAND}" + -D MODE=stdout + -D MATCH_FILE=${MATCH_FILE} + -P ${PROJECT_SOURCE_DIR}/cmake/match.cmake + DEPENDS ${TEST_TARGET_NAME} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + else() + separate_arguments(TEST_COMMAND) + add_test(NAME ${tname} + COMMAND ${TEST_COMMAND} + DEPENDS ${TEST_TARGET_NAME} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + endif() - set(TEST_ENV UR_ADAPTERS_FORCE_LOAD="$") - if(UR_CONFORMANCE_ENABLE_MATCH_FILES) - list(APPEND TEST_ENV GTEST_COLOR=no) + if(UR_CONFORMANCE_ENABLE_MATCH_FILES) + list(APPEND env GTEST_COLOR=no) + endif() + set_tests_properties(${TEST_NAME} PROPERTIES + ENVIRONMENT "${env}" + LABELS "conformance;${adapter}") + endfunction() + + do_add_test(${TEST_NAME} UR_ADAPTERS_FORCE_LOAD="$") + if(UR_CONFORMANCE_TEST_LOADER) + do_add_test(${TEST_NAME}-loader "") endif() - set_tests_properties(${TEST_NAME} PROPERTIES - ENVIRONMENT "${TEST_ENV}" - LABELS "conformance;${adapter}") endfunction() function(add_conformance_test name) @@ -66,29 +69,29 @@ function(add_conformance_test name) unit_tests_helpers) if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL) - add_test_adapter(${name} adapter_cuda) + add_test_adapter(${name} adapter_cuda CUDA) endif() if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL) - add_test_adapter(${name} adapter_hip) + add_test_adapter(${name} adapter_hip HIP) endif() if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL) - add_test_adapter(${name} adapter_level_zero) + add_test_adapter(${name} adapter_level_zero LEVEL_ZERO) endif() if(UR_BUILD_ADAPTER_L0_V2) - add_test_adapter(${name} adapter_level_zero_v2) + add_test_adapter(${name} adapter_level_zero_v2 LEVEL_ZERO) endif() if(UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_ALL) - add_test_adapter(${name} adapter_opencl) + add_test_adapter(${name} adapter_opencl OPENCL) endif() if(UR_BUILD_ADAPTER_NATIVE_CPU OR UR_BUILD_ADAPTER_ALL) - add_test_adapter(${name} adapter_native_cpu) + add_test_adapter(${name} adapter_native_cpu NATIVE_CPU) endif() if(NOT (UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_NATIVE_CPU OR UR_BUILD_ADAPTER_L0_V2 OR UR_BUILD_ADAPTER_ALL)) - add_test_adapter(${name} adapter_mock) + add_test_adapter(${name} adapter_mock MOCK) endif() endfunction() diff --git a/test/conformance/cts_exe.py b/test/conformance/cts_exe.py index 0e40234539..f1f33c5f77 100644 --- a/test/conformance/cts_exe.py +++ b/test/conformance/cts_exe.py @@ -23,11 +23,13 @@ parser.add_argument("--test_command", help="Ctest test case") parser.add_argument("--devices_count", type=str, help="Number of devices on which tests will be run") parser.add_argument("--platforms_count", type=str, help="Number of platforms on which tests will be run") + parser.add_argument("--backend", type=str, help="Number of platforms on which tests will be run") args = parser.parse_args() result = subprocess.Popen([args.test_command, '--gtest_brief=1', # nosec B603 f'--devices_count={args.devices_count}', - f'--platforms_count={args.platforms_count}'], + f'--platforms_count={args.platforms_count}', + f'--backend={args.backend}'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) pat = re.compile(r'\[( )*FAILED( )*\]') diff --git a/test/conformance/source/environment.cpp b/test/conformance/source/environment.cpp index 05dbe8c847..495d51e1c1 100644 --- a/test/conformance/source/environment.cpp +++ b/test/conformance/source/environment.cpp @@ -6,8 +6,11 @@ #include #include #include +#include +#include "ur_api.h" #include "ur_filesystem_resolved.hpp" +#include "uur/checks.h" #ifdef KERNELS_ENVIRONMENT #include "kernel_entry_points.h" @@ -23,16 +26,38 @@ constexpr char ERROR_NO_ADAPTER[] = "Could not load adapter"; PlatformEnvironment *PlatformEnvironment::instance = nullptr; -std::ostream &operator<<(std::ostream &out, - const ur_platform_handle_t &platform) { - size_t size; - urPlatformGetInfo(platform, UR_PLATFORM_INFO_NAME, 0, nullptr, &size); - std::vector name(size); - urPlatformGetInfo(platform, UR_PLATFORM_INFO_NAME, size, name.data(), - nullptr); - out << name.data(); - return out; -} +constexpr std::pair backends[] = { + {"LEVEL_ZERO", UR_PLATFORM_BACKEND_LEVEL_ZERO}, + {"L0", UR_PLATFORM_BACKEND_LEVEL_ZERO}, + {"OPENCL", UR_PLATFORM_BACKEND_OPENCL}, + {"CUDA", UR_PLATFORM_BACKEND_CUDA}, + {"HIP", UR_PLATFORM_BACKEND_HIP}, + {"NATIVE_CPU", UR_PLATFORM_BACKEND_NATIVE_CPU}, + {"UNKNOWN", UR_PLATFORM_BACKEND_UNKNOWN}, + {"MOCK", UR_PLATFORM_BACKEND_UNKNOWN}, +}; + +namespace { +constexpr const char *backend_to_str(ur_platform_backend_t backend) { + for (auto b : backends) { + if (b.second == backend) { + return b.first; + } + } + return "INVALID"; +}; + +ur_platform_backend_t str_to_backend(std::string str) { + + std::transform(str.begin(), str.end(), str.begin(), ::toupper); + for (auto b : backends) { + if (b.first == str) { + return b.second; + } + } + return UR_PLATFORM_BACKEND_UNKNOWN; +}; +} // namespace std::ostream &operator<<(std::ostream &out, const std::vector &platforms) { @@ -42,15 +67,6 @@ std::ostream &operator<<(std::ostream &out, return out; } -std::ostream &operator<<(std::ostream &out, const ur_device_handle_t &device) { - size_t size; - urDeviceGetInfo(device, UR_DEVICE_INFO_NAME, 0, nullptr, &size); - std::vector name(size); - urDeviceGetInfo(device, UR_DEVICE_INFO_NAME, size, name.data(), nullptr); - out << name.data(); - return out; -} - std::ostream &operator<<(std::ostream &out, const std::vector &devices) { for (auto device : devices) { @@ -62,6 +78,10 @@ std::ostream &operator<<(std::ostream &out, uur::PlatformEnvironment::PlatformEnvironment(int argc, char **argv) : platform_options{parsePlatformOptions(argc, argv)} { instance = this; + // Check for errors from parsing platform options + if (!error.empty()) { + return; + } ur_loader_config_handle_t config; if (urLoaderConfigCreate(&config) == UR_RESULT_SUCCESS) { @@ -95,79 +115,119 @@ uur::PlatformEnvironment::PlatformEnvironment(int argc, char **argv) return; } + selectPlatformFromOptions(); +} + +void uur::PlatformEnvironment::selectPlatformFromOptions() { uint32_t adapter_count = 0; urAdapterGet(0, nullptr, &adapter_count); adapters.resize(adapter_count); urAdapterGet(adapter_count, adapters.data(), nullptr); - // Search through the adapters individually so we can store the one we end - // up choosing. + struct platform_info { + ur_adapter_handle_t adapter; + ur_platform_handle_t platform; + std::string name; + ur_platform_backend_t backend; + }; + std::vector platforms; for (auto a : adapters) { uint32_t count = 0; - if (urPlatformGet(&a, 1, 0, nullptr, &count)) { - error = "urPlatformGet() failed to get number of platforms."; - return; - } + ASSERT_SUCCESS(urPlatformGet(&a, 1, 0, nullptr, &count)); + std::vector platform_list(count); + ASSERT_SUCCESS( + urPlatformGet(&a, 1, count, platform_list.data(), nullptr)); - if (count == 0) { - error = "Failed to find any platforms."; - return; - } + for (auto p : platform_list) { + ur_platform_backend_t backend; + ASSERT_SUCCESS(urPlatformGetInfo(p, UR_PLATFORM_INFO_BACKEND, + sizeof(ur_platform_backend_t), + &backend, nullptr)); - std::vector platforms(count); - if (urPlatformGet(&a, 1, count, platforms.data(), nullptr)) { - error = "urPlatformGet failed to get platforms."; - return; + size_t size; + ASSERT_SUCCESS( + urPlatformGetInfo(p, UR_PLATFORM_INFO_NAME, 0, nullptr, &size)); + std::vector platform_name{}; + platform_name.reserve(size); + ASSERT_SUCCESS(urPlatformGetInfo(p, UR_PLATFORM_INFO_NAME, size, + platform_name.data(), nullptr)); + + platforms.push_back(platform_info{ + a, p, std::string(platform_name.data()), backend}); } + } - if (platform_options.platform_name.empty()) { - - if (platforms.size() == 1 || - platform_options.platforms_count == 1) { - platform = platforms[0]; - adapter = a; - } else { - std::stringstream ss_error; - ss_error << "Select a single platform from below using the " - "--platform=NAME " - "command-line option:" - << platforms << std::endl - << "or set --platforms_count=1."; - error = ss_error.str(); - return; - } + std::string default_name{}; + std::map backend_platform_names{}; + auto stream = std::stringstream{platform_options.platform_name}; + for (std::string filter; std::getline(stream, filter, ';');) { + auto split = filter.find(':'); + if (split == std::string::npos) { + default_name = filter; + } else if (split == filter.length() - 1) { + // E.g: `OPENCL:`, ignore it } else { - for (auto candidate : platforms) { - size_t size; - if (urPlatformGetInfo(candidate, UR_PLATFORM_INFO_NAME, 0, - nullptr, &size)) { - error = "urPlatformGetInfoFailed"; - return; - } - std::vector platform_name(size); - if (urPlatformGetInfo(candidate, UR_PLATFORM_INFO_NAME, size, - platform_name.data(), nullptr)) { - error = "urPlatformGetInfo() failed"; - return; - } - if (platform_options.platform_name == platform_name.data()) { - platform = candidate; - adapter = a; - break; - } - } - if (!platform) { - std::stringstream ss_error; - ss_error << "Platform \"" << platform_options.platform_name - << "\" not found. Select a single platform from below " - "using the " - "--platform=NAME command-line options:" - << platforms << std::endl - << "or set --platforms_count=1."; - error = ss_error.str(); - return; - } + backend_platform_names.insert( + {str_to_backend(filter.substr(0, split)), + filter.substr(split + 1)}); + } + } + + std::vector platforms_filtered{}; + std::copy_if(platforms.begin(), platforms.end(), + std::inserter(platforms_filtered, platforms_filtered.begin()), + [&](platform_info info) { + if (!default_name.empty() && default_name != info.name) { + return false; + } + if (backend_platform_names.count(info.backend) && + backend_platform_names[info.backend] != info.name) { + return false; + } + if (platform_options.platform_backend && + platform_options.platform_backend != info.backend) { + return false; + } + return true; + }); + + if (platforms_filtered.size() == 0) { + std::stringstream errstr; + errstr << "No platforms were found with the following filters:"; + if (platform_options.platform_backend) { + errstr << " --backend=" + << backend_to_str(*platform_options.platform_backend); + } + if (!platform_options.platform_name.empty()) { + errstr << " --platform=\"" << platform_options.platform_name + << "\""; } + if (!platform_options.platform_backend && + platform_options.platform_name.empty()) { + errstr << " (none)"; + } + errstr << "\nAvailable platforms:\n"; + for (auto p : platforms) { + errstr << " --backend=" << backend_to_str(p.backend) + << " --platform=\"" << p.name << "\"\n"; + } + FAIL() << errstr.str(); + } else if (platforms_filtered.size() == 1 || + platform_options.platforms_count == 1) { + auto &selected = platforms_filtered[0]; + platform = selected.platform; + adapter = selected.adapter; + std::cerr << "Selected platform: [" << backend_to_str(selected.backend) + << "] " << selected.name << "\n"; + } else if (platforms_filtered.size() > 1) { + std::stringstream errstr; + errstr << "Multiple possible platforms found; please select one of the " + "following or set --platforms_count=1:\n"; + for (auto p : platforms_filtered) { + errstr << " --backend=" << backend_to_str(p.backend) + << " --platform=\"" << p.name << "\"\n"; + } + FAIL() << errstr.str(); } } @@ -196,6 +256,26 @@ void uur::PlatformEnvironment::TearDown() { PlatformEnvironment::PlatformOptions PlatformEnvironment::parsePlatformOptions(int argc, char **argv) { PlatformOptions options{}; + auto parse_backend = [&](std::string backend_string) { + options.platform_backend = str_to_backend(backend_string); + if (options.platform_backend == UR_PLATFORM_BACKEND_UNKNOWN) { + std::stringstream errstr{error}; + errstr << "--backend not valid; expected one of ["; + bool first = true; + for (auto b : backends) { + if (!first) { + errstr << ", "; + } + errstr << b.first; + first = false; + } + errstr << "], but got `" << backend_string << "`"; + error = errstr.str(); + return false; + } + return true; + }; + for (int argi = 1; argi < argc; ++argi) { const char *arg = argv[argi]; if (!(std::strcmp(arg, "-h") && std::strcmp(arg, "--help"))) { @@ -205,6 +285,12 @@ PlatformEnvironment::parsePlatformOptions(int argc, char **argv) { arg, "--platform=", sizeof("--platform=") - 1) == 0) { options.platform_name = std::string(&arg[std::strlen("--platform=")]); + } else if (std::strncmp(arg, "--backend=", sizeof("--backend=") - 1) == + 0) { + std::string backend_string{&arg[std::strlen("--backend=")]}; + if (!parse_backend(backend_string)) { + return options; + } } else if (std::strncmp(arg, "--platforms_count=", sizeof("--platforms_count=") - 1) == 0) { options.platforms_count = std::strtoul( @@ -212,7 +298,7 @@ PlatformEnvironment::parsePlatformOptions(int argc, char **argv) { } } - /* If a platform was not provided using the --platform command line option, + /* If a platform was not provided using the --platform/--backend command line options, * check if environment variable is set to use as a fallback. */ if (options.platform_name.empty()) { auto env_platform = ur_getenv("UR_CTS_ADAPTER_PLATFORM"); @@ -220,6 +306,14 @@ PlatformEnvironment::parsePlatformOptions(int argc, char **argv) { options.platform_name = env_platform.value(); } } + if (!options.platform_backend) { + auto env_backend = ur_getenv("UR_CTS_BACKEND"); + if (env_backend.has_value()) { + if (!parse_backend(env_backend.value())) { + return options; + } + } + } return options; } diff --git a/test/conformance/testing/include/uur/environment.h b/test/conformance/testing/include/uur/environment.h index ec4a39fe7f..bba4c583c8 100644 --- a/test/conformance/testing/include/uur/environment.h +++ b/test/conformance/testing/include/uur/environment.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -17,6 +18,7 @@ struct PlatformEnvironment : ::testing::Environment { struct PlatformOptions { std::string platform_name; + std::optional platform_backend; unsigned long platforms_count = 0; }; @@ -26,13 +28,14 @@ struct PlatformEnvironment : ::testing::Environment { virtual void SetUp() override; virtual void TearDown() override; + void selectPlatformFromOptions(); PlatformOptions parsePlatformOptions(int argc, char **argv); + std::string error{}; PlatformOptions platform_options; std::vector adapters{}; ur_adapter_handle_t adapter = nullptr; ur_platform_handle_t platform = nullptr; - std::string error; static PlatformEnvironment *instance; };