From f58c30705b3f1d8c4c78f9c449525a7cba41525a Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sun, 5 Nov 2023 23:12:56 -0800 Subject: [PATCH] Add OneFuzz build pipeline --- .onefuzz | 0 CMakeLists.txt | 15 +++- CMakePresets.json | 12 ++- build/CopyASan.targets | 24 ++++++ build/DirectXTex-OneFuzz.yml | 144 +++++++++++++++++++++++++++++++++++ build/OneFuzzConfig.json | 33 ++++++++ 6 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 .onefuzz create mode 100644 build/CopyASan.targets create mode 100644 build/DirectXTex-OneFuzz.yml create mode 100644 build/OneFuzzConfig.json diff --git a/.onefuzz b/.onefuzz new file mode 100644 index 0000000..e69de29 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0373374..f8e4286 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ option(USE_PREBUILT_SHADERS "Use externally built HLSL shaders" OFF) option(NO_WCHAR_T "Use legacy wide-character as unsigned short" OFF) +option(BUILD_FUZZING "Build for fuzz testing" OFF) + # Includes the functions for loading/saving OpenEXR files at runtime option(ENABLE_OPENEXR_SUPPORT "Build with OpenEXR support" OFF) @@ -365,7 +367,7 @@ endif() if(MSVC) foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) target_compile_options(${t} PRIVATE /Wall /GR- /fp:fast "$<$>:/guard:cf>") - target_link_options(${t} PRIVATE /DYNAMICBASE /NXCOMPAT) + target_link_options(${t} PRIVATE /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO) endforeach() if((CMAKE_SIZEOF_VOID_P EQUAL 4) AND (NOT (${DIRECTX_ARCH} MATCHES "^arm"))) @@ -503,6 +505,13 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") foreach(t IN LISTS TOOL_EXES) target_compile_options(${t} PRIVATE ${WarningsEXE}) endforeach() + + if (BUILD_FUZZING AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.32) + foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) + target_compile_options(${t} PRIVATE /fsanitize=address /fsanitize-coverage=inline-8bit-counters /fsanitize-coverage=edge /fsanitize-coverage=trace-cmp /fsanitize-coverage=trace-div) + target_link_libraries(${t} PRIVATE sancov.lib) + endforeach() + endif() endif() if(WIN32) @@ -540,4 +549,8 @@ if(BUILD_TESTING AND WIN32 AND (NOT WINDOWS_STORE) AND (NOT (DEFINED XBOX_CONSOL AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/CMakeLists.txt")) enable_testing() add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests) +elseif(BUILD_FUZZING AND WIN32 AND (NOT WINDOWS_STORE) AND (NOT (DEFINED XBOX_CONSOLE_TARGET)) + AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders/CMakeLists.txt")) + message(STATUS "Building for fuzzing") + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 1eaad50..418a05c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -167,6 +167,14 @@ "VCPKG_HOST_TRIPLET": "x64-mingw-static" } }, + { + "name": "Fuzzing", + "cacheVariables": { + "BUILD_FUZZING": true, + "BUILD_TESTING": false + }, + "hidden": true + }, { "name": "x64-Debug" , "description": "MSVC for x64 (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "MSVC" ] }, { "name": "x64-Release" , "description": "MSVC for x64 (Release) with DX12", "inherits": [ "base", "x64", "Release", "MSVC" ] }, @@ -233,7 +241,9 @@ { "name": "x64-Debug-Linux", "description": "WSL Linux x64 (Debug)", "inherits": [ "base", "x64", "Debug", "VCPKG" ] }, { "name": "x64-Release-Linux", "description": "WSL Linux x64 (Release)", "inherits": [ "base", "x64", "Release", "VCPKG" ] }, { "name": "arm64-Debug-Linux", "description": "WSL Linux ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "VCPKG" ] }, - { "name": "arm64-Release-Linux", "description": "WSL Linux ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "VCPKG" ] } + { "name": "arm64-Release-Linux", "description": "WSL Linux ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "VCPKG" ] }, + + { "name": "x64-Fuzzing" , "description": "MSVC for x64 (Release) with ASan", "inherits": [ "base", "x64", "Release", "MSVC", "Fuzzing" ] } ], "testPresets": [ { "name": "x64-Debug" , "configurePreset": "x64-Debug" }, diff --git a/build/CopyASan.targets b/build/CopyASan.targets new file mode 100644 index 0000000..b11e5a0 --- /dev/null +++ b/build/CopyASan.targets @@ -0,0 +1,24 @@ + + + + + .drop + + $(VsInstallRoot)\ + $(VSInstallDir)VC\ + $(VCInstallDir)Auxiliary\Build\Microsoft.VCToolsVersion.default.props + + + + + + + + + + + + + + + diff --git a/build/DirectXTex-OneFuzz.yml b/build/DirectXTex-OneFuzz.yml new file mode 100644 index 0000000..b7d419f --- /dev/null +++ b/build/DirectXTex-OneFuzz.yml @@ -0,0 +1,144 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# +# http://go.microsoft.com/fwlink/?LinkId=248926 + +# Builds the library using CMake and submit for file fuzzing + +schedules: +- cron: "0 12 * * 0" + displayName: 'Submit for File Fuzzing' + branches: + include: + - main + always: true + +trigger: none +pr: none + +resources: + repositories: + - repository: self + type: git + ref: refs/heads/main + +name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r) + +variables: + VS_GENERATOR: 'Visual Studio 17 2022' + WIN11_SDK: '10.0.22000.0' + BUGFILING_PAT: $(BugFilingPAT) + GITHUB_PAT: $(GITHUBPUBLICTOKEN) + ONEFUZZ_PAT: $(OneFuzzPAT) + +pool: + vmImage: windows-2022 + +jobs: +- job: FUZZ_BUILD + displayName: 'Build for file fuzzing' + steps: + - checkout: self + clean: true + fetchTags: false + - task: DeleteFiles@1 + displayName: Delete files from Tests + inputs: + SourceFolder: Tests + Contents: '**' + RemoveSourceFolder: true + RemoveDotFiles: true + - task: CmdLine@2 + displayName: Fetch Tests + inputs: + script: git clone --quiet https://%GITHUB_PAT%@github.com/walbourn/directxtextest.git Tests + workingDirectory: $(Build.SourcesDirectory) + failOnStderr: true + - task: CMake@1 + displayName: 'CMake (MSVC): Config with ASan' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: '-G "$(VS_GENERATOR)" -A x64 -B out -DCMAKE_SYSTEM_VERSION=$(WIN11_SDK) -DBUILD_TOOLS=OFF -DBUILD_SAMPLE=OFF -DBUILD_FUZZING=ON -DBUILD_TESTING=OFF' + - task: CMake@1 + displayName: 'CMake (MSVC): Build with ASan' + inputs: + cwd: '$(Build.SourcesDirectory)' + cmakeArgs: --build out -v --config RelWithDebInfo + - task: CopyFiles@2 + displayName: Copy fuzzer + inputs: + Contents: | + build\OneFuzzConfig.json + out\bin\CMake\RelWithDebInfo\fuzzloaders.exe + TargetFolder: .drop + OverWrite: true + flattenFolders: true + - task: CopyFiles@2 + displayName: Copy symbols + inputs: + Contents: | + out\bin\CMake\RelWithDebInfo\fuzzloaders.pdb + TargetFolder: .drop\symbols + OverWrite: true + flattenFolders: true + - task: PowerShell@2 + displayName: Download seed files + inputs: + targetType: inline + script: | + $seedfiles = "AlphaEdge.dds", + "cubea8r8g8b8.dds", + "default_texture_nm.dds", + "dx5_logo.dds", + "hdrtest.dds", + "normalmap.dds", + "grad4d.hdr", + "grad4dunc.hdr", + "BigTree.hdr", + "CBW8.TGA", + "ccm8.tga", + "CTC16.TGA", + "CTC24.TGA", + "CTC32.TGA", + "UTC16.TGA", + "UTC24.TGA", + "UTC32.TGA", + "UBW8.TGA", + "ucm8.tga", + "testimg.ppm", + "grad4d.pfm"; + + New-Item -ItemType Directory -Force -Path .drop\seeds\ + + foreach($filename in $seedfiles) + { + Write-Host "Fetching: $filename" + $url = "https://raw.githubusercontent.com/walbourn/directxtexmedia/main/" + $filename + $target = [System.IO.Path]::Combine(".drop\seeds\", $filename) + Invoke-WebRequest $url -o $target + } + + - task: MSBuild@1 + displayName: 'Copy ASan binaries' + inputs: + solution: build/CopyASAN.targets + msbuildArguments: /p:TargetFolder=$(Build.SourcesDirectory)\.drop + msbuildVersion: 17.0 + msbuildArchitecture: x64 + - task: PowerShell@2 + displayName: List drop files + inputs: + targetType: inline + script: | + Get-ChildItem ".drop" -Recurse | select FullName + + - task: onefuzz-task@0 + displayName: 'Submit to OneFuzz' + inputs: + onefuzzOSes: 'Windows' + env: + onefuzzDropDirectory: $(Build.SourcesDirectory)\.drop + onefuzzDropPAT: $(ONEFUZZ_PAT) + SYSTEM_ACCESSTOKEN: $(System.AccessToken) + onefuzzBugFilingPAT: $(BUGFILING_PAT) + \ No newline at end of file diff --git a/build/OneFuzzConfig.json b/build/OneFuzzConfig.json new file mode 100644 index 0000000..3da42c6 --- /dev/null +++ b/build/OneFuzzConfig.json @@ -0,0 +1,33 @@ +{ + "ConfigVersion": 3, + "Entries": [ + { + "JobNotificationEmail": "directxtkdev@microsoft.com", + "Skip": false, + "Fuzzer": { + "$type": "libfuzzer", + "FuzzingHarnessExecutableName": "fuzzloaders.exe" + }, + "RebootAfterSetup": false, + "OneFuzzJobs": [ + { + "ProjectName": "Direct3D", + "TargetName": "DirectXTex" + } + ], + "JobDependencies": [ + "fuzzloaders.exe", + "fuzzloaders.pdb", + "clang_rt.asan_dynamic-x86_64.dll", + "msdia140.dll" + ], + "AdoTemplate": { + "Org": "microsoft", + "Project": "OS", + "AssignedTo": "chuckw@microsoft.com", + "AreaPath": "OS\\Core\\SiGMa\\GRFX-Graphics", + "IterationPath": "OS\\Future" + } + } + ] +} \ No newline at end of file