Skip to content

Commit a8a2e9a

Browse files
authored
Merge pull request #2646 from aarongreig/aaron/refactorKnownFailure
Refactor KNOWN_FAILURE implementation to avoid repeated logic.
2 parents 6636fdc + ae350a6 commit a8a2e9a

File tree

4 files changed

+44
-62
lines changed

4 files changed

+44
-62
lines changed

test/conformance/source/environment.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,6 @@ void DevicesEnvironment::SetUp() {
152152
}
153153
}
154154

155-
void DevicesEnvironment::TearDown() {
156-
PlatformEnvironment::TearDown();
157-
for (auto device_tuple : devices) {
158-
if (urDeviceRelease(device_tuple.device)) {
159-
error = "urDeviceRelease() failed";
160-
return;
161-
}
162-
}
163-
}
164-
165155
KernelsEnvironment *KernelsEnvironment::instance = nullptr;
166156

167157
KernelsEnvironment::KernelsEnvironment(int argc, char **argv,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct DevicesEnvironment : PlatformEnvironment {
4848
virtual ~DevicesEnvironment() override = default;
4949

5050
virtual void SetUp() override;
51-
virtual void TearDown() override;
5251

5352
inline const std::vector<DeviceTuple> &GetDevices() const { return devices; }
5453

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ struct urAllDevicesTest : urPlatformTest {
9090
}
9191

9292
void TearDown() override {
93-
for (auto &device : devices) {
94-
EXPECT_SUCCESS(urDeviceRelease(device));
95-
}
9693
UUR_RETURN_ON_FATAL_FAILURE(urPlatformTest::TearDown());
9794
}
9895

@@ -160,9 +157,6 @@ struct urAllDevicesTestWithParam : urPlatformTestWithParam<T> {
160157
}
161158

162159
void TearDown() override {
163-
for (auto &device : devices) {
164-
EXPECT_SUCCESS(urDeviceRelease(device));
165-
}
166160
UUR_RETURN_ON_FATAL_FAILURE(urPlatformTestWithParam<T>::TearDown());
167161
}
168162

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

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,47 @@
1515
#include <vector>
1616

1717
namespace uur {
18+
namespace detail {
19+
struct AdapterInfo {
20+
uint32_t version;
21+
ur_adapter_backend_t backend;
22+
};
23+
24+
inline AdapterInfo getAdapterInfo(ur_adapter_handle_t adapter) {
25+
AdapterInfo info;
26+
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_VERSION, sizeof(info.version),
27+
&info.version, nullptr);
28+
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, sizeof(info.backend),
29+
&info.backend, nullptr);
30+
return info;
31+
}
32+
} // namespace detail
33+
1834
struct Matcher {
1935
Matcher(uint32_t adapterVersion, ur_adapter_backend_t backend,
2036
std::vector<std::string> deviceNames)
2137
: adapterVersion(adapterVersion), backend(backend),
2238
names(std::move(deviceNames)) {}
2339

40+
bool matches(const detail::AdapterInfo &adapterInfo,
41+
const std::string &name) const {
42+
if (backend != adapterInfo.backend) {
43+
return false;
44+
}
45+
if (adapterVersion != adapterInfo.version) {
46+
return false;
47+
}
48+
if (names.empty()) {
49+
return true;
50+
}
51+
for (const auto &matcherName : names) {
52+
if (name.find(matcherName) != std::string::npos) {
53+
return true;
54+
}
55+
}
56+
return false;
57+
}
58+
2459
uint32_t adapterVersion;
2560
ur_adapter_backend_t backend;
2661
std::vector<std::string> names;
@@ -56,26 +91,10 @@ struct NativeCPU : Matcher {
5691
: Matcher(1, UR_ADAPTER_BACKEND_NATIVE_CPU, {il.begin(), il.end()}) {}
5792
};
5893

59-
namespace detail {
60-
struct AdapterInfo {
61-
uint32_t version;
62-
ur_adapter_backend_t backend;
63-
};
64-
65-
inline AdapterInfo getAdapterInfo(ur_adapter_handle_t adapter) {
66-
AdapterInfo info;
67-
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_VERSION, sizeof(info.version),
68-
&info.version, nullptr);
69-
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, sizeof(info.backend),
70-
&info.backend, nullptr);
71-
return info;
72-
}
73-
} // namespace detail
74-
7594
inline bool isKnownFailureOn(ur_adapter_handle_t adapter,
7695
const std::vector<Matcher> &matchers) {
96+
auto adapterInfo = detail::getAdapterInfo(adapter);
7797
for (const auto &matcher : matchers) {
78-
auto adapterInfo = detail::getAdapterInfo(adapter);
7998
if (matcher.adapterVersion == adapterInfo.version &&
8099
matcher.backend == adapterInfo.backend) {
81100
return true;
@@ -89,22 +108,13 @@ inline bool isKnownFailureOn(ur_platform_handle_t platform,
89108
ur_adapter_handle_t adapter = nullptr;
90109
urPlatformGetInfo(platform, UR_PLATFORM_INFO_ADAPTER,
91110
sizeof(ur_adapter_handle_t), &adapter, nullptr);
111+
auto adapterInfo = detail::getAdapterInfo(adapter);
112+
std::string name;
113+
uur::GetPlatformInfo<std::string>(platform, UR_PLATFORM_INFO_NAME, name);
92114
for (const auto &matcher : matchers) {
93-
auto adapterInfo = detail::getAdapterInfo(adapter);
94-
if (matcher.adapterVersion != adapterInfo.version &&
95-
matcher.backend != adapterInfo.backend) {
96-
continue;
97-
}
98-
if (matcher.names.empty()) {
115+
if (matcher.matches(adapterInfo, name)) {
99116
return true;
100117
}
101-
std::string name;
102-
uur::GetPlatformInfo<std::string>(platform, UR_PLATFORM_INFO_NAME, name);
103-
for (const auto &matcherName : matcher.names) {
104-
if (name.find(matcherName) != std::string::npos) {
105-
return true;
106-
}
107-
}
108118
}
109119
return false;
110120
}
@@ -119,24 +129,13 @@ isKnownFailureOn(const std::tuple<ur_platform_handle_t, Param> &param,
119129

120130
inline bool isKnownFailureOn(const DeviceTuple &param,
121131
const std::vector<Matcher> &matchers) {
132+
auto adapterInfo = detail::getAdapterInfo(param.adapter);
133+
std::string name;
134+
uur::GetDeviceInfo<std::string>(param.device, UR_DEVICE_INFO_NAME, name);
122135
for (const auto &matcher : matchers) {
123-
auto adapterInfo = detail::getAdapterInfo(param.adapter);
124-
if (matcher.backend != adapterInfo.backend) {
125-
continue;
126-
}
127-
if (matcher.adapterVersion != adapterInfo.version) {
128-
continue;
129-
}
130-
if (matcher.names.empty()) {
136+
if (matcher.matches(adapterInfo, name)) {
131137
return true;
132138
}
133-
std::string name;
134-
uur::GetDeviceInfo<std::string>(param.device, UR_DEVICE_INFO_NAME, name);
135-
for (const auto &matcherName : matcher.names) {
136-
if (name.find(matcherName) != std::string::npos) {
137-
return true;
138-
}
139-
}
140139
}
141140
return false;
142141
}

0 commit comments

Comments
 (0)