From: Bartosz Golaszewski Date: Sun, 14 May 2017 14:49:47 +0000 (+0200) Subject: tests: convert named_lines into a general 'flags' field X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=96a17a050132889f4dcbd2f759d9ffcb4fad96f1;p=qemu-gpiodev%2Flibgpiod.git tests: convert named_lines into a general 'flags' field We currently have the boolean 'named_lines' field in the test description structure. Convert it to an integer in order to allow passing multiple test switches in the future. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 60e9b66..11330c4 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -380,7 +380,7 @@ static void load_module(struct _test_chip_descr *descr) modarg = xappend(modarg, "-1,%u,", descr->num_lines[i]); modarg[strlen(modarg) - 1] = '\0'; /* Remove the last comma. */ - if (descr->named_lines) + if (descr->flags & TEST_FLAG_NAMED_LINES) modarg = xappend(modarg, " gpio_mockup_named_lines"); status = kmod_module_probe_insert_module(globals.module, 0, diff --git a/tests/gpiod-test.h b/tests/gpiod-test.h index d4404b8..ad6d3b7 100644 --- a/tests/gpiod-test.h +++ b/tests/gpiod-test.h @@ -20,6 +20,7 @@ #define TEST_UNUSED __attribute__((unused)) #define TEST_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg))) #define TEST_CLEANUP(func) __attribute__((cleanup(func))) +#define TEST_BIT(nr) (1UL << (nr)) #define TEST_ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) @@ -28,7 +29,7 @@ typedef void (*_test_func)(void); struct _test_chip_descr { unsigned int num_chips; unsigned int *num_lines; - bool named_lines; + int flags; }; struct _test_case { @@ -43,6 +44,10 @@ struct _test_case { void _test_register(struct _test_case *test); void _test_print_failed(const char *fmt, ...) TEST_PRINTF(1, 2); +enum { + TEST_FLAG_NAMED_LINES = TEST_BIT(0), +}; + /* * This macro should be used for code brevity instead of manually declaring * the _test_case structure. @@ -50,13 +55,13 @@ void _test_print_failed(const char *fmt, ...) TEST_PRINTF(1, 2); * The macro accepts the following arguments: * _a_func: name of the test function * _a_name: name of the test case (will be shown to user) - * _a_named_lines: indicate whether we want the GPIO lines to be named + * _a_flags: various switches for the test case * * The last argument must be an array of unsigned integers specifying the * number of GPIO lines in each subsequent mockup chip. The size of this * array will at the same time specify the number of gpiochips to create. */ -#define TEST_DEFINE(_a_func, _a_name, _a_named_lines, ...) \ +#define TEST_DEFINE(_a_func, _a_name, _a_flags, ...) \ static unsigned int _##_a_func##_lines[] = __VA_ARGS__; \ static struct _test_case _##_a_func##_descr = { \ .name = _a_name, \ @@ -65,7 +70,7 @@ void _test_print_failed(const char *fmt, ...) TEST_PRINTF(1, 2); .num_chips = TEST_ARRAY_SIZE( \ _##_a_func##_lines), \ .num_lines = _##_a_func##_lines, \ - .named_lines = _a_named_lines, \ + .flags = _a_flags, \ }, \ }; \ static TEST_INIT void _test_register_##_a_func##_test(void) \ @@ -74,11 +79,6 @@ void _test_print_failed(const char *fmt, ...) TEST_PRINTF(1, 2); } \ static int _test_##_a_func##_sentinel TEST_UNUSED -enum { - TEST_LINES_UNNAMED = false, - TEST_LINES_NAMED = true, -}; - /* * We want libgpiod tests to co-exist with gpiochips created by other GPIO * drivers. For that reason we can't just use hardcoded device file paths or diff --git a/tests/tests-chip.c b/tests/tests-chip.c index a30b4a8..ef905ca 100644 --- a/tests/tests-chip.c +++ b/tests/tests-chip.c @@ -22,7 +22,7 @@ static void chip_open_good(void) } TEST_DEFINE(chip_open_good, "gpiod_chip_open() - good", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void chip_open_nonexistent(void) { @@ -34,7 +34,7 @@ static void chip_open_nonexistent(void) } TEST_DEFINE(chip_open_nonexistent, "gpiod_chip_open() - nonexistent chip", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void chip_open_notty(void) { @@ -46,7 +46,7 @@ static void chip_open_notty(void) } TEST_DEFINE(chip_open_notty, "gpiod_chip_open() - notty", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void chip_open_by_name_good(void) { @@ -57,7 +57,7 @@ static void chip_open_by_name_good(void) } TEST_DEFINE(chip_open_by_name_good, "gpiod_chip_open_by_name() - good", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void chip_open_by_number_good(void) { @@ -68,7 +68,7 @@ static void chip_open_by_number_good(void) } TEST_DEFINE(chip_open_by_number_good, "gpiod_chip_open_by_number() - good", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void chip_open_lookup(void) { @@ -97,7 +97,7 @@ static void chip_open_lookup(void) } TEST_DEFINE(chip_open_lookup, "gpiod_chip_open_lookup() - good", - TEST_LINES_UNNAMED, { 8, 8, 8 }); + 0, { 8, 8, 8 }); static void chip_open_by_label_good(void) { @@ -109,7 +109,7 @@ static void chip_open_by_label_good(void) } TEST_DEFINE(chip_open_by_label_good, "gpiod_chip_open_by_label() - good", - TEST_LINES_UNNAMED, { 4, 4, 4, 4, 4 }); + 0, { 4, 4, 4, 4, 4 }); static void chip_open_by_label_bad(void) { @@ -120,7 +120,7 @@ static void chip_open_by_label_bad(void) } TEST_DEFINE(chip_open_by_label_bad, "gpiod_chip_open_by_label() - bad", - TEST_LINES_UNNAMED, { 4, 4, 4, 4, 4 }); + 0, { 4, 4, 4, 4, 4 }); static void chip_name(void) { @@ -141,7 +141,7 @@ static void chip_name(void) } TEST_DEFINE(chip_name, "gpiod_chip_name()", - TEST_LINES_UNNAMED, { 8, 8, 8 }); + 0, { 8, 8, 8 }); static void chip_label(void) { @@ -162,7 +162,7 @@ static void chip_label(void) } TEST_DEFINE(chip_label, "gpiod_chip_label()", - TEST_LINES_UNNAMED, { 8, 8, 8 }); + 0, { 8, 8, 8 }); static void chip_num_lines(void) { @@ -191,4 +191,4 @@ static void chip_num_lines(void) } TEST_DEFINE(chip_num_lines, "gpiod_chip_num_lines()", - TEST_LINES_UNNAMED, { 1, 4, 8, 16, 32 }); + 0, { 1, 4, 8, 16, 32 }); diff --git a/tests/tests-event.c b/tests/tests-event.c index 7231866..532b00e 100644 --- a/tests/tests-event.c +++ b/tests/tests-event.c @@ -39,7 +39,7 @@ static void event_rising_edge_good(void) } TEST_DEFINE(event_rising_edge_good, "events - receive single rising edge event", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void event_falling_edge_good(void) { @@ -70,7 +70,7 @@ static void event_falling_edge_good(void) } TEST_DEFINE(event_falling_edge_good, "events - receive single falling edge event", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void event_rising_edge_ignore_falling(void) { @@ -95,7 +95,7 @@ static void event_rising_edge_ignore_falling(void) } TEST_DEFINE(event_rising_edge_ignore_falling, "events - request rising edge & ignore falling edge events", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void event_rising_edge_active_low(void) { @@ -126,7 +126,7 @@ static void event_rising_edge_active_low(void) } TEST_DEFINE(event_rising_edge_active_low, "events - single rising edge event with low active state", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void event_get_value(void) { @@ -163,4 +163,4 @@ static void event_get_value(void) } TEST_DEFINE(event_get_value, "events - mixing events and gpiod_line_get_value()", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); diff --git a/tests/tests-iter.c b/tests/tests-iter.c index fd8fdbb..b4f49ba 100644 --- a/tests/tests-iter.c +++ b/tests/tests-iter.c @@ -38,7 +38,7 @@ static void chip_iter(void) } TEST_DEFINE(chip_iter, "gpiod_chip_iter - simple loop", - TEST_LINES_UNNAMED, { 8, 8, 8 }); + 0, { 8, 8, 8 }); static void chip_iter_noclose(void) { @@ -86,7 +86,7 @@ static void chip_iter_noclose(void) } TEST_DEFINE(chip_iter_noclose, "gpiod_chip_iter - simple loop, noclose variant", - TEST_LINES_UNNAMED, { 8, 8, 8 }); + 0, { 8, 8, 8 }); static void chip_iter_break(void) { @@ -116,7 +116,7 @@ static void chip_iter_break(void) } TEST_DEFINE(chip_iter_break, "gpiod_chip_iter - break", - TEST_LINES_UNNAMED, { 8, 8, 8, 8, 8 }); + 0, { 8, 8, 8, 8, 8 }); static void line_iter(void) { @@ -140,7 +140,7 @@ static void line_iter(void) } TEST_DEFINE(line_iter, "gpiod_line_iter - simple loop, check offsets", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void line_iter_static_initializer(void) { @@ -165,4 +165,4 @@ static void line_iter_static_initializer(void) } TEST_DEFINE(line_iter_static_initializer, "gpiod_line_iter - simple loop, static initializer", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); diff --git a/tests/tests-line.c b/tests/tests-line.c index e809c73..44031af 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -38,7 +38,7 @@ static void line_request_output(void) } TEST_DEFINE(line_request_output, "gpiod_line_request_output() - good", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void line_request_already_requested(void) { @@ -61,7 +61,7 @@ static void line_request_already_requested(void) } TEST_DEFINE(line_request_already_requested, "gpiod_line_request() - already requested", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void line_consumer(void) { @@ -85,7 +85,7 @@ static void line_consumer(void) } TEST_DEFINE(line_consumer, "gpiod_line_consumer() - good", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void line_request_bulk_output(void) { @@ -176,7 +176,7 @@ static void line_request_bulk_output(void) } TEST_DEFINE(line_request_bulk_output, "gpiod_line_request_bulk_output() - good", - TEST_LINES_UNNAMED, { 8, 8 }); + 0, { 8, 8 }); static void line_request_bulk_different_chips(void) { @@ -221,7 +221,7 @@ static void line_request_bulk_different_chips(void) } TEST_DEFINE(line_request_bulk_different_chips, "gpiod_line_request_bulk() - different chips", - TEST_LINES_UNNAMED, { 8, 8 }); + 0, { 8, 8 }); static void line_set_value(void) { @@ -247,7 +247,7 @@ static void line_set_value(void) } TEST_DEFINE(line_set_value, "gpiod_line_set_value() - good", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void line_find_by_name_good(void) { @@ -263,7 +263,7 @@ static void line_find_by_name_good(void) } TEST_DEFINE(line_find_by_name_good, "gpiod_line_find_by_name() - good", - TEST_LINES_NAMED, { 16, 16, 32, 16 }); + TEST_FLAG_NAMED_LINES, { 16, 16, 32, 16 }); static void line_direction(void) { @@ -291,7 +291,7 @@ static void line_direction(void) } TEST_DEFINE(line_direction, "gpiod_line_direction() - set & get", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void line_active_state(void) { @@ -319,7 +319,7 @@ static void line_active_state(void) } TEST_DEFINE(line_active_state, "gpiod_line_active_state() - set & get", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void line_misc_flags(void) { @@ -363,4 +363,4 @@ static void line_misc_flags(void) } TEST_DEFINE(line_misc_flags, "gpiod_line - misc flags", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); diff --git a/tests/tests-misc.c b/tests/tests-misc.c index cdbad7a..53204d5 100644 --- a/tests/tests-misc.c +++ b/tests/tests-misc.c @@ -20,7 +20,7 @@ static void version_string(void) } TEST_DEFINE(version_string, "gpiod_version_string()", - TEST_LINES_UNNAMED, { 1 }); + 0, { 1 }); static void error_handling(void) { @@ -39,4 +39,4 @@ static void error_handling(void) } TEST_DEFINE(error_handling, "error handling", - TEST_LINES_UNNAMED, { 1 }); + 0, { 1 }); diff --git a/tests/tests-simple-api.c b/tests/tests-simple-api.c index 04b0424..24f5a8a 100644 --- a/tests/tests-simple-api.c +++ b/tests/tests-simple-api.c @@ -28,7 +28,7 @@ static void simple_set_get_value(void) } TEST_DEFINE(simple_set_get_value, "simple set/get value - single line", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 }); static void simple_set_get_value_multiple(void) { @@ -83,7 +83,7 @@ static void simple_set_get_value_multiple(void) } TEST_DEFINE(simple_set_get_value_multiple, "simple set/get value - multiple lines", - TEST_LINES_UNNAMED, { 16 }); + 0, { 16 }); static void simple_get_value_multiple_max_lines(void) { @@ -99,7 +99,7 @@ static void simple_get_value_multiple_max_lines(void) } TEST_DEFINE(simple_get_value_multiple_max_lines, "gpiod_simple_get_value_multiple() exceed max lines", - TEST_LINES_UNNAMED, { 128 }); + 0, { 128 }); static void simple_set_value_multiple_max_lines(void) { @@ -115,7 +115,7 @@ static void simple_set_value_multiple_max_lines(void) } TEST_DEFINE(simple_set_value_multiple_max_lines, "gpiod_simple_set_value_multiple() exceed max lines", - TEST_LINES_UNNAMED, { 128 }); + 0, { 128 }); struct simple_event_data { bool got_event; @@ -148,4 +148,4 @@ static void simple_event_loop(void) } TEST_DEFINE(simple_event_loop, "gpiod_simple_event_loop() - single event", - TEST_LINES_UNNAMED, { 8 }); + 0, { 8 });