Skip to content

Commit 00a061e

Browse files
Enable sanitizers for macOS, Linux, Windows (#1559)
Enable Address sanitizer as pointed by #1557 - Add macOS, Windows and Linux sanitizer builds - up ndk to v28 - misc build fixes - fix reported memory leaks and bugs Memleaks + CI issue : #1575
1 parent 6a0aa8e commit 00a061e

File tree

22 files changed

+327
-1059
lines changed

22 files changed

+327
-1059
lines changed

.github/asan_suppress.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Suppress leaks from dbus. No direct leak visible with BN.
2+
# command to dump leaks and suppress annecessary :
3+
# ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt ./UnitTests
4+
# ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js
5+
leak:bmalloc_allocate_casual
6+
leak:reallocate_for_length
7+
leak:dbus_message_new_empty_header

.github/jobs/android.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ jobs:
99
timeoutInMinutes: 45
1010
pool:
1111
vmImage: ${{ parameters.vmImage }}
12-
12+
13+
variables:
14+
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }}
15+
1316
steps:
1417
- template: cmake.yml
1518
parameters:
@@ -26,7 +29,7 @@ jobs:
2629
workingDirectory: 'Apps/Playground/Android'
2730
gradleWrapperFile: 'Apps/Playground/Android/gradlew'
2831
gradleOptions: '-Xmx1536m'
29-
options: '-PJSEngine=${{ parameters.JSEngine }} -PARM64Only -PNDK_VERSION=$(NDK_VERSION)'
32+
options: '-PJSEngine=${{ parameters.JSEngine }} -PARM64Only -PNDK_VERSION=$(NDK_VERSION) -PSANITIZERS=$(SANITIZER_FLAG)'
3033
publishJUnitResults: false
3134
tasks: 'assembleRelease'
3235
displayName: 'Build Playground ${{ parameters.JSEngine }}'

.github/jobs/linux.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parameters:
44
CC: ''
55
CXX: ''
66
JSEngine: ''
7+
enableSanitizers: false
78

89
jobs:
910
- job: ${{ parameters.name }}
@@ -12,6 +13,7 @@ jobs:
1213
vmImage: ${{ parameters.vmImage }}
1314

1415
variables:
16+
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }}
1517
CC: ${{ parameters.CC }}
1618
CXX: ${{ parameters.CXX }}
1719

@@ -22,19 +24,29 @@ jobs:
2224

2325
- script: |
2426
sudo apt-get update
25-
sudo apt-get install libjavascriptcoregtk-4.1-dev libgl1-mesa-dev libcurl4-openssl-dev libwayland-dev
27+
sudo apt-get install libjavascriptcoregtk-4.1-dev libgl1-mesa-dev libcurl4-openssl-dev libwayland-dev clang
2628
displayName: 'Install packages'
2729
2830
- script: |
29-
cmake -G Ninja -B build -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so -D NAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BX_CONFIG_DEBUG=ON -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D OpenGL_GL_PREFERENCE=GLVND -D BABYLON_DEBUG_TRACE=ON
31+
cmake -G Ninja -B build -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so -D NAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BX_CONFIG_DEBUG=ON -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D OpenGL_GL_PREFERENCE=GLVND -D BABYLON_DEBUG_TRACE=ON -D ENABLE_SANITIZERS=$(SANITIZER_FLAG) .
3032
ninja -C build
3133
displayName: 'Build X11'
3234
35+
# Memory leaks on CI is disabled due to memory leaks reported with xvfb and impossible to add to ignore list.
36+
# See https://github.com/BabylonJS/BabylonNative/issues/1575
37+
3338
- script: |
3439
cd build/Apps/Playground
40+
# Command line to suppress false positive memory leaks :
41+
# ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js
3542
xvfb-run ./Playground app:///Scripts/validation_native.js
3643
displayName: 'Validation Tests'
3744
45+
- script: |
46+
cd build/Apps/UnitTests
47+
xvfb-run ./UnitTests
48+
displayName: 'Unit Tests'
49+
3850
- task: PublishBuildArtifacts@1
3951
inputs:
4052
artifactName: '${{ parameters.name }} Rendered Pictures'
@@ -47,8 +59,3 @@ jobs:
4759
pathtoPublish: 'build/Apps/Playground/Errors'
4860
displayName: 'Publish Tests ${{ parameters.name }} Errors'
4961
condition: failed()
50-
51-
- script: |
52-
cd build/Apps/UnitTests
53-
xvfb-run ./UnitTests
54-
displayName: 'Unit Tests'

.github/jobs/macos.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
parameters:
22
name: ''
33
vmImage: ''
4+
enableSanitizers: false
45

56
jobs:
67
- job: ${{ parameters.name }}
78
timeoutInMinutes: 30
89
pool:
910
vmImage: ${{ parameters.vmImage }}
10-
11+
12+
variables:
13+
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }}
14+
1115
steps:
1216
- template: cmake.yml
1317
parameters:
@@ -18,7 +22,7 @@ jobs:
1822
displayName: 'Select XCode $(XCODE_VERSION)'
1923
2024
- script: |
21-
cmake -G Xcode -B buildmacOS -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BABYLON_DEBUG_TRACE=ON
25+
cmake -G Xcode -B buildmacOS -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BABYLON_DEBUG_TRACE=ON -D ENABLE_SANITIZERS=$(SANITIZER_FLAG)
2226
displayName: 'Generate macOS solution'
2327
2428
- script: |

.github/jobs/win32.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ parameters:
1515
- name: graphics_api
1616
type: string
1717
default: D3D11
18+
- name: enableSanitizers
19+
type: boolean
20+
default: false
1821

1922
jobs:
2023
- job: ${{ parameters.name }}
2124
timeoutInMinutes: 60
2225
pool:
2326
vmImage: ${{ parameters.vmImage }}
2427
variables:
28+
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }}
2529
${{ if eq(parameters.napiType, 'jsi') }}:
2630
napiSuffix: '_JSI'
2731
jsEngineDefine: '-DNAPI_JAVASCRIPT_ENGINE=JSI'
@@ -40,7 +44,7 @@ jobs:
4044

4145
# BGFX_CONFIG_MAX_FRAME_BUFFERS is set so enough Framebuffers are available before V8 starts disposing unused ones
4246
- script: |
43-
cmake -G "Visual Studio 17 2022" -B build${{ variables.solutionName }} -A ${{ parameters.platform }} ${{ variables.jsEngineDefine }} -D BX_CONFIG_DEBUG=ON -D GRAPHICS_API=${{ parameters.graphics_api }} -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BGFX_CONFIG_MAX_FRAME_BUFFERS=256 -D BABYLON_DEBUG_TRACE=ON
47+
cmake -G "Visual Studio 17 2022" -B build${{ variables.solutionName }} -A ${{ parameters.platform }} ${{ variables.jsEngineDefine }} -D BX_CONFIG_DEBUG=ON -D GRAPHICS_API=${{ parameters.graphics_api }} -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BGFX_CONFIG_MAX_FRAME_BUFFERS=256 -D BABYLON_DEBUG_TRACE=ON -D ENABLE_SANITIZERS=$(SANITIZER_FLAG)
4448
displayName: 'Generate ${{ variables.solutionName }} solution'
4549
4650
- task: MSBuild@1
@@ -59,9 +63,18 @@ jobs:
5963
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\UnitTests.exe" /v DumpType /t REG_DWORD /d 2
6064
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\UnitTests.exe" /v DumpCount /t REG_DWORD /d 1
6165
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\UnitTests.exe" /v DumpFolder /t REG_SZ /d "$(Build.ArtifactStagingDirectory)/Dumps"
62-
6366
displayName: 'Enable Crash Dumps'
6467
68+
- powershell: |
69+
$vs = vswhere -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
70+
$msvc = Get-ChildItem "$vs\VC\Tools\MSVC" | Sort-Object Name -Descending | Select-Object -First 1
71+
$asanPath = "$($msvc.FullName)\bin\Hostx64\x64"
72+
73+
Write-Host "Adding ASAN runtime folder to PATH: $asanPath"
74+
Write-Host "##vso[task.prependpath]$asanPath"
75+
displayName: "Add ASAN runtime DLLs to PATH"
76+
condition: ${{ parameters.enableSanitizers }}
77+
6578
- script: |
6679
cd build${{ variables.solutionName }}\Apps\Playground
6780
cd RelWithDebInfo

Apps/Playground/X11/App.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,6 @@ int main(int _argc, const char* const* _argv)
296296

297297
XUnmapWindow(display, window);
298298
XDestroyWindow(display, window);
299+
XCloseDisplay(display);
299300
return 0;
300301
}

Apps/UnitTests/X11/App.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ int main()
5353
Babylon::DebugTrace::EnableDebugTrace(true);
5454
Babylon::DebugTrace::SetTraceOutput([](const char* trace) { printf("%s\n", trace); fflush(stdout); });
5555

56-
return RunTests(config);
56+
int ret = RunTests(config);
57+
XCloseDisplay(display);
58+
return ret;
5759
}

0 commit comments

Comments
 (0)