xref: /rk3399_rockchip-uboot/test/rockchip/test-rockchip.c (revision 1dc7864b9b15e2ddbe18cd7e35a874d4fbef9b97)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <command.h>
9 #include "test-rockchip.h"
10 
11 typedef struct board_module {
12 	char *name;
13 	int (*test)(int argc, char * const argv[]);
14 } board_module_t;
15 
16 static board_module_t g_board_modules[] = {
17 	{ .name = "timer",	.test = board_timer_test },
18 	{ .name = "key",	.test = board_key_test },
19 };
20 
21 static int do_rockchip_test(cmd_tbl_t *cmdtp, int flag,
22 			    int argc, char * const argv[])
23 {
24 	ulong ms_start = 0, ms = 0, sec = 0;
25 	board_module_t *module = NULL;
26 	char *module_name = NULL;
27 	int index = 0, err = 0;
28 
29 	if (argc >= 2) {
30 		module_name = argv[1];
31 	} else {
32 		printf("cmd format: test_rockchip [module_name] [args...]\n");
33 		return 0;
34 	}
35 
36 	if (!module_name)
37 		return 0;
38 
39 	printf("***********************************************************\n");
40 	printf("Rockchip Board Module [%s] Test start.\n", module_name);
41 	printf("***********************************************************\n");
42 
43 	for (index = 0; index < ARRAY_SIZE(g_board_modules); index++) {
44 		module = &g_board_modules[index];
45 		if (module && !strcmp(module->name, module_name)) {
46 			ms_start = get_timer(0);
47 
48 			err = module->test(argc, argv);
49 
50 			ms = get_timer(ms_start);
51 			if (ms >= 1000) {
52 				sec = ms / 1000;
53 				ms = ms % 1000;
54 			}
55 		}
56 	}
57 
58 	printf("-----------------------------------------------------------\n");
59 	printf("Rockchip Board Module [%s] Test end <%s>.. Total: %lu.%lus\n",
60 	       module->name, err ? "FAILED" : "PASS", sec, ms);
61 	printf("-----------------------------------------------------------\n\n\n");
62 
63 	return 0;
64 }
65 
66 U_BOOT_CMD(
67 	rktest, 10, 0, do_rockchip_test,
68 	"Rockchip Board Module Test",
69 	""
70 );
71