Skip to content

Commit d5a90ad

Browse files
committed
Refactor fuzz tests
1 parent afefdaa commit d5a90ad

File tree

4 files changed

+120
-141
lines changed

4 files changed

+120
-141
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
name: Build - Fuzztests on L0 HW - Reusable
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
test_label:
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
fuzztest-build-hw:
16+
name: Build and run fuzz tests on L0 HW
17+
if: github.repository == 'oneapi-src/unified-runtime' # run only on upstream; forks won't have the HW
18+
strategy:
19+
matrix:
20+
build_type: [Debug, Release]
21+
compiler: [{c: clang, cxx: clang++}]
22+
23+
runs-on: 'FUZZTESTS'
24+
# In order to use sanitizers, vm.mmap_rnd_bits=28 must be set in the system,
25+
# otherwise random SEGV at the start of the test occurs.
26+
# Alternatively, clang 18.1.0 onwards with fixed sanitizers behavior can be used,
27+
# if available.
28+
# TODO: Remove this advice once clang 18.1.0 is available in the system (like ie. as an apt package).
29+
30+
steps:
31+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
32+
33+
- name: Install pip packages
34+
run: pip install -r third_party/requirements.txt
35+
36+
- name: Download DPC++
37+
run: |
38+
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/nightly-2024-01-29/sycl_linux.tar.gz
39+
mkdir dpcpp_compiler
40+
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz -C dpcpp_compiler
41+
42+
- name: Build level zero with gcc
43+
run: |
44+
git clone -b v1.17.6 --depth=1 https://github.com/oneapi-src/level-zero.git ${{github.workspace}}/level-zero
45+
cd ${{github.workspace}}/level-zero
46+
cmake -B build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
47+
cmake --build build -j $(nproc)
48+
49+
- name: Configure CMake
50+
run: >
51+
cmake
52+
-B${{github.workspace}}/build
53+
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
54+
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
55+
-DUR_ENABLE_TRACING=ON
56+
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
57+
-DUR_BUILD_TESTS=ON
58+
-DUR_USE_ASAN=ON
59+
-DUR_USE_UBSAN=ON
60+
-DUR_BUILD_ADAPTER_L0=ON
61+
-DUR_LEVEL_ZERO_LOADER_LIBRARY=${{github.workspace}}/level-zero/build/lib/libze_loader.so
62+
-DUR_LEVEL_ZERO_INCLUDE_DIR=${{github.workspace}}/level-zero/include/
63+
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
64+
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
65+
66+
- name: Build
67+
run: cmake --build ${{github.workspace}}/build -j $(nproc)
68+
69+
- name: Fuzz test
70+
working-directory: ${{github.workspace}}/build
71+
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "${{inputs.test_label}}" --verbose
72+
73+
- name: Get information about platform
74+
if: ${{ always() }}
75+
run: .github/scripts/get_system_info.sh

.github/workflows/cmake.yml

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -116,66 +116,12 @@ jobs:
116116
working-directory: ${{github.workspace}}/build
117117
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "umf|loader|validation|tracing|unit|urtrace"
118118

119-
fuzztest-build-hw:
120-
name: Build and run quick fuzztest scenarios on L0 HW
121-
if: github.repository == 'oneapi-src/unified-runtime' # run only on upstream; forks won't have the HW
122-
strategy:
123-
matrix:
124-
build_type: [Debug, Release]
125-
compiler: [{c: clang, cxx: clang++}]
126-
127-
runs-on: 'FUZZTESTS'
128-
129-
steps:
130-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
131-
132-
- name: Install pip packages
133-
run: pip install -r third_party/requirements.txt
134-
135-
- name: Download DPC++
136-
run: |
137-
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/sycl-nightly%2F20230626/dpcpp-compiler.tar.gz
138-
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz
139-
140-
- name: Setup DPC++
141-
run: |
142-
source ${{github.workspace}}/dpcpp_compiler/startup.sh
143-
144-
- name: Build level zero
145-
run: |
146-
git clone -b v1.17.6 --depth=1 https://github.com/oneapi-src/level-zero.git ${{github.workspace}}/level-zero
147-
cd ${{github.workspace}}/level-zero
148-
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
149-
cmake --build build -j $(nproc)
150-
151-
- name: Configure CMake
152-
run: >
153-
cmake
154-
-B${{github.workspace}}/build
155-
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
156-
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
157-
-DUR_ENABLE_TRACING=ON
158-
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
159-
-DUR_BUILD_TESTS=ON
160-
-DUR_USE_ASAN=ON
161-
-DUR_USE_UBSAN=ON
162-
-DUR_BUILD_ADAPTER_L0=ON
163-
-DUR_LEVEL_ZERO_LOADER_LIBRARY=${{github.workspace}}/level-zero/build/lib/libze_loader.so
164-
-DUR_LEVEL_ZERO_INCLUDE_DIR=${{github.workspace}}/level-zero/include/
165-
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
166-
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
167-
168-
- name: Build
169-
run: cmake --build ${{github.workspace}}/build -j $(nproc)
170-
171-
- name: Fuzz test
172-
working-directory: ${{github.workspace}}/build
173-
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "fuzz-short" --verbose
174-
175-
- name: Get information about platform
176-
if: ${{ always() }}
177-
run: .github/scripts/get_system_info.sh
178-
119+
fuzztest:
120+
name: Fuzz tests short
121+
uses: ./.github/workflows/build-fuzz-reusable.yml
122+
with:
123+
test_label: "fuzz-short"
124+
179125
level-zero:
180126
name: Level Zero
181127
uses: ./.github/workflows/build-hw-reusable.yml

.github/workflows/nightly.yml

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,8 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
long-fuzz-test-hw:
13-
name: Run long fuzz tests
14-
if: github.repository == 'oneapi-src/unified-runtime' # run only on upstream; forks won't have the HW
15-
strategy:
16-
matrix:
17-
build_type: [Debug, Release]
18-
compiler: [{c: clang, cxx: clang++}]
19-
20-
runs-on: 'FUZZTESTS'
21-
22-
steps:
23-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
24-
25-
- name: Install pip packages
26-
run: pip install -r third_party/requirements.txt
27-
28-
- name: Download DPC++
29-
run: |
30-
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/nightly-2024-01-29/sycl_linux.tar.gz
31-
mkdir dpcpp_compiler
32-
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz -C dpcpp_compiler
33-
34-
- name: Build level zero
35-
run: |
36-
git clone -b v1.17.6 --depth=1 https://github.com/oneapi-src/level-zero.git ${{github.workspace}}/level-zero
37-
cd ${{github.workspace}}/level-zero
38-
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
39-
cmake --build build -j $(nproc)
40-
41-
- name: Configure CMake
42-
run: >
43-
cmake
44-
-B${{github.workspace}}/build
45-
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
46-
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
47-
-DUR_ENABLE_TRACING=ON
48-
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
49-
-DUR_BUILD_TESTS=ON
50-
-DUR_USE_ASAN=ON
51-
-DUR_USE_UBSAN=ON
52-
-DUR_BUILD_ADAPTER_L0=ON
53-
-DUR_LEVEL_ZERO_LOADER_LIBRARY=${{github.workspace}}/level-zero/build/lib/libze_loader.so
54-
-DUR_LEVEL_ZERO_INCLUDE_DIR=${{github.workspace}}/level-zero/include/
55-
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
56-
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
57-
58-
- name: Build
59-
run: |
60-
cmake --build ${{github.workspace}}/build -j $(nproc)
61-
62-
- name: Fuzz long test
63-
working-directory: ${{github.workspace}}/build
64-
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "fuzz-long" --verbose
65-
66-
- name: Get information about platform
67-
if: ${{ always() }}
68-
run: .github/scripts/get_system_info.sh
12+
fuzztest:
13+
name: Fuzz tests long
14+
uses: ./.github/workflows/build-fuzz-reusable.yml
15+
with:
16+
test_label: "fuzz-long"

test/fuzz/CMakeLists.txt

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,11 @@
55

66
function(add_fuzz_test name label)
77
set(TEST_TARGET_NAME fuzztest-${name})
8-
add_ur_executable(${TEST_TARGET_NAME}
9-
urFuzz.cpp)
10-
target_link_libraries(${TEST_TARGET_NAME}
11-
PRIVATE
12-
${PROJECT_NAME}::loader
13-
${PROJECT_NAME}::headers
14-
${PROJECT_NAME}::common
15-
-fsanitize=fuzzer)
16-
add_test(NAME ${TEST_TARGET_NAME}
17-
COMMAND ${TEST_TARGET_NAME} ${ARGN} -verbosity=1
18-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
198

20-
set(ENV_VARS UR_ENABLE_LAYERS=UR_LAYER_FULL_VALIDATION)
21-
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL)
9+
set(ENV_VARS "")
10+
if(UR_USE_UBSAN)
2211
list(APPEND ENV_VARS
23-
UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\"
24-
NEOReadDebugKeys=1
25-
DisableDeepBind=1)
26-
else()
27-
list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_null>\")
12+
UBSAN_OPTIONS=print_stacktrace=1)
2813
endif()
2914
if(UR_ENABLE_TRACING)
3015
list(APPEND ENV_VARS
@@ -33,17 +18,42 @@ function(add_fuzz_test name label)
3318
XPTI_SUBSCRIBERS=$<TARGET_FILE:collector>
3419
UR_ENABLE_LAYERS=UR_LAYER_TRACING)
3520
endif()
21+
22+
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL)
23+
list(APPEND ENV_VARS
24+
UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\")
25+
if(UR_USE_ASAN)
26+
list(APPEND ENV_VARS
27+
NEOReadDebugKeys=1
28+
DisableDeepBind=1)
29+
endif()
30+
else()
31+
list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_null>\")
32+
endif()
33+
34+
add_test(NAME ${TEST_TARGET_NAME}
35+
COMMAND fuzztest-base ${ARGN} -verbosity=1 -detect_leaks=0
36+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
37+
3638
set_tests_properties(${TEST_TARGET_NAME} PROPERTIES
3739
LABELS ${label}
3840
ENVIRONMENT "${ENV_VARS}")
39-
# TODO: Should we check if this sanitizer flag is available?
40-
target_compile_options(${TEST_TARGET_NAME} PRIVATE -g -fsanitize=fuzzer)
41-
target_compile_definitions(${TEST_TARGET_NAME} PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/fill/spir64.bin.0")
42-
target_include_directories(${TEST_TARGET_NAME} PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
43-
44-
add_dependencies(${TEST_TARGET_NAME} generate_device_binaries)
4541
endfunction()
4642

43+
# Create a single binary
44+
add_ur_executable(fuzztest-base
45+
urFuzz.cpp)
46+
target_link_libraries(fuzztest-base
47+
PRIVATE
48+
${PROJECT_NAME}::loader
49+
${PROJECT_NAME}::headers
50+
${PROJECT_NAME}::common
51+
-fsanitize=fuzzer)
52+
target_compile_options(fuzztest-base PRIVATE -g -fsanitize=fuzzer)
53+
target_compile_definitions(fuzztest-base PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/fill/spir64.bin.0")
54+
target_include_directories(fuzztest-base PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
55+
add_dependencies(fuzztest-base generate_device_binaries)
56+
4757
# Add long test
4858
add_fuzz_test(base fuzz-long -max_total_time=600 -seed=1)
4959

0 commit comments

Comments
 (0)