Skip to content

Commit 0cd03bb

Browse files
Make wasm test faster (#8829)
show in developer changelog
1 parent a8c4ad8 commit 0cd03bb

7 files changed

Lines changed: 540 additions & 1008 deletions

File tree

.circleci/config.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,13 @@ jobs:
326326

327327
- run:
328328
name: Run tests
329-
command: cd GDevelop.js && npm run test -- --maxWorkers=4
329+
# Tests are slow under ASan and jest (in a non-TTY environment) only prints
330+
# output when a whole test file finishes, so allow long silences instead of
331+
# killing the step after the default 10 minutes without output.
332+
no_output_timeout: 30m
333+
# malloc_context_size: record fewer stack frames on each malloc/free (default
334+
# is 30) - a small, free speedup that only shortens traces in ASan reports.
335+
command: cd GDevelop.js && ASAN_OPTIONS=malloc_context_size=5 npm run test -- --maxWorkers=4
330336

331337
# Upload artifacts (CircleCI)
332338
- store_artifacts:

GDevelop.js/Bindings/prejs.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// If running under ASAN, disable the "container overflow" checks because of false positives
22
// with std::vector<gd::String>. See https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow.
3-
if (Module['ASAN_OPTIONS'] === undefined)
4-
Module['ASAN_OPTIONS'] ='detect_container_overflow=0';
3+
// Also append options from the ASAN_OPTIONS environment variable when running in Node.js,
4+
// as Emscripten only reads them from Module['ASAN_OPTIONS'] (not from the environment).
5+
if (Module['ASAN_OPTIONS'] === undefined) {
6+
var envAsanOptions =
7+
typeof process !== 'undefined' && process.env && process.env.ASAN_OPTIONS
8+
? ':' + process.env.ASAN_OPTIONS
9+
: '';
10+
Module['ASAN_OPTIONS'] = 'detect_container_overflow=0' + envAsanOptions;
11+
}
512

613
// Prevent calling process["exit"] when there is a abort/runtime crash
714
// (useful for tests when running ASAN, to see the logs).

GDevelop.js/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ elseif("${GDEVELOPJS_BUILD_VARIANT}" STREQUAL "debug-assertions")
2323
# Debug with assertions: no optimization.
2424
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --profiling") # Debugging + profiling support
2525
elseif("${GDEVELOPJS_BUILD_VARIANT}" STREQUAL "debug-sanitizers")
26-
# Debug with sanitizers: no optimization.
26+
# Debug with sanitizers (note: -O3 from the Release build type still applies at compile time).
2727
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --profiling") # Debugging + profiling support
2828
add_compile_options(-fsanitize=address) # Uncomment to auto-detect occurences of memory bugs (memory leak, use after free, overflows, ...) - also enable linking below!
2929
# add_compile_options(-fsanitize=undefined) # Uncomment to auto-detect occurences of undefined behavior - also enable linking below!
@@ -111,6 +111,8 @@ elseif("${GDEVELOPJS_BUILD_VARIANT}" STREQUAL "debug-assertions")
111111
# target_link_libraries(--memoryprofiler) # Uncomment for interactive memory profiling
112112
elseif("${GDEVELOPJS_BUILD_VARIANT}" STREQUAL "debug-sanitizers")
113113
message(STATUS "'debug-sanitizers' variant: enabling ASAN and other sanitizers")
114+
target_link_libraries(GD "-O1") # Some optimization at link time (default is -O0), to make the tests run a bit faster in CI.
115+
target_link_libraries(GD "-s INITIAL_MEMORY=512MB") # Start with a large heap: ASan needs a lot of memory (256MB quarantine for freed allocations, shadow memory) and growing the memory repeatedly has a cost. Overrides TOTAL_MEMORY set above.
114116
target_link_libraries(GD "-fsanitize=address") # Uncomment to auto-detect occurences of memory bugs (memory leak, use after free, overflows, ...) - also enable compiling above!
115117
# target_link_libraries(GD "-fsanitize=undefined") # Uncomment to auto-detect occurences of undefined behavior - also enable compiling above!
116118
target_link_libraries(GD "-fsanitize=null") # Uncomment to auto-detect occurences of undefined behavior - also enable compiling above!

GDevelop.js/__tests__/Serializer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ describe('libGD.js object serialization', function () {
105105
']';
106106

107107
const element = gd.Serializer.fromJSON(json);
108+
// Do NOT delete element, it's a static value.
109+
108110
// Round-trips back to the same JSON (also proves the large input was
109111
// parsed correctly, not just that it didn't crash).
110112
expect(gd.Serializer.toJSON(element)).toBe(json);
111-
element.delete();
112113
});
113114
});
114115

0 commit comments

Comments
 (0)