All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ossama Othman <ossama.othman@intel.com>
To: ell@lists.01.org
Subject: [PATCH v4] unit: Added generic netlink family unit test
Date: Tue, 21 Mar 2017 14:15:45 -0700	[thread overview]
Message-ID: <1490130945-15382-1-git-send-email-ossama.othman@intel.com> (raw)

[-- 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


             reply	other threads:[~2017-03-21 21:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-21 21:15 Ossama Othman [this message]
2017-03-21 21:58 ` [PATCH v4] unit: Added generic netlink family unit test Denis Kenzior
2017-03-21 22:14   ` Othman, Ossama

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1490130945-15382-1-git-send-email-ossama.othman@intel.com \
    --to=ossama.othman@intel.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.