Skip to content

Commit

Permalink
CI: Really run fuzzer for 5 minutes (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Feb 21, 2024
1 parent 780bd7a commit 74934de
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/mediasoup-worker-fuzzer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ jobs:
- name: invoke -r worker fuzzer
run: invoke -r worker fuzzer

# We don't run mediasoup-worker-fuzzer (maybe in the future).
# Run mediasoup-worker-fuzzer for 5 minutes.
- name: run-fuzzer.sh 300
run: cd worker && ./scripts/run-fuzzer.sh 300
3 changes: 3 additions & 0 deletions worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ENV CXX="clang++"

ENV MEDIASOUP_LOCAL_DEV="true"
ENV KEEP_BUILD_ARTIFACTS="1"
# Disable liburing due to this bug:
# https://github.com/versatica/mediasoup/issues/1334
ENV MESON_ARGS="-Dms_disable_liburing=true"

WORKDIR /mediasoup

Expand Down
3 changes: 3 additions & 0 deletions worker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ ENV CXX="g++"

ENV MEDIASOUP_LOCAL_DEV="true"
ENV KEEP_BUILD_ARTIFACTS="1"
# Disable liburing due to this bug:
# https://github.com/versatica/mediasoup/issues/1334
ENV MESON_ARGS="-Dms_disable_liburing=true"

WORKDIR /mediasoup

Expand Down
38 changes: 38 additions & 0 deletions worker/scripts/run-fuzzer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

WORKER_PWD=${PWD}
DURATION_SEC=$1

current_dir_name=${WORKER_PWD##*/}
if [ "${current_dir_name}" != "worker" ] ; then
echo "run-fuzzer.sh [ERROR] $(basename $0) must be called from mediasoup/worker directory" >&2
exit 1
fi

if [ "$#" -eq 0 ] ; then
echo "run-fuzzer.sh [ERROR] duration (in seconds) must be fiven as argument" >&2
exit 1
fi

invoke fuzzer-run-all &

MEDIASOUP_WORKER_FUZZER_PID=$!

i=${DURATION_SEC}

until [ ${i} -eq 0 ]
do
echo "run-fuzzer.sh [INFO] ${i} seconds left"
if ! kill -0 ${MEDIASOUP_WORKER_FUZZER_PID} &> /dev/null ; then
echo "run-fuzzer.sh [ERROR] mediasoup-worker-fuzzer died" >&2
exit 1
else
((i=i-1))
sleep 1
fi
done

echo "run-fuzzer.sh [INFO] mediasoup-worker-fuzzer is still running after given ${DURATION_SEC} seconds so no fuzzer issues so far"

kill -SIGTERM ${MEDIASOUP_WORKER_FUZZER_PID} &> /dev/null
exit 0
16 changes: 10 additions & 6 deletions worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import inspect;
import shutil;
# We import this from a custom location and pylint doesn't know.
from invoke import task; # pylint: disable=import-error
from invoke import task, call; # pylint: disable=import-error

MEDIASOUP_BUILDTYPE = os.getenv('MEDIASOUP_BUILDTYPE') or 'Release';
WORKER_DIR = os.path.dirname(os.path.abspath(
Expand Down Expand Up @@ -135,30 +135,30 @@ def meson_ninja(ctx):


@task(pre=[meson_ninja])
def setup(ctx):
def setup(ctx, meson_args=MESON_ARGS):
"""
Run meson setup
"""
if MEDIASOUP_BUILDTYPE == 'Release':
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype release -Db_ndebug=true {MESON_ARGS} "{BUILD_DIR}"',
f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype release -Db_ndebug=true {meson_args} "{BUILD_DIR}"',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);
elif MEDIASOUP_BUILDTYPE == 'Debug':
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype debug {MESON_ARGS} "{BUILD_DIR}"',
f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype debug {meson_args} "{BUILD_DIR}"',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
);
else:
with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype {MEDIASOUP_BUILDTYPE} -Db_ndebug=if-release {MESON_ARGS} "{BUILD_DIR}"',
f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype {MEDIASOUP_BUILDTYPE} -Db_ndebug=if-release {meson_args} "{BUILD_DIR}"',
echo=True,
pty=PTY_SUPPORTED,
shell=SHELL
Expand Down Expand Up @@ -464,11 +464,15 @@ def tidy(ctx):
);


@task(pre=[setup, flatc])
@task(pre=[call(setup, meson_args=MESON_ARGS + ' -Db_sanitize=address'), flatc])
def fuzzer(ctx):
"""
Build the mediasoup-worker-fuzzer binary (which uses libFuzzer)
"""

# NOTE: We need to pass '-Db_sanitize=address' to enable fuzzer in all Meson
# subprojects, so we pass it to the setup() task.

with ctx.cd(f'"{WORKER_DIR}"'):
ctx.run(
f'"{MESON}" compile -C "{BUILD_DIR}" -j {NUM_CORES} mediasoup-worker-fuzzer',
Expand Down

0 comments on commit 74934de

Please sign in to comment.