diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3ce1e5c..4b88f3d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -135,10 +135,10 @@ IF (${BIDIB_USE_TESTS})
# Physical test
- ADD_EXECUTABLE(swtbahn-standard-testsuite test test/physical/swtbahn-standard/main.c test/physical/swtbahn-standard/testsuite.c)
+ ADD_EXECUTABLE(swtbahn-standard-testsuite test test/physical/swtbahn-standard/main.c test/physical/swtbahn-standard/testsuite.c test/physical/test_common.c)
TARGET_LINK_LIBRARIES(swtbahn-standard-testsuite glib-2.0 pthread yaml bidib_static)
- ADD_EXECUTABLE(swtbahn-full-testsuite test test/physical/swtbahn-full/main.c test/physical/swtbahn-full/testsuite.c)
+ ADD_EXECUTABLE(swtbahn-full-testsuite test test/physical/swtbahn-full/main.c test/physical/swtbahn-full/testsuite.c test/physical/test_common.c)
TARGET_LINK_LIBRARIES(swtbahn-full-testsuite glib-2.0 pthread yaml bidib_static)
ENDIF(${BIDIB_USE_TESTS})
diff --git a/test/physical/Readme.md b/test/physical/Readme.md
index 1166dae..9797e06 100644
--- a/test/physical/Readme.md
+++ b/test/physical/Readme.md
@@ -13,7 +13,9 @@ physical
| |-- main.c
| |-- testsuite.c
| '-- testsuite.h
- '-- Readme.md
+ |-- Readme.md
+ |-- test_common.c
+ '-- test_common.h
```
## Test Cases
@@ -45,7 +47,7 @@ physical
Drives two user-defined trains along the track segments.
For the SWTbahn Full, the first train must be facing clockwise on track segment `T58`,
- and the second train must be facing clockwise on track segment `T46`.
+ and the second train must be facing clockwise on track segment `T78a`.
For a given SWTbahn platform, its points and signals are retrieved using the
diff --git a/test/physical/swtbahn-full/main.c b/test/physical/swtbahn-full/main.c
index 5c10743..98efab6 100755
--- a/test/physical/swtbahn-full/main.c
+++ b/test/physical/swtbahn-full/main.c
@@ -59,12 +59,12 @@ int main(int argc, char **argv) {
return 0;
}
- // if (bidib_start_serial("/dev/tty.usbserial-AK06U8H7", "../../swtbahn-cli/configurations/swtbahn-full/", 0)) {
+ //if (bidib_start_serial("/dev/tty.usbserial-AK06U8H7", "../../swtbahn-cli/configurations/swtbahn-full/", 0)) {
if (bidib_start_serial("/dev/ttyUSB0", "../../swtbahn-cli/configurations/swtbahn-full", 0)) {
printf("testsuite: libbidib failed to start\n");
return 0;
} else {
- printf("Started Serial");
+ printf("testsuite: libbidib started\n");
}
sleep(2); // Wait for the points to finish switching to their default positions.
@@ -74,7 +74,7 @@ int main(int argc, char **argv) {
const int repetitions = atoi(argv[2]);
switch (atoi(argv[1])) {
case 1:
- //bidib_set_track_output_state_all(BIDIB_CS_OFF);
+ bidib_set_track_output_state_all(BIDIB_CS_OFF);
for (int i = 0; i < repetitions; i++) {
testsuite_case_pointParallel(result);
}
@@ -168,7 +168,7 @@ void printWelcome() {
"* SWTbahn-testsuite *",
"* *",
"************************",
- "* UniBa-SWT-2022 *",
+ "* UniBa-SWT-2023 *",
"************************",
""
};
diff --git a/test/physical/swtbahn-full/testsuite.c b/test/physical/swtbahn-full/testsuite.c
index f423865..c2912c1 100644
--- a/test/physical/swtbahn-full/testsuite.c
+++ b/test/physical/swtbahn-full/testsuite.c
@@ -38,242 +38,25 @@
#include "testsuite.h"
-
-#define SIGNAL_WAITING_TIME 3 // in seconds
-#define POINT_WAITING_TIME 3 // in seconds
-#define TRAIN_WAITING_TIME 250000 // in microseconds
-
-t_bidib_id_list_query points;
-t_bidib_id_list_query signals;
-
-// This initialisation function is specific to SWTbahn Full!
+// This initialisation function is specific to SWTbahn Full.
t_testsuite_test_result *testsuite_initTestSuite() {
- points = bidib_get_connected_points();
-
- // Accessories that are not signals
- t_testsuite_ids filterOutIds;
- char *excludedSignalAccessories[4] = {"platformlight1", "platformlight2", "platformlight4a", "platformlight4b"};
- filterOutIds.ids = excludedSignalAccessories;
- filterOutIds.length = 4;
- t_bidib_id_list_query signalsQuery = bidib_get_connected_signals();
- signals = testsuite_filterOutIds(signalsQuery, filterOutIds);
- bidib_free_id_list_query(signalsQuery);
-
- t_testsuite_test_result *result = malloc(sizeof(t_testsuite_test_result));
- result->points = malloc(points.length * sizeof(t_testsuite_point_result));
-
- for (size_t i = 0; i < points.length; i++) {
- result->points[i].stateReachedVerified = 0;
- result->points[i].stateReached = 0;
- result->points[i].stateNotReachedVerified = 0;
- result->points[i].stateNotReached = 0;
- result->points[i].stateError = 0;
- result->points[i].unknownState = 0;
- }
+ char *excludedSignalAccessories[4] = {"platformlight1", "platformlight2",
+ "platformlight4a", "platformlight4b"};
+ t_testsuite_test_result *result = testsuite_initTestSuite_common(excludedSignalAccessories, 4);
return result;
}
-void testsuite_stopBidib(void) {
- bidib_free_id_list_query(points);
- bidib_free_id_list_query(signals);
- bidib_stop();
-}
-
-void testsuite_signal_callback_handler(int signum) {
- testsuite_stopBidib();
- printf("testsuite: SIGINT - stopping libbidib \n");
- exit(signum);
-}
-
-t_bidib_id_list_query testsuite_filterOutIds(t_bidib_id_list_query inputIdQuery, t_testsuite_ids filterOutIds) {
- const size_t count = inputIdQuery.length - filterOutIds.length;
-
- if (count <= 0) {
- printf("testsuite: No IDs will be left after filtering\n");
- }
-
- t_bidib_id_list_query outputIdQuery;
- outputIdQuery.length = 0;
- outputIdQuery.ids = malloc(sizeof(char *) * count);
-
- int isFilteredOut = 0;
-
- for (size_t i = 0; i < inputIdQuery.length; i++) {
- isFilteredOut = 0;
- for (size_t j = 0; j < filterOutIds.length; j++) {
- if (!strcmp(inputIdQuery.ids[i], filterOutIds.ids[j])) {
- isFilteredOut = 1;
- break;
- }
- }
-
- if (!isFilteredOut) {
- size_t len = strlen(inputIdQuery.ids[i]) + 1;
- outputIdQuery.ids[outputIdQuery.length] = malloc(sizeof(char) * len);
- memcpy(outputIdQuery.ids[outputIdQuery.length], inputIdQuery.ids[i], len);
- outputIdQuery.length++;
- }
- }
-
- if (outputIdQuery.length != count) {
- printf("testsuite: Error: %zu IDs were to be filtered, but %d IDs filtered instead\n", filterOutIds.length, (int)inputIdQuery.length - (int)outputIdQuery.length);
- }
-
- return outputIdQuery;
-}
-
-void testsuite_logTestResult(t_testsuite_test_result *result, t_bidib_unified_accessory_state_query state, int accessory_index) {
- if (state.known) {
- switch (state.board_accessory_state.execution_state) {
- case BIDIB_EXEC_STATE_ERROR:
- result->points[accessory_index].stateError++;
- break;
- case BIDIB_EXEC_STATE_NOTREACHED:
- result->points[accessory_index].stateNotReached++;
- break;
- case BIDIB_EXEC_STATE_NOTREACHED_VERIFIED:
- result->points[accessory_index].stateNotReachedVerified++;
- break;
- case BIDIB_EXEC_STATE_REACHED:
- result->points[accessory_index].stateReached++;
- break;
- case BIDIB_EXEC_STATE_REACHED_VERIFIED:
- result->points[accessory_index].stateReachedVerified++;
- break;
- default:
- break;
- }
- } else {
- result->points[accessory_index].unknownState++;
- }
-}
-
-void testsuite_printTestResults(t_testsuite_test_result *result) {
- for (size_t i = 0; i < points.length; i++) {
- printf("\n\n%s\n", points.ids[i]);
- printf(" -> stateReachedVerified: %d \n", result->points[i].stateReachedVerified);
- printf(" -> stateReached: %d \n", result->points[i].stateReached);
- printf(" -> stateNotReachedVerified: %d \n", result->points[i].stateNotReachedVerified);
- printf(" -> stateNotReached: %d \n", result->points[i].stateNotReached);
- printf(" -> stateError: %d \n", result->points[i].stateError);
- printf(" -> unknownState: %d \n", result->points[i].unknownState);
- }
-}
-
-bool testsuite_trainReady(const char *train, const char *segment) {
- if (bidib_get_train_on_track(train)) {
- t_bidib_train_position_query train_position_query =
- bidib_get_train_position(train);
- if (train_position_query.length > 0) {
- for (size_t i = 0; i < train_position_query.length; i++) {
- if (strcmp(segment, train_position_query.segments[i]) == 0) {
- printf("testsuite: %s train ready on %s \n", train, segment);
- bidib_free_train_position_query(train_position_query);
- return true;
- }
- }
- }
-
- printf("testsuite: %s train not on track segment %s \n", train, segment);
- bidib_free_train_position_query(train_position_query);
- return false;
- } else {
- printf("testsuite: %s train not detected on any track \n", train);
- return false;
- }
-}
-
-void testsuite_driveTo(const char *segment, int speed, const char *train) {
- bidib_set_train_speed(train, speed, "master");
- bidib_flush();
-
- while (1) {
- t_bidib_train_position_query trainPosition = bidib_get_train_position(train);
- for (size_t i = 0; i < trainPosition.length; i++) {
- if (!strcmp(segment, trainPosition.segments[i])) {
- bidib_free_train_position_query(trainPosition);
- return;
- }
- }
- bidib_free_train_position_query(trainPosition);
- usleep(TRAIN_WAITING_TIME);
- }
-}
-
-void testsuite_driveToStop(const char *segment, int speed, const char *train) {
- testsuite_driveTo(segment, speed, train);
- bidib_set_train_speed(train, 0, "master");
- bidib_flush();
-}
-
-void set_signal(const char *signal, const char *aspect) {
- bidib_set_signal(signal, aspect);
- bidib_flush();
-}
-
-void switch_point(const char *point, const char *aspect) {
- bidib_switch_point(point, aspect);
- bidib_flush();
-}
-
void testsuite_case_signal() {
- for (size_t i = 0; i < signals.length; i++) {
- set_signal(signals.ids[i], "aspect_caution");
- }
- sleep(SIGNAL_WAITING_TIME);
-
- for (size_t i = 0; i < signals.length; i++) {
- set_signal(signals.ids[i], "aspect_go");
- }
- sleep(SIGNAL_WAITING_TIME);
-
- for (size_t i = 0; i < signals.length; i++) {
- set_signal(signals.ids[i], "aspect_stop");
- }
- sleep(SIGNAL_WAITING_TIME);
-
- for (size_t i = 0; i < signals.length; i++) {
- set_signal(signals.ids[i], "aspect_shunt");
- }
- sleep(SIGNAL_WAITING_TIME);
-
+ char *signalAspects[4] = {"aspect_caution", "aspect_go", "aspect_stop", "aspect_shunt"};
+ testsuite_case_signal_common(signalAspects, 4);
}
void testsuite_case_pointParallel(t_testsuite_test_result *result) {
- for (size_t i = 0; i < points.length; i++) {
- switch_point(points.ids[i], "reverse");
- t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- bidib_free_unified_accessory_state_query(state);
- }
-
- sleep(POINT_WAITING_TIME);
-
- for (size_t i = 0; i < points.length; i++) {
- switch_point(points.ids[i], "normal");
- t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- bidib_free_unified_accessory_state_query(state);
- }
-
- sleep(POINT_WAITING_TIME);
+ testsuite_case_pointParallel_common(result);
}
void testsuite_case_pointSerial(t_testsuite_test_result *result) {
- for (size_t i = 0; i < points.length; i++) {
- switch_point(points.ids[i], "reverse");
- t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- bidib_free_unified_accessory_state_query(state);
- sleep(POINT_WAITING_TIME);
-
- switch_point(points.ids[i], "normal");
- state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- bidib_free_unified_accessory_state_query(state);
- sleep(POINT_WAITING_TIME);
- }
-
+ testsuite_case_pointSerial_common(result);
}
bool route1(const char *train) {
@@ -281,56 +64,56 @@ bool route1(const char *train) {
return false;
}
- switch_point("point22", "reverse");
- switch_point("point23", "normal");
- switch_point("point24", "reverse");
- switch_point("point12", "reverse");
- switch_point("point13", "reverse");
- switch_point("point14", "reverse");
- switch_point("point15", "normal");
- switch_point("point16", "reverse");
- switch_point("point21", "reverse");
- switch_point("point20", "normal");
- switch_point("point19", "normal");
- switch_point("point18b", "reverse");
-
- set_signal("signal30", "aspect_go");
- set_signal("signal33", "aspect_go");
- set_signal("signal35a", "aspect_go");
- set_signal("signal35b", "aspect_go");
- set_signal("signal37", "aspect_go");
+ testsuite_switch_point("point22", "reverse");
+ testsuite_switch_point("point23", "normal");
+ testsuite_switch_point("point24", "reverse");
+ testsuite_switch_point("point12", "reverse");
+ testsuite_switch_point("point13", "reverse");
+ testsuite_switch_point("point14", "reverse");
+ testsuite_switch_point("point15", "normal");
+ testsuite_switch_point("point16", "reverse");
+ testsuite_switch_point("point21", "reverse");
+ testsuite_switch_point("point20", "normal");
+ testsuite_switch_point("point19", "normal");
+ testsuite_switch_point("point18b", "reverse");
+
+ testsuite_set_signal("signal30", "aspect_go");
+ testsuite_set_signal("signal33", "aspect_go");
+ testsuite_set_signal("signal35a", "aspect_go");
+ testsuite_set_signal("signal35b", "aspect_go");
+ testsuite_set_signal("signal37", "aspect_go");
testsuite_driveTo("seg57", 50, train);
- set_signal("signal30", "aspect_stop");
+ testsuite_set_signal("signal30", "aspect_stop");
testsuite_driveTo("seg64", 50, train);
- set_signal("signal33", "aspect_stop");
- set_signal("signal35a", "aspect_stop");
- set_signal("signal35b", "aspect_stop");
+ testsuite_set_signal("signal33", "aspect_stop");
+ testsuite_set_signal("signal35a", "aspect_stop");
+ testsuite_set_signal("signal35b", "aspect_stop");
testsuite_driveTo("seg69", 50, train);
- set_signal("signal37", "aspect_stop");
+ testsuite_set_signal("signal37", "aspect_stop");
testsuite_driveTo("seg46", 50, train);
testsuite_driveToStop("seg47", 20, train);
// Drive backwards through the route
- set_signal("signal26", "aspect_go");
- set_signal("signal38", "aspect_go");
- set_signal("signal36", "aspect_go");
- set_signal("signal34", "aspect_go");
- set_signal("signal32", "aspect_go");
+ testsuite_set_signal("signal26", "aspect_go");
+ testsuite_set_signal("signal38", "aspect_go");
+ testsuite_set_signal("signal36", "aspect_go");
+ testsuite_set_signal("signal34", "aspect_go");
+ testsuite_set_signal("signal32", "aspect_go");
testsuite_driveTo("seg45", -50, train);
- set_signal("signal26", "aspect_stop");
+ testsuite_set_signal("signal26", "aspect_stop");
testsuite_driveTo("seg67", -50, train);
- set_signal("signal38", "aspect_stop");
- set_signal("signal36", "aspect_stop");
+ testsuite_set_signal("signal38", "aspect_stop");
+ testsuite_set_signal("signal36", "aspect_stop");
testsuite_driveTo("seg62", -50, train);
- set_signal("signal34", "aspect_stop");
- set_signal("signal32", "aspect_stop");
+ testsuite_set_signal("signal34", "aspect_stop");
+ testsuite_set_signal("signal32", "aspect_stop");
testsuite_driveTo("seg58", -50, train);
testsuite_driveToStop("seg59", -20, train);
@@ -342,50 +125,50 @@ bool route2(const char *train) {
return false;
}
- switch_point("point22", "normal");
- switch_point("point20", "reverse");
- switch_point("point21", "reverse");
- switch_point("point16", "reverse");
- switch_point("point15", "reverse");
- switch_point("point5", "reverse");
- switch_point("point4", "reverse");
- switch_point("point12", "reverse");
- switch_point("point11", "reverse");
- switch_point("point27", "reverse");
- switch_point("point29", "reverse");
- switch_point("point28", "reverse");
- switch_point("point26", "normal");
- switch_point("point9", "reverse");
- switch_point("point8", "reverse");
- switch_point("point1", "reverse");
- switch_point("point7", "normal");
- switch_point("point6", "reverse");
- switch_point("point17", "reverse");
+ testsuite_switch_point("point22", "normal");
+ testsuite_switch_point("point20", "reverse");
+ testsuite_switch_point("point21", "reverse");
+ testsuite_switch_point("point16", "reverse");
+ testsuite_switch_point("point15", "reverse");
+ testsuite_switch_point("point5", "reverse");
+ testsuite_switch_point("point4", "reverse");
+ testsuite_switch_point("point12", "reverse");
+ testsuite_switch_point("point11", "reverse");
+ testsuite_switch_point("point27", "reverse");
+ testsuite_switch_point("point29", "reverse");
+ testsuite_switch_point("point28", "reverse");
+ testsuite_switch_point("point26", "normal");
+ testsuite_switch_point("point9", "reverse");
+ testsuite_switch_point("point8", "reverse");
+ testsuite_switch_point("point1", "reverse");
+ testsuite_switch_point("point7", "normal");
+ testsuite_switch_point("point6", "reverse");
+ testsuite_switch_point("point17", "reverse");
testsuite_driveTo("seg42b", 50, train);
- switch_point("point16", "normal");
- switch_point("point15", "normal");
- switch_point("point14", "reverse");
- switch_point("point13", "reverse");
- switch_point("point12", "reverse");
- switch_point("point24", "reverse");
- switch_point("point23", "reverse");
- switch_point("point19", "reverse");
- switch_point("point18b", "normal");
- switch_point("point18a", "reverse");
- switch_point("point8", "normal");
- switch_point("point9", "reverse");
- switch_point("point26", "reverse");
- switch_point("point27", "normal");
- switch_point("point11", "normal");
- switch_point("point3", "reverse");
- switch_point("point4", "normal");
- switch_point("point5", "normal");
+ testsuite_switch_point("point16", "normal");
+ testsuite_switch_point("point15", "normal");
+ testsuite_switch_point("point14", "reverse");
+ testsuite_switch_point("point13", "reverse");
+ testsuite_switch_point("point12", "reverse");
+ testsuite_switch_point("point24", "reverse");
+ testsuite_switch_point("point23", "reverse");
+ testsuite_switch_point("point19", "reverse");
+ testsuite_switch_point("point18b", "normal");
+ testsuite_switch_point("point18a", "reverse");
+ testsuite_switch_point("point8", "normal");
+ testsuite_switch_point("point9", "reverse");
+ testsuite_switch_point("point26", "reverse");
+ testsuite_switch_point("point27", "normal");
+ testsuite_switch_point("point11", "normal");
+ testsuite_switch_point("point3", "reverse");
+ testsuite_switch_point("point4", "normal");
+ testsuite_switch_point("point5", "normal");
testsuite_driveTo("seg69", 50, train);
- switch_point("point6", "normal");
- switch_point("point7", "reverse");
+ testsuite_switch_point("point6", "normal");
+ testsuite_switch_point("point7", "reverse");
testsuite_driveTo("seg46", 50, train);
testsuite_driveToStop("seg47", 20, train);
@@ -398,22 +181,22 @@ bool route3(const char *train) {
return false;
}
- switch_point("point18b", "reverse");
- switch_point("point19", "reverse");
- switch_point("point23", "reverse");
- switch_point("point24", "reverse");
- switch_point("point12", "normal");
- switch_point("point4", "reverse");
- switch_point("point5", "reverse");
- switch_point("point15", "reverse");
- switch_point("point16", "normal");
- switch_point("point17", "reverse");
- switch_point("point6", "reverse");
- switch_point("point7", "normal");
- switch_point("point1", "reverse");
- switch_point("point8", "reverse");
- switch_point("point9", "normal");
- switch_point("point10", "reverse");
+ testsuite_switch_point("point18b", "reverse");
+ testsuite_switch_point("point19", "reverse");
+ testsuite_switch_point("point23", "reverse");
+ testsuite_switch_point("point24", "reverse");
+ testsuite_switch_point("point12", "normal");
+ testsuite_switch_point("point4", "reverse");
+ testsuite_switch_point("point5", "reverse");
+ testsuite_switch_point("point15", "reverse");
+ testsuite_switch_point("point16", "normal");
+ testsuite_switch_point("point17", "reverse");
+ testsuite_switch_point("point6", "reverse");
+ testsuite_switch_point("point7", "normal");
+ testsuite_switch_point("point1", "reverse");
+ testsuite_switch_point("point8", "reverse");
+ testsuite_switch_point("point9", "normal");
+ testsuite_switch_point("point10", "reverse");
testsuite_driveTo("seg29", -50, train);
testsuite_driveToStop("seg78b", -20, train);
@@ -426,21 +209,21 @@ bool route4(const char *train) {
return false;
}
- switch_point("point10", "reverse");
- switch_point("point9", "normal");
- switch_point("point8", "reverse");
- switch_point("point1", "reverse");
- switch_point("point7", "normal");
- switch_point("point6", "reverse");
- switch_point("point17", "reverse");
- switch_point("point16", "normal");
- switch_point("point15", "normal");
- switch_point("point14", "reverse");
- switch_point("point13", "reverse");
- switch_point("point12", "reverse");
- switch_point("point24", "reverse");
- switch_point("point23", "normal");
- switch_point("point22", "reverse");
+ testsuite_switch_point("point10", "reverse");
+ testsuite_switch_point("point9", "normal");
+ testsuite_switch_point("point8", "reverse");
+ testsuite_switch_point("point1", "reverse");
+ testsuite_switch_point("point7", "normal");
+ testsuite_switch_point("point6", "reverse");
+ testsuite_switch_point("point17", "reverse");
+ testsuite_switch_point("point16", "normal");
+ testsuite_switch_point("point15", "normal");
+ testsuite_switch_point("point14", "reverse");
+ testsuite_switch_point("point13", "reverse");
+ testsuite_switch_point("point12", "reverse");
+ testsuite_switch_point("point24", "reverse");
+ testsuite_switch_point("point23", "normal");
+ testsuite_switch_point("point22", "reverse");
testsuite_driveTo("seg58", 50, train);
testsuite_driveToStop("seg59", 20, train);
@@ -453,19 +236,19 @@ bool route5(const char *train) {
return false;
}
- switch_point("point22", "reverse");
- switch_point("point23", "normal");
- switch_point("point24", "reverse");
- switch_point("point12", "reverse");
- switch_point("point13", "reverse");
- switch_point("point14", "reverse");
- switch_point("point15", "normal");
- switch_point("point16", "reverse");
- switch_point("point21", "reverse");
- switch_point("point20", "reverse");
+ testsuite_switch_point("point22", "reverse");
+ testsuite_switch_point("point23", "normal");
+ testsuite_switch_point("point24", "reverse");
+ testsuite_switch_point("point12", "reverse");
+ testsuite_switch_point("point13", "reverse");
+ testsuite_switch_point("point14", "reverse");
+ testsuite_switch_point("point15", "normal");
+ testsuite_switch_point("point16", "reverse");
+ testsuite_switch_point("point21", "reverse");
+ testsuite_switch_point("point20", "reverse");
testsuite_driveTo("seg64", -50, train);
- switch_point("point22", "normal");
+ testsuite_switch_point("point22", "normal");
testsuite_driveTo("seg58", -50, train);
testsuite_driveToStop("seg59", -20, train);
@@ -504,39 +287,39 @@ static void *route99(void *arg) {
while (true) {
// train1: forwards
- switch_point("point22", "reverse");
- switch_point("point23", "normal");
- switch_point("point24", "reverse");
- switch_point("point12", "reverse");
- switch_point("point13", "reverse");
- switch_point("point14", "reverse");
- switch_point("point15", "normal");
- switch_point("point16", "reverse");
- switch_point("point21", "reverse");
- switch_point("point20", "normal");
- switch_point("point19", "normal");
- switch_point("point18b", "reverse");
+ testsuite_switch_point("point22", "reverse");
+ testsuite_switch_point("point23", "normal");
+ testsuite_switch_point("point24", "reverse");
+ testsuite_switch_point("point12", "reverse");
+ testsuite_switch_point("point13", "reverse");
+ testsuite_switch_point("point14", "reverse");
+ testsuite_switch_point("point15", "normal");
+ testsuite_switch_point("point16", "reverse");
+ testsuite_switch_point("point21", "reverse");
+ testsuite_switch_point("point20", "normal");
+ testsuite_switch_point("point19", "normal");
+ testsuite_switch_point("point18b", "reverse");
sleep(1);
- set_signal("signal30", "aspect_go");
- set_signal("signal33", "aspect_go");
- set_signal("signal35a", "aspect_go");
- set_signal("signal35b", "aspect_go");
- set_signal("signal37", "aspect_go");
+ testsuite_set_signal("signal30", "aspect_go");
+ testsuite_set_signal("signal33", "aspect_go");
+ testsuite_set_signal("signal35a", "aspect_go");
+ testsuite_set_signal("signal35b", "aspect_go");
+ testsuite_set_signal("signal37", "aspect_go");
sleep(1);
testsuite_driveTo("seg57", 50, train1);
- set_signal("signal30", "aspect_stop");
+ testsuite_set_signal("signal30", "aspect_stop");
testsuite_driveTo("seg64", 50, train1);
- set_signal("signal33", "aspect_stop");
- set_signal("signal35a", "aspect_stop");
- set_signal("signal35b", "aspect_stop");
+ testsuite_set_signal("signal33", "aspect_stop");
+ testsuite_set_signal("signal35a", "aspect_stop");
+ testsuite_set_signal("signal35b", "aspect_stop");
testsuite_driveTo("seg69", 50, train1);
- set_signal("signal37", "aspect_stop");
+ testsuite_set_signal("signal37", "aspect_stop");
testsuite_driveTo("seg46", 50, train1);
sleep(1);
@@ -549,24 +332,24 @@ static void *route99(void *arg) {
sleep(5);
// train1: backwards
- set_signal("signal26", "aspect_go");
- set_signal("signal38", "aspect_go");
- set_signal("signal36", "aspect_go");
- set_signal("signal34", "aspect_go");
- set_signal("signal32", "aspect_go");
+ testsuite_set_signal("signal26", "aspect_go");
+ testsuite_set_signal("signal38", "aspect_go");
+ testsuite_set_signal("signal36", "aspect_go");
+ testsuite_set_signal("signal34", "aspect_go");
+ testsuite_set_signal("signal32", "aspect_go");
sleep(1);
testsuite_driveTo("seg45", -50, train1);
- set_signal("signal26", "aspect_stop");
+ testsuite_set_signal("signal26", "aspect_stop");
testsuite_driveTo("seg67", -50, train1);
- set_signal("signal38", "aspect_stop");
- set_signal("signal36", "aspect_stop");
+ testsuite_set_signal("signal38", "aspect_stop");
+ testsuite_set_signal("signal36", "aspect_stop");
testsuite_driveTo("seg62", -50, train1);
- set_signal("signal34", "aspect_stop");
- set_signal("signal32", "aspect_stop");
+ testsuite_set_signal("signal34", "aspect_stop");
+ testsuite_set_signal("signal32", "aspect_stop");
testsuite_driveTo("seg60", -50, train1);
testsuite_driveTo("seg53", -40, train1);
@@ -588,47 +371,47 @@ static void *route100(void *arg) {
while (true) {
// train2: forwards
- switch_point("point10", "reverse");
- switch_point("point9", "normal");
- switch_point("point8", "reverse");
- switch_point("point1", "reverse");
- switch_point("point7", "normal");
- switch_point("point6", "normal");
- switch_point("point5", "normal");
- switch_point("point4", "normal");
- switch_point("point3", "reverse");
- switch_point("point11", "reverse");
+ testsuite_switch_point("point10", "reverse");
+ testsuite_switch_point("point9", "normal");
+ testsuite_switch_point("point8", "reverse");
+ testsuite_switch_point("point1", "reverse");
+ testsuite_switch_point("point7", "normal");
+ testsuite_switch_point("point6", "normal");
+ testsuite_switch_point("point5", "normal");
+ testsuite_switch_point("point4", "normal");
+ testsuite_switch_point("point3", "reverse");
+ testsuite_switch_point("point11", "reverse");
sleep(1);
- set_signal("signal43", "aspect_shunt");
- set_signal("signal19", "aspect_go");
- set_signal("signal3", "aspect_go");
- set_signal("signal1", "aspect_go");
- set_signal("signal13", "aspect_go");
- set_signal("signal11", "aspect_go");
- set_signal("signal10", "aspect_go");
- set_signal("signal8", "aspect_go");
+ testsuite_set_signal("signal43", "aspect_shunt");
+ testsuite_set_signal("signal19", "aspect_go");
+ testsuite_set_signal("signal3", "aspect_go");
+ testsuite_set_signal("signal1", "aspect_go");
+ testsuite_set_signal("signal13", "aspect_go");
+ testsuite_set_signal("signal11", "aspect_go");
+ testsuite_set_signal("signal10", "aspect_go");
+ testsuite_set_signal("signal8", "aspect_go");
sleep(1);
testsuite_driveTo("seg77", 126, train2);
- set_signal("signal43", "aspect_stop");
+ testsuite_set_signal("signal43", "aspect_stop");
testsuite_driveTo("seg26", 126, train2);
- set_signal("signal19", "aspect_stop");
+ testsuite_set_signal("signal19", "aspect_stop");
testsuite_driveTo("seg1", 126, train2);
- set_signal("signal3", "aspect_stop");
- set_signal("signal1", "aspect_stop");
+ testsuite_set_signal("signal3", "aspect_stop");
+ testsuite_set_signal("signal1", "aspect_stop");
testsuite_driveTo("seg15", 126, train2);
- set_signal("signal13", "aspect_stop");
- set_signal("signal11", "aspect_stop");
+ testsuite_set_signal("signal13", "aspect_stop");
+ testsuite_set_signal("signal11", "aspect_stop");
testsuite_driveTo("seg11", 126, train2);
- set_signal("signal10", "aspect_stop");
- set_signal("signal8", "aspect_stop");
+ testsuite_set_signal("signal10", "aspect_stop");
+ testsuite_set_signal("signal8", "aspect_stop");
testsuite_driveTo("seg31b", 50, train2);
sleep(1);
@@ -641,36 +424,36 @@ static void *route100(void *arg) {
sleep(5);
// train2: backwards
- set_signal("signal22a", "aspect_go");
- set_signal("signal22b", "aspect_go");
- set_signal("signal9", "aspect_go");
- set_signal("signal12", "aspect_go");
- set_signal("signal14", "aspect_go");
- set_signal("signal2", "aspect_go");
- set_signal("signal4a", "aspect_go");
- set_signal("signal4b", "aspect_go");
- set_signal("signal20", "aspect_shunt");
+ testsuite_set_signal("signal22a", "aspect_go");
+ testsuite_set_signal("signal22b", "aspect_go");
+ testsuite_set_signal("signal9", "aspect_go");
+ testsuite_set_signal("signal12", "aspect_go");
+ testsuite_set_signal("signal14", "aspect_go");
+ testsuite_set_signal("signal2", "aspect_go");
+ testsuite_set_signal("signal4a", "aspect_go");
+ testsuite_set_signal("signal4b", "aspect_go");
+ testsuite_set_signal("signal20", "aspect_shunt");
sleep(1);
testsuite_driveTo("seg32", -126, train2);
- set_signal("signal22a", "aspect_stop");
- set_signal("signal22b", "aspect_stop");
+ testsuite_set_signal("signal22a", "aspect_stop");
+ testsuite_set_signal("signal22b", "aspect_stop");
testsuite_driveTo("seg13", -126, train2);
- set_signal("signal9", "aspect_stop");
+ testsuite_set_signal("signal9", "aspect_stop");
testsuite_driveTo("seg17", -126, train2);
- set_signal("signal12", "aspect_stop");
- set_signal("signal14", "aspect_stop");
+ testsuite_set_signal("signal12", "aspect_stop");
+ testsuite_set_signal("signal14", "aspect_stop");
testsuite_driveTo("seg3", -126, train2);
- set_signal("signal2", "aspect_stop");
- set_signal("signal4a", "aspect_stop");
- set_signal("signal4b", "aspect_stop");
+ testsuite_set_signal("signal2", "aspect_stop");
+ testsuite_set_signal("signal4a", "aspect_stop");
+ testsuite_set_signal("signal4b", "aspect_stop");
testsuite_driveTo("seg28", -50, train2);
- set_signal("signal20", "aspect_stop");
+ testsuite_set_signal("signal20", "aspect_stop");
testsuite_driveTo("seg78a", -50, train2);
sleep(1);
@@ -695,36 +478,25 @@ void testsuite_case_swtbahnFullMultipleTrains(const char *train1, const char *tr
pthread_join(route100_thread, NULL);
}
-
bool route_custom_short(const char *train) {
if (!testsuite_trainReady(train, "seg7a")) {
return false;
}
- switch_point("point2", "normal");
- switch_point("point1", "normal");
- switch_point("point7", "normal");
- switch_point("point6", "normal");
- switch_point("point5", "normal");
- switch_point("point4", "normal");
- switch_point("point3", "normal");
-
-
- set_signal("signal5", "aspect_go");
- set_signal("signal17", "aspect_go");
- set_signal("signal", "aspect_go");
+ testsuite_switch_point("point2", "normal");
+ testsuite_switch_point("point1", "normal");
+ testsuite_switch_point("point7", "normal");
+ testsuite_switch_point("point6", "normal");
+ testsuite_switch_point("point5", "normal");
+ testsuite_switch_point("point4", "normal");
+ testsuite_switch_point("point3", "normal");
- testsuite_driveTo("seg58", 50, train);
- sleep(1);
- testsuite_driveToStop("seg59", 20, train);
- sleep(2);
+ testsuite_driveTo("drive_forever", 50, train);
return true;
}
-void testsuite_case_swtbahnFullShortRoute(const char *train)
-{
- sleep(1);
+
+void testsuite_case_swtbahnFullShortRoute(const char *train) {
if (!route_custom_short(train)) {
return;
}
- printf("testsuite_case_swtbahnFullShortRoute finished.\n\n");
}
diff --git a/test/physical/swtbahn-full/testsuite.h b/test/physical/swtbahn-full/testsuite.h
index aa48b97..a5b7639 100644
--- a/test/physical/swtbahn-full/testsuite.h
+++ b/test/physical/swtbahn-full/testsuite.h
@@ -31,45 +31,10 @@
#ifndef TESTSUITE_H
#define TESTSUITE_H
-
-#include "../../../include/bidib.h"
-
-
-typedef struct {
- int stateError;
- int stateNotReached;
- int stateNotReachedVerified;
- int stateReached;
- int stateReachedVerified;
- int unknownState;
-} t_testsuite_point_result;
-
-typedef struct {
- t_testsuite_point_result *points;
-} t_testsuite_test_result;
-
-typedef struct {
- char **ids;
- size_t length;
-} t_testsuite_ids;
-
+#include "../test_common.h"
// Setup
t_testsuite_test_result *testsuite_initTestSuite();
-t_bidib_id_list_query testsuite_filterOutIds(t_bidib_id_list_query inputIdQuery, t_testsuite_ids filterOutIds);
-
-// Teardown
-void testsuite_stopBidib(void);
-void testsuite_signal_callback_handler(int signum);
-
-// Logging
-void testsuite_logTestResult(t_testsuite_test_result *result, t_bidib_unified_accessory_state_query state, int accessory_index);
-void testsuite_printTestResults(t_testsuite_test_result *result);
-
-// Driving
-bool testsuite_trainReady(const char *train, const char *segment);
-void testsuite_driveTo(const char *segment, int speed, const char *train);
-void testsuite_driveToStop(const char *segment, int speed, const char *train);
// Test cases
void testsuite_case_signal();
diff --git a/test/physical/swtbahn-standard/main.c b/test/physical/swtbahn-standard/main.c
index 044123a..f83e6c5 100755
--- a/test/physical/swtbahn-standard/main.c
+++ b/test/physical/swtbahn-standard/main.c
@@ -51,7 +51,7 @@ int main(int argc, char **argv) {
printf(" 2 - Points (serial switching) \n");
printf(" 3 - Signals \n");
printf(" 4 - Track coverage with one train (specified a trainName) \n");
- printf(" 5 - Reverser (runs continuoslz) \n");
+ printf(" 5 - Reverser (runs continuously) \n");
printf("\n");
return 0;
@@ -61,6 +61,7 @@ int main(int argc, char **argv) {
printf("testsuite: libbidib failed to start\n");
return 0;
}
+ sleep(2); // Wait for the points to finish switching to their default positions.
printf("testsuite: Test case %d\n", atoi(argv[1]));
t_testsuite_test_result *result = testsuite_initTestSuite();
@@ -68,18 +69,21 @@ int main(int argc, char **argv) {
const int repetitions = atoi(argv[2]);
switch (atoi(argv[1])) {
case 1:
+ bidib_set_track_output_state_all(BIDIB_CS_OFF);
for (int i = 0; i < repetitions; i++) {
testsuite_case_pointParallel(result);
}
testsuite_printTestResults(result);
break;
case 2:
+ bidib_set_track_output_state_all(BIDIB_CS_OFF);
for (int i = 0; i < repetitions; i++) {
testsuite_case_pointSerial(result);
}
testsuite_printTestResults(result);
break;
case 3:
+ bidib_set_track_output_state_all(BIDIB_CS_OFF);
for (int i = 0; i < repetitions; i++) {
testsuite_case_signal();
}
@@ -126,7 +130,7 @@ void printWelcome() {
"* SWTbahn-testsuite *",
"* *",
"************************",
- "* UniBa-SWT-2022 *",
+ "* UniBa-SWT-2023 *",
"************************",
""
};
diff --git a/test/physical/swtbahn-standard/testsuite.c b/test/physical/swtbahn-standard/testsuite.c
index 4922ea0..e19a76f 100644
--- a/test/physical/swtbahn-standard/testsuite.c
+++ b/test/physical/swtbahn-standard/testsuite.c
@@ -36,235 +36,24 @@
#include "testsuite.h"
-
-#define SIGNAL_WAITING_TIME 3 // in seconds
-#define POINT_WAITING_TIME 3 // in seconds
-#define TRAIN_WAITING_TIME 250000 // in microseconds
-
-t_bidib_id_list_query points;
-t_bidib_id_list_query signals;
-
-
-// This initialisation function is specific to SWTbahn Standard!
+// This initialisation function is specific to SWTbahn Standard.
t_testsuite_test_result *testsuite_initTestSuite() {
- points = bidib_get_connected_points();
-
- // Accessories that are not signals
- t_testsuite_ids filterOutIds;
char *excludedSignalAccessories[1] = {"platformlights"};
- filterOutIds.ids = excludedSignalAccessories;
- filterOutIds.length = 1;
- signals = testsuite_filterOutIds(bidib_get_connected_signals(), filterOutIds);
-
- t_testsuite_test_result *result = malloc(sizeof(t_testsuite_test_result));
- result->points = malloc(points.length * sizeof(t_testsuite_point_result));
-
- for (size_t i = 0; i < points.length; i++) {
- result->points[i].stateReachedVerified = 0;
- result->points[i].stateReached = 0;
- result->points[i].stateNotReachedVerified = 0;
- result->points[i].stateNotReached = 0;
- result->points[i].stateError = 0;
- result->points[i].unknownState = 0;
- }
+ t_testsuite_test_result *result = testsuite_initTestSuite_common(excludedSignalAccessories, 1);
return result;
}
-void testsuite_stopBidib(void) {
- bidib_free_id_list_query(points);
- bidib_free_id_list_query(signals);
- bidib_stop();
-}
-
-void testsuite_signal_callback_handler(int signum) {
- testsuite_stopBidib();
- printf("testsuite: SIGINT - stopping libbidib \n");
- exit(signum);
-}
-
-t_bidib_id_list_query testsuite_filterOutIds(t_bidib_id_list_query inputIdQuery, t_testsuite_ids filterOutIds) {
- const size_t count = inputIdQuery.length - filterOutIds.length;
-
- if (count <= 0) {
- printf("testsuite: No IDs will be left after filtering\n");
- }
-
- t_bidib_id_list_query outputIdQuery;
- outputIdQuery.length = 0;
- outputIdQuery.ids = malloc(sizeof(char *) * count);
-
- int isFilteredOut = 0;
-
- for (size_t i = 0; i < inputIdQuery.length; i++) {
- isFilteredOut = 0;
- for (size_t j = 0; j < filterOutIds.length; j++) {
- if (!strcmp(inputIdQuery.ids[i], filterOutIds.ids[j])) {
- isFilteredOut = 1;
- break;
- }
- }
-
- if (!isFilteredOut) {
- size_t len = strlen(inputIdQuery.ids[i]) + 1;
- outputIdQuery.ids[outputIdQuery.length] = malloc(sizeof(char) * len) ;
- memcpy(outputIdQuery.ids[outputIdQuery.length], inputIdQuery.ids[i], len);
- outputIdQuery.length++;
- }
- }
-
- if (outputIdQuery.length != count) {
- printf("testsuite: Error: %zu IDs were to be filtered, but %d IDs filtered instead\n", filterOutIds.length, (int)inputIdQuery.length - (int)outputIdQuery.length);
- }
-
- return outputIdQuery;
-}
-
-void testsuite_logTestResult(t_testsuite_test_result *result, t_bidib_unified_accessory_state_query state, int accessory_index) {
- if (state.known) {
- switch (state.board_accessory_state.execution_state) {
- case BIDIB_EXEC_STATE_ERROR:
- result->points[accessory_index].stateError++;
- break;
- case BIDIB_EXEC_STATE_NOTREACHED:
- result->points[accessory_index].stateNotReached++;
- break;
- case BIDIB_EXEC_STATE_NOTREACHED_VERIFIED:
- result->points[accessory_index].stateNotReachedVerified++;
- break;
- case BIDIB_EXEC_STATE_REACHED:
- result->points[accessory_index].stateReached++;
- break;
- case BIDIB_EXEC_STATE_REACHED_VERIFIED:
- result->points[accessory_index].stateReachedVerified++;
- break;
- default:
- break;
- }
- } else {
- result->points[accessory_index].unknownState++;
- }
-}
-
-void testsuite_printTestResults(t_testsuite_test_result *result) {
- for (size_t i = 0; i < points.length; i++) {
- printf("\n\n%s\n", points.ids[i]);
- printf(" -> stateReachedVerified: %d \n", result->points[i].stateReachedVerified);
- printf(" -> stateReached: %d \n", result->points[i].stateReached);
- printf(" -> stateNotReachedVerified: %d \n", result->points[i].stateNotReachedVerified);
- printf(" -> stateNotReached: %d \n", result->points[i].stateNotReached);
- printf(" -> stateError: %d \n", result->points[i].stateError);
- printf(" -> unknownState: %d \n", result->points[i].unknownState);
- }
-}
-
-bool testsuite_trainReady(const char *train) {
- const char *segment = "seg1";
- if (bidib_get_train_on_track(train)) {
- t_bidib_train_position_query train_position_query = bidib_get_train_position(train);
- if (train_position_query.length > 0) {
- for (size_t i = 0; i < train_position_query.length; i++) {
- if (strcmp(segment, train_position_query.segments[i]) == 0) {
- printf("testsuite: %s train ready on %s \n", train, segment);
- bidib_free_train_position_query(train_position_query);
- return true;
- }
- }
- }
-
- printf("testsuite: %s train not on track segment %s \n", train, segment);
- bidib_free_train_position_query(train_position_query);
- return false;
- } else {
- printf("testsuite: %s train not detected on any track \n", train);
- return false;
- }
-}
-
-void testsuite_driveTo(const char *segment, int speed, const char *train) {
- bidib_set_train_speed(train, speed, "master");
- bidib_flush();
-
- while (1) {
- t_bidib_train_position_query trainPosition = bidib_get_train_position(train);
-
- for (size_t i = 0; i < trainPosition.length; i++) {
- if (!strcmp(segment, trainPosition.segments[i])) {
- bidib_free_train_position_query(trainPosition);
- return;
- }
- }
- bidib_free_train_position_query(trainPosition);
- usleep(TRAIN_WAITING_TIME);
- }
-}
-
-void testsuite_driveToStop(const char *segment, int speed, const char *train) {
- testsuite_driveTo(segment, speed, train);
- bidib_set_train_speed(train, 0, "master");
- bidib_flush();
-}
-
-void set_signal(const char *signal, const char *aspect) {
- bidib_set_signal(signal, aspect);
- bidib_flush();
-}
-
-void switch_point(const char *point, const char *aspect) {
- bidib_switch_point(point, aspect);
- bidib_flush();
-}
-
void testsuite_case_signal() {
- for (size_t i = 0; i < signals.length; i++) {
- set_signal(signals.ids[i], "aspect_caution");
- }
- sleep(SIGNAL_WAITING_TIME);
-
- for (size_t i = 0; i < signals.length; i++) {
- set_signal(signals.ids[i], "aspect_go");
- }
- sleep(SIGNAL_WAITING_TIME);
-
- for (size_t i = 0; i < signals.length; i++) {
- set_signal(signals.ids[i], "aspect_stop");
- }
- sleep(SIGNAL_WAITING_TIME);
-
+ char *signalAspects[3] = {"aspect_caution", "aspect_go", "aspect_stop"};
+ testsuite_case_signal_common(signalAspects, 3);
}
void testsuite_case_pointParallel(t_testsuite_test_result *result) {
- for (size_t i = 0; i < points.length; i++) {
- switch_point(points.ids[i], "reverse");
- t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- bidib_free_unified_accessory_state_query(state);
- }
-
- sleep(POINT_WAITING_TIME);
-
- for (size_t i = 0; i < points.length; i++) {
- switch_point(points.ids[i], "normal");
- t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- bidib_free_unified_accessory_state_query(state);
- }
-
- sleep(POINT_WAITING_TIME);
+ testsuite_case_pointParallel_common(result);
}
void testsuite_case_pointSerial(t_testsuite_test_result *result) {
- for (size_t i = 0; i < points.length; i++) {
- switch_point(points.ids[i], "reverse");
- t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- sleep(POINT_WAITING_TIME);
- bidib_free_unified_accessory_state_query(state);
- switch_point(points.ids[i], "normal");
- state = bidib_get_point_state(points.ids[i]);
- testsuite_logTestResult(result, state, i);
- bidib_free_unified_accessory_state_query(state);
- sleep(POINT_WAITING_TIME);
- }
+ testsuite_case_pointSerial_common(result);
}
void testsuite_case_reverser(void) {
@@ -284,7 +73,8 @@ void testsuite_case_reverser(void) {
for (int retry = 0; retry < max_retries && state_unknown; retry++) {
t_bidib_reverser_state_query rev_state_query =
bidib_get_reverser_state(reverser_id);
- state_unknown = !rev_state_query.available || rev_state_query.data.state_value == BIDIB_REV_EXEC_STATE_UNKNOWN;
+ state_unknown = !rev_state_query.available
+ || rev_state_query.data.state_value == BIDIB_REV_EXEC_STATE_UNKNOWN;
if (!state_unknown) {
char *state_value_str = "unknown";
switch (rev_state_query.data.state_value) {
@@ -314,59 +104,59 @@ void testsuite_case_reverser(void) {
}
void testsuite_case_swtbahnStandardTrackCoverage(const char *train) {
- if (!testsuite_trainReady(train)) {
+ if (!testsuite_trainReady(train, "seg1")) {
return;
}
- switch_point("point1", "normal");
- switch_point("point2", "normal");
- switch_point("point3", "normal");
+ testsuite_switch_point("point1", "normal");
+ testsuite_switch_point("point2", "normal");
+ testsuite_switch_point("point3", "normal");
testsuite_driveTo("seg12", 80, train);
- switch_point("point6", "reverse");
- switch_point("point8", "reverse");
- switch_point("point2", "reverse");
- switch_point("point3", "reverse");
- switch_point("point4", "reverse");
- switch_point("point5", "reverse");
- switch_point("point12", "normal");
- switch_point("point10", "reverse");
- switch_point("point9", "reverse");
- switch_point("point11", "reverse");
+ testsuite_switch_point("point6", "reverse");
+ testsuite_switch_point("point8", "reverse");
+ testsuite_switch_point("point2", "reverse");
+ testsuite_switch_point("point3", "reverse");
+ testsuite_switch_point("point4", "reverse");
+ testsuite_switch_point("point5", "reverse");
+ testsuite_switch_point("point12", "normal");
+ testsuite_switch_point("point10", "reverse");
+ testsuite_switch_point("point9", "reverse");
+ testsuite_switch_point("point11", "reverse");
testsuite_driveToStop("seg37", 80, train);
- switch_point("point12", "reverse");
+ testsuite_switch_point("point12", "reverse");
testsuite_driveToStop("seg40", -80, train);
- switch_point("point12", "normal");
- switch_point("point11", "normal");
- switch_point("point10", "normal");
+ testsuite_switch_point("point12", "normal");
+ testsuite_switch_point("point11", "normal");
+ testsuite_switch_point("point10", "normal");
testsuite_driveTo("seg28", 50, train);
- switch_point("point7", "normal");
- switch_point("point4", "normal");
- switch_point("point9", "normal");
+ testsuite_switch_point("point7", "normal");
+ testsuite_switch_point("point4", "normal");
+ testsuite_switch_point("point9", "normal");
testsuite_driveTo("seg21", 80, train);
- switch_point("point5", "normal");
+ testsuite_switch_point("point5", "normal");
testsuite_driveTo("seg28", 80, train);
- switch_point("point7", "reverse");
- switch_point("point8", "normal");
- switch_point("point2", "reverse");
- switch_point("point3", "normal");
- switch_point("point6", "normal");
- switch_point("point1", "reverse");
+ testsuite_switch_point("point7", "reverse");
+ testsuite_switch_point("point8", "normal");
+ testsuite_switch_point("point2", "reverse");
+ testsuite_switch_point("point3", "normal");
+ testsuite_switch_point("point6", "normal");
+ testsuite_switch_point("point1", "reverse");
testsuite_driveToStop("seg4", 80, train);
- switch_point("point1", "normal");
+ testsuite_switch_point("point1", "normal");
testsuite_driveTo("seg1", -20, train);
sleep(1);
diff --git a/test/physical/swtbahn-standard/testsuite.h b/test/physical/swtbahn-standard/testsuite.h
index 248084a..6aef2e4 100644
--- a/test/physical/swtbahn-standard/testsuite.h
+++ b/test/physical/swtbahn-standard/testsuite.h
@@ -31,45 +31,10 @@
#ifndef TESTSUITE_H
#define TESTSUITE_H
-
-#include "../../../include/bidib.h"
-
-
-typedef struct {
- int stateError;
- int stateNotReached;
- int stateNotReachedVerified;
- int stateReached;
- int stateReachedVerified;
- int unknownState;
-}t_testsuite_point_result;
-
-typedef struct {
- t_testsuite_point_result *points;
-}t_testsuite_test_result;
-
-typedef struct {
- char **ids;
- size_t length;
-}t_testsuite_ids;
-
+#include "../test_common.h"
// Setup
t_testsuite_test_result *testsuite_initTestSuite();
-t_bidib_id_list_query testsuite_filterOutIds(t_bidib_id_list_query inputIdQuery, t_testsuite_ids filterOutIds);
-
-// Teardown
-void testsuite_stopBidib(void);
-void testsuite_signal_callback_handler(int signum);
-
-// Logging
-void testsuite_logTestResult(t_testsuite_test_result *result, t_bidib_unified_accessory_state_query state, int accessory_index);
-void testsuite_printTestResults(t_testsuite_test_result *result);
-
-// Driving
-bool testsuite_trainReady(const char *train);
-void testsuite_driveTo(const char *segment, int speed, const char *train);
-void testsuite_driveToStop(const char *segment, int speed, const char *train);
// Test cases
void testsuite_case_signal();
diff --git a/test/physical/test_common.c b/test/physical/test_common.c
new file mode 100644
index 0000000..5ae7455
--- /dev/null
+++ b/test/physical/test_common.c
@@ -0,0 +1,260 @@
+/*
+ *
+ * Copyright (C) 2022 University of Bamberg, Software Technologies Research Group
+ * ,
+ *
+ * This file is part of the BiDiB library (libbidib), used to communicate with
+ * BiDiB systems over a serial connection. This library was
+ * developed as part of Nicolas Gross’ student project.
+ *
+ * libbidib is licensed under the GNU GENERAL PUBLIC LICENSE (Version 3), see
+ * the LICENSE file at the project's top-level directory for details or consult
+ * .
+ *
+ * libbidib is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or any later version.
+ *
+ * libbidib is a RESEARCH PROTOTYPE and distributed WITHOUT ANY WARRANTY, without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * The following people contributed to the conception and realization of the
+ * present libbidib (in alphabetic order by surname):
+ *
+ * - Christof Lehanka
+ * - Bernhard Luedtke
+ * - Eugene Yip
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "test_common.h"
+
+
+#define SIGNAL_WAITING_TIME_S 3 // in seconds
+#define POINT_WAITING_TIME_S 3 // in seconds
+#define TRAIN_WAITING_TIME_US 250000 // in microseconds
+
+t_bidib_id_list_query points;
+t_bidib_id_list_query signals;
+
+t_testsuite_test_result *testsuite_initTestSuite_common(char **excludedSignalAccessories,
+ size_t excludedSignalAccessories_len) {
+ points = bidib_get_connected_points();
+
+ // Accessories that are not signals
+ t_testsuite_ids filterOutIds;
+ filterOutIds.ids = excludedSignalAccessories;
+ filterOutIds.length = excludedSignalAccessories_len;
+ t_bidib_id_list_query signalsQuery = bidib_get_connected_signals();
+ signals = testsuite_filterOutIds(signalsQuery, filterOutIds);
+ bidib_free_id_list_query(signalsQuery);
+
+ t_testsuite_test_result *result = malloc(sizeof(t_testsuite_test_result));
+ result->points = malloc(points.length * sizeof(t_testsuite_point_result));
+
+ for (size_t i = 0; i < points.length; i++) {
+ result->points[i].stateReachedVerified = 0;
+ result->points[i].stateReached = 0;
+ result->points[i].stateNotReachedVerified = 0;
+ result->points[i].stateNotReached = 0;
+ result->points[i].stateError = 0;
+ result->points[i].unknownState = 0;
+ }
+ return result;
+}
+
+t_bidib_id_list_query testsuite_filterOutIds(t_bidib_id_list_query inputIdQuery, t_testsuite_ids filterOutIds) {
+ const size_t count = inputIdQuery.length - filterOutIds.length;
+
+ if (count <= 0) {
+ printf("testsuite: No IDs will be left after filtering\n");
+ }
+
+ t_bidib_id_list_query outputIdQuery;
+ outputIdQuery.length = 0;
+ outputIdQuery.ids = malloc(sizeof(char *) * count);
+
+ bool isFilteredOut = false;
+
+ for (size_t i = 0; i < inputIdQuery.length; i++) {
+ isFilteredOut = false;
+ for (size_t j = 0; j < filterOutIds.length; j++) {
+ if (!strcmp(inputIdQuery.ids[i], filterOutIds.ids[j])) {
+ isFilteredOut = true;
+ break;
+ }
+ }
+
+ if (!isFilteredOut) {
+ outputIdQuery.ids[outputIdQuery.length] = strdup(inputIdQuery.ids[i]);
+ outputIdQuery.length++;
+ }
+ }
+
+ if (outputIdQuery.length != count) {
+ printf("testsuite: Error: %zu IDs were to be filtered, but %d IDs filtered instead\n",
+ filterOutIds.length, (int)inputIdQuery.length - (int)outputIdQuery.length);
+ }
+
+ return outputIdQuery;
+}
+
+void testsuite_stopBidib(void) {
+ bidib_free_id_list_query(points);
+ bidib_free_id_list_query(signals);
+ bidib_stop();
+}
+
+void testsuite_signal_callback_handler(int signum) {
+ testsuite_stopBidib();
+ printf("testsuite: SIGINT - stopping libbidib \n");
+ exit(signum);
+}
+
+void testsuite_logTestResult(t_testsuite_test_result *result,
+ t_bidib_unified_accessory_state_query state,
+ int accessory_index) {
+ if (state.known) {
+ switch (state.board_accessory_state.execution_state) {
+ case BIDIB_EXEC_STATE_ERROR:
+ result->points[accessory_index].stateError++;
+ break;
+ case BIDIB_EXEC_STATE_NOTREACHED:
+ result->points[accessory_index].stateNotReached++;
+ break;
+ case BIDIB_EXEC_STATE_NOTREACHED_VERIFIED:
+ result->points[accessory_index].stateNotReachedVerified++;
+ break;
+ case BIDIB_EXEC_STATE_REACHED:
+ result->points[accessory_index].stateReached++;
+ break;
+ case BIDIB_EXEC_STATE_REACHED_VERIFIED:
+ result->points[accessory_index].stateReachedVerified++;
+ break;
+ default:
+ break;
+ }
+ } else {
+ result->points[accessory_index].unknownState++;
+ }
+}
+
+void testsuite_printTestResults(t_testsuite_test_result *result) {
+ for (size_t i = 0; i < points.length; i++) {
+ printf("\n\n%s\n", points.ids[i]);
+ printf(" -> stateReachedVerified: %d \n", result->points[i].stateReachedVerified);
+ printf(" -> stateReached: %d \n", result->points[i].stateReached);
+ printf(" -> stateNotReachedVerified: %d \n", result->points[i].stateNotReachedVerified);
+ printf(" -> stateNotReached: %d \n", result->points[i].stateNotReached);
+ printf(" -> stateError: %d \n", result->points[i].stateError);
+ printf(" -> unknownState: %d \n", result->points[i].unknownState);
+ }
+}
+
+bool testsuite_trainReady(const char *train, const char *segment) {
+ if (bidib_get_train_on_track(train)) {
+ t_bidib_train_position_query train_position_query = bidib_get_train_position(train);
+ if (train_position_query.length > 0) {
+ for (size_t i = 0; i < train_position_query.length; i++) {
+ if (strcmp(segment, train_position_query.segments[i]) == 0) {
+ printf("testsuite: %s train ready on %s \n", train, segment);
+ bidib_free_train_position_query(train_position_query);
+ return true;
+ }
+ }
+ }
+
+ printf("testsuite: %s train not on track segment %s \n", train, segment);
+ bidib_free_train_position_query(train_position_query);
+ return false;
+ } else {
+ printf("testsuite: %s train not detected on any track \n", train);
+ return false;
+ }
+}
+
+void testsuite_driveTo(const char *segment, int speed, const char *train) {
+ bidib_set_train_speed(train, speed, "master");
+ bidib_flush();
+
+ while (1) {
+ t_bidib_train_position_query trainPosition = bidib_get_train_position(train);
+ for (size_t i = 0; i < trainPosition.length; i++) {
+ if (!strcmp(segment, trainPosition.segments[i])) {
+ bidib_free_train_position_query(trainPosition);
+ return;
+ }
+ }
+ bidib_free_train_position_query(trainPosition);
+ usleep(TRAIN_WAITING_TIME_US);
+ }
+}
+
+void testsuite_driveToStop(const char *segment, int speed, const char *train) {
+ testsuite_driveTo(segment, speed, train);
+ bidib_set_train_speed(train, 0, "master");
+ bidib_flush();
+}
+
+void testsuite_set_signal(const char *signal, const char *aspect) {
+ bidib_set_signal(signal, aspect);
+ bidib_flush();
+}
+
+void testsuite_switch_point(const char *point, const char *aspect) {
+ bidib_switch_point(point, aspect);
+ bidib_flush();
+}
+
+void testsuite_case_signal_common(char **aspects, size_t aspects_len) {
+ for (size_t i = 0; i < aspects_len; i++) {
+ for (size_t n = 0; n < signals.length; n++) {
+ testsuite_set_signal(signals.ids[n], aspects[i]);
+ }
+ sleep(SIGNAL_WAITING_TIME_S);
+ }
+}
+
+void testsuite_case_pointParallel_common(t_testsuite_test_result *result) {
+ for (size_t i = 0; i < points.length; i++) {
+ testsuite_switch_point(points.ids[i], "reverse");
+ t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
+ testsuite_logTestResult(result, state, i);
+ bidib_free_unified_accessory_state_query(state);
+ }
+
+ sleep(POINT_WAITING_TIME_S);
+
+ for (size_t i = 0; i < points.length; i++) {
+ testsuite_switch_point(points.ids[i], "normal");
+ t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
+ testsuite_logTestResult(result, state, i);
+ bidib_free_unified_accessory_state_query(state);
+ }
+
+ sleep(POINT_WAITING_TIME_S);
+}
+
+void testsuite_case_pointSerial_common(t_testsuite_test_result *result) {
+ for (size_t i = 0; i < points.length; i++) {
+ testsuite_switch_point(points.ids[i], "reverse");
+ t_bidib_unified_accessory_state_query state = bidib_get_point_state(points.ids[i]);
+ testsuite_logTestResult(result, state, i);
+ bidib_free_unified_accessory_state_query(state);
+ sleep(POINT_WAITING_TIME_S);
+
+ testsuite_switch_point(points.ids[i], "normal");
+ state = bidib_get_point_state(points.ids[i]);
+ testsuite_logTestResult(result, state, i);
+ bidib_free_unified_accessory_state_query(state);
+ sleep(POINT_WAITING_TIME_S);
+ }
+}
diff --git a/test/physical/test_common.h b/test/physical/test_common.h
new file mode 100644
index 0000000..60accbc
--- /dev/null
+++ b/test/physical/test_common.h
@@ -0,0 +1,86 @@
+/*
+ *
+ * Copyright (C) 2022 University of Bamberg, Software Technologies Research Group
+ * ,
+ *
+ * This file is part of the BiDiB library (libbidib), used to communicate with
+ * BiDiB systems over a serial connection. This library was
+ * developed as part of Nicolas Gross’ student project.
+ *
+ * libbidib is licensed under the GNU GENERAL PUBLIC LICENSE (Version 3), see
+ * the LICENSE file at the project's top-level directory for details or consult
+ * .
+ *
+ * libbidib is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or any later version.
+ *
+ * libbidib is a RESEARCH PROTOTYPE and distributed WITHOUT ANY WARRANTY, without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * The following people contributed to the conception and realization of the
+ * present libbidib (in alphabetic order by surname):
+ *
+ * - Christof Lehanka
+ * - Bernhard Luedtke
+ * - Eugene Yip
+ *
+ */
+
+
+#ifndef TEST_COMMON_H
+#define TEST_COMMON_H
+
+#include "../../include/bidib.h"
+#include
+#include
+
+typedef struct {
+ int stateError;
+ int stateNotReached;
+ int stateNotReachedVerified;
+ int stateReached;
+ int stateReachedVerified;
+ int unknownState;
+} t_testsuite_point_result;
+
+typedef struct {
+ t_testsuite_point_result *points;
+} t_testsuite_test_result;
+
+typedef struct {
+ char **ids;
+ size_t length;
+} t_testsuite_ids;
+
+extern t_bidib_id_list_query points;
+extern t_bidib_id_list_query signals;
+
+// Setup
+t_testsuite_test_result *testsuite_initTestSuite_common(char **excludedSignalAccessories, size_t excludedSignalAccessories_len);
+t_bidib_id_list_query testsuite_filterOutIds(t_bidib_id_list_query inputIdQuery, t_testsuite_ids filterOutIds);
+
+// Teardown
+void testsuite_stopBidib(void);
+void testsuite_signal_callback_handler(int signum);
+
+// Logging
+void testsuite_logTestResult(t_testsuite_test_result *result, t_bidib_unified_accessory_state_query state, int accessory_index);
+void testsuite_printTestResults(t_testsuite_test_result *result);
+
+// Driving
+bool testsuite_trainReady(const char *train, const char *segment);
+void testsuite_driveTo(const char *segment, int speed, const char *train);
+void testsuite_driveToStop(const char *segment, int speed, const char *train);
+
+// Accessories
+void testsuite_set_signal(const char *signal, const char *aspect);
+void testsuite_switch_point(const char *point, const char *aspect);
+
+// Common test base
+void testsuite_case_signal_common(char **aspects, size_t aspects_len);
+void testsuite_case_pointParallel_common(t_testsuite_test_result *result);
+void testsuite_case_pointSerial_common(t_testsuite_test_result *result);
+
+#endif