Skip to content

Commit 584314d

Browse files
committed
[UR][Tests] Add a CMake option to limit the test devices count
and test platforms count in CTS.
1 parent 95db255 commit 584314d

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

test/conformance/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
set(UR_CONFORMANCE_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
7+
option(UR_TEST_DEVICES_COUNT "Count of devices on which CTS will be run" 1)
8+
option(UR_TEST_PLATFORMS_COUNT "Count of platforms on which CTS will be run" 1)
79

810
function(add_test_adapter name adapter)
911
set(TEST_TARGET_NAME test-${name})
@@ -12,7 +14,7 @@ function(add_test_adapter name adapter)
1214
add_test(NAME ${TEST_NAME}
1315
COMMAND ${CMAKE_COMMAND}
1416
-D TEST_FILE=${Python3_EXECUTABLE}
15-
-D TEST_ARGS="${UR_CONFORMANCE_TEST_DIR}/cts_exe.py --test_command ${CMAKE_BINARY_DIR}/bin/${TEST_TARGET_NAME}"
17+
-D TEST_ARGS="${UR_CONFORMANCE_TEST_DIR}/cts_exe.py --test_command ${CMAKE_BINARY_DIR}/bin/${TEST_TARGET_NAME} --test_devices_count=${UR_TEST_DEVICES_COUNT} --test_platforms_count=${UR_TEST_PLATFORMS_COUNT}"
1618
-D MODE=stdout
1719
-D MATCH_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_${adapter}.match
1820
-P ${PROJECT_SOURCE_DIR}/cmake/match.cmake

test/conformance/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ In the future, when all bugs are fixed, and the tests pass,
88
this solution will no longer be necessary.
99
When you fix any test, the match file must be updated
1010
Empty match files indicate that there are no failing tests
11-
in a particular group for the corresponding adapter.
11+
in a particular group for the corresponding adapter.
12+
13+
## How to limit the test devices count
14+
15+
To limit how many devices you want to run the CTS on,
16+
use CMake option UR_TEST_DEVICES_COUNT. If you want to run
17+
the tests on all available devices, set 0.
18+
The default value is 1.

test/conformance/cts_exe.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
parser = ArgumentParser()
2222
parser.add_argument("--test_command", help="Ctest test case")
23+
parser.add_argument("--test_devices_count", type=str, help="Number of devices on which tests will be run")
24+
parser.add_argument("--test_platforms_count", type=str, help="Number of platforms on which tests will be run")
2325
args = parser.parse_args()
2426

25-
result = subprocess.Popen([args.test_command, '--gtest_brief=1'], stdout = subprocess.PIPE, text = True) # nosec B603
27+
result = subprocess.Popen([args.test_command, '--gtest_brief=1', f'--devices_count={args.test_devices_count}',
28+
f'--platforms_count={args.test_platforms_count}'],
29+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) # nosec B603
2630

2731
pat = re.compile(r'\[( )*FAILED( )*\]')
2832
output_list = []

test/conformance/source/environment.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
#include <algorithm>
67
#include <cstring>
78
#include <fstream>
89

@@ -209,6 +210,22 @@ DevicesEnvironment::DevicesEnvironment(int argc, char **argv)
209210
error = "Could not find any devices associated with the platform";
210211
return;
211212
}
213+
// Get the argument (test_devices_count) to limit test devices count.
214+
u_long count_set = 0;
215+
for (int i = 1; i < argc; ++i) {
216+
if (std::strcmp(argv[i], "--test_devices_count") == 0 && i + 1 < argc) {
217+
count_set = std::strtoul(argv[i + 1], nullptr, 10);
218+
break;
219+
}
220+
}
221+
// In case, the count_set is "0", the variable count will not be changed.
222+
// The CTS will run on all devices.
223+
if (count_set > (std::numeric_limits<uint32_t>::max)()) {
224+
error = "Invalid test_devices_count argument";
225+
return;
226+
} else if (count_set > 0) {
227+
count = (std::min)(count, static_cast<uint32_t>(count_set));
228+
}
212229
devices.resize(count);
213230
if (urDeviceGet(platform, UR_DEVICE_TYPE_ALL, count, devices.data(),
214231
nullptr)) {

0 commit comments

Comments
 (0)