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

Worker tests: use unique pointers when possible #1421

Merged
merged 18 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/mediasoup-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ jobs:
# 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'
- 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.
Expand Down
6 changes: 5 additions & 1 deletion worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN set -x \
&& apt-get install --yes \
gcc g++ clang pkg-config bash-completion wget curl \
screen python3-pip python3-yaml pkg-config zlib1g-dev \
libgss-dev libssl-dev libxml2-dev
libgss-dev libssl-dev libxml2-dev gdb

# Install node 20.
RUN set -x \
Expand All @@ -21,6 +21,10 @@ RUN set -x \
&& apt-get update \
&& apt-get install nodejs --yes

# Enable core dumps.
RUN set -x \
&& echo "mkdir -p /tmp/cores && chmod 777 /tmp/cores && echo \"/tmp/cores/core.%e.sig%s.%p\" > /proc/sys/kernel/core_pattern && ulimit -c unlimited" >> ~/.bashrc

# Make CC and CXX point to clang/clang++ installed above.
ENV LANG="C.UTF-8"
ENV CC="clang"
Expand Down
5 changes: 2 additions & 3 deletions worker/test/src/RTC/Codecs/TestH264.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ SCENARIO("parse H264 payload descriptor", "[codecs][h264]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::H264::Parse(buffer, sizeof(buffer));
std::unique_ptr<Codecs::H264::PayloadDescriptor> payloadDescriptor{ Codecs::H264::Parse(
buffer, sizeof(buffer)) };

REQUIRE(payloadDescriptor);

delete payloadDescriptor;
}
}
36 changes: 18 additions & 18 deletions worker/test/src/RTC/Codecs/TestH264_SVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
std::unique_ptr<RTC::Codecs::H264_SVC::PayloadDescriptor> payloadDescriptor{
Codecs::H264_SVC::Parse(buffer, sizeof(buffer))
};

REQUIRE(payloadDescriptor);

Expand All @@ -31,8 +33,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")
REQUIRE(payloadDescriptor->isKeyFrame == true);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);

delete payloadDescriptor;
}

SECTION("parse payload descriptor for NALU 8")
Expand All @@ -49,7 +49,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
std::unique_ptr<RTC::Codecs::H264_SVC::PayloadDescriptor> payloadDescriptor{
Codecs::H264_SVC::Parse(buffer, sizeof(buffer))
};

REQUIRE(payloadDescriptor);

Expand All @@ -59,8 +61,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);

delete payloadDescriptor;
}

SECTION("parse payload descriptor for NALU 1")
Expand All @@ -77,7 +77,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
std::unique_ptr<RTC::Codecs::H264_SVC::PayloadDescriptor> payloadDescriptor{
Codecs::H264_SVC::Parse(buffer, sizeof(buffer))
};

REQUIRE(payloadDescriptor);

Expand All @@ -87,8 +89,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);

delete payloadDescriptor;
}

SECTION("parse payload descriptor for NALU 5")
Expand All @@ -105,7 +105,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
std::unique_ptr<RTC::Codecs::H264_SVC::PayloadDescriptor> payloadDescriptor{
Codecs::H264_SVC::Parse(buffer, sizeof(buffer))
};

REQUIRE(payloadDescriptor);

Expand All @@ -115,8 +117,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")
REQUIRE(payloadDescriptor->isKeyFrame == true);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);

delete payloadDescriptor;
}

SECTION("parse payload descriptor for NALU 14")
Expand All @@ -133,7 +133,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
std::unique_ptr<RTC::Codecs::H264_SVC::PayloadDescriptor> payloadDescriptor{
Codecs::H264_SVC::Parse(buffer, sizeof(buffer))
};

REQUIRE(payloadDescriptor);

Expand All @@ -145,8 +147,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == true);
REQUIRE(payloadDescriptor->hasSlIndex == true);

delete payloadDescriptor;
}

SECTION("parse payload descriptor for NALU 20")
Expand All @@ -163,7 +163,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
std::unique_ptr<RTC::Codecs::H264_SVC::PayloadDescriptor> payloadDescriptor{
Codecs::H264_SVC::Parse(buffer, sizeof(buffer))
};

REQUIRE(payloadDescriptor);

Expand All @@ -175,7 +177,5 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == true);
REQUIRE(payloadDescriptor->hasSlIndex == true);

delete payloadDescriptor;
}
}
10 changes: 4 additions & 6 deletions worker/test/src/RTC/Codecs/TestVP8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]")

std::memcpy(buffer, originalBuffer, sizeof(buffer));

const auto* payloadDescriptor = Codecs::VP8::Parse(buffer, sizeof(buffer));
std::unique_ptr<Codecs::VP8::PayloadDescriptor> payloadDescriptor{ Codecs::VP8::Parse(
buffer, sizeof(buffer)) };

REQUIRE(payloadDescriptor);

Expand Down Expand Up @@ -77,8 +78,6 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]")
REQUIRE(std::memcmp(buffer, originalBuffer, sizeof(buffer)) == 0);
}
}

delete payloadDescriptor;
}

SECTION("parse payload descriptor 2")
Expand Down Expand Up @@ -113,7 +112,8 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]")
std::memcpy(buffer, originalBuffer, sizeof(buffer));

// Parse the buffer.
const auto* payloadDescriptor = Codecs::VP8::Parse(buffer, sizeof(buffer));
std::unique_ptr<Codecs::VP8::PayloadDescriptor> payloadDescriptor{ Codecs::VP8::Parse(
buffer, sizeof(buffer)) };

REQUIRE(payloadDescriptor);

Expand Down Expand Up @@ -152,8 +152,6 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]")
REQUIRE(std::memcmp(buffer, originalBuffer, sizeof(buffer)) == 0);
}
}

delete payloadDescriptor;
};

SECTION("parse payload descriptor. I flag set but no space for pictureId")
Expand Down
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestBye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ SCENARIO("RTCP BYE parsing", "[parser][rtcp][bye]")
{
SECTION("parse BYE packet")
{
ByePacket* packet = ByePacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<ByePacket> packet{ ByePacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -64,8 +64,6 @@ SCENARIO("RTCP BYE parsing", "[parser][rtcp][bye]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}

SECTION("create ByePacket")
Expand Down
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestFeedbackPsAfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ SCENARIO("RTCP Feedback PS AFB parsing", "[parser][rtcp][feedback-ps][afb]")
{
using namespace TestFeedbackPsAfb;

FeedbackPsAfbPacket* packet = FeedbackPsAfbPacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<FeedbackPsAfbPacket> packet{ FeedbackPsAfbPacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -56,7 +56,5 @@ SCENARIO("RTCP Feedback PS AFB parsing", "[parser][rtcp][feedback-ps][afb]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}
}
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ SCENARIO("RTCP Feedback PS FIR parsing", "[parser][rtcp][feedback-ps][fir]")

SECTION("parse FeedbackPsFirPacket")
{
FeedbackPsFirPacket* packet = FeedbackPsFirPacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<FeedbackPsFirPacket> packet{ FeedbackPsFirPacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -61,8 +61,6 @@ SCENARIO("RTCP Feedback PS FIR parsing", "[parser][rtcp][feedback-ps][fir]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}

SECTION("create FeedbackPsFirPacket")
Expand Down
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ SCENARIO("RTCP Feedback PS LEI parsing", "[parser][rtcp][feedback-ps][lei]")

SECTION("parse FeedbackPsLeiPacket")
{
FeedbackPsLeiPacket* packet = FeedbackPsLeiPacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<FeedbackPsLeiPacket> packet{ FeedbackPsLeiPacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -58,8 +58,6 @@ SCENARIO("RTCP Feedback PS LEI parsing", "[parser][rtcp][feedback-ps][lei]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}

SECTION("create FeedbackPsLeiPacket")
Expand Down
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ SCENARIO("RTCP Feeback RTP PLI parsing", "[parser][rtcp][feedback-ps][pli]")

SECTION("parse FeedbackPsPliPacket")
{
FeedbackPsPliPacket* packet = FeedbackPsPliPacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<FeedbackPsPliPacket> packet{ FeedbackPsPliPacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -52,8 +52,6 @@ SCENARIO("RTCP Feeback RTP PLI parsing", "[parser][rtcp][feedback-ps][pli]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}

SECTION("create FeedbackPsPliPacket")
Expand Down
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ SCENARIO("RTCP Feedback PS parsing", "[parser][rtcp][feedback-ps][remb]")

SECTION("parse FeedbackPsRembPacket")
{
FeedbackPsRembPacket* packet = FeedbackPsRembPacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<FeedbackPsRembPacket> packet{ FeedbackPsRembPacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -60,8 +60,6 @@ SCENARIO("RTCP Feedback PS parsing", "[parser][rtcp][feedback-ps][remb]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}

SECTION("create FeedbackPsRembPacket")
Expand Down
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ SCENARIO("RTCP Feedback PS RPSI parsing", "[parser][rtcp][feedback-ps][rpsi]")

SECTION("parse FeedbackPsRpsiPacket")
{
FeedbackPsRpsiPacket* packet = FeedbackPsRpsiPacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<FeedbackPsRpsiPacket> packet{ FeedbackPsRpsiPacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -66,7 +66,5 @@ SCENARIO("RTCP Feedback PS RPSI parsing", "[parser][rtcp][feedback-ps][rpsi]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}
}
6 changes: 2 additions & 4 deletions worker/test/src/RTC/RTCP/TestFeedbackPsSli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ SCENARIO("RTCP Feedback PS SLI parsing", "[parser][rtcp][feedback-ps][sli]")

SECTION("parse FeedbackPsSliPacket")
{
FeedbackPsSliPacket* packet = FeedbackPsSliPacket::Parse(buffer, sizeof(buffer));
std::unique_ptr<FeedbackPsSliPacket> packet{ FeedbackPsSliPacket::Parse(buffer, sizeof(buffer)) };

REQUIRE(packet);

verify(packet);
verify(packet.get());

SECTION("serialize packet instance")
{
Expand All @@ -63,7 +63,5 @@ SCENARIO("RTCP Feedback PS SLI parsing", "[parser][rtcp][feedback-ps][sli]")
REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
}
}

delete packet;
}
}
Loading
Loading