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,
#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)))
struct _test_chip_descr {
unsigned int num_chips;
unsigned int *num_lines;
- bool named_lines;
+ int flags;
};
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.
* 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, \
.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) \
} \
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
}
TEST_DEFINE(chip_open_good,
"gpiod_chip_open() - good",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
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)
{
}
TEST_DEFINE(chip_open_notty,
"gpiod_chip_open() - notty",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
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)
{
}
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)
{
}
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)
{
}
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)
{
}
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)
{
}
TEST_DEFINE(chip_name,
"gpiod_chip_name()",
- TEST_LINES_UNNAMED, { 8, 8, 8 });
+ 0, { 8, 8, 8 });
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)
{
}
TEST_DEFINE(chip_num_lines,
"gpiod_chip_num_lines()",
- TEST_LINES_UNNAMED, { 1, 4, 8, 16, 32 });
+ 0, { 1, 4, 8, 16, 32 });
}
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)
{
}
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)
{
}
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)
{
}
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)
{
}
TEST_DEFINE(event_get_value,
"events - mixing events and gpiod_line_get_value()",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
}
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)
{
}
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)
{
}
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)
{
}
TEST_DEFINE(line_iter,
"gpiod_line_iter - simple loop, check offsets",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
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 });
}
TEST_DEFINE(line_request_output,
"gpiod_line_request_output() - good",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
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)
{
}
TEST_DEFINE(line_consumer,
"gpiod_line_consumer() - good",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
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)
{
}
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)
{
}
TEST_DEFINE(line_set_value,
"gpiod_line_set_value() - good",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
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)
{
}
TEST_DEFINE(line_direction,
"gpiod_line_direction() - set & get",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
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)
{
}
TEST_DEFINE(line_misc_flags,
"gpiod_line - misc flags",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });
}
TEST_DEFINE(version_string,
"gpiod_version_string()",
- TEST_LINES_UNNAMED, { 1 });
+ 0, { 1 });
static void error_handling(void)
{
}
TEST_DEFINE(error_handling,
"error handling",
- TEST_LINES_UNNAMED, { 1 });
+ 0, { 1 });
}
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)
{
}
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)
{
}
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)
{
}
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;
}
TEST_DEFINE(simple_event_loop,
"gpiod_simple_event_loop() - single event",
- TEST_LINES_UNNAMED, { 8 });
+ 0, { 8 });