Skip to content

Commit

Permalink
[UR][Tests] Add a CMake option to limit the test devices count in CTS
Browse files Browse the repository at this point in the history
  • Loading branch information
szadam committed Oct 30, 2023
1 parent 31127d9 commit f2e3ee9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/scripts/devcloud-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ cmake \
-DUR_BUILD_TESTS=ON \
-DUR_FORMAT_CPP_STYLE=OFF \
-DUR_BUILD_ADAPTER_${adapter_name}=ON \
-DUR_CONFORMANCE_TARGET_TRIPLES=${adapter.triplet}
-DUR_CONFORMANCE_TARGET_TRIPLES=${adapter.triplet} \
-DUR_TEST_DEVICES_COUNT=1

cmake --build ${workspace}/build -j $(nproc)

Expand Down
3 changes: 2 additions & 1 deletion test/conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(UR_CONFORMANCE_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
option(UR_TEST_DEVICES_COUNT "Count of devices on which CTS will be run" 1)

function(add_test_adapter name adapter)
set(TEST_TARGET_NAME test-${name})
Expand All @@ -12,7 +13,7 @@ function(add_test_adapter name adapter)
add_test(NAME ${TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-D TEST_FILE=${Python3_EXECUTABLE}
-D TEST_ARGS="${UR_CONFORMANCE_TEST_DIR}/cts_exe.py --test_command ${CMAKE_BINARY_DIR}/bin/${TEST_TARGET_NAME}"
-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}"
-D MODE=stdout
-D MATCH_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_${adapter}.match
-P ${PROJECT_SOURCE_DIR}/cmake/match.cmake
Expand Down
9 changes: 8 additions & 1 deletion test/conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ In the future, when all bugs are fixed, and the tests pass,
this solution will no longer be necessary.
When you fix any test, the match file must be updated
Empty match files indicate that there are no failing tests
in a particular group for the corresponding adapter.
in a particular group for the corresponding adapter.

## How to limit the test devices count

To limit how many devices you want to run the CTS on,
use CMake option UR_TEST_DEVICES_COUNT. If you want to run
the tests on all available devices, set 0.
The default value is 1.
4 changes: 3 additions & 1 deletion test/conformance/cts_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

parser = ArgumentParser()
parser.add_argument("--test_command", help="Ctest test case")
parser.add_argument("--test_devices_count", type=str, help="Number of devices on which tests will be run")
args = parser.parse_args()

result = subprocess.Popen([args.test_command, '--gtest_brief=1'], stdout = subprocess.PIPE, text = True) # nosec B603
result = subprocess.Popen([args.test_command, '--gtest_brief=1', args.test_devices_count], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, text=True) # nosec B603

pat = re.compile(r'\[( )*FAILED( )*\]')
output_list = []
Expand Down
16 changes: 16 additions & 0 deletions test/conformance/source/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <algorithm>
#include <cstring>
#include <fstream>

Expand All @@ -12,6 +13,7 @@
#include "kernel_entry_points.h"
#endif

#include <ur_util.hpp>
#include <uur/environment.h>
#include <uur/utils.h>

Expand Down Expand Up @@ -184,6 +186,7 @@ PlatformEnvironment::parsePlatformOptions(int argc, char **argv) {

DevicesEnvironment *DevicesEnvironment::instance = nullptr;

// The third expected parameter of argv is test_devices_count.
DevicesEnvironment::DevicesEnvironment(int argc, char **argv)
: PlatformEnvironment(argc, argv) {
instance = this;
Expand All @@ -199,6 +202,19 @@ DevicesEnvironment::DevicesEnvironment(int argc, char **argv)
error = "Could not find any devices associated with the platform";
return;
}
// Get the argument (test_devices_count) to limit test devices count.
u_long count_set = 0;
if (argc >= 3) {
count_set = std::strtoul(argv[2], nullptr, 10);
}
// In case, the count_set is "0", the variable count will not be changed.
// The CTS will run on all devices.
if (count_set > (std::numeric_limits<uint32_t>::max)()) {
error = "Invalid test_devices_count argument";
return;
} else if (count_set > 0) {
count = std::min(count, static_cast<uint32_t>(count_set));
}
devices.resize(count);
if (urDeviceGet(platform, UR_DEVICE_TYPE_ALL, count, devices.data(),
nullptr)) {
Expand Down

0 comments on commit f2e3ee9

Please sign in to comment.