Skip to content

Commit

Permalink
refactor test cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstink committed Sep 17, 2023
1 parent 29d72ec commit 5fdd30f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 60 deletions.
57 changes: 16 additions & 41 deletions symmetri/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ include(FetchContent)

FetchContent_Declare(
concurrentqueue
GIT_REPOSITORY https://github.com/cameron314/concurrentqueue
GIT_TAG master
GIT_REPOSITORY https://github.com/cameron314/concurrentqueue
GIT_TAG master
)

# FetchContent_MakeAvailable(concurrentqueue)
# https://stackoverflow.com/questions/65527126/disable-install-for-fetchcontent
FetchContent_GetProperties(concurrentqueue)

if(NOT concurrentqueue_POPULATED)
FetchContent_Populate(concurrentqueue)
add_subdirectory(${concurrentqueue_SOURCE_DIR} ${concurrentqueue_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()


include_directories(${EIGEN3_INCLUDE_DIRS} ../include ..)

include(CTest)
Expand All @@ -29,42 +29,17 @@ set(test_files

install(DIRECTORY ${test_files} DESTINATION ${PROJECT_SOURCE_DIR}/build/symmetri/tests)

add_executable(${PROJECT_NAME}_actions_test test_actions.cc)
target_link_libraries(${PROJECT_NAME}_actions_test PRIVATE Catch2::Catch2WithMain pthread ${PROJECT_NAME} concurrentqueue)
add_test(${PROJECT_NAME}_actions_test ${PROJECT_NAME}_actions_test)

add_executable(${PROJECT_NAME}_parser_test test_parser.cc)
target_link_libraries(${PROJECT_NAME}_parser_test PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME})
add_test(${PROJECT_NAME}_parser_test ${PROJECT_NAME}_parser_test)

add_executable(${PROJECT_NAME}_model_test test_petri.cc)
target_link_libraries(${PROJECT_NAME}_model_test PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue )
add_test(${PROJECT_NAME}_model_test ${PROJECT_NAME}_model_test)

add_executable(${PROJECT_NAME}_symmetri_test test_symmetri.cc)
target_link_libraries(${PROJECT_NAME}_symmetri_test PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue )
add_executable(${PROJECT_NAME}_symmetri_test
test_actions.cc
test_parser.cc
test_petri.cc
test_symmetri.cc
maxplus.cc
test_external_input.cc
test_priorities.cc
test_bugs.cc
test_types.cc
test_callback.cc
)
target_link_libraries(${PROJECT_NAME}_symmetri_test PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue)
add_test(${PROJECT_NAME}_symmetri_test ${PROJECT_NAME}_symmetri_test)

add_executable(${PROJECT_NAME}_maxplus_test maxplus.cc)
target_link_libraries(${PROJECT_NAME}_maxplus_test PRIVATE Catch2::Catch2WithMain)
add_test(${PROJECT_NAME}_maxplus_test ${PROJECT_NAME}_maxplus_test)

add_executable(${PROJECT_NAME}_external_input_test test_external_input.cc)
target_link_libraries(${PROJECT_NAME}_external_input_test PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue )
add_test(${PROJECT_NAME}_external_input_test ${PROJECT_NAME}_external_input_test)

add_executable(${PROJECT_NAME}_priorities_test test_priorities.cc)
target_link_libraries(${PROJECT_NAME}_priorities_test PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue )
add_test(${PROJECT_NAME}_priorities_test ${PROJECT_NAME}_priorities_test)

add_executable(${PROJECT_NAME}_symmetri_bugs test_bugs.cc)
target_link_libraries(${PROJECT_NAME}_symmetri_bugs PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue )
add_test(${PROJECT_NAME}_symmetri_bugs ${PROJECT_NAME}_symmetri_bugs)

add_executable(${PROJECT_NAME}_types test_types.cc)
target_link_libraries(${PROJECT_NAME}_types PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue )
add_test(${PROJECT_NAME}_types ${PROJECT_NAME}_types)

add_executable(${PROJECT_NAME}_Callback test_callback.cc)
target_link_libraries(${PROJECT_NAME}_Callback PRIVATE Catch2::Catch2WithMain ${PROJECT_NAME} concurrentqueue )
add_test(${PROJECT_NAME}_Callback ${PROJECT_NAME}_Callback)
4 changes: 2 additions & 2 deletions symmetri/tests/test_bugs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void t() {
});
}

std::tuple<Net, Store, PriorityTable, Marking> testNet() {
std::tuple<Net, Store, PriorityTable, Marking> BugsTestNet() {
Net net = {{"t", {{"Pa"}, {"Pb"}}}};
Store store = {{"t", &t}};
PriorityTable priority;
Expand All @@ -33,7 +33,7 @@ std::tuple<Net, Store, PriorityTable, Marking> testNet() {
}

TEST_CASE("Firing the same transition before it can complete should work") {
auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = BugsTestNet();
auto stp = std::make_shared<TaskSystem>(2);
Petri m(net, store, priority, m0, {}, "s", stp);
REQUIRE(m.scheduled_callbacks.empty());
Expand Down
4 changes: 2 additions & 2 deletions symmetri/tests/test_external_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
using namespace symmetri;

std::atomic<bool> i_ran(false);
void t() { i_ran.store(true); }
void tExtInput() { i_ran.store(true); }

TEST_CASE("Test external input.") {
Net net = {
{"t0", {{}, {"Pa"}}}, {"t1", {{"Pa"}, {"Pb"}}}, {"t2", {{"Pc"}, {"Pb"}}}};
// we can omit t0, it will be auto-filled as {"t0", DirectMutation{}}
Store store = {{"t1", &t},
Store store = {{"t1", &tExtInput},
{"t2", []() {
std::this_thread::sleep_for(std::chrono::milliseconds(15));
}}};
Expand Down
16 changes: 8 additions & 8 deletions symmetri/tests/test_petri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ using namespace moodycamel;
// global counters to keep track of how often the transitions are called.
std::atomic<unsigned int> T0_COUNTER, T1_COUNTER;
// two transitions
void t0() {
void petri0() {
auto inc = T0_COUNTER.load() + 1;
T0_COUNTER.store(inc);
}
auto t1() {
auto petri1() {
auto inc = T1_COUNTER.load() + 1;
T1_COUNTER.store(inc);
return symmetri::state::Completed;
}

std::tuple<Net, Store, PriorityTable, Marking> testNet() {
std::tuple<Net, Store, PriorityTable, Marking> PetriTestNet() {
T0_COUNTER.store(0);
T1_COUNTER.store(0);

Net net = {{"t0", {{"Pa", "Pb"}, {"Pc"}}},
{"t1", {{"Pc", "Pc"}, {"Pb", "Pb", "Pd"}}}};

Store store = {{"t0", &t0}, {"t1", &t1}};
Store store = {{"t0", &petri0}, {"t1", &petri1}};
PriorityTable priority;

Marking m0 = {{"Pa", 4}, {"Pb", 2}, {"Pc", 0}, {"Pd", 0}};
return {net, store, priority, m0};
}

TEST_CASE("Test equaliy of nets") {
auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = PetriTestNet();
auto net2 = net;
auto net3 = net;
REQUIRE(stateNetEquality(net, net2));
Expand All @@ -49,7 +49,7 @@ TEST_CASE("Test equaliy of nets") {
}

TEST_CASE("Run one transition iteration in a petri net") {
auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = PetriTestNet();

auto stp = std::make_shared<TaskSystem>(1);
Petri m(net, store, priority, m0, {}, "s", stp);
Expand Down Expand Up @@ -83,7 +83,7 @@ TEST_CASE("Run one transition iteration in a petri net") {
TEST_CASE("Run until net dies") {
using namespace moodycamel;

auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = PetriTestNet();
auto stp = std::make_shared<TaskSystem>(1);
Petri m(net, store, priority, m0, {}, "s", stp);

Expand All @@ -109,7 +109,7 @@ TEST_CASE("Run until net dies") {
TEST_CASE("Run until net dies with nullptr") {
using namespace moodycamel;

auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = PetriTestNet();
// we can pass an empty story, and DirectMutation will be used for the
// undefined transitions
store = {};
Expand Down
2 changes: 0 additions & 2 deletions symmetri/tests/test_priorities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using namespace symmetri;
using namespace moodycamel;

void t() {}

TEST_CASE(
"Run a transition with a higher priority over one with a lower priority") {
std::list<PriorityTable> priorities = {{{"t0", 1}, {"t1", 0}},
Expand Down
10 changes: 5 additions & 5 deletions symmetri/tests/test_symmetri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace symmetri;
void t0() {}
auto t1() {}

std::tuple<Net, Store, PriorityTable, Marking> testNet() {
std::tuple<Net, Store, PriorityTable, Marking> SymmetriTestNet() {
Net net = {{"t0", {{"Pa", "Pb"}, {"Pc"}}},
{"t1", {{"Pc", "Pc"}, {"Pb", "Pb", "Pd"}}}};

Expand All @@ -20,7 +20,7 @@ std::tuple<Net, Store, PriorityTable, Marking> testNet() {
}

TEST_CASE("Create a using the net constructor without end condition.") {
auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = SymmetriTestNet();
auto stp = std::make_shared<TaskSystem>(1);

PetriNet app(net, m0, {}, store, priority, "test_net_without_end", stp);
Expand All @@ -36,7 +36,7 @@ TEST_CASE("Create a using the net constructor with end condition.") {
auto stp = std::make_shared<TaskSystem>(1);

Marking final_marking({{"Pa", 0}, {"Pb", 2}, {"Pc", 0}, {"Pd", 2}});
auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = SymmetriTestNet();
PetriNet app(net, m0, final_marking, store, priority, "test_net_with_end",
stp);
// we can run the net
Expand Down Expand Up @@ -67,7 +67,7 @@ TEST_CASE("Create a using pnml constructor.") {
}

TEST_CASE("Reuse an application with a new case_id.") {
auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = SymmetriTestNet();
const auto initial_id = "initial0";
const auto new_id = "something_different0";
auto stp = std::make_shared<TaskSystem>(1);
Expand All @@ -86,7 +86,7 @@ TEST_CASE("Reuse an application with a new case_id.") {
}

TEST_CASE("Can not reuse an active application with a new case_id.") {
auto [net, store, priority, m0] = testNet();
auto [net, store, priority, m0] = SymmetriTestNet();
const auto initial_id = "initial1";
const auto new_id = "something_different1";
auto stp = std::make_shared<TaskSystem>(1);
Expand Down

0 comments on commit 5fdd30f

Please sign in to comment.