Skip to content

Commit 3162a40

Browse files
RossBruntonkbenzie
authored andcommitted
Update tests to handle platforms with no devices (#18620)
1 parent 64ab968 commit 3162a40

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

test/conformance/device/urDeviceGet.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66

77
#include <uur/fixtures.h>
88

9-
using urDeviceGetTest = uur::urPlatformTest;
9+
struct urDeviceGetTest : uur::urPlatformTest {
10+
void SetUp() {
11+
UUR_RETURN_ON_FATAL_FAILURE(uur::urPlatformTest::SetUp());
12+
13+
// These tests require at least one device in the platform
14+
uint32_t totalCount = 0;
15+
ASSERT_SUCCESS(
16+
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &totalCount));
17+
if (!totalCount) {
18+
GTEST_SKIP() << "Platform has no devices";
19+
}
20+
}
21+
};
1022
UUR_INSTANTIATE_PLATFORM_TEST_SUITE(urDeviceGetTest);
1123

1224
TEST_P(urDeviceGetTest, Success) {

test/conformance/device/urDeviceGetSelected.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ static int unset_env(const char *name) {
2929

3030
} // namespace uur
3131

32-
using urDeviceGetSelectedTest = uur::urPlatformTest;
32+
struct urDeviceGetSelectedTest : uur::urPlatformTest {
33+
void SetUp() {
34+
UUR_RETURN_ON_FATAL_FAILURE(uur::urPlatformTest::SetUp());
35+
36+
// These tests require at least one device in the platform
37+
uint32_t totalCount = 0;
38+
ASSERT_SUCCESS(
39+
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &totalCount));
40+
if (!totalCount) {
41+
GTEST_SKIP() << "Platform has no devices";
42+
}
43+
}
44+
};
3345
UUR_INSTANTIATE_PLATFORM_TEST_SUITE(urDeviceGetSelectedTest);
3446

3547
/* adpater agnostic tests -- none assume the existence or support of any

test/conformance/memory-migrate/urMemBufferMigrateAcrossDevices.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ struct urMultiDeviceContextTest : uur::urPlatformTest {
1616
uur::urPlatformTest::SetUp();
1717
ASSERT_SUCCESS(
1818
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &num_devices));
19-
ASSERT_NE(num_devices, 0);
20-
if (num_devices == 1) {
19+
if (num_devices <= 1) {
2120
return;
2221
}
2322

@@ -35,7 +34,7 @@ struct urMultiDeviceContextTest : uur::urPlatformTest {
3534

3635
void TearDown() {
3736
uur::urPlatformTest::TearDown();
38-
if (num_devices == 1) {
37+
if (num_devices <= 1) {
3938
return;
4039
}
4140
for (auto i = 0u; i < num_devices; ++i) {
@@ -54,7 +53,7 @@ struct urMultiDeviceContextTest : uur::urPlatformTest {
5453
struct urMultiDeviceContextMemBufferTest : urMultiDeviceContextTest {
5554
void SetUp() {
5655
urMultiDeviceContextTest::SetUp();
57-
if (num_devices == 1) {
56+
if (num_devices <= 1) {
5857
return;
5958
}
6059
ASSERT_SUCCESS(urMemBufferCreate(context, 0 /*flags=*/, buffer_size_bytes,
@@ -148,7 +147,7 @@ struct urMultiDeviceContextMemBufferTest : urMultiDeviceContextTest {
148147
UUR_INSTANTIATE_PLATFORM_TEST_SUITE(urMultiDeviceContextMemBufferTest);
149148

150149
TEST_P(urMultiDeviceContextMemBufferTest, WriteRead) {
151-
if (num_devices == 1) {
150+
if (num_devices <= 1) {
152151
GTEST_SKIP();
153152
}
154153
T fill_val = 42;
@@ -172,7 +171,7 @@ TEST_P(urMultiDeviceContextMemBufferTest, WriteRead) {
172171
}
173172

174173
TEST_P(urMultiDeviceContextMemBufferTest, FillRead) {
175-
if (num_devices == 1) {
174+
if (num_devices <= 1) {
176175
GTEST_SKIP();
177176
}
178177
T fill_val = 42;
@@ -196,7 +195,7 @@ TEST_P(urMultiDeviceContextMemBufferTest, FillRead) {
196195
}
197196

198197
TEST_P(urMultiDeviceContextMemBufferTest, WriteKernelRead) {
199-
if (num_devices == 1) {
198+
if (num_devices <= 1) {
200199
GTEST_SKIP();
201200
}
202201

@@ -232,7 +231,7 @@ TEST_P(urMultiDeviceContextMemBufferTest, WriteKernelRead) {
232231
}
233232

234233
TEST_P(urMultiDeviceContextMemBufferTest, WriteKernelKernelRead) {
235-
if (num_devices == 1) {
234+
if (num_devices <= 1) {
236235
GTEST_SKIP();
237236
}
238237

0 commit comments

Comments
 (0)