Skip to contentSkip to conversation

unit: Added generic netlink family unit test

PATCH In review Ossama Othman 3 participants 3 messages Mar 21, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 unit: Added generic netlink family unit test

---
 unit/test-genl.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)
unit/test-genl.c +40 -3
index d15d92c..dce9a41 100644
@@ -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;
 }
Signature · 1 line
2.7.4
#1 lore raw

Hi Ossama,

Quoted 4 lines · Ossama Othman
---
 unit/test-genl.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

< snip>

unit/test-genl.c int main(int argc, char *argv[]) · line 87

Quoted 6 lines
unit/test-genl.c +6 -0
+	l_genl_family_set_watches(family,
+				  NULL,
+				  family_vanished,
+				  &vanished_called,
+				  NULL);
+

We don't use mixed tabs & spaces for indentation, so I fixed this up to only use tabs and applied this patch.

Thanks!

Regards,
-Denis

#2 lore raw

Hi Denis,

Quoted 11 lines · Denis Kenzior

+ l_genl_family_set_watches(family,

unit/test-genl.c int main(int argc, char *argv[]) · line 87

Quoted 6 lines
unit/test-genl.c +5 -0
+                                 NULL,
+                                 family_vanished,
+                                 &vanished_called,
+                                 NULL);
+

We don't use mixed tabs & spaces for indentation, so I fixed this up to only use tabs and applied this patch.

Much appreciated! I missed that.

-Ossama