From: Bartosz Golaszewski Date: Fri, 2 Aug 2019 18:40:12 +0000 (+0200) Subject: tests: drop manual test case links and use GList X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=bab1cdd2a07cffe7a5923bc38c50c38ada882a7c;p=qemu-gpiodev%2Flibgpiod.git tests: drop manual test case links and use GList Let's not handcode a linked list if GLib already provides us with a robust implementation. Use GList to link the tests at registration. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 9eb5d61..9afae72 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -33,9 +33,7 @@ struct gpiod_test_event_thread { }; static struct { - _GpiodTestCase *test_list_head; - _GpiodTestCase *test_list_tail; - guint num_tests; + GList *tests; struct gpio_mockup *mockup; } globals; @@ -92,15 +90,20 @@ static void unref_mockup(void) gpio_mockup_unref(globals.mockup); } -int main(gint argc, gchar **argv) +static void add_test_from_list(gpointer element, gpointer data G_GNUC_UNUSED) { - _GpiodTestCase *test; + _GpiodTestCase *test = element; + + g_test_add_data_func(test->path, test, test_func_wrapper); +} +int main(gint argc, gchar **argv) +{ g_test_init(&argc, &argv, NULL); g_test_set_nonfatal_assertions(); g_debug("running libgpiod test suite"); - g_debug("%u tests registered", globals.num_tests); + g_debug("%u tests registered", g_list_length(globals.tests)); /* * Setup libgpiomockup first so that it runs its own kernel version @@ -115,27 +118,14 @@ int main(gint argc, gchar **argv) check_kernel(); - for (test = globals.test_list_head; test; test = test->_next) - g_test_add_data_func(test->path, test, test_func_wrapper); + g_list_foreach(globals.tests, add_test_from_list, NULL); return g_test_run(); } void _gpiod_test_register(_GpiodTestCase *test) { - _GpiodTestCase *tmp; - - if (!globals.test_list_head) { - globals.test_list_head = globals.test_list_tail = test; - test->_next = NULL; - } else { - tmp = globals.test_list_tail; - globals.test_list_tail = test; - test->_next = NULL; - tmp->_next = test; - } - - globals.num_tests++; + globals.tests = g_list_append(globals.tests, test); } const gchar *gpiod_test_chip_path(guint index) diff --git a/tests/gpiod-test.h b/tests/gpiod-test.h index bb0f8be..8047964 100644 --- a/tests/gpiod-test.h +++ b/tests/gpiod-test.h @@ -36,8 +36,6 @@ typedef void (*_gpiod_test_func)(void); typedef struct _gpiod_test_case _GpiodTestCase; struct _gpiod_test_case { - _GpiodTestCase *_next; - const gchar *path; _gpiod_test_func func;