Skip to content

Commit 5e376ec

Browse files
committed
Add CTS macro for marking tests as known failures in code
The new `UUR_KNOWN_FAILURE_ON` macro can be used to skip tests on devices where the test is known to fail. This can be done for a devices in an adapter or by substring match of the device name. For example: ```cpp UUR_KNOWN_FAILURE_ON(uur::OpenCL{"Intel(R) UHD Graphics 770"}); ``` This invocation is also used in a few places in order to have clean CTS runs on machines with this iGPU.
1 parent e7ee297 commit 5e376ec

File tree

7 files changed

+135
-3
lines changed

7 files changed

+135
-3
lines changed

scripts/core/INTRO.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,13 @@ no valid platforms, then the tests will fail. Command line arguments take priori
430430

431431
A (case insensitive) backend to force the test to use. For example, `opencl`, `level_zero`, `hip` and so on.
432432

433+
.. envvar:: UR_CTS_ALSO_RUN_KNOWN_FAILURES
434+
435+
A boolean option to enable running tests which have been marked as known
436+
failures using the :c:macro:`UUR_KNOWN_FAILURE_ON` macro. Enabled when the
437+
environment variable is set to any of the following values: ``1``, ``on``,
438+
``ON``, ``yes``, ``YES``, ``true``, ``TRUE``.
439+
433440
Service identifiers
434441
---------------------
435442

test/conformance/kernel/urKernelSetArgValue.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
#include "uur/known_failure.h"
67
#include <uur/fixtures.h>
78

89
struct urKernelSetArgValueTest : uur::urKernelTest {
@@ -45,6 +46,7 @@ TEST_P(urKernelSetArgValueTest, InvalidKernelArgumentIndex) {
4546
}
4647

4748
TEST_P(urKernelSetArgValueTest, InvalidKernelArgumentSize) {
49+
UUR_KNOWN_FAILURE_ON(uur::OpenCL{"Intel(R) UHD Graphics 770"});
4850
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE,
4951
urKernelSetArgValue(kernel, 2, 0, nullptr, &arg_value));
5052
}

test/conformance/memory/urMemImageCreate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#include "uur/known_failure.h"
56
#include <uur/fixtures.h>
67
#include <uur/raii.h>
78

@@ -188,6 +189,7 @@ TEST_P(urMemImageCreateTest, InvalidNullPointerImageFormat) {
188189
}
189190

190191
TEST_P(urMemImageCreateTest, InvalidSize) {
192+
UUR_KNOWN_FAILURE_ON(uur::OpenCL{"Intel(R) UHD Graphics 770"});
191193

192194
uur::raii::Mem image_handle = nullptr;
193195

test/conformance/memory/urMemImageCreateWithImageFormatParam.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#include "uur/known_failure.h"
56
#include <uur/fixtures.h>
67
#include <vector>
78

@@ -90,6 +91,7 @@ UUR_TEST_SUITE_P(
9091
uur::deviceTestWithParamPrinter<ur_image_format_t>);
9192

9293
TEST_P(urMemImageCreateTestWithImageFormatParam, Success) {
94+
UUR_KNOWN_FAILURE_ON(uur::OpenCL{"Intel(R) UHD Graphics 770"});
9395
ur_image_channel_order_t channel_order =
9496
std::get<1>(GetParam()).channelOrder;
9597
ur_image_channel_type_t channel_type = std::get<1>(GetParam()).channelType;

test/conformance/program/urProgramGetFunctionPointer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
#include "uur/known_failure.h"
67
#include <uur/fixtures.h>
78

89
struct urProgramGetFunctionPointerTest : uur::urProgramTest {
@@ -20,6 +21,7 @@ struct urProgramGetFunctionPointerTest : uur::urProgramTest {
2021
UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urProgramGetFunctionPointerTest);
2122

2223
TEST_P(urProgramGetFunctionPointerTest, Success) {
24+
UUR_KNOWN_FAILURE_ON(uur::OpenCL{"Intel(R) UHD Graphics 770"});
2325
void *function_pointer = nullptr;
2426
ASSERT_SUCCESS(urProgramGetFunctionPointer(
2527
device, program, function_name.data(), &function_pointer));
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#ifndef UR_CONFORMANCE_INCLUDE_KNOWN_FAILURE_H_INCLUDED
7+
#define UR_CONFORMANCE_INCLUDE_KNOWN_FAILURE_H_INCLUDED
8+
9+
#include "uur/utils.h"
10+
#include <string>
11+
#include <string_view>
12+
#include <vector>
13+
14+
namespace uur {
15+
struct DeviceMatcher {
16+
DeviceMatcher(uint32_t adapterVersion, ur_platform_backend_t backend,
17+
std::vector<std::string> deviceNames)
18+
: adapterVersion(adapterVersion), backend(backend),
19+
deviceNames(deviceNames) {}
20+
21+
uint32_t adapterVersion;
22+
ur_platform_backend_t backend;
23+
std::vector<std::string> deviceNames;
24+
};
25+
26+
struct OpenCL : DeviceMatcher {
27+
OpenCL(std::initializer_list<std::string> il)
28+
: DeviceMatcher(1, UR_PLATFORM_BACKEND_OPENCL, {il.begin(), il.end()}) {
29+
}
30+
};
31+
32+
struct LevelZero : DeviceMatcher {
33+
LevelZero(std::initializer_list<std::string> il)
34+
: DeviceMatcher(1, UR_PLATFORM_BACKEND_LEVEL_ZERO,
35+
{il.begin(), il.end()}) {}
36+
};
37+
38+
struct LevelZeroV2 : DeviceMatcher {
39+
LevelZeroV2(std::initializer_list<std::string> il)
40+
: DeviceMatcher(2, UR_PLATFORM_BACKEND_LEVEL_ZERO,
41+
{il.begin(), il.end()}) {}
42+
};
43+
44+
struct CUDA : DeviceMatcher {
45+
CUDA(std::initializer_list<std::string> il)
46+
: DeviceMatcher(1, UR_PLATFORM_BACKEND_CUDA, {il.begin(), il.end()}) {}
47+
};
48+
49+
struct HIP : DeviceMatcher {
50+
HIP(std::initializer_list<std::string> il)
51+
: DeviceMatcher(1, UR_PLATFORM_BACKEND_HIP, {il.begin(), il.end()}) {}
52+
};
53+
54+
struct NativeCPU : DeviceMatcher {
55+
NativeCPU(std::initializer_list<std::string> il)
56+
: DeviceMatcher(1, UR_PLATFORM_BACKEND_NATIVE_CPU,
57+
{il.begin(), il.end()}) {}
58+
};
59+
60+
inline bool isKnownFailureOn(ur_adapter_handle_t adapter,
61+
ur_platform_handle_t platform,
62+
ur_device_handle_t device,
63+
std::vector<DeviceMatcher> deviceMatchers) {
64+
for (const auto &deviceMatcher : deviceMatchers) {
65+
uint32_t adapterVersion = 0;
66+
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_VERSION,
67+
sizeof(adapterVersion), &adapterVersion, nullptr);
68+
ur_platform_backend_t backend = UR_PLATFORM_BACKEND_UNKNOWN;
69+
uur::GetPlatformInfo<ur_platform_backend_t>(
70+
platform, UR_PLATFORM_INFO_BACKEND, backend);
71+
if (deviceMatcher.adapterVersion != adapterVersion &&
72+
deviceMatcher.backend != backend) {
73+
continue;
74+
}
75+
if (deviceMatcher.deviceNames.empty()) {
76+
return true;
77+
}
78+
std::string deviceName;
79+
uur::GetDeviceInfo<std::string>(device, UR_DEVICE_INFO_NAME,
80+
deviceName);
81+
for (const auto &unsupportedDeviceName : deviceMatcher.deviceNames) {
82+
if (deviceName.find(unsupportedDeviceName) != std::string::npos) {
83+
return true;
84+
}
85+
}
86+
}
87+
return false;
88+
}
89+
} // namespace uur
90+
91+
#define UUR_KNOWN_FAILURE_ON(...) \
92+
if (uur::isKnownFailureOn(adapter, platform, device, {__VA_ARGS__})) { \
93+
using namespace std::literals; \
94+
std::string platformName; \
95+
uur::GetPlatformInfo<std::string>(platform, UR_PLATFORM_INFO_NAME, \
96+
platformName); \
97+
std::string deviceName; \
98+
uur::GetDeviceInfo<std::string>(device, UR_DEVICE_INFO_NAME, \
99+
deviceName); \
100+
const char *alsoRunKnownFailures = \
101+
std::getenv("UR_CTS_ALSO_RUN_KNOWN_FAILURES"); \
102+
if (alsoRunKnownFailures && (alsoRunKnownFailures == "1"sv || \
103+
alsoRunKnownFailures == "yes"sv || \
104+
alsoRunKnownFailures == "YES"sv || \
105+
alsoRunKnownFailures == "on"sv || \
106+
alsoRunKnownFailures == "ON"sv || \
107+
alsoRunKnownFailures == "true"sv || \
108+
alsoRunKnownFailures == "TRUE"sv)) { \
109+
std::cerr << "Known failure on: " << platformName << ", " \
110+
<< deviceName << "\n"; \
111+
} else { \
112+
GTEST_SKIP() << "Known failure on: " << platformName << ", " \
113+
<< deviceName; \
114+
} \
115+
}
116+
117+
#endif // UR_CONFORMANCE_INCLUDE_KNOWN_FAILURE_H_INCLUDED

test/conformance/testing/include/uur/utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ ur_result_t GetInfo(ObjectTy object, InfoTy info, Callable cb, T &out_value) {
4343

4444
// special case for strings
4545
if constexpr (std::is_same_v<std::string, T>) {
46-
std::vector<char> data(size);
47-
result = cb(object, info, size, data.data(), nullptr);
46+
std::string value(size, '\0');
47+
result = cb(object, info, size, value.data(), nullptr);
4848
if (result != UR_RESULT_SUCCESS) {
4949
return result;
5050
}
51-
out_value = std::string(data.data(), data.size());
51+
out_value = value.substr(0, value.find_last_of('\0'));
5252
return UR_RESULT_SUCCESS;
5353
} else {
5454
if (size != sizeof(T)) {

0 commit comments

Comments
 (0)