Skip to content

Commit f124b82

Browse files
committed
Add unit test to check the aspect is correctly reported.
1 parent cedd602 commit f124b82

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_sycl_unittest(AssertTests OBJECT
22
assert.cpp
3+
support_native.cpp
34
)
45

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//==---------- support_native.cpp --- Check support is correctly reported --==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "ur_mock_helpers.hpp"
10+
11+
#include <sycl/sycl.hpp>
12+
13+
#include <helpers/UrMock.hpp>
14+
15+
#include <gtest/gtest.h>
16+
17+
template <bool Support>
18+
static ur_result_t redefinedDeviceGetInfoAfter(void *pParams) {
19+
auto &Params = *reinterpret_cast<ur_device_get_info_params_t *>(pParams);
20+
if (*Params.ppropName == UR_DEVICE_INFO_USE_NATIVE_ASSERT) {
21+
if (*Params.ppPropValue)
22+
*reinterpret_cast<ur_bool_t *>(*Params.ppPropValue) = Support;
23+
if (*Params.ppPropSizeRet)
24+
**Params.ppPropSizeRet = sizeof(ur_bool_t);
25+
}
26+
return UR_RESULT_SUCCESS;
27+
}
28+
29+
TEST(SupportNativeAssert, True) {
30+
mock::getCallbacks().set_after_callback("urDeviceGetInfo",
31+
&redefinedDeviceGetInfoAfter<true>);
32+
33+
sycl::unittest::UrMock<> Mock;
34+
sycl::platform Plt = sycl::platform();
35+
36+
const sycl::device Dev = Plt.get_devices()[0];
37+
38+
ASSERT_TRUE(Dev.has(sycl::aspect::ext_oneapi_native_assert));
39+
}
40+
41+
TEST(SupportNativeAssert, False) {
42+
mock::getCallbacks().set_after_callback("urDeviceGetInfo",
43+
&redefinedDeviceGetInfoAfter<false>);
44+
45+
sycl::unittest::UrMock<> Mock;
46+
sycl::platform Plt = sycl::platform();
47+
48+
const sycl::device Dev = Plt.get_devices()[0];
49+
50+
ASSERT_FALSE(Dev.has(sycl::aspect::ext_oneapi_native_assert));
51+
}

0 commit comments

Comments
 (0)