xref: /rk3399_rockchip-uboot/test/rockchip/test-rockchip.c (revision ed5ce517739a2041dc32bb2c8aa2437f7889c5ce)
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 	{ .name = "emmc",	.test = board_emmc_test },
20 	{ .name = "regulator",	.test = board_regulator_test },
21 };
22 
23 static int do_rockchip_test(cmd_tbl_t *cmdtp, int flag,
24 			    int argc, char * const argv[])
25 {
26 	ulong ms_start = 0, ms = 0, sec = 0;
27 	board_module_t *module = NULL;
28 	char *module_name = NULL;
29 	int index = 0, err = 0;
30 
31 	if (argc >= 2) {
32 		module_name = argv[1];
33 	} else {
34 		printf("cmd format: test_rockchip [module_name] [args...]\n");
35 		return 0;
36 	}
37 
38 	if (!module_name)
39 		return 0;
40 
41 	printf("***********************************************************\n");
42 	printf("Rockchip Board Module [%s] Test start.\n", module_name);
43 	printf("***********************************************************\n");
44 
45 	for (index = 0; index < ARRAY_SIZE(g_board_modules); index++) {
46 		module = &g_board_modules[index];
47 		if (module && !strcmp(module->name, module_name)) {
48 			ms_start = get_timer(0);
49 
50 			err = module->test(argc, argv);
51 
52 			ms = get_timer(ms_start);
53 			if (ms >= 1000) {
54 				sec = ms / 1000;
55 				ms = ms % 1000;
56 			}
57 		}
58 	}
59 
60 	printf("-----------------------------------------------------------\n");
61 	printf("Rockchip Board Module [%s] Test end <%s>.. Total: %lu.%lus\n",
62 	       module->name, err ? "FAILED" : "PASS", sec, ms);
63 	printf("-----------------------------------------------------------\n\n\n");
64 
65 	return 0;
66 }
67 
68 U_BOOT_CMD(
69 	rktest, 10, 0, do_rockchip_test,
70 	"Rockchip Board Module Test",
71 	""
72 );
73