Skip to content

Commit 1a48b0d

Browse files
committed
Improvements to align CTS and Spec for Loader.
- Add a null pointer check for urLoaderConfigCreate - Add a null pointer and invalid size check for urLoaderConfigGetinfo - Add invalid size test for urLoaderConfigGetInfo - Add reference count test for urLoaderConfigGetInfo - Add new test for urLoaderConfigSetCodeLocationCallback - Add new test for UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS to test the list is valid (empty or valid values) - Updated doc wording to say no layers are enabled by default
1 parent 7ecf64d commit 1a48b0d

File tree

9 files changed

+129
-11
lines changed

9 files changed

+129
-11
lines changed

include/ur_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ UR_APIEXPORT ur_result_t UR_APICALL
707707
urLoaderConfigEnableLayer(
708708
ur_loader_config_handle_t hLoaderConfig, ///< [in] Handle to config object the layer will be enabled for.
709709
const char *pLayerName ///< [in] Null terminated string containing the name of the layer to
710-
///< enable.
710+
///< enable. Empty if none are enabled.
711711
);
712712

713713
///////////////////////////////////////////////////////////////////////////////

scripts/core/INTRO.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ for these parameter structs can be found in the main API header.
286286
Layers
287287
---------------------
288288
UR comes with a mechanism that allows various API intercept layers to be enabled, either through the API or with an environment variable (see `Environment Variables`_).
289-
Layers currently included with the runtime are as follows:
289+
By default, no layers are enabled. Layers currently included with the runtime are as follows:
290290

291291
.. list-table::
292292
:header-rows: 1

scripts/core/loader.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ params:
135135
desc: "[in] Handle to config object the layer will be enabled for."
136136
- type: const char*
137137
name: pLayerName
138-
desc: "[in] Null terminated string containing the name of the layer to enable."
138+
desc: "[in] Null terminated string containing the name of the layer to enable. Empty if none are enabled."
139139
returns:
140140
- $X_RESULT_ERROR_LAYER_NOT_PRESENT:
141141
- "If layer specified with `pLayerName` can't be found by the loader."

source/loader/ur_libapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ ur_result_t UR_APICALL urLoaderConfigEnableLayer(
151151
hLoaderConfig, ///< [in] Handle to config object the layer will be enabled for.
152152
const char *
153153
pLayerName ///< [in] Null terminated string containing the name of the layer to
154-
///< enable.
154+
///< enable. Empty if none are enabled.
155155
) try {
156156
return ur_lib::urLoaderConfigEnableLayer(hLoaderConfig, pLayerName);
157157
} catch (...) {

source/ur_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ ur_result_t UR_APICALL urLoaderConfigEnableLayer(
143143
hLoaderConfig, ///< [in] Handle to config object the layer will be enabled for.
144144
const char *
145145
pLayerName ///< [in] Null terminated string containing the name of the layer to
146-
///< enable.
146+
///< enable. Empty if none are enabled.
147147
) {
148148
ur_result_t result = UR_RESULT_SUCCESS;
149149
return result;

test/loader/loader_config/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_ur_executable(test-loader-config
99
urLoaderConfigEnableLayer.cpp
1010
urLoaderConfigRelease.cpp
1111
urLoaderConfigRetain.cpp
12+
urLoaderConfigSetCodeLocationCallback.cpp
1213
)
1314

1415
target_link_libraries(test-loader-config

test/loader/loader_config/urLoaderConfigCreate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct LoaderConfigCreateTest : ::testing::Test {
1717

1818
TEST_F(LoaderConfigCreateTest, Success) {
1919
ASSERT_SUCCESS(urLoaderConfigCreate(&loaderConfig));
20+
ASSERT_TRUE(loaderConfig != nullptr);
2021
}
2122

2223
TEST_F(LoaderConfigCreateTest, InvalidNullPointerLoaderConfig) {

test/loader/loader_config/urLoaderConfigGetInfo.cpp

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "fixtures.hpp"
77

8-
struct urLoaderConfigGetInfoTest
8+
struct urLoaderConfigGetInfoWithParamTest
99
: LoaderConfigTest,
1010
::testing::WithParamInterface<ur_loader_config_info_t> {
1111
void SetUp() override {
@@ -23,30 +23,111 @@ struct urLoaderConfigGetInfoTest
2323
};
2424

2525
INSTANTIATE_TEST_SUITE_P(
26-
, urLoaderConfigGetInfoTest,
26+
, urLoaderConfigGetInfoWithParamTest,
2727
::testing::Values(UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS,
2828
UR_LOADER_CONFIG_INFO_REFERENCE_COUNT));
2929

30-
TEST_P(urLoaderConfigGetInfoTest, Success) {
30+
TEST_P(urLoaderConfigGetInfoWithParamTest, Success) {
3131
ASSERT_SUCCESS(urLoaderConfigGetInfo(loaderConfig, infoType, infoSize,
3232
infoAllocation.data(), nullptr));
3333
}
3434

35-
TEST_P(urLoaderConfigGetInfoTest, InvalidNullHandleLoaderConfig) {
35+
TEST_P(urLoaderConfigGetInfoWithParamTest, InvalidNullHandleLoaderConfig) {
3636
ASSERT_EQ(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
3737
urLoaderConfigGetInfo(nullptr, infoType, infoSize,
3838
infoAllocation.data(), nullptr));
3939
}
4040

41-
TEST_P(urLoaderConfigGetInfoTest, InvalidNullPointer) {
41+
TEST_P(urLoaderConfigGetInfoWithParamTest, InvalidNullPointer) {
42+
ASSERT_EQ(
43+
UR_RESULT_ERROR_INVALID_NULL_POINTER,
44+
urLoaderConfigGetInfo(loaderConfig, infoType, 1, nullptr, nullptr));
45+
4246
ASSERT_EQ(
4347
UR_RESULT_ERROR_INVALID_NULL_POINTER,
4448
urLoaderConfigGetInfo(loaderConfig, infoType, 0, nullptr, nullptr));
4549
}
4650

47-
TEST_P(urLoaderConfigGetInfoTest, InvalidEnumerationInfoType) {
51+
TEST_P(urLoaderConfigGetInfoWithParamTest, InvalidEnumerationInfoType) {
4852
ASSERT_EQ(UR_RESULT_ERROR_INVALID_ENUMERATION,
4953
urLoaderConfigGetInfo(loaderConfig,
5054
UR_LOADER_CONFIG_INFO_FORCE_UINT32, 0,
5155
nullptr, &infoSize));
5256
}
57+
58+
TEST_P(urLoaderConfigGetInfoWithParamTest, InvalidSize) {
59+
ASSERT_EQ(UR_RESULT_ERROR_INVALID_SIZE,
60+
urLoaderConfigGetInfo(loaderConfig, infoType, 0,
61+
infoAllocation.data(), &infoSize));
62+
63+
ASSERT_EQ(UR_RESULT_ERROR_INVALID_SIZE,
64+
urLoaderConfigGetInfo(loaderConfig, infoType, infoSize - 1,
65+
infoAllocation.data(), &infoSize));
66+
}
67+
68+
using urLoaderConfigGetInfoTest = LoaderConfigTest;
69+
70+
TEST_F(urLoaderConfigGetInfoTest, ReferenceCountNonZero) {
71+
uint32_t referenceCount = 0;
72+
ASSERT_SUCCESS(urLoaderConfigGetInfo(
73+
loaderConfig, UR_LOADER_CONFIG_INFO_REFERENCE_COUNT,
74+
sizeof(referenceCount), &referenceCount, nullptr));
75+
ASSERT_GT(referenceCount, 0);
76+
}
77+
78+
std::vector<std::string> splitString(const std::string &str, char delimiter) {
79+
std::vector<std::string> tokens;
80+
std::stringstream ss(str);
81+
std::string token;
82+
while (std::getline(ss, token, delimiter)) {
83+
tokens.push_back(token);
84+
}
85+
return tokens;
86+
}
87+
88+
bool isLayerStringValid(std::string &layersString,
89+
const std::vector<std::string> &validLayers) {
90+
if (layersString.empty()) {
91+
return true;
92+
}
93+
94+
layersString.pop_back(); // remove null terminator before comparing
95+
std::vector<std::string> layers = splitString(layersString, ';');
96+
97+
for (const std::string &layer : layers) {
98+
if (std::find(validLayers.begin(), validLayers.end(), layer) ==
99+
validLayers.end()) {
100+
return false;
101+
}
102+
}
103+
104+
return true;
105+
}
106+
107+
TEST_F(urLoaderConfigGetInfoTest, ValidLayersList) {
108+
std::vector<std::string> layerNames{
109+
"UR_LAYER_PARAMETER_VALIDATION",
110+
"UR_LAYER_BOUNDS_CHECKING",
111+
"UR_LAYER_LEAK_CHECKING",
112+
"UR_LAYER_LIFETIME_VALIDATION",
113+
"UR_LAYER_FULL_VALIDATION",
114+
"UR_LAYER_TRACING",
115+
"UR_LAYER_ASAN",
116+
"UR_LAYER_MSAN",
117+
"UR_LAYER_TSAN",
118+
};
119+
120+
std::string availableLayers;
121+
size_t availableLayersLength = 0;
122+
123+
ASSERT_SUCCESS(urLoaderConfigGetInfo(loaderConfig,
124+
UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS,
125+
0, nullptr, &availableLayersLength));
126+
127+
availableLayers.resize(availableLayersLength);
128+
ASSERT_SUCCESS(urLoaderConfigGetInfo(
129+
loaderConfig, UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS,
130+
availableLayersLength, availableLayers.data(), nullptr));
131+
132+
ASSERT_TRUE(isLayerStringValid(availableLayers, layerNames));
133+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
ur_code_location_t codeLocationCallback([[maybe_unused]] void *userData) {
9+
ur_code_location_t codeloc;
10+
codeloc.columnNumber = 1;
11+
codeloc.lineNumber = 2;
12+
codeloc.functionName = "fname";
13+
codeloc.sourceFile = "sfile";
14+
15+
return codeloc;
16+
}
17+
18+
struct urLoaderConfigSetCodeLocationCallbackTest : LoaderConfigTest {};
19+
20+
TEST_F(urLoaderConfigSetCodeLocationCallbackTest, Success) {
21+
ASSERT_SUCCESS(urLoaderConfigSetCodeLocationCallback(
22+
loaderConfig, codeLocationCallback, nullptr));
23+
}
24+
25+
TEST_F(urLoaderConfigSetCodeLocationCallbackTest, InvalidNullHandle) {
26+
ASSERT_EQ(urLoaderConfigSetCodeLocationCallback(
27+
nullptr, codeLocationCallback, nullptr),
28+
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
29+
}
30+
31+
TEST_F(urLoaderConfigSetCodeLocationCallbackTest, InvalidNullPointer) {
32+
ASSERT_EQ(
33+
urLoaderConfigSetCodeLocationCallback(loaderConfig, nullptr, nullptr),
34+
UR_RESULT_ERROR_INVALID_NULL_POINTER);
35+
}

0 commit comments

Comments
 (0)