Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Run worker tests with Address Sanitizer (only Linux) #1416

Merged
merged 12 commits into from
Jul 1, 2024
21 changes: 21 additions & 0 deletions .github/workflows/mediasoup-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,24 @@ jobs:
run: invoke -r worker test
# TODO: Maybe fix this one day.
if: runner.os != 'Windows'

# TODO: Uncomment once https://github.com/versatica/mediasoup/issues/1417
# is fixed.
# - name: invoke -r worker test-asan-address
# run: invoke -r worker test-asan-address
# # Address Sanitizer only works on Linux.
# if: runner.os == 'Linux'

# TODO: Uncomment once https://github.com/versatica/mediasoup/issues/1417
# is fixed.
# - name: invoke -r worker test-asan-undefined
# run: invoke -r worker test-asan-undefined
# # Address Sanitizer only works on Linux.
# if: runner.os == 'Linux'

# TODO: Uncomment once https://github.com/versatica/mediasoup/issues/1417
# is fixed.
# - name: invoke -r worker test-asan-thread
# run: invoke -r worker test-asan-thread
# # Address Sanitizer only works on Linux.
# if: runner.os == 'Linux'
12 changes: 10 additions & 2 deletions doc/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,17 @@ 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.

### `invoke test-asan`
### `invoke test-asan-address`

Run test with Address Sanitizer.
Run test with Address Sanitizer with `-fsanitize=address`.

### `invoke test-asan-undefined`

Run test with Address Sanitizer with `-fsanitize=undefined`.

### `invoke test-asan-thread`

Run test with Address Sanitizer with `-fsanitize=thread`.

### `invoke tidy`

Expand Down
14 changes: 11 additions & 3 deletions worker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ endif
lint \
format \
test \
test-asan \
test-asan-address \
test-asan-undefined \
test-asan-thread \
tidy \
fuzzer \
fuzzer-run-all \
Expand Down Expand Up @@ -96,8 +98,14 @@ format: invoke
test: invoke
"$(PYTHON)" -m invoke test

test-asan: invoke
"$(PYTHON)" -m invoke test-asan
test-asan-address: invoke
"$(PYTHON)" -m invoke test-asan-address

test-asan-undefined: invoke
"$(PYTHON)" -m invoke test-asan-undefined

test-asan-thread: invoke
"$(PYTHON)" -m invoke test-asan-thread

tidy: invoke
"$(PYTHON)" -m invoke tidy
Expand Down
68 changes: 63 additions & 5 deletions worker/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ test(
workdir: meson.project_source_root(),
)

mediasoup_worker_test_asan = executable(
'mediasoup-worker-test-asan',
mediasoup_worker_test_asan_address = executable(
'mediasoup-worker-test-asan-address',
build_by_default: false,
install: true,
install_tag: 'mediasoup-worker-test-asan',
install_tag: 'mediasoup-worker-test-asan-address',
dependencies: dependencies + [
catch2_proj.get_variable('catch2_dep'),
],
Expand All @@ -417,8 +417,66 @@ mediasoup_worker_test_asan = executable(
)

test(
'mediasoup-worker-test-asan',
mediasoup_worker_test_asan,
'mediasoup-worker-test-asan-address',
mediasoup_worker_test_asan_address,
workdir: meson.project_source_root(),
)

mediasoup_worker_test_asan_undefined = executable(
'mediasoup-worker-test-asan-undefined',
build_by_default: false,
install: true,
install_tag: 'mediasoup-worker-test-asan-undefined',
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=undefined',
],
link_args: [
'-fsanitize=undefined',
],
)

test(
'mediasoup-worker-test-asan-undefined',
mediasoup_worker_test_asan_undefined,
workdir: meson.project_source_root(),
)

mediasoup_worker_test_asan_thread = executable(
'mediasoup-worker-test-asan-thread',
build_by_default: false,
install: true,
install_tag: 'mediasoup-worker-test-asan-thread',
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=thread',
],
link_args: [
'-fsanitize=thread',
],
)

test(
'mediasoup-worker-test-asan-thread',
mediasoup_worker_test_asan_thread,
workdir: meson.project_source_root(),
)

Expand Down
12 changes: 6 additions & 6 deletions worker/subprojects/catch2.wrap
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[wrap-file]
directory = Catch2-3.5.3
source_url = https://github.com/catchorg/Catch2/archive/v3.5.3.tar.gz
source_filename = Catch2-3.5.3.tar.gz
source_hash = 8d723b0535c94860ef8cf6231580fa47d67a3416757ecb10639e40d748ab6c71
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.5.3-1/Catch2-3.5.3.tar.gz
wrapdb_version = 3.5.3-1
directory = Catch2-3.6.0
source_url = https://github.com/catchorg/Catch2/archive/v3.6.0.tar.gz
source_filename = Catch2-3.6.0.tar.gz
source_hash = 485932259a75c7c6b72d4b874242c489ea5155d17efa345eb8cc72159f49f356
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.6.0-1/Catch2-3.6.0.tar.gz
wrapdb_version = 3.6.0-1

[provide]
catch2 = catch2_dep
Expand Down
18 changes: 9 additions & 9 deletions worker/subprojects/liburing.wrap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[wrap-file]
directory = liburing-liburing-2.4
source_url = https://github.com/axboe/liburing/archive/refs/tags/liburing-2.4.tar.gz
source_filename = liburing-2.4.tar.gz
source_hash = 2398ec82d967a6f903f3ae1fd4541c754472d3a85a584dc78c5da2fabc90706b
patch_filename = liburing_2.4-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/liburing_2.4-2/get_patch
patch_hash = 0435ae1012065fa96a22e1068c2e39e2f7c7c03b58a812774434a6e7455d7f20
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/liburing_2.4-2/liburing-2.4.tar.gz
wrapdb_version = 2.4-2
directory = liburing-liburing-2.5
source_url = https://github.com/axboe/liburing/archive/refs/tags/liburing-2.5.tar.gz
source_filename = liburing-2.5.tar.gz
source_hash = 456f5f882165630f0dc7b75e8fd53bd01a955d5d4720729b4323097e6e9f2a98
patch_filename = liburing_2.5-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/liburing_2.5-1/get_patch
patch_hash = d72f651e0edd8102535af575d682ce86c3fc2fdabb40b8faa2659d0f7d437f44
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/liburing_2.5-1/liburing-2.5.tar.gz
wrapdb_version = 2.5-1

[provide]
dependency_names = liburing
74 changes: 68 additions & 6 deletions worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,83 @@ def test(ctx):
);


@task(pre=[setup, flatc])
def test_asan(ctx):
@task(pre=[call(setup, meson_args=MESON_ARGS + ' -Db_sanitize=address'), flatc])
def test_asan_address(ctx):
"""
Run worker test with Address Sanitizer with '-fsanitize=address'
"""
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" compile -C "{BUILD_DIR}" -j {NUM_CORES} mediasoup-worker-test-asan-address',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" install -C "{BUILD_DIR}" --no-rebuild --tags mediasoup-worker-test-asan-address',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);

mediasoup_test_tags = os.getenv('MEDIASOUP_TEST_TAGS') or '';

with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'ASAN_OPTIONS=detect_leaks=1 "{BUILD_DIR}/mediasoup-worker-test-asan-address" --invisibles {mediasoup_test_tags}',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);


@task(pre=[call(setup, meson_args=MESON_ARGS + ' -Db_sanitize=undefined'), flatc])
def test_asan_undefined(ctx):
"""
Run worker test with undefined Sanitizer with -fsanitize=undefined
"""
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" compile -C "{BUILD_DIR}" -j {NUM_CORES} mediasoup-worker-test-asan-undefined',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" install -C "{BUILD_DIR}" --no-rebuild --tags mediasoup-worker-test-asan-undefined',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);

mediasoup_test_tags = os.getenv('MEDIASOUP_TEST_TAGS') or '';

with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'ASAN_OPTIONS=detect_leaks=1 "{BUILD_DIR}/mediasoup-worker-test-asan-undefined" --invisibles {mediasoup_test_tags}',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);


@task(pre=[call(setup, meson_args=MESON_ARGS + ' -Db_sanitize=thread'), flatc])
def test_asan_thread(ctx):
"""
Run worker test with Address Sanitizer
Run worker test with thread Sanitizer with -fsanitize=thread
"""
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" compile -C "{BUILD_DIR}" -j {NUM_CORES} mediasoup-worker-test-asan',
f'"{MESON}" compile -C "{BUILD_DIR}" -j {NUM_CORES} mediasoup-worker-test-asan-thread',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" install -C "{BUILD_DIR}" --no-rebuild --tags mediasoup-worker-test-asan',
f'"{MESON}" install -C "{BUILD_DIR}" --no-rebuild --tags mediasoup-worker-test-asan-thread',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
Expand All @@ -413,7 +475,7 @@ def test_asan(ctx):

with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'ASAN_OPTIONS=detect_leaks=1 "{BUILD_DIR}/mediasoup-worker-test-asan" --invisibles --use-colour=yes {mediasoup_test_tags}',
f'ASAN_OPTIONS=detect_leaks=1 "{BUILD_DIR}/mediasoup-worker-test-asan-thread" --invisibles {mediasoup_test_tags}',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
Expand Down
1 change: 1 addition & 0 deletions worker/test/src/RTC/TestRtpPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
// clang-format on

Expand Down
Loading