Skip to content

Commit

Permalink
change(tests): Give tests names that reflect the data structure teste…
Browse files Browse the repository at this point in the history
…d to more easily identify them
  • Loading branch information
DNedic committed Feb 26, 2024
1 parent 539a93f commit 482ce29
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 66 deletions.
12 changes: 7 additions & 5 deletions tests/mpmc/priority_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "lockfree.hpp"

TEST_CASE("Write to empty, lowest priority and read back",
TEST_CASE("mpmc::PriorityQueue - Write to empty, lowest priority and read back",
"[mpmc_pq_write_empty_lowest]") {
lockfree::mpmc::PriorityQueue<int16_t, 20, 3> queue;

Expand All @@ -18,8 +18,9 @@ TEST_CASE("Write to empty, lowest priority and read back",
REQUIRE(read == -1024);
}

TEST_CASE("Write to empty, highest priority and read back",
"[mpmc_pq_write_empty_highest]") {
TEST_CASE(
"mpmc::PriorityQueue - Write to empty, highest priority and read back",
"[mpmc_pq_write_empty_highest]") {
lockfree::mpmc::PriorityQueue<int16_t, 20, 3> queue;

bool const push_success = queue.Push(-1024, 2);
Expand All @@ -31,7 +32,8 @@ TEST_CASE("Write to empty, highest priority and read back",
REQUIRE(read == -1024);
}

TEST_CASE("Write multiple with different priority and read back ensuring "
TEST_CASE("mpmc::PriorityQueue - Write multiple with different priority and "
"read back ensuring "
"proper sequence",
"[mpmc_pq_write_multiple_read_multiple]") {
lockfree::mpmc::PriorityQueue<uint64_t, 10, 4> queue;
Expand Down Expand Up @@ -66,7 +68,7 @@ TEST_CASE("Write multiple with different priority and read back ensuring "
REQUIRE(read == 1024);
}

TEST_CASE("Optional API", "[mpmc_pq_optional_api]") {
TEST_CASE("mpmc::PriorityQueue - Optional API", "[mpmc_pq_optional_api]") {
lockfree::mpmc::PriorityQueue<int16_t, 20, 3> queue;

bool const push_success = queue.Push(-1024, 0);
Expand Down
13 changes: 7 additions & 6 deletions tests/mpmc/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

#include "lockfree.hpp"

TEST_CASE("Write to empty and read back", "[mpmc_q_write_empty]") {
TEST_CASE("mpmc::Queue - Write to empty and read back",
"[mpmc_q_write_empty]") {
lockfree::mpmc::Queue<int16_t, 20> queue;

bool const push_success = queue.Push(-1024);
Expand All @@ -17,15 +18,15 @@ TEST_CASE("Write to empty and read back", "[mpmc_q_write_empty]") {
REQUIRE(pop_success);
}

TEST_CASE("Read empty", "[mpmc_q_read_empty]") {
TEST_CASE("mpmc::Queue - Read empty", "[mpmc_q_read_empty]") {
lockfree::mpmc::Queue<uint8_t, 20> queue;

uint8_t read = 0;
bool const pop_success = queue.Pop(read);
REQUIRE(!pop_success);
}

TEST_CASE("Write full", "[mpmc_q_write_full]") {
TEST_CASE("mpmc::Queue - Write full", "[mpmc_q_write_full]") {
lockfree::mpmc::Queue<uint8_t, 5> queue;

bool push_success = queue.Push(1U);
Expand All @@ -37,7 +38,7 @@ TEST_CASE("Write full", "[mpmc_q_write_full]") {
REQUIRE(!push_success);
}

TEST_CASE("Write multiple to empty and read back",
TEST_CASE("mpmc::Queue - Write multiple to empty and read back",
"[mpmc_q_write_empty_multiple]") {
lockfree::mpmc::Queue<float, 20> queue;

Expand All @@ -59,7 +60,7 @@ TEST_CASE("Write multiple to empty and read back",
REQUIRE(pop_success);
}

TEST_CASE("Write with overflow and read back from start",
TEST_CASE("mpmc::Queue - Write with overflow and read back from start",
"[mpmc_q_write_overflow]") {
lockfree::mpmc::Queue<int32_t, 4> queue;

Expand All @@ -81,7 +82,7 @@ TEST_CASE("Write with overflow and read back from start",
REQUIRE(read == 1000);
}

TEST_CASE("Optional API", "[mpmc_q_optional_api]") {
TEST_CASE("mpmc::Queue - Optional API", "[mpmc_q_optional_api]") {
lockfree::mpmc::Queue<uint64_t, 20> queue;

REQUIRE(!queue.PopOptional());
Expand Down
34 changes: 21 additions & 13 deletions tests/spsc/bipartite_buf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "lockfree.hpp"

TEST_CASE("Write to the beginning", "[bb_write_beginning]") {
TEST_CASE("spsc::BipartiteBuf - Write to the beginning",
"[bb_write_beginning]") {
lockfree::spsc::BipartiteBuf<uint8_t, 512U> bb;
const uint8_t test_data[320] = {0xE5U};

Expand All @@ -23,21 +24,24 @@ TEST_CASE("Write to the beginning", "[bb_write_beginning]") {
REQUIRE(std::equal(std::begin(test_data), std::end(test_data), read.first));
}

TEST_CASE("Try to acquire too much data", "[bb_acquire_too_much]") {
TEST_CASE("spsc::BipartiteBuf - Try to acquire too much data",
"[bb_acquire_too_much]") {
lockfree::spsc::BipartiteBuf<uint8_t, 512U> bb;
auto *write_location = bb.WriteAcquire(512U + rand());
REQUIRE(write_location == nullptr);
}

TEST_CASE("Try to acquire read with an empty buffer", "[bb_read_empty]") {
TEST_CASE("spsc::BipartiteBuf - Try to acquire read with an empty buffer",
"[bb_read_empty]") {
lockfree::spsc::BipartiteBuf<uint8_t, 512U> bb;

auto read = bb.ReadAcquire();
REQUIRE(read.first == nullptr);
REQUIRE(read.second == 0);
}

TEST_CASE("Write with overflow condition", "[bb_write_overflow]") {
TEST_CASE("spsc::BipartiteBuf - Write with overflow condition",
"[bb_write_overflow]") {
lockfree::spsc::BipartiteBuf<uint32_t, 512U> bb;
const uint32_t test_data[320] = {0xE5A1D2C3U};

Expand Down Expand Up @@ -66,8 +70,9 @@ TEST_CASE("Write with overflow condition", "[bb_write_overflow]") {
std::equal(std::begin(test_data2), std::end(test_data2), read.first));
}

TEST_CASE("Read data written after overflow condition write",
"[bb_read_after_overflow_write]") {
TEST_CASE(
"spsc::BipartiteBuf - Read data written after overflow condition write",
"[bb_read_after_overflow_write]") {
lockfree::spsc::BipartiteBuf<int16_t, 512U> bb;
const int16_t test_data[320] = {-222};

Expand Down Expand Up @@ -105,7 +110,7 @@ TEST_CASE("Read data written after overflow condition write",
std::equal(std::begin(test_data3), std::end(test_data3), read.first));
}

TEST_CASE("Interleaved write and read with enough space",
TEST_CASE("spsc::BipartiteBuf - Interleaved write and read with enough space",
"[bb_interleaved_success]") {
lockfree::spsc::BipartiteBuf<double, 512U> bb;
const double test_data[320] = {42.4242};
Expand All @@ -132,7 +137,7 @@ TEST_CASE("Interleaved write and read with enough space",
REQUIRE(std::equal(std::begin(test_data), std::end(test_data), read.first));
}

TEST_CASE("Interleaved write and read with enough space 2",
TEST_CASE("spsc::BipartiteBuf - Interleaved write and read with enough space 2",
"[bb_interleaved_success2]") {
lockfree::spsc::BipartiteBuf<char, 512U> bb;
const char test_data[320] = {'A'};
Expand All @@ -156,8 +161,9 @@ TEST_CASE("Interleaved write and read with enough space 2",
REQUIRE(std::equal(std::begin(test_data), std::end(test_data), read.first));
}

TEST_CASE("Interleaved write and read without enough space",
"[bb_interleaved_fail]") {
TEST_CASE(
"spsc::BipartiteBuf - Interleaved write and read without enough space",
"[bb_interleaved_fail]") {
lockfree::spsc::BipartiteBuf<uint8_t, 512U> bb;
const uint8_t test_data[320] = {0xE5U};

Expand All @@ -178,7 +184,8 @@ TEST_CASE("Interleaved write and read without enough space",
REQUIRE(write_location == nullptr);
}

TEST_CASE("Test keeping the chunk of data when write ends exactly in the end "
TEST_CASE("spsc::BipartiteBuf - Test keeping the chunk of data when write ends "
"exactly in the end "
"of the buffer.",
"[bb_exact_end_write_release_proper_invalidation_test]") {
constexpr size_t size = 8;
Expand All @@ -199,7 +206,7 @@ TEST_CASE("Test keeping the chunk of data when write ends exactly in the end "
REQUIRE((read_buf_second_half - base) == (write_buf_second_half - base));
}

TEST_CASE("std::span API test", "[bb_std_span_api]") {
TEST_CASE("spsc::BipartiteBuf - std::span API test", "[bb_std_span_api]") {
lockfree::spsc::BipartiteBuf<double, 512U> bb;

auto *write_ptr = bb.WriteAcquire(320);
Expand Down Expand Up @@ -236,7 +243,8 @@ TEST_CASE("std::span API test", "[bb_std_span_api]") {
REQUIRE(read_pair.first == read_span.data());
}

TEST_CASE("Multithreaded read/write multiple", "[bb_multithread_multiple]") {
TEST_CASE("spsc::BipartiteBuf - Multithreaded read/write multiple",
"[bb_multithread_multiple]") {
std::vector<std::thread> threads;
lockfree::spsc::BipartiteBuf<unsigned int, 1024U> bb;
std::vector<unsigned int> written;
Expand Down
15 changes: 9 additions & 6 deletions tests/spsc/priority_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "lockfree.hpp"

TEST_CASE("Write to empty, lowest priority and read back",
TEST_CASE("spsc::PriorityQueue - Write to empty, lowest priority and read back",
"[pq_write_empty_lowest]") {
lockfree::spsc::PriorityQueue<int16_t, 20, 3> queue;

Expand All @@ -19,8 +19,9 @@ TEST_CASE("Write to empty, lowest priority and read back",
REQUIRE(read == -1024);
}

TEST_CASE("Write to empty, highest priority and read back",
"[pq_write_empty_highest]") {
TEST_CASE(
"spsc::PriorityQueue - Write to empty, highest priority and read back",
"[pq_write_empty_highest]") {
lockfree::spsc::PriorityQueue<int16_t, 20, 3> queue;

bool const push_success = queue.Push(-1024, 2);
Expand All @@ -32,7 +33,8 @@ TEST_CASE("Write to empty, highest priority and read back",
REQUIRE(read == -1024);
}

TEST_CASE("Write multiple with different priority and read back ensuring "
TEST_CASE("spsc::PriorityQueue - Write multiple with different priority and "
"read back ensuring "
"proper sequence",
"[pq_write_multiple_read_multiple]") {
lockfree::spsc::PriorityQueue<uint64_t, 10, 4> queue;
Expand Down Expand Up @@ -67,7 +69,8 @@ TEST_CASE("Write multiple with different priority and read back ensuring "
REQUIRE(read == 1024);
}

TEST_CASE("Multithreaded read/write", "[pq_multithreaded]") {
TEST_CASE("spsc::PriorityQueue - Multithreaded read/write",
"[pq_multithreaded]") {
lockfree::spsc::PriorityQueue<uint64_t, 10, 4> queue;
std::vector<std::thread> threads;
std::vector<uint64_t> written;
Expand Down Expand Up @@ -139,7 +142,7 @@ TEST_CASE("Multithreaded read/write", "[pq_multithreaded]") {
}
}

TEST_CASE("Optional API", "[pq_optional_api]") {
TEST_CASE("spsc::PriorityQueue - Optional API", "[pq_optional_api]") {
lockfree::spsc::PriorityQueue<int16_t, 20, 3> queue;

bool const push_success = queue.Push(-1024, 0);
Expand Down
15 changes: 8 additions & 7 deletions tests/spsc/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "lockfree.hpp"

TEST_CASE("Write to empty and read back", "[q_write_empty]") {
TEST_CASE("spsc::Queue - Write to empty and read back", "[q_write_empty]") {
lockfree::spsc::Queue<int16_t, 20> queue;

bool const push_success = queue.Push(-1024);
Expand All @@ -18,15 +18,15 @@ TEST_CASE("Write to empty and read back", "[q_write_empty]") {
REQUIRE(pop_success);
}

TEST_CASE("Read empty", "[q_read_empty]") {
TEST_CASE("spsc::Queue - Read empty", "[q_read_empty]") {
lockfree::spsc::Queue<uint8_t, 20> queue;

uint8_t read = 0;
bool const pop_success = queue.Pop(read);
REQUIRE(!pop_success);
}

TEST_CASE("Write full", "[q_write_full]") {
TEST_CASE("spsc::Queue - Write full", "[q_write_full]") {
lockfree::spsc::Queue<uint8_t, 5> queue;

bool push_success = queue.Push(1U);
Expand All @@ -37,7 +37,8 @@ TEST_CASE("Write full", "[q_write_full]") {
REQUIRE(!push_success);
}

TEST_CASE("Write multiple to empty and read back", "[q_write_empty_multiple]") {
TEST_CASE("spsc::Queue - Write multiple to empty and read back",
"[q_write_empty_multiple]") {
lockfree::spsc::Queue<float, 20> queue;

bool push_success = queue.Push(2.7183F);
Expand All @@ -58,7 +59,7 @@ TEST_CASE("Write multiple to empty and read back", "[q_write_empty_multiple]") {
REQUIRE(pop_success);
}

TEST_CASE("Write with overflow and read back from start",
TEST_CASE("spsc::Queue - Write with overflow and read back from start",
"[q_write_overflow]") {
lockfree::spsc::Queue<int32_t, 4> queue;

Expand All @@ -80,7 +81,7 @@ TEST_CASE("Write with overflow and read back from start",
REQUIRE(read == 1000);
}

TEST_CASE("Optional API", "[q_optional_api]") {
TEST_CASE("spsc::Queue - Optional API", "[q_optional_api]") {
lockfree::spsc::Queue<uint64_t, 20> queue;

REQUIRE(!queue.PopOptional());
Expand All @@ -89,7 +90,7 @@ TEST_CASE("Optional API", "[q_optional_api]") {
REQUIRE(queue.PopOptional() == -1024);
}

TEST_CASE("Multithreaded read/write", "[q_multithread]") {
TEST_CASE("spsc::Queue - Multithreaded read/write", "[q_multithread]") {
std::vector<std::thread> threads;
lockfree::spsc::Queue<uint64_t, 1024U> queue;
std::vector<uint64_t> written;
Expand Down
Loading

0 comments on commit 482ce29

Please sign in to comment.