Skip to content

Commit

Permalink
switch to unity testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Jun 25, 2024
1 parent 9382ed0 commit e837734
Show file tree
Hide file tree
Showing 22 changed files with 4,282 additions and 490 deletions.
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ list(FILTER AUX_TEST_SOURCES EXCLUDE REGEX "test_.*\\.c")
list(FILTER AUX_TEST_SOURCES EXCLUDE REGEX "perf_.*\\.c")
list(FILTER AUX_TEST_SOURCES EXCLUDE REGEX "mock_.*\\.c")

pkg_check_modules(PC_CHECK REQUIRED check)
include_directories(${PC_CHECK_INCLUDE_DIRS})
link_directories(${PC_CHECK_LIBRARY_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/unity-2.5.2/src/)

foreach(curTest ${TEST_SOURCES})
get_filename_component(curTestName ${curTest} NAME_WE)
add_test(NAME ${curTestName} COMMAND ${curTestName} ${curTest})
add_executable(${curTestName} ${curTest} ${AUX_TEST_SOURCES})
target_link_libraries(${curTestName} sdr_serverLib ${PC_CHECK_LIBRARIES})
add_executable(${curTestName} ${curTest} ${AUX_TEST_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/test/unity-2.5.2/src/unity.c)
target_link_libraries(${curTestName} sdr_serverLib)
endforeach()

foreach(curPerfTest ${PERF_SOURCES})
get_filename_component(curPerfTestName ${curPerfTest} NAME_WE)
add_executable(${curPerfTestName} ${curPerfTest})
target_link_libraries(${curPerfTestName} sdr_serverLib ${PC_CHECK_LIBRARIES})
target_link_libraries(${curPerfTestName} sdr_serverLib)
endforeach()

if(CMAKE_BUILD_TYPE MATCHES Debug)
Expand Down
2 changes: 1 addition & 1 deletion docker/bionic.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ENV DEBIAN_FRONTEND noninteractive
COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg
RUN echo "deb http://r2cloud.s3.amazonaws.com bionic main" >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic bionic main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion docker/bookworm.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ENV DEBIAN_FRONTEND noninteractive
COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg
RUN echo "deb http://r2cloud.s3.amazonaws.com bookworm main" >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic bookworm main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion docker/bullseye.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ENV DEBIAN_FRONTEND noninteractive
COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg
RUN echo "deb http://r2cloud.s3.amazonaws.com bullseye main" >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic bullseye main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion docker/buster.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ENV DEBIAN_FRONTEND noninteractive
COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg
RUN echo "deb http://r2cloud.s3.amazonaws.com buster main" >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic buster main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion docker/focal.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ENV DEBIAN_FRONTEND noninteractive
COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg
RUN echo "deb http://r2cloud.s3.amazonaws.com focal main" >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic focal main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion docker/jammy.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ENV DEBIAN_FRONTEND noninteractive
COPY --chmod=644 r2cloud.gpg /etc/apt/trusted.gpg.d/r2cloud.gpg
RUN echo "deb http://r2cloud.s3.amazonaws.com jammy main" >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic jammy main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion docker/stretch.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RUN echo 'deb http://archive.debian.org/debian/ stretch main non-free contrib' >
RUN echo 'deb http://archive.debian.org/debian-security/ stretch/updates main non-free contrib' >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com stretch main" >> /etc/apt/sources.list
RUN echo "deb http://r2cloud.s3.amazonaws.com/cpu-generic stretch main" >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev check pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --no-install-recommends -y build-essential file valgrind cmake libconfig-dev pkg-config libvolk2-dev libvolk2-bin librtlsdr-dev zlib1g-dev && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion test/perf_xlating.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(void) {
uint32_t target_freq = 48000;
float *taps = NULL;
size_t len;
int code = create_low_pass_filter(1.0, sampling_freq, target_freq / 2, 2000, &taps, &len);
int code = create_low_pass_filter(1.0f, sampling_freq, target_freq / 2, 2000, &taps, &len);
if (code != 0) {
exit(EXIT_FAILURE);
}
Expand Down
137 changes: 51 additions & 86 deletions test/test_config.c
Original file line number Diff line number Diff line change
@@ -1,110 +1,75 @@
#include <stdlib.h>
#include <check.h>
#include <unity.h>
#include "../src/config.h"

struct server_config *config = NULL;

START_TEST (test_missing_file) {
int code = create_server_config(&config, "non-existing-configration-file.config");
ck_assert_int_eq(code, -1);
void test_missing_file() {
int code = create_server_config(&config, "non-existing-configration-file.config");
TEST_ASSERT_EQUAL_INT(code, -1);
}
END_TEST

START_TEST (test_invalid_format) {
int code = create_server_config(&config, "invalid.format.config");
ck_assert_int_eq(code, -1);
void test_invalid_format() {
int code = create_server_config(&config, "invalid.format.config");
TEST_ASSERT_EQUAL_INT(code, -1);
}
END_TEST

START_TEST (test_missing_required) {
int code = create_server_config(&config, "invalid.config");
ck_assert_int_eq(code, -1);
void test_missing_required() {
int code = create_server_config(&config, "invalid.config");
TEST_ASSERT_EQUAL_INT(code, -1);
}
END_TEST

START_TEST (test_invalid_timeout) {
int code = create_server_config(&config, "invalid2.config");
ck_assert_int_eq(code, -1);
void test_invalid_timeout() {
int code = create_server_config(&config, "invalid2.config");
TEST_ASSERT_EQUAL_INT(code, -1);
}
END_TEST

START_TEST (test_invalid_queue_size_config) {
int code = create_server_config(&config, "invalid.queue_size.config");
ck_assert_int_eq(code, -1);
void test_invalid_queue_size_config() {
int code = create_server_config(&config, "invalid.queue_size.config");
TEST_ASSERT_EQUAL_INT(code, -1);
}
END_TEST

START_TEST (test_minimal_config) {
int code = create_server_config(&config, "minimal.config");
ck_assert_int_eq(code, 0);
void test_minimal_config() {
int code = create_server_config(&config, "minimal.config");
TEST_ASSERT_EQUAL_INT(code, 0);
}
END_TEST

START_TEST (test_success) {
int code = create_server_config(&config, "configuration.config");
ck_assert_int_eq(code, 0);
ck_assert_int_eq(2400000, config->band_sampling_rate);
ck_assert_int_eq(1, config->gain_mode);
ck_assert_int_eq(42, config->gain);
ck_assert_int_eq(0, config->bias_t);
ck_assert_int_eq(config->ppm, 10);
ck_assert_int_eq(config->device_index, 1);
ck_assert_str_eq(config->device_serial, "00000400");
ck_assert_str_eq(config->bind_address, "127.0.0.1");
ck_assert_int_eq(config->port, 8089);
ck_assert_int_eq(config->buffer_size, 131072);
ck_assert_str_eq(config->base_path, "/tmp/");
ck_assert_int_eq(config->read_timeout_seconds, 10);
ck_assert_int_eq(config->use_gzip, 0);
ck_assert_int_eq(config->queue_size, 64);
ck_assert_int_eq(config->lpf_cutoff_rate, 5);
void test_success() {
int code = create_server_config(&config, "configuration.config");
TEST_ASSERT_EQUAL_INT(code, 0);
TEST_ASSERT_EQUAL_INT(2400000, config->band_sampling_rate);
TEST_ASSERT_EQUAL_INT(1, config->gain_mode);
TEST_ASSERT_EQUAL_INT(42, config->gain);
TEST_ASSERT_EQUAL_INT(0, config->bias_t);
TEST_ASSERT_EQUAL_INT(config->ppm, 10);
TEST_ASSERT_EQUAL_INT(config->device_index, 1);
TEST_ASSERT_EQUAL_STRING(config->device_serial, "00000400");
TEST_ASSERT_EQUAL_STRING(config->bind_address, "127.0.0.1");
TEST_ASSERT_EQUAL_INT(config->port, 8089);
TEST_ASSERT_EQUAL_INT(config->buffer_size, 131072);
TEST_ASSERT_EQUAL_STRING(config->base_path, "/tmp/");
TEST_ASSERT_EQUAL_INT(config->read_timeout_seconds, 10);
TEST_ASSERT_EQUAL_INT(config->use_gzip, 0);
TEST_ASSERT_EQUAL_INT(config->queue_size, 64);
TEST_ASSERT_EQUAL_INT(config->lpf_cutoff_rate, 5);
}
END_TEST

void teardown() {
destroy_server_config(config);
config = NULL;
void tearDown() {
destroy_server_config(config);
config = NULL;
}

void setup() {
//do nothing
}

Suite* common_suite(void) {
Suite *s;
TCase *tc_core;

s = suite_create("config");

/* Core test case */
tc_core = tcase_create("Core");

tcase_add_test(tc_core, test_success);
tcase_add_test(tc_core, test_missing_required);
tcase_add_test(tc_core, test_missing_file);
tcase_add_test(tc_core, test_invalid_format);
tcase_add_test(tc_core, test_minimal_config);
tcase_add_test(tc_core, test_invalid_timeout);
tcase_add_test(tc_core, test_invalid_queue_size_config);

tcase_add_checked_fixture(tc_core, setup, teardown);
suite_add_tcase(s, tc_core);

return s;
void setUp() {
//do nothing
}

int main(void) {
int number_failed;
Suite *s;
SRunner *sr;

s = common_suite();
sr = srunner_create(s);

srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
UNITY_BEGIN();
RUN_TEST(test_success);
RUN_TEST(test_missing_required);
RUN_TEST(test_missing_file);
RUN_TEST(test_invalid_format);
RUN_TEST(test_minimal_config);
RUN_TEST(test_invalid_timeout);
RUN_TEST(test_invalid_queue_size_config);
return UNITY_END();
}

Loading

0 comments on commit e837734

Please sign in to comment.