From 33b74cfb2dac32bb9876acbaa96319d70d6dcb0b Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Wed, 24 Jul 2024 17:14:53 -0300 Subject: [PATCH] Improving detection of garbage collection bugs --- CONTRIBUTING.md | 14 +++++++++++++- run-tests | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 31a83acd..8fc9fbd1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,7 +47,19 @@ Flag | Effect ./run-tests -k | Run all tests even if some tests are failing ./run-tests -o gtest | The gtest output format might be easier to read if you are using print statements for debugging. -For convenience, when the test script is run without any parameters, it also runs the linter at the end. +For convenience, when the test script is run without any busted parameters, it also runs the linter at the end. + +#### Testing garbage collection + +Doing proper GC testing takes longer, so we have a special mode for doing that. +For testing garbage collection more carefully, pass "gc" as the first parameter +of the script. The rest of the parameters will do the same as before: + +```sh +$ ./run-tests gc # Run all tests but with proper GC testing +$ ./run-tests gc spec/parser_spec.lua # Run just one of the test suite files + # but with proper GC testing +``` ### Running the benchmarks suite diff --git a/run-tests b/run-tests index e804cbe1..87fbb1c0 100755 --- a/run-tests +++ b/run-tests @@ -1,11 +1,17 @@ #!/bin/bash -# HOW TO USE: This is a wrapper around busted. The command-line arguments are the same. +# HOW TO USE: This is a wrapper around busted. Pass "gc" as the first argument for testing the +# garbage collector. Except for "gc", the command-line arguments are the same of busted # # EXAMPLES: # ./run-tests # ./run-tests -k # ./run-tests spec/coder_spec.lua +# ./run-tests gc +# ./run-tests gc -k + +test_gc="" +[ "$1" = "gc" ] && test_gc="y" && shift echo "--- Test Suite ---" @@ -21,6 +27,11 @@ FLAGS=(--verbose --no-keep-going) # Also, add some compiler flags to verify standard compliance. export CFLAGS='-O0 -std=c99 -Wall -Werror -Wundef -Wpedantic -Wno-unused' +# When testing the garbage collector, we use -O2 for a greater chance of finding bugs. +# The HARDMEMTESTS macro makes lualib do garbage collection whenever it can. +[ -n "$test_gc" ] && + CFLAGS='-DHARDMEMTESTS -O2 -std=c99 -Wall -Werror -Wundef -Wpedantic -Wno-unused' + if [ "$#" -eq 0 ]; then if command -v parallel >/dev/null; then parallel busted -o utfTerminal "${FLAGS[@]}" ::: spec/*_spec.lua