Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
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
8void lut_main();
11// FIXME Needs fixing (check with code owners)
12// int brake_main();
13void apps_main();
14void bms_main();
15
16// Defines a map from a string to a main function.
17typedef 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
24static 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
33 for (int n = 0; n < NUM_TESTS; ++n) {
34 name_to_main[n].main();
35 }
36 exit(EXIT_SUCCESS);
37}
38
39void 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
49int 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) {
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}
int main(void)
The application entry point.
Definition: main.c:99
void run_test(const char *name)
Definition: main.c:39
void bms_main()
Definition: BMSTest.c:32
#define NUM_TESTS
Definition: main.c:30
void apps_main()
Definition: AppsTest.c:13
static map name_to_main[]
Definition: main.c:24
void wheel_speed_main()
void run_all_tests()
Definition: main.c:32
void torque_control_main()
void lut_main()
Definition: LUT.c:115
Definition: main.c:17
void(* main)()
Definition: main.c:19
const char * name
Definition: main.c:18