Vehicle Control Unit
0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Core
Tests
main.c
Go to the documentation of this file.
1
#include <stdbool.h>
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
#include <unistd.h>
6
7
// Forward declare the main functions
8
void
lut_main
();
9
void
wheel_speed_main
();
10
void
torque_control_main
();
11
// FIXME Needs fixing (check with code owners)
12
// int brake_main();
13
void
apps_main
();
14
void
bms_main
();
15
16
// Defines a map from a string to a main function.
17
typedef
struct
{
18
const
char
*
name
;
19
void (*
main
)();
20
}
map
;
21
22
// NOTE run_all_tests calls each of the values (mains) of this!
23
// Adding aliases / multiple of the same will cause multiple runs
24
static
map
name_to_main
[] = {{
"apps"
,
apps_main
},
25
/*{ "brake", brake_main },*/
26
{
"bms"
,
bms_main
},
27
{
"lut"
,
lut_main
},
28
{
"torque_control"
,
torque_control_main
},
29
{
"wheel_speed"
,
wheel_speed_main
}};
30
#define NUM_TESTS (sizeof(name_to_main) / sizeof(name_to_main[0]))
31
32
void
run_all_tests
() {
33
for
(
int
n = 0; n <
NUM_TESTS
; ++n) {
34
name_to_main
[n].
main
();
35
}
36
exit(EXIT_SUCCESS);
37
}
38
39
void
run_test
(
const
char
*name) {
40
for
(
int
n = 0; n <
NUM_TESTS
; ++n) {
41
map
entry =
name_to_main
[n];
42
if
(strncmp(entry.
name
, name, strlen(entry.
name
)) == 0) {
43
entry.
main
();
44
}
45
}
46
exit(EXIT_SUCCESS);
47
}
48
49
int
main
(
int
argc,
char
**argv) {
50
bool
all =
false
;
51
52
int
opt;
53
while
((opt = getopt(argc, argv,
"a"
)) != -1) {
54
switch
(opt) {
55
case
'a'
:
56
all =
true
;
57
break
;
58
default
:
59
fprintf(stderr,
"Usage: %s [-a] [tests]\n"
, argv[0]);
60
exit(EXIT_FAILURE);
61
}
62
}
63
64
if
(all) {
65
run_all_tests
();
66
}
67
68
if
(optind >= argc) {
69
fprintf(stderr,
"Expected name of test\n"
);
70
exit(EXIT_FAILURE);
71
}
72
73
for
(
int
n = optind; n < argc; ++n) {
74
run_test
(argv[n]);
75
}
76
77
return
EXIT_SUCCESS;
78
}
main
int main(void)
The application entry point.
Definition:
main.c:99
run_test
void run_test(const char *name)
Definition:
main.c:39
bms_main
void bms_main()
Definition:
BMSTest.c:32
NUM_TESTS
#define NUM_TESTS
Definition:
main.c:30
apps_main
void apps_main()
Definition:
AppsTest.c:13
name_to_main
static map name_to_main[]
Definition:
main.c:24
wheel_speed_main
void wheel_speed_main()
Definition:
WheelSpeedTest.c:17
run_all_tests
void run_all_tests()
Definition:
main.c:32
torque_control_main
void torque_control_main()
Definition:
TorqueControlActuatorTest.c:14
lut_main
void lut_main()
Definition:
LUT.c:115
map
Definition:
main.c:17
map::main
void(* main)()
Definition:
main.c:19
map::name
const char * name
Definition:
main.c:18
Generated by
1.9.5