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

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

---
 Makefile.am             |  3 ++
 unit/test-genl-family.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 unit/test-genl-family.c

diff --git a/Makefile.am b/Makefile.am
index d2e33de..39ebe66 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,6 +119,7 @@ unit_tests = unit/test-unit \
 			unit/test-settings \
 			unit/test-netlink \
 			unit/test-genl \
+			unit/test-genl-family \
 			unit/test-genl-msg \
 			unit/test-siphash \
 			unit/test-hwdb \
@@ -174,6 +175,8 @@ unit_test_netlink_LDADD = ell/libell-private.la
 
 unit_test_genl_LDADD = ell/libell-private.la
 
+unit_test_genl_family_LDADD = ell/libell-private.la
+
 unit_test_genl_msg_LDADD = ell/libell-private.la
 
 unit_test_dbus_LDADD = ell/libell-private.la
diff --git a/unit/test-genl-family.c b/unit/test-genl-family.c
new file mode 100644
index 0000000..5109fad
--- /dev/null
+++ b/unit/test-genl-family.c
@@ -0,0 +1,99 @@
+/*
+ *
+ *  Embedded Linux library
+ *
+ *  Copyright (C) 2011-2017  Intel Corporation. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/socket.h>
+
+#include <ell/ell.h>
+
+static void do_debug(const char *str, void *user_data)
+{
+	const char *prefix = user_data;
+
+	l_info("%s%s", prefix, str);
+}
+
+static void family_vanished(void *user_data)
+{
+	bool *vanished_called = user_data;
+
+	*vanished_called = true;
+}
+
+static void idle_handler(struct l_idle *idle, void *user_data)
+{
+	static int count = 0;
+
+	/*
+	 * Allow the main loop to iterate at least once.  Otherwise
+	 * the generic netlink watches won't 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;
+
+	l_log_set_stderr();
+
+	genl = l_genl_new_default();
+
+	l_genl_set_debug(genl, do_debug, "[GENL] ", 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_handler, NULL, NULL);
+
+	l_main_run();
+
+	l_idle_remove(idle);
+
+	l_genl_family_unref(family);
+	l_genl_unref(genl);
+
+	l_main_exit();
+
+	return vanished_called ? 0 : -1;
+}
-- 
2.7.4


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

* [PATCH v3] unit: Added generic netlink family unit test
  2017-03-21 19:37 [PATCH] unit: Added generic netlink family unit test Ossama Othman
@ 2017-03-21 19:57 ` Ossama Othman
  2017-03-21 20:42   ` Denis Kenzior
  0 siblings, 1 reply; 6+ messages in thread
From: Ossama Othman @ 2017-03-21 19:57 UTC (permalink / raw)
  To: ell

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

---
 Makefile.am             |  3 ++
 unit/test-genl-family.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 unit/test-genl-family.c

diff --git a/Makefile.am b/Makefile.am
index d2e33de..39ebe66 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,6 +119,7 @@ unit_tests = unit/test-unit \
 			unit/test-settings \
 			unit/test-netlink \
 			unit/test-genl \
+			unit/test-genl-family \
 			unit/test-genl-msg \
 			unit/test-siphash \
 			unit/test-hwdb \
@@ -174,6 +175,8 @@ unit_test_netlink_LDADD = ell/libell-private.la
 
 unit_test_genl_LDADD = ell/libell-private.la
 
+unit_test_genl_family_LDADD = ell/libell-private.la
+
 unit_test_genl_msg_LDADD = ell/libell-private.la
 
 unit_test_dbus_LDADD = ell/libell-private.la
diff --git a/unit/test-genl-family.c b/unit/test-genl-family.c
new file mode 100644
index 0000000..5109fad
--- /dev/null
+++ b/unit/test-genl-family.c
@@ -0,0 +1,99 @@
+/*
+ *
+ *  Embedded Linux library
+ *
+ *  Copyright (C) 2011-2017  Intel Corporation. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/socket.h>
+
+#include <ell/ell.h>
+
+static void do_debug(const char *str, void *user_data)
+{
+	const char *prefix = user_data;
+
+	l_info("%s%s", prefix, str);
+}
+
+static void family_vanished(void *user_data)
+{
+	bool *vanished_called = user_data;
+
+	*vanished_called = true;
+}
+
+static void idle_handler(struct l_idle *idle, void *user_data)
+{
+	static int count = 0;
+
+	/*
+	 * Allow the main loop to iterate at least once.  Otherwise
+	 * the generic netlink watches won't 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;
+
+	l_log_set_stderr();
+
+	genl = l_genl_new_default();
+
+	l_genl_set_debug(genl, do_debug, "[GENL] ", 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_handler, NULL, NULL);
+
+	l_main_run();
+
+	l_idle_remove(idle);
+
+	l_genl_family_unref(family);
+	l_genl_unref(genl);
+
+	l_main_exit();
+
+	return vanished_called ? 0 : -1;
+}
-- 
2.7.4


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

* Re: [PATCH v3] unit: Added generic netlink family unit test
  2017-03-21 19:57 ` [PATCH v3] " Ossama Othman
@ 2017-03-21 20:42   ` Denis Kenzior
  2017-03-21 20:46     ` Othman, Ossama
  0 siblings, 1 reply; 6+ messages in thread
From: Denis Kenzior @ 2017-03-21 20:42 UTC (permalink / raw)
  To: ell

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

Hi Ossama,

On 03/21/2017 02:57 PM, Ossama Othman wrote:
> ---
>  Makefile.am             |  3 ++
>  unit/test-genl-family.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++

Do you want to add this test to unit/test-genl instead?  That test is a 
no-op at this point anyway.

>  2 files changed, 102 insertions(+)
>  create mode 100644 unit/test-genl-family.c
>
> diff --git a/Makefile.am b/Makefile.am
> index d2e33de..39ebe66 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -119,6 +119,7 @@ unit_tests = unit/test-unit \
>  			unit/test-settings \
>  			unit/test-netlink \
>  			unit/test-genl \
> +			unit/test-genl-family \
>  			unit/test-genl-msg \
>  			unit/test-siphash \
>  			unit/test-hwdb \
> @@ -174,6 +175,8 @@ unit_test_netlink_LDADD = ell/libell-private.la
>
>  unit_test_genl_LDADD = ell/libell-private.la
>
> +unit_test_genl_family_LDADD = ell/libell-private.la
> +
>  unit_test_genl_msg_LDADD = ell/libell-private.la
>
>  unit_test_dbus_LDADD = ell/libell-private.la
> diff --git a/unit/test-genl-family.c b/unit/test-genl-family.c
> new file mode 100644
> index 0000000..5109fad
> --- /dev/null
> +++ b/unit/test-genl-family.c
> @@ -0,0 +1,99 @@
> +/*
> + *
> + *  Embedded Linux library
> + *
> + *  Copyright (C) 2011-2017  Intel Corporation. All rights reserved.
> + *
> + *  This library is free software; you can redistribute it and/or
> + *  modify it under the terms of the GNU Lesser General Public
> + *  License as published by the Free Software Foundation; either
> + *  version 2.1 of the License, or (at your option) any later version.
> + *
> + *  This library is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + *  Lesser General Public License for more details.
> + *
> + *  You should have received a copy of the GNU Lesser General Public
> + *  License along with this library; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <sys/socket.h>
> +
> +#include <ell/ell.h>
> +
> +static void do_debug(const char *str, void *user_data)
> +{
> +	const char *prefix = user_data;
> +
> +	l_info("%s%s", prefix, str);
> +}
> +

I know test-genl does this, but...  generally our unit tests don't print 
anything.  Do you really need this?

> +static void family_vanished(void *user_data)
> +{
> +	bool *vanished_called = user_data;
> +
> +	*vanished_called = true;
> +}
> +
> +static void idle_handler(struct l_idle *idle, void *user_data)
> +{
> +	static int count = 0;
> +
> +	/*
> +	 * Allow the main loop to iterate at least once.  Otherwise
> +	 * the generic netlink watches won't 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;
> +
> +	l_log_set_stderr();
> +
> +	genl = l_genl_new_default();
> +
> +	l_genl_set_debug(genl, do_debug, "[GENL] ", 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_handler, NULL, NULL);
> +
> +	l_main_run();
> +
> +	l_idle_remove(idle);
> +
> +	l_genl_family_unref(family);
> +	l_genl_unref(genl);
> +
> +	l_main_exit();
> +
> +	return vanished_called ? 0 : -1;

This is probably okay, but it might be better to use asserts, especially 
if more tests are added to this unit file in the future.

> +}
>

Regards,
-Denis

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

* Re: [PATCH v3] unit: Added generic netlink family unit test
  2017-03-21 20:42   ` Denis Kenzior
@ 2017-03-21 20:46     ` Othman, Ossama
  0 siblings, 0 replies; 6+ messages in thread
From: Othman, Ossama @ 2017-03-21 20:46 UTC (permalink / raw)
  To: ell

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

Hi Denis,

On Tue, Mar 21, 2017 at 1:42 PM, Denis Kenzior <denkenz@gmail.com> wrote:
>
> On 03/21/2017 02:57 PM, Ossama Othman wrote:
>
>> ---
>>  Makefile.am             |  3 ++
>>  unit/test-genl-family.c | 99 ++++++++++++++++++++++++++++++
>> +++++++++++++++++++
>>
>
> Do you want to add this test to unit/test-genl instead?  That test is a
> no-op at this point anyway.


Okay, that's fine with me.


> +static void do_debug(const char *str, void *user_data)
>> +{
>> +       const char *prefix = user_data;
>> +
>> +       l_info("%s%s", prefix, str);
>> +}
>> +
>>
>
> I know test-genl does this, but...  generally our unit tests don't print
> anything.  Do you really need this?


Not at all.  I was just trying to be consistent with test-genl.

+       return vanished_called ? 0 : -1;
>>
>
> This is probably okay, but it might be better to use asserts, especially
> if more tests are added to this unit file in the future.
>

Okay, I'll go back to returning 0 and rely on an assert() instead.

Thanks Denis!
-Ossama

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 2174 bytes --]

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

* Re: [PATCH] unit: Added generic netlink family unit test
  2017-03-21 19:30 [PATCH] " Ossama Othman
@ 2017-03-21 19:34 ` Othman, Ossama
  0 siblings, 0 replies; 6+ messages in thread
From: Othman, Ossama @ 2017-03-21 19:34 UTC (permalink / raw)
  To: ell

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

Hi,

On Tue, Mar 21, 2017 at 12:30 PM, Ossama Othman <ossama.othman@intel.com>
wrote:
>
> +static void family_vanished(void *user_data)
> +{
> +       bool *vanished_called = user_data;
> +
> +       *vanished_called = true;
> +       l_main_quit();
>

I just noticed this extraneous l_main_quit() call.  It doesn't affect the
unit test result but I'll resend the patch with it removed.


> +}
> +
> +static void idle_handler(struct l_idle *idle, void *user_data)
> +{
> +       static int count = 0;
> +
> +       /*
> +        * Allow the main loop to iterate at least once.  Otherwise
> +        * the generic netlink watches won't be called.
> +        */
> +       if (count++ == 1)
> +               l_main_quit();
> +}


Thanks,
-Ossama

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 1322 bytes --]

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

* [PATCH] unit: Added generic netlink family unit test
@ 2017-03-21 19:30 Ossama Othman
  2017-03-21 19:34 ` Othman, Ossama
  0 siblings, 1 reply; 6+ messages in thread
From: Ossama Othman @ 2017-03-21 19:30 UTC (permalink / raw)
  To: ell

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

---
 Makefile.am             |   3 ++
 unit/test-genl-family.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
 create mode 100644 unit/test-genl-family.c

diff --git a/Makefile.am b/Makefile.am
index d2e33de..39ebe66 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,6 +119,7 @@ unit_tests = unit/test-unit \
 			unit/test-settings \
 			unit/test-netlink \
 			unit/test-genl \
+			unit/test-genl-family \
 			unit/test-genl-msg \
 			unit/test-siphash \
 			unit/test-hwdb \
@@ -174,6 +175,8 @@ unit_test_netlink_LDADD = ell/libell-private.la
 
 unit_test_genl_LDADD = ell/libell-private.la
 
+unit_test_genl_family_LDADD = ell/libell-private.la
+
 unit_test_genl_msg_LDADD = ell/libell-private.la
 
 unit_test_dbus_LDADD = ell/libell-private.la
diff --git a/unit/test-genl-family.c b/unit/test-genl-family.c
new file mode 100644
index 0000000..ec644a2
--- /dev/null
+++ b/unit/test-genl-family.c
@@ -0,0 +1,100 @@
+/*
+ *
+ *  Embedded Linux library
+ *
+ *  Copyright (C) 2011-2017  Intel Corporation. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/socket.h>
+
+#include <ell/ell.h>
+
+static void do_debug(const char *str, void *user_data)
+{
+	const char *prefix = user_data;
+
+	l_info("%s%s", prefix, str);
+}
+
+static void family_vanished(void *user_data)
+{
+	bool *vanished_called = user_data;
+
+	*vanished_called = true;
+	l_main_quit();
+}
+
+static void idle_handler(struct l_idle *idle, void *user_data)
+{
+	static int count = 0;
+
+	/*
+	 * Allow the main loop to iterate at least once.  Otherwise
+	 * the generic netlink watches won't 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;
+
+	l_log_set_stderr();
+
+	genl = l_genl_new_default();
+
+	l_genl_set_debug(genl, do_debug, "[GENL] ", 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_handler, NULL, NULL);
+
+	l_main_run();
+
+	l_idle_remove(idle);
+
+	l_genl_family_unref(family);
+	l_genl_unref(genl);
+
+	l_main_exit();
+
+	return vanished_called ? 0 : -1;
+}
-- 
2.7.4


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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21 19:37 [PATCH] unit: Added generic netlink family unit test Ossama Othman
2017-03-21 19:57 ` [PATCH v3] " Ossama Othman
2017-03-21 20:42   ` Denis Kenzior
2017-03-21 20:46     ` Othman, Ossama
  -- strict thread matches above, loose matches on Subject: below --
2017-03-21 19:30 [PATCH] " Ossama Othman
2017-03-21 19:34 ` 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.