-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
executable file
·179 lines (154 loc) · 4.43 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
*
* Copyright (C) 2022 University of Bamberg, Software Technologies Research Group
* <https://www.uni-bamberg.de/>, <http://www.swt-bamberg.de/>
*
* This file is part of the BiDiB library (libbidib), used to communicate with
* BiDiB <www.bidib.org> 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
* <http://www.gnu.org/licenses/>.
*
* 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 <https://github.com/clehanka>
* - Bernhard Luedtke <https://github.com/BLuedtke>
* - Eugene Yip <https://github.com/eyip002>
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include "testsuite.h"
int argumentsValid(int argc, char **argv);
void printWelcome();
int main(int argc, char **argv) {
printWelcome();
signal(SIGINT, testsuite_signal_callback_handler);
if (!argumentsValid(argc, argv)) {
printf("Usage: testsuite <testCaseNumber> <repetitions> [trainName] [trainName] \n");
printf(" Test cases: \n");
printf(" 1 - Points (parallel switching) \n");
printf(" 2 - Points (serial switching) \n");
printf(" 3 - Signals \n");
printf(" 4 - Track coverage with one train (specify a trainName) \n");
printf(" 5 - Track coverage with two trains (specify two trainNames) \n");
printf(" 6 - Drive short test route with one train (specify a trainName)\n");
printf("\n");
return 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("testsuite: libbidib started\n");
}
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();
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();
}
break;
case 4:
for (int i = 0; i < repetitions; i++) {
testsuite_case_swtbahnFullTrackCoverage(argv[3]);
}
break;
case 5:
for (int i = 0; i < repetitions; i++) {
testsuite_case_swtbahnFullMultipleTrains(argv[3], argv[4]);
}
break;
case 6:
for (int i = 0; i < repetitions; i++) {
testsuite_case_swtbahnFullShortRoute(argv[3]);
}
break;
default:
break;
}
testsuite_stopBidib();
free(result->points);
free(result);
return 0;
}
int argumentsValid(int argc, char **argv) {
if (argc < 2) {
return 0;
}
const int testCaseNumber = atoi(argv[1]);
switch (testCaseNumber) {
case 1:
case 2:
case 3:
if (argc != 3) {
return 0;
}
break;
case 4:
if (argc != 4) {
return 0;
}
break;
case 5:
if (argc != 5) {
return 0;
}
break;
case 6:
if (argc != 4) {
return 0;
}
break;
default:
return 0;
}
return 1;
}
void printWelcome() {
char *message[8] = {
"************************",
"* *",
"* SWTbahn-testsuite *",
"* *",
"************************",
"* UniBa-SWT-2023 *",
"************************",
""
};
for (size_t i = 0; i < 8; i++) {
printf("%s\n", message[i]);
}
}