2024-06-05 01:27:48 +03:00
# Running Tests
2021-02-27 01:12:04 +03:00
2024-06-05 01:27:48 +03:00
To reproduce a CI failure, see the section on [Running with Sanitizers ](#running-with-sanitizers ).
2021-02-27 01:12:04 +03:00
2024-06-05 01:27:48 +03:00
The simplest way to run tests locally is to use the `default` preset from ``CMakePresets.json``:
2021-02-27 01:12:04 +03:00
```sh
2024-06-05 01:27:48 +03:00
cmake --preset default
cmake --build --preset default
ctest --preset default
2021-02-27 01:12:04 +03:00
```
2024-06-05 01:27:48 +03:00
If you want to avoid building and running LibWeb tests, you can use a Lagom-only build.
2021-02-27 01:12:04 +03:00
```sh
2024-06-08 00:41:53 +03:00
cmake -GNinja -S Meta/Lagom -B Build/lagom
2021-02-27 01:12:04 +03:00
```
2024-06-05 01:27:48 +03:00
The tests can be run via ninja after doing a build. Note that `test-js` requires the `LADYBIRD_SOURCE_DIR` environment variable to be set
to the root of the ladybird source tree.
2021-02-27 01:12:04 +03:00
```sh
2024-06-05 01:27:48 +03:00
# /path/to/ladybird repository
2024-06-03 15:40:19 +03:00
export LADYBIRD_SOURCE_DIR=${PWD}
2021-09-07 11:35:29 +03:00
cd Build/lagom
2022-05-08 19:26:10 +03:00
ninja
2021-09-07 11:35:29 +03:00
ninja test
2021-02-27 01:12:04 +03:00
```
2021-05-17 19:48:55 +03:00
To see the stdout/stderr output of failing tests, the recommended way is to set the environment variable [`CTEST_OUTPUT_ON_FAILURE` ](https://cmake.org/cmake/help/latest/manual/ctest.1.html#options ) to 1.
2021-02-27 01:12:04 +03:00
2021-05-16 05:13:31 +03:00
```sh
CTEST_OUTPUT_ON_FAILURE=1 ninja test
# or, using ctest directly...
ctest --output-on-failure
```
2024-06-05 01:27:48 +03:00
# Running with Sanitizers
2021-05-16 05:13:31 +03:00
CI runs host tests with Address Sanitizer and Undefined Sanitizer instrumentation enabled. These tools catch many
classes of common C++ errors, including memory leaks, out of bounds access to stack and heap allocations, and
signed integer overflow. For more info on the sanitizers, check out the Address Sanitizer [wiki page ](https://github.com/google/sanitizers/wiki ),
or the Undefined Sanitizer [documentation ](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html ) from clang.
2022-01-06 17:07:15 +03:00
Note that a sanitizer build will take significantly longer than a non-sanitizer build, and will mess with caches in tools such as `ccache` .
2024-06-05 01:27:48 +03:00
The sanitizers can be enabled with the `-DENABLE_FOO_SANITIZER` set of flags.
2021-05-16 05:13:31 +03:00
2024-06-05 01:27:48 +03:00
The simplest way to enable sanitizers is to use the `Sanitizer` preset.
2021-02-27 01:12:04 +03:00
```sh
2024-06-05 01:27:48 +03:00
cmake --preset Sanitizer
cmake --build --preset Sanitizer
ctest --preset Sanitizer
2021-02-27 01:12:04 +03:00
```
2024-06-05 01:27:48 +03:00
Or from a Lagom build:
2021-02-27 01:12:04 +03:00
2024-06-05 01:27:48 +03:00
To ensure that the test behaves the same way as CI, make sure to set the ASAN_OPTIONS and UBSAN_OPTIONS appropriately.
The Sanitizer test preset already sets these environment variables.
2021-02-27 01:12:04 +03:00
```sh
2024-06-05 01:27:48 +03:00
export ASAN_OPTIONS='strict_string_checks=1:check_initialization_order=1:strict_init_order=1:detect_stack_use_after_return=1:allocator_may_return_null=1'
export UBSAN_OPTIONS='print_stacktrace=1:print_summary=1:halt_on_error=1'
2024-06-08 00:41:53 +03:00
cmake -GNinja -S Meta/Lagom -B Build/lagom -DENABLE_ADDRESS_SANITIZER=ON -DENABLE_UNDEFINED_SANITIZER=ON
2024-06-05 01:27:48 +03:00
cd Build/lagom
ninja
CTEST_OUTPUT_ON_FAILURE=1 LADYBIRD_SOURCE_DIR=${PWD}/../.. ninja test
2021-02-27 01:12:04 +03:00
```