tests: convert named_lines into a general 'flags' field
authorBartosz Golaszewski <bartekgola@gmail.com>
Sun, 14 May 2017 14:49:47 +0000 (16:49 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Sun, 14 May 2017 14:55:27 +0000 (16:55 +0200)
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 <bartekgola@gmail.com>
tests/gpiod-test.c
tests/gpiod-test.h
tests/tests-chip.c
tests/tests-event.c
tests/tests-iter.c
tests/tests-line.c
tests/tests-misc.c
tests/tests-simple-api.c

index 60e9b660e1010b60b830175c093d9ebf73239e9a..11330c4d5866b631632c3dd4518669a5286c34a1 100644 (file)
@@ -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,
index d4404b860ee95b556e7cffc4a624db7f53071b30..ad6d3b786cf549cc7777a1e62269c8b47393fdfa 100644 (file)
@@ -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
index a30b4a86c31eb82f55d2d001a9a27cfa87995d75..ef905ca999ac6100716045ace52ea34433fcf7ac 100644 (file)
@@ -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 });
index 7231866311060164ad66c8b5a0961c904eb8a607..532b00e92d9d937f16224ca4046559db4de241dc 100644 (file)
@@ -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 });
index fd8fdbba6b67da611c731b97ca87de37e21a4645..b4f49ba4a1b843f4ef81c42fbaf0ee1bc3713d82 100644 (file)
@@ -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 });
index e809c7309d1afc6ba94da90d3d37105640c15fda..44031afeb9a7b577c74931bde7eef3f4f5cd36e6 100644 (file)
@@ -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 });
index cdbad7a12e02c0f7205aa123971ed06fab6e362c..53204d5bfdacc1be4710a639266889000647d8b1 100644 (file)
@@ -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 });
index 04b0424c0d51f623dd0b4884b7b8aa13039f29ab..24f5a8acffd28ad4cd4643d891ba4de61d03aa5a 100644 (file)
@@ -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 });