Skip to content

Commit

Permalink
Refactor fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PatKamin authored and kbenzie committed Jul 2, 2024
1 parent b7bf7f9 commit c841c9a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 141 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/build-fuzz-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
name: Build - Fuzztests on L0 HW - Reusable

on:
workflow_call:
inputs:
test_label:
required: true
type: string

permissions:
contents: read

jobs:
fuzztest-build-hw:
name: Build and run fuzz tests on L0 HW
if: github.repository == 'oneapi-src/unified-runtime' # run only on upstream; forks won't have the HW
strategy:
matrix:
build_type: [Debug, Release]
compiler: [{c: clang, cxx: clang++}]

runs-on: 'FUZZTESTS'
# In order to use sanitizers, vm.mmap_rnd_bits=28 must be set in the system,
# otherwise random SEGV at the start of the test occurs.
# Alternatively, clang 18.1.0 onwards with fixed sanitizers behavior can be used,
# if available.
# TODO: Remove this advice once clang 18.1.0 is available in the system (like ie. as an apt package).

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install pip packages
run: pip install -r third_party/requirements.txt

- name: Download DPC++
run: |
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/nightly-2024-01-29/sycl_linux.tar.gz
mkdir dpcpp_compiler
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz -C dpcpp_compiler
- name: Build level zero with gcc
run: |
git clone -b v1.16.1 --depth=1 https://github.com/oneapi-src/level-zero.git ${{github.workspace}}/level-zero
cd ${{github.workspace}}/level-zero
cmake -B build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
cmake --build build -j $(nproc)
- name: Configure CMake
run: >
cmake
-B${{github.workspace}}/build
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUR_ENABLE_TRACING=ON
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DUR_BUILD_TESTS=ON
-DUR_USE_ASAN=ON
-DUR_USE_UBSAN=ON
-DUR_BUILD_ADAPTER_L0=ON
-DUR_LEVEL_ZERO_LOADER_LIBRARY=${{github.workspace}}/level-zero/build/lib/libze_loader.so
-DUR_LEVEL_ZERO_INCLUDE_DIR=${{github.workspace}}/level-zero/include/
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
- name: Build
run: cmake --build ${{github.workspace}}/build -j $(nproc)

- name: Fuzz test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "${{inputs.test_label}}" --verbose

- name: Get information about platform
if: ${{ always() }}
run: .github/scripts/get_system_info.sh
66 changes: 6 additions & 60 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,66 +116,12 @@ jobs:
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "umf|loader|validation|tracing|unit|urtrace"

fuzztest-build-hw:
name: Build and run quick fuzztest scenarios on L0 HW
if: github.repository == 'oneapi-src/unified-runtime' # run only on upstream; forks won't have the HW
strategy:
matrix:
build_type: [Debug, Release]
compiler: [{c: clang, cxx: clang++}]

runs-on: 'FUZZTESTS'

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install pip packages
run: pip install -r third_party/requirements.txt

- name: Download DPC++
run: |
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/sycl-nightly%2F20230626/dpcpp-compiler.tar.gz
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz
- name: Setup DPC++
run: |
source ${{github.workspace}}/dpcpp_compiler/startup.sh
- name: Build level zero
run: |
git clone -b v1.16.1 --depth=1 https://github.com/oneapi-src/level-zero.git ${{github.workspace}}/level-zero
cd ${{github.workspace}}/level-zero
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
cmake --build build -j $(nproc)
- name: Configure CMake
run: >
cmake
-B${{github.workspace}}/build
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUR_ENABLE_TRACING=ON
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DUR_BUILD_TESTS=ON
-DUR_USE_ASAN=ON
-DUR_USE_UBSAN=ON
-DUR_BUILD_ADAPTER_L0=ON
-DUR_LEVEL_ZERO_LOADER_LIBRARY=${{github.workspace}}/level-zero/build/lib/libze_loader.so
-DUR_LEVEL_ZERO_INCLUDE_DIR=${{github.workspace}}/level-zero/include/
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
- name: Build
run: cmake --build ${{github.workspace}}/build -j $(nproc)

- name: Fuzz test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "fuzz-short" --verbose

- name: Get information about platform
if: ${{ always() }}
run: .github/scripts/get_system_info.sh

fuzztest:
name: Fuzz tests short
uses: ./.github/workflows/build-fuzz-reusable.yml
with:
test_label: "fuzz-short"

level-zero:
name: Level Zero
uses: ./.github/workflows/build-hw-reusable.yml
Expand Down
62 changes: 5 additions & 57 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,8 @@ permissions:
contents: read

jobs:
long-fuzz-test-hw:
name: Run long fuzz tests
if: github.repository == 'oneapi-src/unified-runtime' # run only on upstream; forks won't have the HW
strategy:
matrix:
build_type: [Debug, Release]
compiler: [{c: clang, cxx: clang++}]

runs-on: 'FUZZTESTS'

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install pip packages
run: pip install -r third_party/requirements.txt

- name: Download DPC++
run: |
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/nightly-2024-01-29/sycl_linux.tar.gz
mkdir dpcpp_compiler
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz -C dpcpp_compiler
- name: Build level zero
run: |
git clone -b v1.16.1 --depth=1 https://github.com/oneapi-src/level-zero.git ${{github.workspace}}/level-zero
cd ${{github.workspace}}/level-zero
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
cmake --build build -j $(nproc)
- name: Configure CMake
run: >
cmake
-B${{github.workspace}}/build
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUR_ENABLE_TRACING=ON
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DUR_BUILD_TESTS=ON
-DUR_USE_ASAN=ON
-DUR_USE_UBSAN=ON
-DUR_BUILD_ADAPTER_L0=ON
-DUR_LEVEL_ZERO_LOADER_LIBRARY=${{github.workspace}}/level-zero/build/lib/libze_loader.so
-DUR_LEVEL_ZERO_INCLUDE_DIR=${{github.workspace}}/level-zero/include/
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
- name: Build
run: |
cmake --build ${{github.workspace}}/build -j $(nproc)
- name: Fuzz long test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "fuzz-long" --verbose

- name: Get information about platform
if: ${{ always() }}
run: .github/scripts/get_system_info.sh
fuzztest:
name: Fuzz tests long
uses: ./.github/workflows/build-fuzz-reusable.yml
with:
test_label: "fuzz-long"
58 changes: 34 additions & 24 deletions test/fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@

function(add_fuzz_test name label)
set(TEST_TARGET_NAME fuzztest-${name})
add_ur_executable(${TEST_TARGET_NAME}
urFuzz.cpp)
target_link_libraries(${TEST_TARGET_NAME}
PRIVATE
${PROJECT_NAME}::loader
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
-fsanitize=fuzzer)
add_test(NAME ${TEST_TARGET_NAME}
COMMAND ${TEST_TARGET_NAME} ${ARGN} -verbosity=1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set(ENV_VARS UR_ENABLE_LAYERS=UR_LAYER_FULL_VALIDATION)
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL)
set(ENV_VARS "")
if(UR_USE_UBSAN)
list(APPEND ENV_VARS
UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\"
NEOReadDebugKeys=1
DisableDeepBind=1)
else()
list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_null>\")
UBSAN_OPTIONS=print_stacktrace=1)
endif()
if(UR_ENABLE_TRACING)
list(APPEND ENV_VARS
Expand All @@ -33,17 +18,42 @@ function(add_fuzz_test name label)
XPTI_SUBSCRIBERS=$<TARGET_FILE:collector>
UR_ENABLE_LAYERS=UR_LAYER_TRACING)
endif()

if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL)
list(APPEND ENV_VARS
UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\")
if(UR_USE_ASAN)
list(APPEND ENV_VARS
NEOReadDebugKeys=1
DisableDeepBind=1)
endif()
else()
list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_null>\")
endif()

add_test(NAME ${TEST_TARGET_NAME}
COMMAND fuzztest-base ${ARGN} -verbosity=1 -detect_leaks=0
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_tests_properties(${TEST_TARGET_NAME} PROPERTIES
LABELS ${label}
ENVIRONMENT "${ENV_VARS}")
# TODO: Should we check if this sanitizer flag is available?
target_compile_options(${TEST_TARGET_NAME} PRIVATE -g -fsanitize=fuzzer)
target_compile_definitions(${TEST_TARGET_NAME} PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/fill/spir64.bin.0")
target_include_directories(${TEST_TARGET_NAME} PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})

add_dependencies(${TEST_TARGET_NAME} generate_device_binaries)
endfunction()

# Create a single binary
add_ur_executable(fuzztest-base
urFuzz.cpp)
target_link_libraries(fuzztest-base
PRIVATE
${PROJECT_NAME}::loader
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
-fsanitize=fuzzer)
target_compile_options(fuzztest-base PRIVATE -g -fsanitize=fuzzer)
target_compile_definitions(fuzztest-base PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/fill/spir64.bin.0")
target_include_directories(fuzztest-base PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
add_dependencies(fuzztest-base generate_device_binaries)

# Add long test
add_fuzz_test(base fuzz-long -max_total_time=600 -seed=1)

Expand Down

0 comments on commit c841c9a

Please sign in to comment.