1 /*
2 * Copyright 2019 The Hafnium Authors.
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
7 */
8
9 #include <stddef.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <unistd.h>
14
15 #include "hf/memiter.h"
16
17 #include "hftest_common.h"
18 #include "test/hftest.h"
19 #include <sys/reboot.h>
20
test_main(int argc,const char * argv[])21 void test_main(int argc, const char *argv[])
22 {
23 static const char json_command[] = "json";
24 static const char run_command[] = "run";
25 const char *command;
26
27 if (argc < 2) {
28 HFTEST_LOG("Unable to parse command.");
29 return;
30 }
31 command = argv[1];
32
33 hftest_use_registered_list();
34
35 if (strncmp(command, json_command, sizeof(json_command)) == 0) {
36 hftest_json();
37 return;
38 }
39
40 if (strncmp(command, run_command, sizeof(run_command)) == 0) {
41 struct memiter suite_name;
42 struct memiter test_name;
43
44 if (argc != 4) {
45 HFTEST_LOG("Unable to parse test.");
46 return;
47 }
48
49 memiter_init(&suite_name, argv[2], strnlen_s(argv[2], 64));
50 memiter_init(&test_name, argv[3], strnlen_s(argv[3], 64));
51 hftest_run(suite_name, test_name, NULL);
52 return;
53 }
54
55 hftest_help();
56 }
57
main(int argc,const char * argv[])58 int main(int argc, const char *argv[])
59 {
60 test_main(argc, argv);
61 reboot(RB_POWER_OFF);
62 return 0;
63 }
64