From 10764b034e8af16bb0f75cd0b12eaf36b5faf952 Mon Sep 17 00:00:00 2001 From: tengshuangshuang Date: Mon, 23 Dec 2024 19:25:53 +0800 Subject: [PATCH 1/3] test:driver_audio bug fix Signed-off-by: tengshuangshuang --- examples/camera/camera_main.c | 2 +- testing/drivertest/drivertest_audio.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/camera/camera_main.c b/examples/camera/camera_main.c index 221fa4c4b8b..43f1fff9d52 100644 --- a/examples/camera/camera_main.c +++ b/examples/camera/camera_main.c @@ -680,7 +680,7 @@ int main(int argc, FAR char *argv[]) { gettimeofday(&now, NULL); timersub(&now, &start, &delta); - if (timercmp(&delta, &wait, >)) + if (timercmp(&delta, &wait, > /* For checkpatch */)) { printf("Expire time is pasted. GoTo next state.\n"); if (app_state == APP_STATE_BEFORE_CAPTURE) diff --git a/testing/drivertest/drivertest_audio.c b/testing/drivertest/drivertest_audio.c index 2f019fcdd32..5ce08329f15 100644 --- a/testing/drivertest/drivertest_audio.c +++ b/testing/drivertest/drivertest_audio.c @@ -481,7 +481,7 @@ static bool audio_test_timeout(FAR struct audio_state_s *state, gettimeofday(&now, NULL); timersub(&now, &start, &delta); - return timercmp(&delta, &wait, >); + return timercmp(&delta, &wait, > /* For checkpatch */); } static int audio_test_stop(FAR struct audio_state_s *state, int direction) @@ -741,8 +741,8 @@ static int audio_test_setup(FAR void **audio_state) attr.mq_curmsgs = 0; attr.mq_flags = 0; - snprintf(state->mqname, sizeof(state->mqname), "/tmp/%0lx", - (unsigned long)((uintptr_t)state)); + snprintf(state->mqname, sizeof(state->mqname), "/tmp/%p", + ((void *)state)); state->mq = mq_open(state->mqname, O_RDWR | O_CREAT, 0644, &attr); assert_false(state->mq < 0); From f22727ac1ecb9f80219de146a885fd4c8b89e139 Mon Sep 17 00:00:00 2001 From: zhangshoukui Date: Thu, 16 Jan 2025 16:29:25 +0800 Subject: [PATCH 2/3] Remove Useless filtering.The string for filtering rules should not point to a stack space ==1805058==ERROR: AddressSanitizer: heap-use-after-free on address 0xe18126a0 at pc 0x52b06320 bp 0xd7b13ee8 sp 0xd7b13ed8 READ of size 1 at 0xe18126a0 thread T0 #0 0x52b0631f in tre_parse regex/regcomp.c:1356 #1 0x52b2b1d0 in regcomp regex/regcomp.c:3710 #2 0x48f55435 in c_regexmatch cmocka/src/cmocka.c:494 #3 0x48f65bcf in _cmocka_run_group_tests cmocka/src/cmocka.c:3252 #4 0x48f67e2d in cmocka_fs_test_main apps/testing/testsuites/kernel/fs/cmocka_fs_test.c:201 #5 0x46210b2a in nxtask_startup sched/task_startup.c:72 #6 0x45ff40fb in nxtask_start task/task_start.c:116 #7 0x462695bb in pre_start sim/sim_initialstate.c:52 Signed-off-by: zhangshoukui --- testing/drivertest/drivertest_framebuffer.c | 5 ----- testing/drivertest/drivertest_lcd.c | 5 ----- 2 files changed, 10 deletions(-) diff --git a/testing/drivertest/drivertest_framebuffer.c b/testing/drivertest/drivertest_framebuffer.c index 03edb568033..2d84567eb26 100644 --- a/testing/drivertest/drivertest_framebuffer.c +++ b/testing/drivertest/drivertest_framebuffer.c @@ -532,7 +532,6 @@ int main(int argc, FAR char *argv[]) /* Initialize the state data */ struct fb_state_s fb_state; - char test_filter[64]; memset(&fb_state, 0, sizeof(struct fb_state_s)); snprintf(fb_state.devpath, sizeof(fb_state.devpath), "%s", @@ -552,9 +551,5 @@ int main(int argc, FAR char *argv[]) fb_teardown, &fb_state), }; - snprintf(test_filter, sizeof(test_filter), "test_case_fb_%d", - fb_state.test_case_id); - cmocka_set_test_filter(test_filter); - return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/testing/drivertest/drivertest_lcd.c b/testing/drivertest/drivertest_lcd.c index 22195b8bfb3..39530f79e20 100644 --- a/testing/drivertest/drivertest_lcd.c +++ b/testing/drivertest/drivertest_lcd.c @@ -418,7 +418,6 @@ int main(int argc, FAR char *argv[]) /* Initialize the state data */ struct lcd_state_s lcd_state; - char test_filter[64]; memset(&lcd_state, 0, sizeof(struct lcd_state_s)); snprintf(lcd_state.devpath, sizeof(lcd_state.devpath), "%s", @@ -438,9 +437,5 @@ int main(int argc, FAR char *argv[]) lcd_teardown, &lcd_state), }; - snprintf(test_filter, sizeof(test_filter), "test_case_lcd_%d", - lcd_state.test_case_id); - cmocka_set_test_filter(test_filter); - return cmocka_run_group_tests(tests, NULL, NULL); } From 22eedf29308001f06cde6b844236d8ab109195ac Mon Sep 17 00:00:00 2001 From: zhangshoukui Date: Thu, 16 Jan 2025 16:31:14 +0800 Subject: [PATCH 3/3] optimize GPIO test for sim test pass cmocka_driver_gpio //gpio input/output is tested by default cmocka_driver_gpio -a /dev/gpio0 -b /dev/gpio1 -l // test loop cmocka_driver_gpio -a /dev/gpio0 -b /dev/gpio0 // gpio input/output is tested by default Signed-off-by: zhangshoukui --- testing/drivertest/drivertest_gpio.c | 78 +++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/testing/drivertest/drivertest_gpio.c b/testing/drivertest/drivertest_gpio.c index a84acf20dcf..32a0afd3d48 100644 --- a/testing/drivertest/drivertest_gpio.c +++ b/testing/drivertest/drivertest_gpio.c @@ -49,6 +49,7 @@ struct pre_build_s { FAR char *gpio_a; FAR char *gpio_b; + bool loop; }; /**************************************************************************** @@ -62,10 +63,11 @@ struct pre_build_s static void show_usage(FAR const char *progname, int exitcode) { printf("Usage: %s -a [dev/gpio0] -b" - " [dev/gpio1] \n", progname); + " [dev/gpio1] -l [loop test]\n", progname); printf("Where:\n"); printf(" -a gpio_a location [default location: dev/gpio0].\n"); printf(" -b gpio_b location [default location: dev/gpio1].\n"); + printf(" -l [default: Test the input and output of GPIO ]\n"); exit(exitcode); } @@ -78,7 +80,7 @@ static void parse_commandline(int argc, FAR char **argv, { int option; - while ((option = getopt(argc, argv, "a:b:")) != ERROR) + while ((option = getopt(argc, argv, "a:b:l")) != ERROR) { switch (option) { @@ -88,6 +90,9 @@ static void parse_commandline(int argc, FAR char **argv, case 'b': pre_build->gpio_b = optarg; break; + case 'l': + pre_build->loop = true; + break; case '?': printf("Unknown option: %c\n", optopt); show_usage(argv[0], EXIT_FAILURE); @@ -133,10 +138,55 @@ static int setup(FAR void **state) } /**************************************************************************** - * Name: gpiotest01 + * Name: drivertest_gpio_one + ****************************************************************************/ + +static void drivertest_gpio_one(FAR void **state) +{ + FAR struct pre_build_s *pre_build; + bool outvalue; + bool invalue; + int fd[2]; + int ret; + int i; + int j; + + pre_build = (FAR struct pre_build_s *)*state; + fd[0] = open(pre_build->gpio_a, O_RDWR); + assert_false(fd[0] < 0); + + fd[1] = open(pre_build->gpio_b, O_RDWR); + assert_false(fd[1] < 0); + + /* Test Single GPIO I/O functionality */ + + for (i = 0; i < 2; i++) + { + ret = ioctl(fd[i], GPIOC_SETPINTYPE, GPIO_INPUT_PIN | GPIO_OUTPUT_PIN); + assert_false(ret < 0); + for (j = 0; j < GPIOTEST_MAXVALUE; j++) + { + outvalue = gpiotest_randbin(); + ret = ioctl(fd[i], GPIOC_WRITE, outvalue); + assert_false(ret < 0); + + ret = ioctl(fd[i], GPIOC_READ, &invalue); + assert_false(ret < 0); + + printf("[input and output test] outvalue is %d, invalue is %d\n", + outvalue, invalue); + assert_int_equal(invalue, outvalue); + } + + close(fd[i]); + } +} + +/**************************************************************************** + * Name: drivertest_gpio_loop ****************************************************************************/ -static void gpiotest01(FAR void **state) +static void drivertest_gpio_loop(FAR void **state) { FAR struct pre_build_s *pre_build; int fd_a; @@ -179,7 +229,7 @@ static void gpiotest01(FAR void **state) ret = ioctl(fd_b, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); assert_false(ret < 0); - printf("[__Verify__] outvalue is %d, invalue is %d\n", + printf("[Loop test] outvalue is %d, invalue is %d\n", outvalue, invalue); assert_int_equal(invalue, outvalue); } @@ -205,7 +255,7 @@ static void gpiotest01(FAR void **state) ret = ioctl(fd_a, GPIOC_READ, (unsigned long)((uintptr_t)&invalue)); assert_false(ret < 0); - printf("[__Verify__] outvalue is %d, invalue is %d\n", + printf("[Loop test] outvalue is %d, invalue is %d\n", outvalue, invalue); assert_int_equal(invalue, outvalue); } @@ -233,16 +283,28 @@ static int teardown(FAR void **state) int main(int argc, FAR char *argv[]) { + void (*drivertest_gpio)(FAR void **state); FAR struct pre_build_s pre_build = { .gpio_a = "dev/gpio0", - .gpio_b = "dev/gpio1" + .gpio_b = "dev/gpio1", + .loop = false }; parse_commandline(argc, argv, &pre_build); + + if (pre_build.loop) + { + drivertest_gpio = drivertest_gpio_loop; + } + else + { + drivertest_gpio = drivertest_gpio_one; + } + const struct CMUnitTest tests[] = { - cmocka_unit_test_prestate_setup_teardown(gpiotest01, setup, + cmocka_unit_test_prestate_setup_teardown(drivertest_gpio, setup, teardown, &pre_build), };