mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
drivertest_uart: Pass in the specified parameters to test
https://github.com/apache/nuttx/blob/master/tools/ci/testrun/script/test_framework/test_cmocka.py cmocka --skip test_case_posix_timer|test_case_oneshot|write_default|read_default|burst_test|gpiotest01 In the CI of the community, this test is skipped because this test will block the terminal, and I think that the test added to cmocka should not be designed this way Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
This commit is contained in:
parent
83eba58232
commit
7b65b2bb41
1 changed files with 33 additions and 13 deletions
|
|
@ -64,6 +64,7 @@
|
|||
struct test_confs_s
|
||||
{
|
||||
FAR const char *dev_path;
|
||||
int test_case_id;
|
||||
};
|
||||
|
||||
struct test_state_s
|
||||
|
|
@ -199,10 +200,10 @@ static int teardown(FAR void **state)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: write_default
|
||||
* Name: drivertest_uart_write
|
||||
****************************************************************************/
|
||||
|
||||
static void write_default(FAR void **state)
|
||||
static void drivertest_uart_write(FAR void **state)
|
||||
{
|
||||
FAR struct test_state_s *test_state = (FAR struct test_state_s *)*state;
|
||||
int res = write(test_state->fd,
|
||||
|
|
@ -213,10 +214,10 @@ static void write_default(FAR void **state)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: read_default
|
||||
* Name: drivertest_uart_read
|
||||
****************************************************************************/
|
||||
|
||||
static void read_default(FAR void **state)
|
||||
static void drivertest_uart_read(FAR void **state)
|
||||
{
|
||||
FAR struct test_state_s *test_state = (FAR struct test_state_s *)*state;
|
||||
size_t buffer_size = sizeof(DEFAULT_CONTENT);
|
||||
|
|
@ -245,10 +246,10 @@ static void read_default(FAR void **state)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: burst_test
|
||||
* Name: drivertest_uart_burst
|
||||
****************************************************************************/
|
||||
|
||||
static void burst_test(FAR void **state)
|
||||
static void drivertest_uart_burst(FAR void **state)
|
||||
{
|
||||
FAR struct test_state_s *test_state = (FAR struct test_state_s *)*state;
|
||||
int res = 0;
|
||||
|
|
@ -303,6 +304,12 @@ static void show_usage(FAR const char *progname, int exitcode)
|
|||
printf("Where:\n");
|
||||
printf(" -d <dev path> uart device path "
|
||||
"[default device: /dev/console].\n");
|
||||
printf(" -n <test_case_id> selects the testcase to uart.\n"
|
||||
"[default test: drivertest_uart_write].\n"
|
||||
" Case 0: drivertest_uart_write test\n"
|
||||
" Case 1: drivertest_uart_read test\n"
|
||||
" Case 2: drivertest_uart_burst test\n"
|
||||
);
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
|
|
@ -315,13 +322,16 @@ static void parse_args(int argc, FAR char **argv,
|
|||
{
|
||||
int option;
|
||||
|
||||
while ((option = getopt(argc, argv, "d:")) != ERROR)
|
||||
while ((option = getopt(argc, argv, "d:n:")) != ERROR)
|
||||
{
|
||||
switch (option)
|
||||
{
|
||||
case 'd':
|
||||
conf->dev_path = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
conf->test_case_id = atoi(optarg);
|
||||
break;
|
||||
case '?':
|
||||
printf("Unknown option: %c\n", optopt);
|
||||
show_usage(argv[0], EXIT_FAILURE);
|
||||
|
|
@ -340,20 +350,30 @@ static void parse_args(int argc, FAR char **argv,
|
|||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
void (*drivertest_uart)(FAR void **state) = NULL;
|
||||
struct test_confs_s confs =
|
||||
{
|
||||
.dev_path = CONFIG_TESTING_DRIVER_TEST_UART_DEVICE
|
||||
.dev_path = CONFIG_TESTING_DRIVER_TEST_UART_DEVICE,
|
||||
.test_case_id = 0
|
||||
};
|
||||
|
||||
parse_args(argc, argv, &confs);
|
||||
switch (confs.test_case_id)
|
||||
{
|
||||
case 1:
|
||||
drivertest_uart = drivertest_uart_read;
|
||||
break;
|
||||
case 2:
|
||||
drivertest_uart = drivertest_uart_burst;
|
||||
break;
|
||||
default:
|
||||
drivertest_uart = drivertest_uart_write;
|
||||
break;
|
||||
}
|
||||
|
||||
const struct CMUnitTest tests[] =
|
||||
{
|
||||
cmocka_unit_test_prestate_setup_teardown(write_default, setup,
|
||||
teardown, &confs),
|
||||
cmocka_unit_test_prestate_setup_teardown(read_default, setup,
|
||||
teardown, &confs),
|
||||
cmocka_unit_test_prestate_setup_teardown(burst_test, setup,
|
||||
cmocka_unit_test_prestate_setup_teardown(drivertest_uart, setup,
|
||||
teardown, &confs),
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue