[systemd-devel] [PATCH 2/2] sd-rtnl: fix test cases for rtnl tunnel attr

Susant Sahani susant at redhat.com
Sun Apr 13 21:06:45 PDT 2014


This patch fix the test cases for tunneling type safe
address rtnl attributes and enhances module loading
support .
---
 src/test/test-rtnl-manual.c | 49 +++++++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/src/test/test-rtnl-manual.c b/src/test/test-rtnl-manual.c
index c8133db..612a467 100644
--- a/src/test/test-rtnl-manual.c
+++ b/src/test/test-rtnl-manual.c
@@ -34,35 +34,52 @@
 #include "event-util.h"
 #include "rtnl-internal.h"
 
-static int load_module(const char *mod_name) {
-        struct kmod_ctx *ctx;
-        struct kmod_list *list = NULL, *l;
-        int r;
+static struct kmod_ctx *ctx;
+
+static int kmod_init_ctx(void) {
 
         ctx = kmod_new(NULL, NULL);
         if (!ctx) {
-                kmod_unref(ctx);
                 return -ENOMEM;
         }
 
-        r = kmod_module_new_from_lookup(ctx, mod_name, &list);
+        return 0;
+}
+
+static void kmod_ctx_free(void) {
+
+        assert(ctx);
+
+        kmod_unref(ctx);
+}
+
+static int load_module(const char *mod_name) {
+        struct kmod_list *modlist = NULL, *l;
+        int r;
+        int i = 0;
+
+        r = kmod_module_new_from_lookup(ctx, mod_name, &modlist);
         if (r < 0)
                 return -1;
 
-        kmod_list_foreach(l, list) {
+        kmod_list_foreach(l, modlist) {
                 struct kmod_module *mod = kmod_module_get_module(l);
 
                 r = kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
+
+                printf("i = %d, r = %d\n", i++, r);
+
                 if (r >= 0)
                         r = 0;
                 else
                         r = -1;
 
                 kmod_module_unref(mod);
+
+
         }
 
-        kmod_module_unref_list(list);
-        kmod_unref(ctx);
+        kmod_module_unref_list(modlist);
 
         return r;
 }
@@ -72,6 +89,10 @@ static int test_tunnel_configure(sd_rtnl *rtnl) {
         sd_rtnl_message *m, *n;
         struct in_addr local, remote;
 
+        r = kmod_init_ctx();
+        if(r < 0)
+                return EXIT_TEST_SKIP;
+
         /* skip test if module cannot be loaded */
         r = load_module("ipip");
         if(r < 0)
@@ -92,10 +113,10 @@ static int test_tunnel_configure(sd_rtnl *rtnl) {
         assert_se(sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA, "ipip") >= 0);
 
         inet_pton(AF_INET, "192.168.21.1", &local.s_addr);
-        assert_se(sd_rtnl_message_append_u32(m, IFLA_IPTUN_LOCAL, local.s_addr) >= 0);
+        assert_se(sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &local) >= 0);
 
         inet_pton(AF_INET, "192.168.21.2", &remote.s_addr);
-        assert_se(sd_rtnl_message_append_u32(m, IFLA_IPTUN_REMOTE, remote.s_addr) >= 0);
+        assert_se(sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &remote) >= 0);
 
         assert_se(sd_rtnl_message_close_container(m) >= 0);
         assert_se(sd_rtnl_message_close_container(m) >= 0);
@@ -122,10 +143,10 @@ static int test_tunnel_configure(sd_rtnl *rtnl) {
         assert_se(sd_rtnl_message_append_u8(n, IFLA_IPTUN_PROTO, IPPROTO_IPIP) >= 0);
 
         inet_pton(AF_INET, "192.168.21.3", &local.s_addr);
-        assert_se(sd_rtnl_message_append_u32(n, IFLA_IPTUN_LOCAL, local.s_addr) >= 0);
+        assert_se(sd_rtnl_message_append_in_addr(n, IFLA_IPTUN_LOCAL, &local) >= 0);
 
         inet_pton(AF_INET, "192.168.21.4", &remote.s_addr);
-        assert_se(sd_rtnl_message_append_u32(n, IFLA_IPTUN_REMOTE, remote.s_addr) >= 0);
+        assert_se(sd_rtnl_message_append_in_addr(n, IFLA_IPTUN_REMOTE, &remote) >= 0);
 
         assert_se(sd_rtnl_message_close_container(n) >= 0);
         assert_se(sd_rtnl_message_close_container(n) >= 0);
@@ -134,6 +155,8 @@ static int test_tunnel_configure(sd_rtnl *rtnl) {
 
         assert_se((m = sd_rtnl_message_unref(n)) == NULL);
 
+        kmod_ctx_free();
+
         return EXIT_SUCCESS;
 }
 
-- 
1.9.0



More information about the systemd-devel mailing list