Skip to content

Commit f1dd200

Browse files
committed
[UR] Add tests for lifetime validation
1 parent f7bd6d9 commit f1dd200

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

test/layers/validation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ endfunction()
5252
add_validation_test(parameters parameters.cpp)
5353
add_validation_match_test(leaks leaks.out.match leaks.cpp)
5454
add_validation_match_test(leaks_mt leaks_mt.out.match leaks_mt.cpp)
55+
add_validation_match_test(lifetime lifetime.out.match lifetime.cpp)

test/layers/validation/fixtures.hpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,57 @@ struct urTest : ::testing::Test {
3030
ur_loader_config_handle_t loader_config = nullptr;
3131
};
3232

33-
struct valPlatformsTest : urTest {
33+
struct valAdaptersTest : urTest {
3434

3535
void SetUp() override {
3636
urTest::SetUp();
3737

3838
uint32_t adapter_count;
3939
ASSERT_EQ(urAdapterGet(0, nullptr, &adapter_count), UR_RESULT_SUCCESS);
40+
ASSERT_GT(adapter_count, 0);
4041
adapters.resize(adapter_count);
4142
ASSERT_EQ(urAdapterGet(adapter_count, adapters.data(), nullptr),
4243
UR_RESULT_SUCCESS);
43-
44-
uint32_t count;
45-
ASSERT_EQ(
46-
urPlatformGet(adapters.data(), adapter_count, 0, nullptr, &count),
47-
UR_RESULT_SUCCESS);
48-
ASSERT_NE(count, 0);
49-
platforms.resize(count);
50-
ASSERT_EQ(urPlatformGet(adapters.data(), adapter_count, count,
51-
platforms.data(), nullptr),
52-
UR_RESULT_SUCCESS);
5344
}
5445

5546
void TearDown() override {
56-
for (auto &adapter : adapters) {
47+
for (auto adapter : adapters) {
5748
ASSERT_EQ(urAdapterRelease(adapter), UR_RESULT_SUCCESS);
5849
}
5950
urTest::TearDown();
6051
}
6152

6253
std::vector<ur_adapter_handle_t> adapters;
54+
};
55+
56+
struct valAdapterTest : valAdaptersTest {
57+
58+
void SetUp() override {
59+
valAdaptersTest::SetUp();
60+
adapter = adapters[0]; // TODO - which to choose?
61+
}
62+
63+
ur_adapter_handle_t adapter;
64+
};
65+
66+
struct valPlatformsTest : valAdaptersTest {
67+
68+
void SetUp() override {
69+
valAdaptersTest::SetUp();
70+
71+
uint32_t count;
72+
ASSERT_EQ(urPlatformGet(adapters.data(),
73+
static_cast<uint32_t>(adapters.size()), 0,
74+
nullptr, &count),
75+
UR_RESULT_SUCCESS);
76+
ASSERT_GT(count, 0);
77+
platforms.resize(count);
78+
ASSERT_EQ(urPlatformGet(adapters.data(),
79+
static_cast<uint32_t>(adapters.size()), count,
80+
platforms.data(), nullptr),
81+
UR_RESULT_SUCCESS);
82+
}
83+
6384
std::vector<ur_platform_handle_t> platforms;
6485
};
6586

test/layers/validation/lifetime.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2023 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+
#include "fixtures.hpp"
7+
8+
TEST_F(urTest, testUrAdapterHandleLifetimeExpectFail) {
9+
size_t size = 0;
10+
ur_adapter_handle_t adapter = (ur_adapter_handle_t)0xC0FFEE;
11+
ur_adapter_info_t info_type = UR_ADAPTER_INFO_BACKEND;
12+
ASSERT_EQ(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size),
13+
UR_RESULT_ERROR_INVALID_ARGUMENT);
14+
}
15+
16+
TEST_F(valAdapterTest, testUrAdapterHandleLifetimeExpectSuccess) {
17+
size_t size = 0;
18+
ur_adapter_info_t info_type = UR_ADAPTER_INFO_BACKEND;
19+
ASSERT_EQ(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size),
20+
UR_RESULT_SUCCESS);
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{IGNORE}}
2+
[ RUN ] urTest.testUrAdapterHandleLifetimeExpectFail
3+
<VALIDATION>[ERROR]: There are no valid references to handle {{[0-9xa-fA-F]+}}
4+
{{IGNORE}}
5+
[ RUN ] valAdapterTest.testUrAdapterHandleLifetimeExpectSuccess
6+
{{^(?!.*There are no valid references to handle).*$}}
7+
{{IGNORE}}

0 commit comments

Comments
 (0)