1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "auto_test.h"
#include "rtconfig.h"
#define MAX_TESTS 100
typedef int (*TestFunc)(void);
typedef struct {
const char* name;
TestFunc func;
rt_err_t passed;
} TestCase;
TestCase test_cases[MAX_TESTS];
int test_count = 0;
// 注册测试用例
void register_test(const char* name, TestFunc func) {
if (test_count < MAX_TESTS) {
test_cases[test_count].name = name;
test_cases[test_count].func = func;
test_cases[test_count].passed = 0;
test_count++;
} else {
rt_kprintf("Exceeded the maximum number of test cases(%d)\n", MAX_TESTS);
}
}
// 运行所有测试
void run_all_tests() {
int passed_count = 0;
rt_kprintf("Run tests...\n");
for (int i = 0; i < test_count; i++) {
rt_err_t result = test_cases[i].func();
test_cases[i].passed = result;
if (result == RT_EOK) {
rt_kprintf("[PASS] %s\n", test_cases[i].name);
passed_count++;
} else {
rt_kprintf("[FAIL] %s %d\n", test_cases[i].name, result);
}
}
#if defined(TARGET_ARMV8_AARCH64)
rt_kprintf("\n%s aarch64 test results: \n", BOARD_NAME);
#else
rt_kprintf("\n%s aarch32 test results: \n", BOARD_NAME);
#endif
rt_kprintf("PASS: %d / %d\n", passed_count, test_count);
if (passed_count < test_count)
{
rt_kprintf("[test_failure] example:\n");
for (int i = 0; i < test_count; i++) {
if (test_cases[i].passed != RT_EOK) {
rt_kprintf(" - %s\n", test_cases[i].name);
}
}
}
else
{
rt_kprintf("[test_success]\n");
}
rt_kprintf("[rtthread_test_end]\n");
}
int auto_test() {
#if defined BSP_USING_CAN
register_test("can_loopback_sample", can_loopback_sample);
#endif
#if defined BSP_USING_SPI
register_test("spi_sample", fspim_test_sample);
#endif
#if defined BSP_USING_GPIO
register_test("gpio_sample", gpio_toggle_sample);
#endif
#if defined(BSP_USING_I2C) || defined(BSP_USING_I2C_MSG)
register_test("i2c_sample", i2c_sample);
#endif
#if defined BSP_USING_QSPI
#if !defined(TARGET_PD2408)
register_test("qspi_sample", qspi_sample);
#endif
#endif
// 运行测试
run_all_tests();
return 0;
}
|