Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver test issue fix #2951

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/camera/camera_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions testing/drivertest/drivertest_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions testing/drivertest/drivertest_framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
}
78 changes: 70 additions & 8 deletions testing/drivertest/drivertest_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct pre_build_s
{
FAR char *gpio_a;
FAR char *gpio_b;
bool loop;
};

/****************************************************************************
Expand All @@ -62,10 +63,11 @@ struct pre_build_s
static void show_usage(FAR const char *progname, int exitcode)
{
printf("Usage: %s -a <gpio_a>[dev/gpio0] -b"
" <gpio_b>[dev/gpio1] \n", progname);
" <gpio_b>[dev/gpio1] -l [loop test]\n", progname);
printf("Where:\n");
printf(" -a <gpio_a> gpio_a location [default location: dev/gpio0].\n");
printf(" -b <gpio_b> gpio_b location [default location: dev/gpio1].\n");
printf(" -l <loop test> [default: Test the input and output of GPIO ]\n");
exit(exitcode);
}

Expand All @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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),
};

Expand Down
5 changes: 0 additions & 5 deletions testing/drivertest/drivertest_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
}
Loading