From: Bartosz Golaszewski Date: Thu, 22 Feb 2018 20:21:56 +0000 (+0100) Subject: tests: add a new cleanup macro X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=5c5a4ca9b3b58495aa3578235ad94bab22f3c602;p=qemu-gpiodev%2Flibgpiod.git tests: add a new cleanup macro The most commonly used cleanup attribute is the one used for automatic closing of GPIO chips. For brevity: hide the long TEST_CLEANUP(...) invocation behind a shorter TEST_CLEANUP_CHIP macro. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/gpiod-test.h b/tests/gpiod-test.h index b8f13c1..49b39f4 100644 --- a/tests/gpiod-test.h +++ b/tests/gpiod-test.h @@ -132,6 +132,8 @@ void test_free_chip_iter(struct gpiod_chip_iter **iter); void test_free_chip_iter_noclose(struct gpiod_chip_iter **iter); void test_free_line_iter(struct gpiod_line_iter **iter); +#define TEST_CLEANUP_CHIP TEST_CLEANUP(test_close_chip) + bool test_regex_match(const char *str, const char *pattern); /* diff --git a/tests/tests-chip.c b/tests/tests-chip.c index 3fa1cbd..e3112c6 100644 --- a/tests/tests-chip.c +++ b/tests/tests-chip.c @@ -18,7 +18,7 @@ static void chip_open_good(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -53,7 +53,7 @@ TEST_DEFINE(chip_open_notty, static void chip_open_by_name_good(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; chip = gpiod_chip_open_by_name(test_chip_name(0)); TEST_ASSERT_NOT_NULL(chip); @@ -64,7 +64,7 @@ TEST_DEFINE(chip_open_by_name_good, static void chip_open_by_number_good(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; chip = gpiod_chip_open_by_number(test_chip_num(0)); TEST_ASSERT_NOT_NULL(chip); @@ -75,10 +75,10 @@ TEST_DEFINE(chip_open_by_number_good, static void chip_open_lookup(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip_by_label = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip_by_name = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip_by_path = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip_by_num = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip_by_label = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip_by_name = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip_by_path = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip_by_num = NULL; chip_by_name = gpiod_chip_open_lookup(test_chip_name(1)); chip_by_path = gpiod_chip_open_lookup(test_chip_path(1)); @@ -102,7 +102,7 @@ TEST_DEFINE(chip_open_lookup, static void chip_open_by_label_good(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; chip = gpiod_chip_open_by_label("gpio-mockup-D"); TEST_ASSERT_NOT_NULL(chip); @@ -114,7 +114,7 @@ TEST_DEFINE(chip_open_by_label_good, static void chip_open_by_label_bad(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; chip = gpiod_chip_open_by_label("nonexistent_gpio_chip"); TEST_ASSERT_NULL(chip); @@ -126,9 +126,9 @@ TEST_DEFINE(chip_open_by_label_bad, static void chip_name(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip0 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip1 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip2 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip0 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip1 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip2 = NULL; chip0 = gpiod_chip_open(test_chip_path(0)); chip1 = gpiod_chip_open(test_chip_path(1)); @@ -147,9 +147,9 @@ TEST_DEFINE(chip_name, static void chip_label(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip0 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip1 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip2 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip0 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip1 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip2 = NULL; chip0 = gpiod_chip_open(test_chip_path(0)); chip1 = gpiod_chip_open(test_chip_path(1)); @@ -168,11 +168,11 @@ TEST_DEFINE(chip_label, static void chip_num_lines(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip0 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip1 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip2 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip3 = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip4 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip0 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip1 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip2 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip3 = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip4 = NULL; chip0 = gpiod_chip_open(test_chip_path(0)); chip1 = gpiod_chip_open(test_chip_path(1)); @@ -197,7 +197,7 @@ TEST_DEFINE(chip_num_lines, static void chip_get_lines(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_bulk bulk; unsigned int offsets[4]; struct gpiod_line *line; @@ -230,7 +230,7 @@ TEST_DEFINE(chip_get_lines, static void chip_get_all_lines(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_bulk bulk; struct gpiod_line *line; int rv; @@ -257,7 +257,7 @@ TEST_DEFINE(chip_get_all_lines, static void chip_find_line_good(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; chip = gpiod_chip_open(test_chip_path(1)); @@ -274,7 +274,7 @@ TEST_DEFINE(chip_find_line_good, static void chip_find_line_not_found(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; chip = gpiod_chip_open(test_chip_path(1)); diff --git a/tests/tests-event.c b/tests/tests-event.c index 45d5c4e..748c550 100644 --- a/tests/tests-event.c +++ b/tests/tests-event.c @@ -17,7 +17,7 @@ static void event_rising_edge_good(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; @@ -48,7 +48,7 @@ TEST_DEFINE(event_rising_edge_good, static void event_falling_edge_good(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; @@ -79,7 +79,7 @@ TEST_DEFINE(event_falling_edge_good, static void event_rising_edge_ignore_falling(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct timespec ts = { 0, 300 }; struct gpiod_line *line; int rv; @@ -104,7 +104,7 @@ TEST_DEFINE(event_rising_edge_ignore_falling, static void event_rising_edge_active_low(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; @@ -136,7 +136,7 @@ TEST_DEFINE(event_rising_edge_active_low, static void event_get_value(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; @@ -173,7 +173,7 @@ TEST_DEFINE(event_get_value, static void event_get_value_active_low(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct timespec ts = { 1, 0 }; struct gpiod_line_event ev; struct gpiod_line *line; @@ -211,7 +211,7 @@ TEST_DEFINE(event_get_value_active_low, static void event_wait_multiple(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_bulk bulk, event_bulk; struct timespec ts = { 1, 0 }; struct gpiod_line *line; @@ -247,7 +247,7 @@ TEST_DEFINE(event_wait_multiple, static void event_get_fd_when_values_requested(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int rv, fd; @@ -270,7 +270,7 @@ TEST_DEFINE(event_get_fd_when_values_requested, static void event_request_bulk_fail(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_bulk bulk = GPIOD_LINE_BULK_INITIALIZER; struct gpiod_line *line; int rv, i; diff --git a/tests/tests-gpioinfo.c b/tests/tests-gpioinfo.c index 2037569..1529f18 100644 --- a/tests/tests-gpioinfo.c +++ b/tests/tests-gpioinfo.c @@ -40,7 +40,7 @@ TEST_DEFINE(gpioinfo_dump_all_chips, static void gpioinfo_dump_all_chips_one_exported(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int rv; diff --git a/tests/tests-iter.c b/tests/tests-iter.c index ffc67d2..a905e6b 100644 --- a/tests/tests-iter.c +++ b/tests/tests-iter.c @@ -45,9 +45,9 @@ static void chip_iter_noclose(void) { TEST_CLEANUP(test_free_chip_iter_noclose) struct gpiod_chip_iter *iter = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipA = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipB = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipC = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipA = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipB = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipC = NULL; struct gpiod_chip *chip; bool A, B, C; @@ -118,7 +118,7 @@ TEST_DEFINE(chip_iter_break, static void line_iter(void) { TEST_CLEANUP(test_free_line_iter) struct gpiod_line_iter *iter = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; unsigned int i = 0; diff --git a/tests/tests-line.c b/tests/tests-line.c index bae3451..b9e6ec3 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -17,7 +17,7 @@ static void line_request_output(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line_0; struct gpiod_line *line_1; int status; @@ -44,7 +44,7 @@ TEST_DEFINE(line_request_output, static void line_request_already_requested(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int status; @@ -67,7 +67,7 @@ TEST_DEFINE(line_request_already_requested, static void line_consumer(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int status; @@ -91,7 +91,7 @@ TEST_DEFINE(line_consumer, static void line_consumer_long_string(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int status; @@ -118,8 +118,8 @@ TEST_DEFINE(line_consumer_long_string, static void line_request_bulk_output(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipA = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipB = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipA = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipB = NULL; struct gpiod_line_bulk bulkB = GPIOD_LINE_BULK_INITIALIZER; struct gpiod_line_bulk bulkA; struct gpiod_line *lineA0; @@ -204,8 +204,8 @@ TEST_DEFINE(line_request_bulk_output, static void line_request_bulk_different_chips(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipA = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipB = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipA = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipB = NULL; struct gpiod_line_request_config req; struct gpiod_line_bulk bulk; struct gpiod_line *lineA0; @@ -249,7 +249,7 @@ TEST_DEFINE(line_request_bulk_different_chips, static void line_request_null_default_vals_for_output(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_bulk bulk = GPIOD_LINE_BULK_INITIALIZER; struct gpiod_line *line; int rv, vals[3]; @@ -287,7 +287,7 @@ TEST_DEFINE(line_request_null_default_vals_for_output, static void line_set_value(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int status; @@ -311,8 +311,8 @@ TEST_DEFINE(line_set_value, static void line_get_value_different_chips(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipA = NULL; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chipB = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipA = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chipB = NULL; struct gpiod_line *lineA1, *lineA2, *lineB1, *lineB2; struct gpiod_line_bulk bulkA, bulkB, bulk; int rv, vals[4]; @@ -427,7 +427,7 @@ TEST_DEFINE(line_find_unnamed_lines, static void line_direction(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int status; @@ -455,7 +455,7 @@ TEST_DEFINE(line_direction, static void line_active_state(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int status; @@ -485,7 +485,7 @@ TEST_DEFINE(line_active_state, static void line_misc_flags(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_request_config config; struct gpiod_line *line; int status; @@ -528,7 +528,7 @@ TEST_DEFINE(line_misc_flags, static void line_open_source_open_drain_input_invalid(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int rv; @@ -554,7 +554,7 @@ TEST_DEFINE(line_open_source_open_drain_input_invalid, static void line_open_source_open_drain_simultaneously(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; int rv; @@ -576,7 +576,7 @@ TEST_DEFINE(line_open_source_open_drain_simultaneously, static void line_null_consumer(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_request_config config; struct gpiod_line *line; int rv; @@ -613,7 +613,7 @@ TEST_DEFINE(line_null_consumer, static void line_empty_consumer(void) { - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_request_config config; struct gpiod_line *line; int rv; @@ -655,7 +655,7 @@ static void line_bulk_foreach(void) "gpio-mockup-A-2", "gpio-mockup-A-3" }; - TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_bulk bulk = GPIOD_LINE_BULK_INITIALIZER; struct gpiod_line *line, **lineptr; int i;