Skip to content
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
2 changes: 1 addition & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ envCython.Program(f'{visionipc_dir.abspath}/visionipc_pyx.so', f'{visionipc_dir.
LIBS=vipc_libs)

if GetOption('extras'):
env.Program('msgq/test_runner', ['msgq/test_runner.cc', 'msgq/msgq_tests.cc'], LIBS=[msgq]+common)
env.Program('msgq/test_runner', ['msgq/msgq_tests.cc'], LIBS=[msgq]+common)

Export('visionipc', 'msgq', 'msgq_python')
2 changes: 0 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import os
import platform
import subprocess
import sysconfig
import catch2

arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
if platform.system() == "Darwin":
Expand All @@ -11,7 +10,6 @@ if platform.system() == "Darwin":
common = []

cpppath = [
catch2.INCLUDE_DIR,
"#/",
'#msgq/',
'/usr/lib/include',
Expand Down
4 changes: 2 additions & 2 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ test:
ty:
run: ty check .
codespell:
run: codespell {files} -L ned,stdio,master --builtin clear,rare,informal,usage,code,names,en-GB_to_en-US -S uv.lock,*_pyx.cpp,catch2*
run: codespell {files} -L ned,stdio,master --builtin clear,rare,informal,usage,code,names,en-GB_to_en-US -S uv.lock,*_pyx.cpp
files: git ls-tree -r HEAD --name-only
cppcheck:
run: cppcheck --error-exitcode=1 --inline-suppr --language=c++ --force --quiet -j4 --check-level=exhaustive $(git ls-files '*.cc' | grep -v -E '(msgq_tests|test_runner)\.cc')
cpplint:
run: cpplint --exclude=msgq/catch2/ --exclude=msgq/ipc_pyx.cpp --exclude=msgq/visionipc/visionipc_pyx.cpp --recursive --quiet --counting=detailed --linelength=240 --filter=-build,-legal,-readability,-runtime,-whitespace,+build/include_subdir,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/comma,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+whitespace/forcolon,+whitespace/parens,+whitespace/semicolon,+whitespace/tab,+readability/braces msgq/
run: cpplint --exclude=msgq/ipc_pyx.cpp --exclude=msgq/visionipc/visionipc_pyx.cpp --recursive --quiet --counting=detailed --linelength=240 --filter=-build,-legal,-readability,-runtime,-whitespace,+build/include_subdir,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/comma,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+whitespace/forcolon,+whitespace/parens,+whitespace/semicolon,+whitespace/tab,+readability/braces msgq/

# *** tests ***
test_runner:
Expand Down
172 changes: 83 additions & 89 deletions msgq/msgq_tests.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <catch2/catch.hpp>
#include "msgq/test_runner.h"
#include "msgq/msgq.h"

static void cleanup_test_queue() {
Expand Down Expand Up @@ -71,39 +71,32 @@ TEST_CASE("msgq_init_subscriber")

TEST_CASE("msgq_msg_send first message")
{
cleanup_test_queue();
msgq_queue_t q;
msgq_new_queue(&q, "test_queue", 1024);
msgq_init_publisher(&q);

REQUIRE(*q.write_pointer == 0);

size_t msg_size = 128;

SECTION("Aligned message size")
const size_t msg_sizes[] = {128, 127};
for (size_t msg_size : msg_sizes)
{
}
SECTION("Unaligned message size")
{
msg_size--;
}
char *data = new char[msg_size];

for (size_t i = 0; i < msg_size; i++)
{
data[i] = i;
}
cleanup_test_queue();
msgq_queue_t q;
msgq_new_queue(&q, "test_queue", 1024);
msgq_init_publisher(&q);

REQUIRE(*q.write_pointer == 0);
char *data = new char[msg_size];
for (size_t i = 0; i < msg_size; i++)
{
data[i] = i;
}

msgq_msg_t msg;
msgq_msg_init_data(&msg, data, msg_size);
msgq_msg_t msg;
msgq_msg_init_data(&msg, data, msg_size);

msgq_msg_send(&msg, &q);
REQUIRE(*(int64_t *)q.data == msg_size); // Check size tag
REQUIRE(*q.write_pointer == 128 + sizeof(int64_t));
REQUIRE(memcmp(q.data + sizeof(int64_t), data, msg_size) == 0);
msgq_msg_send(&msg, &q);
REQUIRE(*(int64_t *)q.data == msg_size); // Check size tag
REQUIRE(*q.write_pointer == 128 + sizeof(int64_t));
REQUIRE(memcmp(q.data + sizeof(int64_t), data, msg_size) == 0);

delete[] data;
msgq_msg_close(&msg);
delete[] data;
msgq_msg_close(&msg);
}
}

TEST_CASE("msgq_msg_send test wraparound")
Expand Down Expand Up @@ -140,84 +133,85 @@ TEST_CASE("msgq_msg_send test wraparound")

TEST_CASE("msgq_msg_recv test wraparound")
{
cleanup_test_queue();
msgq_queue_t q_pub, q_sub;
msgq_new_queue(&q_pub, "test_queue", 1024);
msgq_new_queue(&q_sub, "test_queue", 1024);
const bool keep_up_cases[] = {false, true};
for (bool keep_up_with_writer : keep_up_cases)
{
cleanup_test_queue();
msgq_queue_t q_pub, q_sub;
msgq_new_queue(&q_pub, "test_queue", 1024);
msgq_new_queue(&q_sub, "test_queue", 1024);

msgq_init_publisher(&q_pub);
msgq_init_subscriber(&q_sub);
msgq_init_publisher(&q_pub);
msgq_init_subscriber(&q_sub);

REQUIRE((*q_pub.write_pointer >> 32) == 0);
REQUIRE((*q_sub.read_pointers[0] >> 32) == 0);
REQUIRE((*q_pub.write_pointer >> 32) == 0);
REQUIRE((*q_sub.read_pointers[0] >> 32) == 0);

const size_t msg_size = 120;
msgq_msg_t msg1;
msgq_msg_init_size(&msg1, msg_size);
const size_t msg_size = 120;
msgq_msg_t msg1;
msgq_msg_init_size(&msg1, msg_size);

SECTION("Check cycle counter after reset")
{
for (int i = 0; i < 8; i++)
{
msgq_msg_send(&msg1, &q_pub);
if (keep_up_with_writer)
{
msgq_msg_t msg2;
msgq_msg_recv(&msg2, &q_sub);
REQUIRE(msg2.size > 0);
msgq_msg_close(&msg2);
}
}

msgq_msg_t msg2;
msgq_msg_recv(&msg2, &q_sub);
REQUIRE(msg2.size == 0); // Reader had to reset
msgq_msg_close(&msg2);
}
SECTION("Check cycle counter while keeping up with writer")
{
for (int i = 0; i < 8; i++)
if (!keep_up_with_writer)
{
msgq_msg_send(&msg1, &q_pub);

msgq_msg_t msg2;
msgq_msg_recv(&msg2, &q_sub);
REQUIRE(msg2.size > 0);
REQUIRE(msg2.size == 0); // Reader had to reset
msgq_msg_close(&msg2);
}
}

REQUIRE((*q_sub.read_pointers[0] >> 32) == 1);
msgq_msg_close(&msg1);
REQUIRE((*q_sub.read_pointers[0] >> 32) == 1);
msgq_msg_close(&msg1);
}
}

TEST_CASE("msgq_msg_send test invalidation")
{
cleanup_test_queue();
msgq_queue_t q_pub, q_sub;
msgq_new_queue(&q_pub, "test_queue", 1024);
msgq_new_queue(&q_sub, "test_queue", 1024);

msgq_init_publisher(&q_pub);
msgq_init_subscriber(&q_sub);
*q_sub.write_pointer = (uint64_t)1 << 32;
for (int read_pointer_location = 0; read_pointer_location < 3; read_pointer_location++)
{
cleanup_test_queue();
msgq_queue_t q_pub, q_sub;
msgq_new_queue(&q_pub, "test_queue", 1024);
msgq_new_queue(&q_sub, "test_queue", 1024);

REQUIRE(*q_sub.read_valids[0] == true);
msgq_init_publisher(&q_pub);
msgq_init_subscriber(&q_sub);
*q_sub.write_pointer = (uint64_t)1 << 32;

SECTION("read pointer in tag")
{
*q_sub.read_pointers[0] = 0;
}
SECTION("read pointer in data section")
{
*q_sub.read_pointers[0] = 64;
}
SECTION("read pointer in wraparound section")
{
*q_pub.write_pointer = ((uint64_t)1 << 32) | 1000; // Writer is one cycle ahead
*q_sub.read_pointers[0] = 1020;
}
REQUIRE(*q_sub.read_valids[0] == true);
if (read_pointer_location == 0)
{
*q_sub.read_pointers[0] = 0;
}
else if (read_pointer_location == 1)
{
*q_sub.read_pointers[0] = 64;
}
else
{
*q_pub.write_pointer = ((uint64_t)1 << 32) | 1000; // Writer is one cycle ahead
*q_sub.read_pointers[0] = 1020;
}

msgq_msg_t msg;
msgq_msg_init_size(&msg, 128);
msgq_msg_send(&msg, &q_pub);
msgq_msg_t msg;
msgq_msg_init_size(&msg, 128);
msgq_msg_send(&msg, &q_pub);

REQUIRE(*q_sub.read_valids[0] == false);
REQUIRE(*q_sub.read_valids[0] == false);

msgq_msg_close(&msg);
msgq_msg_close(&msg);
}
}

TEST_CASE("msgq_init_subscriber init 2 subscribers")
Expand All @@ -243,7 +237,7 @@ TEST_CASE("msgq_init_subscriber init 2 subscribers")
REQUIRE(q2.reader_id == 1);
}

TEST_CASE("Write 1 msg, read 1 msg", "[integration]")
TEST_CASE("Write 1 msg, read 1 msg")
{
cleanup_test_queue();
const size_t msg_size = 128;
Expand Down Expand Up @@ -279,7 +273,7 @@ TEST_CASE("Write 1 msg, read 1 msg", "[integration]")
msgq_msg_close(&incoming_msg2);
}

TEST_CASE("Write 2 msg, read 2 msg - conflate = false", "[integration]")
TEST_CASE("Write 2 msg, read 2 msg - conflate = false")
{
cleanup_test_queue();
const size_t msg_size = 128;
Expand Down Expand Up @@ -316,7 +310,7 @@ TEST_CASE("Write 2 msg, read 2 msg - conflate = false", "[integration]")
msgq_msg_close(&incoming_msg2);
}

TEST_CASE("Write 2 msg, read 2 msg - conflate = true", "[integration]")
TEST_CASE("Write 2 msg, read 2 msg - conflate = true")
{
cleanup_test_queue();
const size_t msg_size = 128;
Expand Down Expand Up @@ -354,7 +348,7 @@ TEST_CASE("Write 2 msg, read 2 msg - conflate = true", "[integration]")
msgq_msg_close(&incoming_msg2);
}

TEST_CASE("1 publisher, 1 slow subscriber", "[integration]")
TEST_CASE("1 publisher, 1 slow subscriber")
{
cleanup_test_queue();
msgq_queue_t writer, reader;
Expand Down Expand Up @@ -397,7 +391,7 @@ TEST_CASE("1 publisher, 1 slow subscriber", "[integration]")
REQUIRE(n_skipped == 1428);
}

TEST_CASE("1 publisher, 2 subscribers", "[integration]")
TEST_CASE("1 publisher, 2 subscribers")
{
cleanup_test_queue();
msgq_queue_t writer, reader1, reader2;
Expand Down
2 changes: 0 additions & 2 deletions msgq/test_runner.cc

This file was deleted.

Loading
Loading