|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include <detail/allowlist.hpp>
|
| 10 | +#include <sycl/platform.hpp> |
10 | 11 |
|
11 | 12 | #include <gtest/gtest.h>
|
12 | 13 |
|
| 14 | +#ifdef _WIN32 |
| 15 | +#include <windows.h> // SetEnvironmentVariable |
| 16 | +#endif |
| 17 | + |
13 | 18 | constexpr char SyclDeviceAllowList[] =
|
14 | 19 | "BackendName:opencl,DeviceType:gpu,DeviceVendorId:0x8086,DriverVersion:{{("
|
15 | 20 | "19\\.(4[3-9]|[5-9]\\d)\\..*)|([2-9][0-9]\\.\\d+\\..*)|(\\d+\\.\\d+\\."
|
@@ -85,6 +90,35 @@ TEST(DeviceIsAllowedTests, CheckSupportedOpenCLGPUDeviceIsAllowed) {
|
85 | 90 | EXPECT_EQ(Actual, true);
|
86 | 91 | }
|
87 | 92 |
|
| 93 | +TEST(DeviceIsAllowedTests, CheckLocalizationDoesNotImpact) { |
| 94 | + // The localization can affect std::stringstream output. |
| 95 | + // We want to make sure that DeviceVenderId doesn't have a comma |
| 96 | + // inserted (ie "0x8,086" ), which will break the platform retrieval. |
| 97 | + |
| 98 | + try { |
| 99 | + auto previous = std::locale::global(std::locale("en_US.UTF-8")); |
| 100 | +#ifdef _WIN32 |
| 101 | + SetEnvironmentVariableA("SYCL_DEVICE_ALLOWLIST", SyclDeviceAllowList); |
| 102 | +#else |
| 103 | + setenv("SYCL_DEVICE_ALLOWLIST", SyclDeviceAllowList, 1); |
| 104 | +#endif |
| 105 | + |
| 106 | + auto post_platforms = sycl::platform::get_platforms(); |
| 107 | + std::locale::global(previous); |
| 108 | +#ifdef _WIN32 |
| 109 | + SetEnvironmentVariableA("SYCL_DEVICE_ALLOWLIST", nullptr); |
| 110 | +#else |
| 111 | + unsetenv("SYCL_DEVICE_ALLOWLIST"); |
| 112 | +#endif |
| 113 | + |
| 114 | + EXPECT_NE(size_t{0}, post_platforms.size()); |
| 115 | + } catch (...) { |
| 116 | + // It is possible that the en_US locale is not available. |
| 117 | + // In this case, we just skip the test. |
| 118 | + GTEST_SKIP() << "Locale en_US.UTF-8 not available."; |
| 119 | + } |
| 120 | +} |
| 121 | + |
88 | 122 | TEST(DeviceIsAllowedTests, CheckSupportedOpenCLCPUDeviceIsAllowed) {
|
89 | 123 | bool Actual = sycl::detail::deviceIsAllowed(
|
90 | 124 | OpenCLCPUDeviceDesc, sycl::detail::parseAllowList(SyclDeviceAllowList));
|
|
0 commit comments