Skip to content

Commit a44475c

Browse files
authored
Add OneFuzz build pipeline (#220)
1 parent e448991 commit a44475c

File tree

9 files changed

+426
-8
lines changed

9 files changed

+426
-8
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
#
4+
# https://go.microsoft.com/fwlink/?LinkID=324981
5+
6+
# OneFuzz code coverage pipeline
7+
8+
pr: none
9+
trigger: none
10+
11+
resources:
12+
repositories:
13+
- repository: self
14+
type: git
15+
ref: refs/heads/main
16+
- repository: testRepo
17+
name: walbourn/directxmeshtest
18+
type: github
19+
endpoint: microsoft
20+
ref: refs/heads/main
21+
22+
pool:
23+
vmImage: windows-latest
24+
25+
parameters:
26+
- name: sasUrl
27+
type: string
28+
displayName: SAS URL
29+
- name: branch
30+
type: string
31+
displayName: Branch
32+
- name: jobID
33+
type: string
34+
displayName: OneFuzz Job ID
35+
- name: buildDate
36+
type: string
37+
displayName: Build Date
38+
- name: commitID
39+
type: string
40+
displayName: Commit ID
41+
42+
variables:
43+
- name: coverage-file
44+
value: cobertura-coverage.xml
45+
- name: job-ID
46+
value: ${{ parameters.jobID }}
47+
- name: build-date
48+
value: ${{ parameters.buildDate }}
49+
- name: branch
50+
value: ${{ parameters.branch }}
51+
- name: sas-url
52+
value: ${{ parameters.sasUrl }}
53+
- name: commit-ID
54+
value: ${{ parameters.commitID }}
55+
56+
jobs:
57+
- job: prod
58+
displayName: Prod Task
59+
workspace:
60+
clean: all
61+
steps:
62+
- checkout: self
63+
clean: true
64+
fetchTags: false
65+
fetchDepth: 1
66+
path: 's'
67+
- checkout: testRepo
68+
displayName: Fetch Tests
69+
clean: true
70+
fetchTags: false
71+
fetchDepth: 1
72+
path: 's/Tests'
73+
- powershell: |
74+
Write-Host "Job ID: $(job-ID), Build Date: $(build-date), Branch: $(branch)"
75+
$SASUrl = [System.Uri]::new("$(sas-url)")
76+
azcopy cp $SASUrl.AbsoluteUri ./ --recursive
77+
$ContainerName = $SASURL.LocalPath.Split("/")[1]
78+
Write-Host "##vso[task.setvariable variable=container-name;]$ContainerName"
79+
cd $ContainerName
80+
$size = ((Get-Item .\$(coverage-file)).length)
81+
if ($size -eq 0) {
82+
Write-Host "Cobertura coverage XML is empty."
83+
exit 1
84+
}
85+
displayName: 'Get code coverage from OneFuzz'
86+
87+
- task: PublishCodeCoverageResults@1
88+
inputs:
89+
codeCoverageTool: 'Cobertura'
90+
summaryFileLocation: ./$(container-name)\$(coverage-file)
91+
pathToSources: $(Build.SourcesDirectory)
92+
displayName: 'Generate coverage report'
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
#
4+
# https://go.microsoft.com/fwlink/?LinkID=324981
5+
6+
# Builds the library using CMake and submit for file fuzzing
7+
8+
schedules:
9+
- cron: "0 12 1 * *"
10+
displayName: 'Submit for File Fuzzing (Monthly)'
11+
branches:
12+
include:
13+
- main
14+
always: true
15+
16+
trigger: none
17+
pr: none
18+
19+
resources:
20+
repositories:
21+
- repository: self
22+
type: git
23+
ref: refs/heads/main
24+
- repository: testRepo
25+
name: walbourn/directxmeshtest
26+
type: github
27+
endpoint: microsoft
28+
ref: refs/heads/main
29+
30+
name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
31+
32+
variables:
33+
Codeql.Enabled: false
34+
VS_GENERATOR: 'Visual Studio 17 2022'
35+
WIN11_SDK: '10.0.22000.0'
36+
37+
pool:
38+
vmImage: windows-2022
39+
40+
jobs:
41+
- job: FUZZ_BUILD
42+
displayName: 'Build for file fuzzing'
43+
steps:
44+
- checkout: self
45+
clean: true
46+
fetchTags: false
47+
fetchDepth: 1
48+
path: 's'
49+
- checkout: testRepo
50+
displayName: Fetch Tests
51+
clean: true
52+
fetchTags: false
53+
fetchDepth: 1
54+
path: 's/Tests'
55+
- task: CMake@1
56+
displayName: 'CMake (MSVC): Config with ASan'
57+
inputs:
58+
cwd: '$(Build.SourcesDirectory)'
59+
cmakeArgs: '-G "$(VS_GENERATOR)" -A x64 -B out -DCMAKE_SYSTEM_VERSION=$(WIN11_SDK) -DBUILD_TOOLS=OFF -DBUILD_FUZZING=ON -DBUILD_TESTING=OFF'
60+
- task: CMake@1
61+
displayName: 'CMake (MSVC): Build with ASan'
62+
inputs:
63+
cwd: '$(Build.SourcesDirectory)'
64+
cmakeArgs: --build out -v --config RelWithDebInfo
65+
- task: CopyFiles@2
66+
displayName: Copy fuzzer
67+
inputs:
68+
Contents: |
69+
build\OneFuzzConfig.json
70+
out\bin\RelWithDebInfo\fuzzloaders.exe
71+
TargetFolder: .drop
72+
OverWrite: true
73+
flattenFolders: true
74+
- task: CopyFiles@2
75+
displayName: Copy symbols
76+
inputs:
77+
Contents: |
78+
out\bin\RelWithDebInfo\fuzzloaders.pdb
79+
TargetFolder: .drop\symbols
80+
OverWrite: true
81+
flattenFolders: true
82+
- task: PowerShell@2
83+
displayName: Download seed files
84+
inputs:
85+
targetType: inline
86+
script: |
87+
$seedfiles = "cube._obj",
88+
"cup.mtl",
89+
"cup._obj",
90+
"cylinder.vbo",
91+
"torus.vbo",
92+
"player_ship_a.mtl",
93+
"player_ship_a._obj",
94+
"shuttle._obj",
95+
"teapot._obj",
96+
"vp.mtl";
97+
98+
New-Item -ItemType Directory -Force -Path .drop\seeds\
99+
100+
foreach($filename in $seedfiles)
101+
{
102+
Write-Host "Fetching: $filename"
103+
$url = "https://raw.githubusercontent.com/walbourn/directxmeshmedia/main/" + $filename
104+
$target = [System.IO.Path]::Combine(".drop\seeds\", $filename)
105+
Invoke-WebRequest -Uri $url -OutFile $target
106+
}
107+
108+
- task: PowerShell@2
109+
displayName: Copy OneFuzz setup script
110+
inputs:
111+
targetType: 'inline'
112+
script: |
113+
Copy-Item -Path .\build\onefuzz-setup.ps1 -Destination .drop/setup.ps1
114+
115+
- task: MSBuild@1
116+
displayName: 'Copy ASan binaries'
117+
inputs:
118+
solution: build/CopyASAN.targets
119+
msbuildArguments: /p:TargetFolder=$(Build.SourcesDirectory)\.drop
120+
msbuildVersion: 17.0
121+
msbuildArchitecture: x64
122+
- task: PowerShell@2
123+
displayName: List drop files
124+
inputs:
125+
targetType: inline
126+
script: |
127+
Get-ChildItem ".drop" -Recurse | select FullName
128+
129+
- task: onefuzz-task@0
130+
displayName: 'Submit to OneFuzz'
131+
inputs:
132+
onefuzzOSes: 'Windows'
133+
env:
134+
onefuzzDropDirectory: $(Build.SourcesDirectory)\.drop
135+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

.onefuzz

Whitespace-only changes.

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)
3131

3232
option(ENABLE_CODE_COVERAGE "Build with code-coverage" OFF)
3333

34+
option(BUILD_FUZZING "Build for fuzz testing" OFF)
35+
3436
set(CMAKE_CXX_STANDARD 17)
3537
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3638
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -298,6 +300,18 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
298300
foreach(t IN LISTS TOOL_EXES)
299301
target_compile_options(${t} PRIVATE ${WarningsEXE})
300302
endforeach()
303+
304+
if(BUILD_FUZZING AND (NOT WINDOWS_STORE))
305+
string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
306+
string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
307+
308+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.32)
309+
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
310+
target_compile_options(${t} PRIVATE ${ASAN_SWITCHES})
311+
target_link_libraries(${t} PRIVATE ${ASAN_LIBS})
312+
endforeach()
313+
endif()
314+
endif()
301315
endif()
302316

303317
if(WIN32)
@@ -342,5 +356,8 @@ if(WIN32 AND (NOT WINDOWS_STORE) AND (NOT (DEFINED XBOX_CONSOLE_TARGET)))
342356
if(ENABLE_CODE_COVERAGE AND (DEFINED COV_COMPILER_SWITCHES))
343357
target_compile_options(${PROJECT_NAME} PRIVATE ${COV_COMPILER_SWITCHES})
344358
endif()
359+
elseif(BUILD_FUZZING AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders/CMakeLists.txt"))
360+
message(STATUS "Building for fuzzing")
361+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders)
345362
endif()
346363
endif()

CMakePresets.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@
220220
},
221221
"hidden": true
222222
},
223+
{
224+
"name": "Fuzzing",
225+
"cacheVariables": {
226+
"BUILD_FUZZING": true,
227+
"BUILD_TESTING": false
228+
},
229+
"hidden": true
230+
},
223231

224232
{ "name": "x64-Debug" , "description": "MSVC for x64 (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "MSVC" ] },
225233
{ "name": "x64-Release" , "description": "MSVC for x64 (Release) with DX12", "inherits": [ "base", "x64", "Release", "MSVC" ] },
@@ -294,20 +302,21 @@
294302
{ "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC", "VCPKG", "MinGW32" ] },
295303
{ "name": "x86-Release-MinGW", "description": "MinG-W32 (Release)", "inherits": [ "base", "x86", "Release", "GNUC", "VCPKG", "MinGW32" ] },
296304

305+
{ "name": "x64-Debug-Linux", "description": "WSL Linux x64 (Debug)", "inherits": [ "base", "x64", "Debug", "VCPKG" ] },
306+
{ "name": "x64-Release-Linux", "description": "WSL Linux x64 (Release)", "inherits": [ "base", "x64", "Release", "VCPKG" ] },
307+
{ "name": "arm64-Debug-Linux", "description": "WSL Linux ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "VCPKG" ] },
308+
{ "name": "arm64-Release-Linux", "description": "WSL Linux ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "VCPKG" ] },
309+
297310
{ "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "Intel" ] },
298311
{ "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release) with DX12", "inherits": [ "base", "x64", "Release", "Intel" ] },
299312

300313
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
301314
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) with DX12", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] },
302315

303-
{ "name": "x64-Debug-Linux", "description": "WSL Linux x64 (Debug)", "inherits": [ "base", "x64", "Debug", "VCPKG" ] },
304-
{ "name": "x64-Release-Linux", "description": "WSL Linux x64 (Release)", "inherits": [ "base", "x64", "Release", "VCPKG" ] },
305-
{ "name": "arm64-Debug-Linux", "description": "WSL Linux ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "VCPKG" ] },
306-
{ "name": "arm64-Release-Linux", "description": "WSL Linux ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "VCPKG" ] },
307-
308316
{ "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) with DX12 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC", "Analyze" ] },
309317
{ "name": "x64-Coverage" , "description": "MSVC for x64 (Debug) with DX12 w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "MSVC", "Coverage" ] },
310-
{ "name": "x64-Coverage-Clang", "description": "Clang/LLVM for x64 (Debug) with DX12 w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "Clang", "Coverage" ] }
318+
{ "name": "x64-Coverage-Clang", "description": "Clang/LLVM for x64 (Debug) with DX12 w/ Code Coverage", "inherits": [ "base", "x64", "Debug", "Clang", "Coverage" ] },
319+
{ "name": "x64-Fuzzing" , "description": "MSVC for x64 (Release) with ASan", "inherits": [ "base", "x64", "Release", "MSVC", "Fuzzing" ] }
311320
],
312321
"testPresets": [
313322
{ "name": "x64-Debug" , "configurePreset": "x64-Debug" },

Utilities/WaveFrontReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace DX
7474

7575
WaveFrontReader() noexcept : hasNormals(false), hasTexcoords(false) {}
7676

77-
HRESULT Load(_In_z_ const wchar_t* szFileName, bool ccw = true)
77+
HRESULT Load(_In_z_ const wchar_t* szFileName, bool ccw = true, bool loadmtl = true)
7878
{
7979
Clear();
8080

@@ -392,7 +392,7 @@ namespace DX
392392
BoundingBox::CreateFromPoints(bounds, positions.size(), positions.data(), sizeof(XMFLOAT3));
393393

394394
// If an associated material file was found, read that in as well.
395-
if (*strMaterialFilename)
395+
if (*strMaterialFilename && loadmtl)
396396
{
397397
#ifdef _WIN32
398398
wchar_t ext[_MAX_EXT] = {};

build/CopyASan.targets

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="CopyASanFiles" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<PropertyGroup>
5+
<TargetFolder Condition="'$(TargetFolder)'==''">.drop</TargetFolder>
6+
7+
<VSInstallDir>$(VsInstallRoot)\</VSInstallDir>
8+
<VCInstallDir>$(VSInstallDir)VC\</VCInstallDir>
9+
<VCToolsVersionProps>$(VCInstallDir)Auxiliary\Build\Microsoft.VCToolsVersion.default.props</VCToolsVersionProps>
10+
</PropertyGroup>
11+
12+
<Import Project="$(VCToolsVersionProps)" Condition="Exists('$(VCToolsVersionProps)')" />
13+
14+
<ItemGroup>
15+
<ASanFiles Include="$(VCInstallDir)Tools\MSVC\$(VCToolsVersion)\bin\HostX64\x64\clang_rt.*.dll" />
16+
<ASanFiles Include="$(VSInstallDir)Common7\IDE\msdia140.dll" />
17+
</ItemGroup>
18+
19+
<Target Name="CopyASanFiles">
20+
<Message Text="VCToolsVersion: $(VCToolsVersion)" />
21+
<Copy SourceFiles="@(ASanFiles)" DestinationFolder="$(TargetFolder)" />
22+
</Target>
23+
24+
</Project>

0 commit comments

Comments
 (0)