tests: add a new cleanup macro
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 22 Feb 2018 20:21:56 +0000 (21:21 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 22 Feb 2018 20:21:56 +0000 (21:21 +0100)
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 <bartekgola@gmail.com>
tests/gpiod-test.h
tests/tests-chip.c
tests/tests-event.c
tests/tests-gpioinfo.c
tests/tests-iter.c
tests/tests-line.c

index b8f13c1cf81c23dc4a1999fed9631f9cd2aeb026..49b39f4e1c3749c1b6f5cc79796e7ad09dd78a0d 100644 (file)
@@ -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);
 
 /*
index 3fa1cbd4092be34512a6855961a8518357f162e1..e3112c69298ca8d22f72decaf629835e8af0d169 100644 (file)
@@ -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));
index 45d5c4e747114127b20852f069c46aa422e117e7..748c550ea4bb649baa09f767fcd04c988f6b10a8 100644 (file)
@@ -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;
index 2037569e3a5893fb296da97d2a6d47db298bf6b4..1529f181ca62ccf118017886baae14cca5d1fee9 100644 (file)
@@ -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;
 
index ffc67d235175e71503643c7dd26a6b0c3d7c4f5d..a905e6b68ec842e3afa4a515027162e6adb5c481 100644 (file)
@@ -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;
 
index bae3451801a22cc4e8acc7e2992fc9e0883a2f38..b9e6ec3ad3e9f9a6a9e241d8b567008702c82585 100644 (file)
@@ -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;