SystemC-Components-Test/tests/ordered_semaphore/test.cpp

40 lines
1007 B
C++
Raw Normal View History

2023-12-22 20:42:21 +01:00
#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
2022-10-02 11:39:06 +02:00
#define SC_INCLUDE_DYNAMIC_PROCESSES
2023-12-22 20:42:21 +01:00
#endif
#include <catch2/catch_all.hpp>
#include <factory.h>
2022-10-02 11:39:06 +02:00
#include <scc/ordered_semaphore.h>
#include <scc/utilities.h>
#include <systemc>
using namespace sc_core;
2023-12-22 20:42:21 +01:00
struct top : public sc_core::sc_module {
top()
: top("top") {}
top(sc_module_name const& nm)
: sc_core::sc_module(nm) {}
2022-10-02 11:39:06 +02:00
scc::ordered_semaphore sem{"sem", 2};
scc::ordered_semaphore_t<2> sem_t{"sem_t"};
};
factory::add<top> tb;
TEST_CASE("simple ordered_semaphore test", "[SCC][ordered_semaphore]") {
auto& dut = factory::get<top>();
2023-12-22 20:42:21 +01:00
auto run1 = sc_spawn([&dut]() {
2022-10-02 11:39:06 +02:00
dut.sem.wait();
dut.sem_t.wait();
dut.sem.set_capacity(4);
2022-10-02 19:18:57 +02:00
dut.sem_t.set_capacity(4); // should fail
2022-10-02 11:39:06 +02:00
dut.sem_t.post();
dut.sem.post();
});
sc_start(1_ns);
REQUIRE(run1.terminated());
2022-10-02 19:18:57 +02:00
REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0);
REQUIRE(sc_report_handler::get_count(SC_WARNING) == 1);
2022-10-02 11:39:06 +02:00
}