All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] unit: Added generic netlink family unit test
@ 2017-03-21 21:15 Ossama Othman
  2017-03-21 21:58 ` Denis Kenzior
  0 siblings, 1 reply; 3+ messages in thread
From: Ossama Othman @ 2017-03-21 21:15 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1866 bytes --]

---
 unit/test-genl.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/unit/test-genl.c b/unit/test-genl.c
index d15d92c..dce9a41 100644
--- a/unit/test-genl.c
+++ b/unit/test-genl.c
@@ -25,6 +25,7 @@
 #endif
 
 #include <sys/socket.h>
+#include <assert.h>
 
 #include <ell/ell.h>
 
@@ -35,14 +36,38 @@ static void do_debug(const char *str, void *user_data)
 	l_info("%s%s", prefix, str);
 }
 
-static void idle_callback(void *user_data)
+static void family_vanished(void *user_data)
 {
-	l_main_quit();
+	bool *vanished_called = user_data;
+
+	*vanished_called = true;
+}
+
+static void idle_callback(struct l_idle *idle, void *user_data)
+{
+	static int count = 0;
+
+	/*
+	 * Allow the main loop to iterate at least twice to allow the
+	 * generic netlink watches to be called.
+	 */
+	if (++count > 1)
+		l_main_quit();
 }
 
 int main(int argc, char *argv[])
 {
 	struct l_genl *genl;
+	struct l_genl_family *family;
+	struct l_idle *idle;
+
+	/*
+	 * Use a bogus family name to trigger the vanished watch to
+	 * be called.
+	 */
+	static const char BOGUS_GENL_NAME[] = "bogus_genl_family";
+
+	bool vanished_called = false;
 
 	if (!l_main_init())
 		return -1;
@@ -53,13 +78,25 @@ int main(int argc, char *argv[])
 
 	l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
 
-	l_idle_oneshot(idle_callback, NULL, NULL);
+	family = l_genl_family_new(genl, BOGUS_GENL_NAME);
+	l_genl_family_set_watches(family,
+				  NULL,
+				  family_vanished,
+				  &vanished_called,
+				  NULL);
+
+	idle = l_idle_create(idle_callback, NULL, NULL);
 
 	l_main_run();
 
+	l_idle_remove(idle);
+
+	l_genl_family_unref(family);
 	l_genl_unref(genl);
 
 	l_main_exit();
 
+	assert(vanished_called);
+
 	return 0;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-21 22:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-21 21:15 [PATCH v4] unit: Added generic netlink family unit test Ossama Othman
2017-03-21 21:58 ` Denis Kenzior
2017-03-21 22:14   ` Othman, Ossama

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.