} \
static int _gu_##test##_sentinel GU_UNUSED
+/*
+ * This macro should be used for code brevity instead of manually declaring
+ * the gu_test 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
+ *
+ * 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 GU_DEFINE_TEST(_a_func, _a_name, _a_named_lines, ...) \
static unsigned int _##_a_func##_lines[] = __VA_ARGS__; \
static struct gu_test _##_a_func##_descr = { \
GU_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
+ * gpiochip names.
+ *
+ * The test suite detects the chips that were exported by the gpio-mockup
+ * module and stores them in the internal test context structure. Test cases
+ * should use the routines declared below to access the gpiochip path, name
+ * or number by index corresponding with the order in which the mockup chips
+ * were requested in the GU_DEFINE_TEST() macro.
+ */
const char * gu_chip_path(unsigned int index);
const char * gu_chip_name(unsigned int index);
unsigned int gu_chip_num(unsigned int index);
+/*
+ * Every GU_ASSERT_*() macro expansion can make a test function return, so it
+ * would be quite difficult to keep track of every resource allocation. At
+ * the same time we don't want any deliberate memory leaks as we also use this
+ * test suite to find actual memory leaks in the library with valgrind.
+ *
+ * For this reason, the tests should generally always use the GU_CLEANUP()
+ * macro for dynamically allocated variables and objects that need closing.
+ *
+ * The functions below can be reused by different tests for common use cases.
+ */
void gu_close_chip(struct gpiod_chip **chip);
void gu_free_str(char **str);
void gu_free_chip_iter(struct gpiod_chip_iter **iter);