Skip to content

Commit c51833a

Browse files
Add tests
1 parent bda4569 commit c51833a

File tree

449 files changed

+40193
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

449 files changed

+40193
-0
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: LLVM
2+
SortIncludes: false

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "third_party/googletest"]
2+
path = third_party/googletest
3+
url = https://github.com/google/googletest.git

BUILD.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# oneAPI Level Zero Tests Build Guide
2+
3+
## Dependencies
4+
5+
### Linux Dependencies
6+
Requires the `level-zero`, `level-zero-devel`, `opencl-headers`,
7+
`libpng-dev`, `ocl-icd-opencl-dev`, `libboost-all-dev`, & `libva-dev` packages
8+
to be installed.
9+
10+
### Dependencies
11+
For building against level-zero, you can either build against the version you
12+
have installed on your system (automatic, Linux only), or specify an install
13+
prefix with the `L0_ROOT` cmake flag during configuration.
14+
This `L0_ROOT` must point to the top-level install directory where level-zero was installed.
15+
for example: `-DL0_ROOT=/home/username/level-zero/build/output/`.
16+
17+
Some tests depend on level-zero's OpenCL interop functionality in order to work.
18+
If OpenCL is available on the system (specify a non-standard path with
19+
`OPENCL_ROOT`), then the interop support will be enabled automatically. To
20+
require the interop support, set the `REQUIRE_LEVELZERO_OPENCL_INTEROP` cmake
21+
flag to `YES`.
22+
23+
Some benchmarks written against OpenCL are included to enable easy performance
24+
comparisons. These benchmarks will be built automatically if OpenCL is available
25+
on the system. To require that these benchmarks also be built, set the
26+
`REQUIRE_OPENCL_BENCHMARKS` cmake flag to `YES`.
27+
28+
[Google Test](https://github.com/google/googletest) is used by all tests in this
29+
repo for handling test case generation and result analysis.
30+
31+
Google Test is included as a submodule at `third_party/googletest`. You can
32+
provide a path to your own version with the `GTEST_ROOT` cmake flag.
33+
34+
## Building
35+
36+
This project uses cmake to configure the build. By default, all the tests are
37+
built.
38+
39+
The `install` target will by default create an `out` directory in your cmake
40+
build directory containing the built test executables and their data files.
41+
Nothing will get installed to any system paths. You can override the default
42+
install location by setting `CMAKE_INSTALL_PREFIX`.
43+
44+
```
45+
mkdir build
46+
cd build
47+
cmake -D CMAKE_INSTALL_PREFIX=$PWD/../out ..
48+
cmake --build . --config Release --target install
49+
```
50+
51+
### Building a subset of the test executables
52+
53+
Test executables are divided into a group hierarchy, and it is possible to
54+
select a specific grouping of test executables for build using the `GROUP`
55+
cmake flag. The following group specifiers are available:
56+
57+
- `/`: All tests.
58+
- `/perf_tests`: All the performance tests.
59+
- `/negative_tests`: All the negative tests.
60+
- `/conformance_tests`: All the conformance tests.
61+
- `/conformance_tests/core`: All of the conformance tests for the core API.
62+
- `/conformance_tests/tools`: All of the conformance tests for the tools API.
63+
- `/conformance_tests/tools/tracing`: All of the tools API conformance tests
64+
related to tracing.
65+
- `/conformance_tests/tools/sysman`: ALl of the tools API conformance tests
66+
relating to system management.
67+
- `/conformance_tests/tools/pin`: ALl of the tools API conformance tests
68+
relating to Instrumenting of L0 applications.
69+
70+
```
71+
cmake
72+
-D GROUP=/perf_tests
73+
-D CMAKE_INSTALL_PREFIX=$PWD/../out/perf_tests
74+
..
75+
cmake --build . --config Release --target install
76+
```
77+
78+
The group that any particular test executable belongs to can be seen by looking
79+
in its `CMakeLists.txt` file at the `add_lzt_test()` call.

CMakeLists.txt

+287
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
# Copyright (C) 2019 Intel Corporation
2+
# SPDX-License-Identifier: MIT
3+
4+
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
5+
if(POLICY CMP0074)
6+
cmake_policy(SET CMP0074 NEW)
7+
endif()
8+
project(level-zero-tests)
9+
10+
# Generate VERSION and VERSION_SUFFIX (if building in tree) files to facilitate
11+
# artifact publishing.
12+
file(WRITE "${CMAKE_BINARY_DIR}/VERSION" "${PROJECT_VERSION}")
13+
find_program(GIT_EXE NAMES "git")
14+
if(GIT_EXE AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
15+
if(MSVC)
16+
execute_process(
17+
COMMAND CMD /c git rev-list --count HEAD
18+
OUTPUT_VARIABLE VERSION_SUFFIX
19+
)
20+
else()
21+
execute_process(
22+
COMMAND git rev-list --count HEAD
23+
OUTPUT_VARIABLE VERSION_SUFFIX
24+
)
25+
endif()
26+
string(STRIP "${VERSION_SUFFIX}" VERSION_SUFFIX)
27+
file(WRITE "${CMAKE_BINARY_DIR}/VERSION_SUFFIX" "${VERSION_SUFFIX}")
28+
endif()
29+
30+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
31+
32+
include(clang_tools)
33+
include(custom_functions)
34+
include(vs2019_missing_redist_workaround)
35+
36+
find_package(PNG REQUIRED)
37+
38+
if(NOT TARGET GTest::GTest AND NOT TARGET GMock::GMock)
39+
if(NOT DEFINED GTEST_ROOT)
40+
set(GTEST_ROOT "${CMAKE_SOURCE_DIR}/third_party/googletest")
41+
if(NOT EXISTS GTEST_ROOT)
42+
if(GIT_EXE AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
43+
set(SUBMODULE_INIT_CMD submodule update --init --recursive)
44+
set(SUBMODULE_INIT_CMD_STRING "submodule update --init --recursive")
45+
message(WARNING "Unable to locate third_party/googletest submodule in checkout - Trying to fetch with ${GIT_EXE} ${SUBMODULE_INIT_CMD_STRING}")
46+
execute_process(
47+
COMMAND ${GIT_EXE} ${SUBMODULE_INIT_CMD}
48+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
49+
RESULT_VARIABLE SUBMODULE_INIT_RESULT)
50+
if(NOT SUBMODULE_INIT_RESULT EQUAL "0")
51+
message(FATAL_ERROR "Google test submodule checkout failed with ${SUBMODULE_INIT_RESULT}")
52+
endif()
53+
endif()
54+
endif()
55+
endif()
56+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
57+
add_subdirectory("${GTEST_ROOT}" "${GTEST_ROOT}/build" EXCLUDE_FROM_ALL)
58+
add_library(GTest::GTest ALIAS gtest)
59+
add_library(GMock::GMock ALIAS gmock)
60+
endif()
61+
enable_testing()
62+
63+
set(Boost_USE_STATIC_LIBS ON)
64+
set(Boost_USE_MULTITHREADED ON)
65+
set(Boost_USE_STATIC_RUNTIME OFF)
66+
find_package(Boost 1.65 REQUIRED COMPONENTS log program_options timer chrono system)
67+
68+
option(REQUIRE_LEVELZERO_OPENCL_INTEROP
69+
"Enables OpenCL interop testing with oneAPI Level Zero (requires OpenCL)"
70+
NO
71+
)
72+
if(REQUIRE_LEVELZERO_OPENCL_INTEROP)
73+
list(APPEND LevelZero_COMPONENTS "OpenCL")
74+
endif()
75+
76+
find_package(LevelZero REQUIRED COMPONENTS ${LevelZero_COMPONENTS})
77+
78+
option(REQUIRE_OPENCL_BENCHMARKS
79+
"Ensures that the OpenCL benchmarks are also built (requires OpenCL)"
80+
NO
81+
)
82+
if(REQUIRE_OPENCL_BENCHMARKS)
83+
find_package(OpenCL 2.1 REQUIRED)
84+
if(NOT OpenCL_FOUND)
85+
message(ERROR "OpenCL Benchmarks were requested but OpenCL was not found.")
86+
endif()
87+
endif()
88+
89+
set(MEDIA_ROOT_DIRECTORY "${CMAKE_SOURCE_DIR}/mediadata")
90+
set(MEDIA_DIRECTORY "${MEDIA_ROOT_DIRECTORY}/merged")
91+
set(MEDIADATA_ROOT "${MEDIA_ROOT_DIRECTORY}/external")
92+
file(COPY "${MEDIA_ROOT_DIRECTORY}/internal/bmp" DESTINATION "${MEDIA_DIRECTORY}")
93+
file(COPY "${MEDIA_ROOT_DIRECTORY}/internal/png" DESTINATION "${MEDIA_DIRECTORY}")
94+
95+
if(NOT DEFINED GROUP)
96+
set(GROUP "/")
97+
endif()
98+
99+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
100+
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/out" CACHE PATH "..." FORCE)
101+
endif()
102+
103+
function(assert_valid_test_group_name group_name)
104+
set(regex "^([/]([A-Za-z0-9_]*))*$")
105+
string(REGEX MATCH "${regex}" valid_name "${group_name}")
106+
if(NOT "${group_name}" STREQUAL "${valid_name}")
107+
message(FATAL_ERROR "${group_name} is not a valid test group name, valid regex: ${regex}")
108+
endif()
109+
endfunction()
110+
111+
# Cmake 3.8 doesn't support the list(SUBLIST ...) command
112+
function(list_sublist list_var start_index length result_var)
113+
if(length EQUAL 0)
114+
set("${result_var}" "" PARENT_SCOPE)
115+
return()
116+
endif()
117+
math(EXPR end_index "${start_index}+${length}-1")
118+
set("${result_var}" "")
119+
foreach(index RANGE ${start_index} ${end_index})
120+
list(GET "${list_var}" "${index}" item)
121+
list(APPEND "${result_var}" "${item}")
122+
endforeach()
123+
set("${result_var}" "${${result_var}}" PARENT_SCOPE)
124+
endfunction()
125+
126+
function(is_test_group_member group1 group2 result_var)
127+
assert_valid_test_group_name("${group1}")
128+
assert_valid_test_group_name("${group2}")
129+
string(REGEX MATCHALL "([A-Za-z0-9_])+" group1_list "${group1}")
130+
string(REGEX MATCHALL "([A-Za-z0-9_])+" group2_list "${group2}")
131+
list(LENGTH group1_list group1_list_length)
132+
list(LENGTH group2_list group2_list_length)
133+
if(group1_list_length GREATER group2_list_length)
134+
set(list_length ${group2_list_length})
135+
else()
136+
set(list_length ${group1_list_length})
137+
endif()
138+
# list(SUBLIST group2_list 0 "${group1_list_length}" group2_common)
139+
list_sublist(group2_list 0 "${list_length}" group2_common)
140+
if(group2_common STREQUAL group1_list)
141+
set("${result_var}" "TRUE" PARENT_SCOPE)
142+
else()
143+
set("${result_var}" "FALSE" PARENT_SCOPE)
144+
endif()
145+
endfunction()
146+
147+
function(add_lzt_test_executable)
148+
set(options "")
149+
set(oneValueArgs NAME PREFIX GROUP)
150+
set(multiValueArgs SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES KERNELS MEDIA)
151+
cmake_parse_arguments(ADD_LZT_TEST_EXECUTABLE
152+
"${options}" "${oneValueArgs}" "${multiValueArgs}"
153+
${ARGN}
154+
)
155+
156+
assert_valid_test_group_name("${ADD_LZT_TEST_EXECUTABLE_GROUP}")
157+
158+
is_test_group_member("${GROUP}" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" in_scope)
159+
if(NOT in_scope)
160+
return()
161+
endif()
162+
163+
is_test_group_member("/conformance_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_conformance_test)
164+
is_test_group_member("/perf_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_perf_test)
165+
is_test_group_member("/negative_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_negative_test)
166+
if(is_conformance_test)
167+
list(APPEND ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES
168+
level_zero_tests::test_harness
169+
GMock::GMock
170+
GTest::GTest
171+
)
172+
set(component "conformance-tests")
173+
elseif(is_negative_test)
174+
list(APPEND ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES
175+
level_zero_tests::test_harness
176+
GMock::GMock
177+
GTest::GTest
178+
)
179+
set(component "negative-tests")
180+
elseif(is_perf_test)
181+
list(APPEND ADD_LZT_TEST_EXECUTABLE_INCLUDE_DIRECTORIES
182+
${CMAKE_SOURCE_DIR}/perf_tests/common/include
183+
)
184+
set(component "perf-tests")
185+
endif()
186+
187+
add_executable(${ADD_LZT_TEST_EXECUTABLE_NAME} ${ADD_LZT_TEST_EXECUTABLE_SOURCES})
188+
189+
target_link_libraries(${ADD_LZT_TEST_EXECUTABLE_NAME}
190+
PRIVATE
191+
LevelZero::LevelZero
192+
${ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES}
193+
)
194+
195+
target_include_directories(${ADD_LZT_TEST_EXECUTABLE_NAME}
196+
PRIVATE
197+
${CMAKE_CURRENT_SOURCE_DIR}/include
198+
${ADD_LZT_TEST_EXECUTABLE_INCLUDE_DIRECTORIES}
199+
)
200+
201+
set(destination "${CMAKE_INSTALL_PREFIX}/${ADD_LZT_TEST_EXECUTABLE_PREFIX}")
202+
203+
foreach(kernel ${ADD_LZT_TEST_EXECUTABLE_KERNELS})
204+
install(
205+
FILES "${CMAKE_CURRENT_SOURCE_DIR}/kernels/${kernel}.spv"
206+
DESTINATION ${destination}
207+
)
208+
endforeach()
209+
210+
foreach(media ${ADD_LZT_TEST_EXECUTABLE_MEDIA})
211+
install(
212+
FILES "${MEDIA_DIRECTORY}/${media}"
213+
DESTINATION ${destination}
214+
)
215+
endforeach()
216+
217+
install(
218+
TARGETS ${ADD_LZT_TEST_EXECUTABLE_NAME}
219+
DESTINATION ${destination}
220+
COMPONENT ${component}
221+
)
222+
223+
if(MSVC)
224+
set_target_properties(${ADD_LZT_TEST_EXECUTABLE_NAME}
225+
PROPERTIES
226+
VS_DEBUGGER_COMMAND_ARGUMENTS ""
227+
VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)"
228+
)
229+
endif()
230+
endfunction()
231+
232+
function(add_lzt_test)
233+
set(options REQUIRES_OPENCL_INTEROP)
234+
set(oneValueArgs NAME GROUP)
235+
set(multiValueArgs SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES KERNELS MEDIA)
236+
cmake_parse_arguments(ADD_LZT_TEST
237+
"${options}" "${oneValueArgs}" "${multiValueArgs}"
238+
${ARGN}
239+
)
240+
241+
assert_valid_test_group_name("${ADD_LZT_TEST_GROUP}")
242+
243+
is_test_group_member("${GROUP}" "${ADD_LZT_TEST_GROUP}" in_scope)
244+
if(NOT in_scope)
245+
message(STATUS "Ignoring ${ADD_LZT_TEST_NAME} because it is not in ${GROUP}")
246+
return()
247+
else()
248+
message(STATUS "Adding ${ADD_LZT_TEST_NAME}")
249+
endif()
250+
251+
if(
252+
ADD_LZT_TEST_REQUIRES_OPENCL_INTEROP AND
253+
NOT LevelZero_OpenCL_INTEROP
254+
)
255+
message(STATUS "Disabling build of ${ADD_LZT_TEST_NAME} since oneAPI Level Zero OpenCL interop is not available")
256+
return()
257+
endif()
258+
259+
add_lzt_test_executable(
260+
NAME ${ADD_LZT_TEST_NAME}
261+
GROUP ${ADD_LZT_TEST_GROUP}
262+
SOURCES ${ADD_LZT_TEST_SOURCES}
263+
INCLUDE_DIRECTORIES ${ADD_LZT_TEST_INCLUDE_DIRECTORIES}
264+
LINK_LIBRARIES ${ADD_LZT_TEST_LINK_LIBRARIES}
265+
KERNELS ${ADD_LZT_TEST_KERNELS}
266+
MEDIA ${ADD_LZT_TEST_MEDIA}
267+
)
268+
269+
file(APPEND
270+
"${CMAKE_INSTALL_PREFIX}/manifest.txt"
271+
"${ADD_LZT_TEST_NAME}${CMAKE_NEWLINE}"
272+
)
273+
endfunction()
274+
275+
if(WIN32)
276+
set(CMAKE_NEWLINE "\r\n")
277+
else()
278+
set(CMAKE_NEWLINE "\n")
279+
endif()
280+
281+
add_subdirectory(utils)
282+
add_subdirectory(perf_tests)
283+
add_subdirectory(conformance_tests)
284+
add_subdirectory(negative_tests)
285+
286+
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION "${CMAKE_BINARY_DIR}/out")
287+
include(InstallRequiredSystemLibraries)

0 commit comments

Comments
 (0)