From d8a6ecc63059e04b1cf7b0410c94c9e2e3be80ed Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 2 Aug 2012 08:14:14 +0400 Subject: [PATCH] zdtm: Netns basic test Only checks for lo, one simple ifaddr and two routes are handled. Sanity test and nothing more. Signed-off-by: Pavel Emelyanov --- test/zdtm/live/static/Makefile | 1 + test/zdtm/live/static/netns.c | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 test/zdtm/live/static/netns.c diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile index 00f9943d2..2878d3134 100644 --- a/test/zdtm/live/static/Makefile +++ b/test/zdtm/live/static/Makefile @@ -51,6 +51,7 @@ TST_NOFILE = \ pty00 \ tty00 \ mountpoints \ + netns \ session01 \ # jobctl00 \ diff --git a/test/zdtm/live/static/netns.c b/test/zdtm/live/static/netns.c new file mode 100644 index 000000000..5b84e5f41 --- /dev/null +++ b/test/zdtm/live/static/netns.c @@ -0,0 +1,61 @@ +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Check that network environment (links, addresses and routes) are preserved"; +const char *test_author = "Pavel Emelianov "; + +static int test_fn(int argc, char **argv) +{ + if (system("ip link set lo up")) { + fail("Can't set lo up"); + return -1; + } + + if (system("ip addr add 1.2.3.4 dev lo")) { + fail("Can't add addr on lo"); + return -1; + } + + if (system("ip route add 1.2.3.5 dev lo")) { + fail("Can't add route via lo"); + return -1; + } + + if (system("ip route add 1.2.3.6 via 1.2.3.5")) { + fail("Can't add route via lo (2)"); + return -1; + } + + if (system("ip link > ip.dump && ip addr >> ip.dump && ip route >> ip.dump")) { + fail("Can't save net config"); + return -1; + } + + test_daemon(); + test_waitsig(); + + if (system("ip link > ip.rst && ip addr >> ip.rst && ip route >> ip.rst")) { + fail("Can't get net config"); + return -1; + } + + if (system("diff ip.rst ip.dump")) { + fail("Net config differs after restore"); + return -1; + } + + pass(); + return 0; +} + +#define CLONE_NEWNET 0x40000000 + +int main(int argc, char **argv) +{ + test_init_ns(argc, argv, CLONE_NEWNET, test_fn); + return 0; +} +