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 <stdalign.h>
10 #include <stddef.h>
11 #include <stdint.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <unistd.h>
15 
16 #include "hf/memiter.h"
17 
18 #include "hftest_common.h"
19 #include "test/hftest.h"
20 #include <sys/reboot.h>
21 
test_main(int argc,const char * argv[])22 void test_main(int argc, const char *argv[])
23 {
24 	static const char json_command[] = "json";
25 	static const char run_command[] = "run";
26 	const char *command;
27 
28 	if (argc < 2) {
29 		HFTEST_LOG("Unable to parse command.");
30 		return;
31 	}
32 	command = argv[1];
33 
34 	hftest_use_registered_list();
35 
36 	if (strncmp(command, json_command, sizeof(json_command)) == 0) {
37 		hftest_json();
38 		return;
39 	}
40 
41 	if (strncmp(command, run_command, sizeof(run_command)) == 0) {
42 		struct memiter suite_name;
43 		struct memiter test_name;
44 
45 		if (argc != 4) {
46 			HFTEST_LOG("Unable to parse test.");
47 			return;
48 		}
49 
50 		memiter_init(&suite_name, argv[2], strnlen_s(argv[2], 64));
51 		memiter_init(&test_name, argv[3], strnlen_s(argv[3], 64));
52 		hftest_run(suite_name, test_name, NULL);
53 		return;
54 	}
55 
56 	hftest_help();
57 }
58 
main(int argc,const char * argv[])59 int main(int argc, const char *argv[])
60 {
61 	test_main(argc, argv);
62 	reboot(RB_POWER_OFF);
63 	return 0;
64 }
65