From 15cdc143bf89a0a788b3e6210f1b7bb3d6fb3053 Mon Sep 17 00:00:00 2001 From: satoren Date: Fri, 14 Jul 2023 00:17:07 +0900 Subject: [PATCH] add test with ASAN (#1118) --- doc/Building.md | 5 +++++ worker/Makefile | 6 ++++++ worker/meson.build | 49 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/doc/Building.md b/doc/Building.md index ca18ebf5ad..a591bbfc9f 100644 --- a/doc/Building.md +++ b/doc/Building.md @@ -154,6 +154,11 @@ Rewrites mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/ Builds and runs the `mediasoup-worker-test` binary at `worker/out/Release/` (or at `worker/out/Debug/` if the "MEDIASOUP_BUILDTYPE" environment variable is set to "Debug"), which uses [Catch2](https://github.com/catchorg/Catch2) to run test units located at `worker/test/` folder. + +### 'make test-asan' + +Run test with Address Sanitizer. + ### `make tidy` Runs [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) and performs C++ code checks following `worker/.clang-tidy` rules. diff --git a/worker/Makefile b/worker/Makefile index ed969cce4c..af74457eb5 100644 --- a/worker/Makefile +++ b/worker/Makefile @@ -81,6 +81,7 @@ endif lint \ format \ test \ + test-asan \ tidy \ fuzzer \ fuzzer-run-all \ @@ -225,6 +226,11 @@ else $(BUILD_DIR)/mediasoup-worker-test --invisibles --use-colour=yes $(MEDIASOUP_TEST_TAGS) endif +test-asan: setup + $(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker-test-asan + $(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker-test-asan + ASAN_OPTIONS=detect_leaks=1 $(BUILD_DIR)/mediasoup-worker-test-asan --invisibles --use-colour=yes $(MEDIASOUP_TEST_TAGS) + tidy: $(PYTHON) ./scripts/clang-tidy.py \ -clang-tidy-binary=./scripts/node_modules/.bin/clang-tidy \ diff --git a/worker/meson.build b/worker/meson.build index ba2ed3f321..9aaff0da55 100644 --- a/worker/meson.build +++ b/worker/meson.build @@ -280,15 +280,7 @@ executable( cpp_args: cpp_args + ['-DMS_EXECUTABLE'], ) -mediasoup_worker_test = executable( - 'mediasoup-worker-test', - build_by_default: false, - install: true, - install_tag: 'mediasoup-worker-test', - dependencies: dependencies + [ - catch2_proj.get_variable('catch2_dep'), - ], - sources: common_sources + [ +test_sources = [ 'test/src/tests.cpp', 'test/src/PayloadChannel/TestPayloadChannelNotification.cpp', 'test/src/PayloadChannel/TestPayloadChannelRequest.cpp', @@ -333,7 +325,17 @@ mediasoup_worker_test = executable( 'test/src/Utils/TestJson.cpp', 'test/src/Utils/TestString.cpp', 'test/src/Utils/TestTime.cpp', +] + +mediasoup_worker_test = executable( + 'mediasoup-worker-test', + build_by_default: false, + install: true, + install_tag: 'mediasoup-worker-test', + dependencies: dependencies + [ + catch2_proj.get_variable('catch2_dep'), ], + sources: common_sources + test_sources, include_directories: include_directories( 'include', 'test/include', @@ -350,6 +352,35 @@ test( workdir: meson.project_source_root(), ) +mediasoup_worker_test_asan = executable( + 'mediasoup-worker-test-asan', + build_by_default: false, + install: true, + install_tag: 'mediasoup-worker-test-asan', + dependencies: dependencies + [ + catch2_proj.get_variable('catch2_dep'), + ], + sources: common_sources + test_sources, + include_directories: include_directories( + 'include', + 'test/include', + ), + cpp_args: cpp_args + [ + '-DMS_LOG_STD', + '-DMS_TEST', + '-fsanitize=address', + ], + link_args: [ + '-fsanitize=address', + ], +) + +test( + 'mediasoup-worker-test-asan', + mediasoup_worker_test_asan, + workdir: meson.project_source_root(), +) + executable( 'mediasoup-worker-fuzzer', build_by_default: false,