Skip to content

Commit

Permalink
tests: Implement TEST_SKIP()
Browse files Browse the repository at this point in the history
Implement TEST_SKIP() macro that is similar to IGNORE_TEST() from,
cpputest, but works at run-time.

Use TEST_SKIP() instead of plain returns for tests that need to
be skipped.

Use test_harness.h header instead of CppUTest/TestHarness.h
in all tests.
  • Loading branch information
gavv committed Dec 20, 2024
1 parent cbeada5 commit b7a474e
Show file tree
Hide file tree
Showing 39 changed files with 222 additions and 117 deletions.
1 change: 0 additions & 1 deletion .ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
!.justfile
!.projectile
!.unisonignore
!TODO.org
3rdparty/_distfiles
3rdparty/dr_wav
3rdparty/hedley
Expand Down
6 changes: 5 additions & 1 deletion scripts/scons_helpers/format-header.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import filecmp
import fnmatch
import os
import re
Expand Down Expand Up @@ -42,6 +43,8 @@ def make_guard(path):
arr = ['roc', 'public_api', dirname, basename]
else:
arr = ['roc', 'public_api', basename]
elif dirname == '.':
arr = ['roc', basename]
else:
arr = [dirname, basename]
while not arr[0].startswith('roc_') and arr[0] != 'roc':
Expand Down Expand Up @@ -201,4 +204,5 @@ def walk_dir(directory, patterns):
with tempfile.NamedTemporaryFile('w+') as fp:
format_file(fp, path)
fp.flush()
shutil.copy(fp.name, path)
if not filecmp.cmp(path, fp.name):
shutil.copy(fp.name, path)
17 changes: 11 additions & 6 deletions src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,23 @@ if GetOption('enable_tests') or GetOption('enable_benchmarks'):
common_test_env.Prepend(LIBS=[all_modules_libs])

if GetOption('enable_tests'):
test_main_object = common_test_env.Object('tests/test_main.cpp')
test_main_objects = []
for src in common_test_env.Glob('tests/test_*.cpp'):
test_main_objects += common_test_env.Object(src)

if GetOption('enable_benchmarks'):
bench_main_object = common_test_env.Object('tests/bench_main.cpp')
bench_main_objects = []
for src in common_test_env.Glob('tests/bench_*.cpp'):
bench_main_objects += common_test_env.Object(src)

test_targets = []

for test_name in env['ROC_MODULES'] + ['public_api']:
test_dir = 'tests/' + test_name

test_env = common_test_env.DeepClone()
test_env.Append(CPPPATH=['#src/' + test_dir])
test_env.Append(CPPPATH=['#src/tests'])
test_env.Append(CPPPATH=['#src/tests/' + test_name])

if test_name == 'public_api':
if GetOption('disable_shared') and not GetOption('enable_static'):
Expand All @@ -288,12 +293,12 @@ if GetOption('enable_tests') or GetOption('enable_benchmarks'):
for kind in ['test', 'bench']:
if kind == 'test':
if GetOption('enable_tests'):
main_object = test_main_object
main_objects = test_main_objects
else:
continue
else:
if GetOption('enable_benchmarks'):
main_object = bench_main_object
main_objects = bench_main_objects
else:
continue

Expand All @@ -310,7 +315,7 @@ if GetOption('enable_tests') or GetOption('enable_benchmarks'):
if not sources:
continue

sources_and_objects = sources + main_object + sanitizer_objects
sources_and_objects = sources + main_objects + sanitizer_objects
if test_name == 'public_api':
sources_and_objects += public_api_objects

Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>
#include "test_harness.h"

#include "roc_core/stddefs.h"

Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>
#include "test_harness.h"

#include "roc_core/stddefs.h"

Expand Down
9 changes: 4 additions & 5 deletions src/tests/public_api/test_loopback_encoder_2_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>

#include "test_harness.h"
#include "test_helpers/utils.h"

#include "roc_core/macro_helpers.h"
Expand Down Expand Up @@ -408,7 +407,7 @@ TEST(loopback_encoder_2_decoder, source_control) {

TEST(loopback_encoder_2_decoder, source_repair) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

sender_conf.fec_encoding = ROC_FEC_ENCODING_RS8M;
Expand Down Expand Up @@ -452,7 +451,7 @@ TEST(loopback_encoder_2_decoder, source_repair) {

TEST(loopback_encoder_2_decoder, source_repair_losses) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

sender_conf.fec_encoding = ROC_FEC_ENCODING_RS8M;
Expand Down Expand Up @@ -496,7 +495,7 @@ TEST(loopback_encoder_2_decoder, source_repair_losses) {

TEST(loopback_encoder_2_decoder, source_repair_control) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

sender_conf.fec_encoding = ROC_FEC_ENCODING_RS8M;
Expand Down
13 changes: 6 additions & 7 deletions src/tests/public_api/test_loopback_sender_2_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>

#include "test_harness.h"
#include "test_helpers/context.h"
#include "test_helpers/proxy.h"
#include "test_helpers/receiver.h"
Expand Down Expand Up @@ -166,7 +165,7 @@ TEST(loopback_sender_2_receiver, rtp_rtcp) {

TEST(loopback_sender_2_receiver, rs8m_without_losses) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

enum { Flags = test::FlagRS8M, SampleRate = 44100, FrameChans = 2, PacketChans = 2 };
Expand All @@ -192,7 +191,7 @@ TEST(loopback_sender_2_receiver, rs8m_without_losses) {

TEST(loopback_sender_2_receiver, rs8m_with_losses) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

enum {
Expand Down Expand Up @@ -232,7 +231,7 @@ TEST(loopback_sender_2_receiver, rs8m_with_losses) {

TEST(loopback_sender_2_receiver, ldpc_without_losses) {
if (!is_ldpc_supported()) {
return;
TEST_SKIP();
}

enum { Flags = test::FlagLDPC, SampleRate = 44100, FrameChans = 2, PacketChans = 2 };
Expand All @@ -258,7 +257,7 @@ TEST(loopback_sender_2_receiver, ldpc_without_losses) {

TEST(loopback_sender_2_receiver, ldpc_with_losses) {
if (!is_ldpc_supported()) {
return;
TEST_SKIP();
}

enum {
Expand Down Expand Up @@ -632,7 +631,7 @@ TEST(loopback_sender_2_receiver, multitrack_separate_contexts) {
// Smoke test for various counters, durations, etc.
TEST(loopback_sender_2_receiver, metrics_measurements) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

enum {
Expand Down
7 changes: 3 additions & 4 deletions src/tests/public_api/test_plugin_plc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>

#include "test_harness.h"
#include "test_helpers/context.h"
#include "test_helpers/proxy.h"
#include "test_helpers/receiver.h"
Expand Down Expand Up @@ -231,7 +230,7 @@ TEST_GROUP(plugin_plc) {
// Check that all all packets were restored by FEC and not by PLC.
TEST(plugin_plc, losses_restored_by_fec) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

enum { Flags = test::FlagRS8M | test::FlagLoseSomePkts };
Expand Down Expand Up @@ -284,7 +283,7 @@ TEST(plugin_plc, losses_restored_by_fec) {
// Check that PLC was used to restore packets.
TEST(plugin_plc, losses_restored_by_plc) {
if (!is_rs8m_supported()) {
return;
TEST_SKIP();
}

enum {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>
#include "test_harness.h"

#include "roc_core/macro_helpers.h"
#include "roc_core/stddefs.h"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_receiver_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>
#include "test_harness.h"

#include "roc_core/macro_helpers.h"
#include "roc_core/stddefs.h"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>
#include "test_harness.h"

#include "roc_core/macro_helpers.h"
#include "roc_core/stddefs.h"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_sender_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>
#include "test_harness.h"

#include "roc_core/macro_helpers.h"
#include "roc_core/stddefs.h"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>
#include "test_harness.h"

#include "roc/version.h"

Expand Down
3 changes: 1 addition & 2 deletions src/tests/roc_fec/test_block_encoder_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>

#include "test_harness.h"
#include "test_helpers/mock_arena.h"

#include "roc_core/array.h"
Expand Down
7 changes: 3 additions & 4 deletions src/tests/roc_fec/test_block_writer_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>

#include "test_harness.h"
#include "test_helpers/packet_dispatcher.h"

#include "roc_core/heap_arena.h"
Expand Down Expand Up @@ -2592,7 +2591,7 @@ TEST(block_writer_reader, reader_oversized_repair_block) {

TEST(block_writer_reader, reader_invalid_fec_scheme_source_packet) {
if (CodecMap::instance().num_schemes() == 1) {
return;
TEST_SKIP();
}

for (size_t n_scheme = 0; n_scheme < CodecMap::instance().num_schemes(); ++n_scheme) {
Expand Down Expand Up @@ -2665,7 +2664,7 @@ TEST(block_writer_reader, reader_invalid_fec_scheme_source_packet) {

TEST(block_writer_reader, reader_invalid_fec_scheme_repair_packet) {
if (CodecMap::instance().num_schemes() == 1) {
return;
TEST_SKIP();
}

for (size_t n_scheme = 0; n_scheme < CodecMap::instance().num_schemes(); ++n_scheme) {
Expand Down
15 changes: 7 additions & 8 deletions src/tests/roc_fec/test_block_writer_reader_duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <CppUTest/TestHarness.h>

#include "test_harness.h"
#include "test_helpers/packet_dispatcher.h"

#include "roc_core/heap_arena.h"
Expand Down Expand Up @@ -113,7 +112,7 @@ TEST_GROUP(block_writer_reader_duration) {

TEST(block_writer_reader_duration, no_losses) {
if (!fec_supported()) {
return;
TEST_SKIP();
}

test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory,
Expand Down Expand Up @@ -155,7 +154,7 @@ TEST(block_writer_reader_duration, no_losses) {

TEST(block_writer_reader_duration, lost_first_packet_in_first_block) {
if (!fec_supported()) {
return;
TEST_SKIP();
}

test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory,
Expand Down Expand Up @@ -202,7 +201,7 @@ TEST(block_writer_reader_duration, lost_first_packet_in_first_block) {

TEST(block_writer_reader_duration, lost_first_packet_in_third_block) {
if (!fec_supported()) {
return;
TEST_SKIP();
}

test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory,
Expand Down Expand Up @@ -249,7 +248,7 @@ TEST(block_writer_reader_duration, lost_first_packet_in_third_block) {

TEST(block_writer_reader_duration, lost_almost_every_packet) {
if (!fec_supported()) {
return;
TEST_SKIP();
}

test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory,
Expand Down Expand Up @@ -297,7 +296,7 @@ TEST(block_writer_reader_duration, lost_almost_every_packet) {

TEST(block_writer_reader_duration, lost_single_block) {
if (!fec_supported()) {
return;
TEST_SKIP();
}

test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory,
Expand Down Expand Up @@ -349,7 +348,7 @@ TEST(block_writer_reader_duration, lost_single_block) {

TEST(block_writer_reader_duration, resize_block_middle) {
if (!fec_supported()) {
return;
TEST_SKIP();
}

test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory,
Expand Down
Loading

0 comments on commit b7a474e

Please sign in to comment.