diff --git a/.github/workflows/build-fuzz-reusable.yml b/.github/workflows/build-fuzz-reusable.yml new file mode 100644 index 0000000000..4bd5b115ed --- /dev/null +++ b/.github/workflows/build-fuzz-reusable.yml @@ -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 diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f812552029..fbb7ecc664 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index eabb8c65e7..6c14faf7df 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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" diff --git a/test/fuzz/CMakeLists.txt b/test/fuzz/CMakeLists.txt index bc8512e4b3..c3b867928e 100644 --- a/test/fuzz/CMakeLists.txt +++ b/test/fuzz/CMakeLists.txt @@ -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=\"$\" - NEOReadDebugKeys=1 - DisableDeepBind=1) - else() - list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$\") + UBSAN_OPTIONS=print_stacktrace=1) endif() if(UR_ENABLE_TRACING) list(APPEND ENV_VARS @@ -33,17 +18,42 @@ function(add_fuzz_test name label) XPTI_SUBSCRIBERS=$ 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=\"$\") + if(UR_USE_ASAN) + list(APPEND ENV_VARS + NEOReadDebugKeys=1 + DisableDeepBind=1) + endif() + else() + list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$\") + 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)