[1/2] testcases: netns: Check TUN support enabled

Message ID 20180802141251.1571-1-mylene.josserand@bootlin.com
State Changes Requested
Delegated to: Petr Vorel
Headers show
Series
  • [1/2] testcases: netns: Check TUN support enabled
Related show

Commit Message

Mylène Josserand Aug. 2, 2018, 2:12 p.m.
In case TUN support is not enabled, the test will fail while
performing the "ip" command with following error:
   open: No such file or directory
   netns_netlink    1  TBROK  :  netns_netlink.c:143: system() failed

As the system() call is not setting errno, we are not able to know
if the error is produced by a mis-configuration or not.

Because of that, this commit adds a check during the setup function to see
if the device "/dev/net/tun" is available or not. It is the file
that "ip tuntap add mode tap" command is looking for (and fails with
the "open" error).

Signed-off-by: Mylène Josserand <mylene.josserand@bootlin.com>
---
 testcases/kernel/containers/netns/netns_netlink.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Petr Vorel Oct. 4, 2018, 12:59 p.m. | #1
Hi Mylène,

> In case TUN support is not enabled, the test will fail while
> performing the "ip" command with following error:
>    open: No such file or directory
>    netns_netlink    1  TBROK  :  netns_netlink.c:143: system() failed

> As the system() call is not setting errno, we are not able to know
> if the error is produced by a mis-configuration or not.

> Because of that, this commit adds a check during the setup function to see
> if the device "/dev/net/tun" is available or not. It is the file
> that "ip tuntap add mode tap" command is looking for (and fails with
> the "open" error).

> Signed-off-by: Mylène Josserand <mylene.josserand@bootlin.com>
> ---
>  testcases/kernel/containers/netns/netns_netlink.c | 9 +++++++++
>  1 file changed, 9 insertions(+)

> diff --git a/testcases/kernel/containers/netns/netns_netlink.c b/testcases/kernel/containers/netns/netns_netlink.c
> index 47e8235d6..077ec5dab 100644
> --- a/testcases/kernel/containers/netns/netns_netlink.c
> +++ b/testcases/kernel/containers/netns/netns_netlink.c
> @@ -57,6 +57,15 @@ static void cleanup(void)

>  static void setup(void)
>  {
> +	/* Check that the TUN support is available */
> +	int netfd = open("/dev/net/tun", O_RDWR);
> +	if (netfd == -1) {
> +		if (errno == ENODEV || errno == ENOENT)
> +			tst_brkm(TCONF, NULL, "TUN support is missing?");
> +
> +		tst_brkm(TBROK | TERRNO, NULL, "opening /dev/net/tun failed");
> +	}

Can you please implement your patch via .needs_drivers (recently contributed by
Alexey Kodanev)?


Kind regards,
Petr

Patch

diff --git a/testcases/kernel/containers/netns/netns_netlink.c b/testcases/kernel/containers/netns/netns_netlink.c
index 47e8235d6..077ec5dab 100644
--- a/testcases/kernel/containers/netns/netns_netlink.c
+++ b/testcases/kernel/containers/netns/netns_netlink.c
@@ -57,6 +57,15 @@  static void cleanup(void)
 
 static void setup(void)
 {
+	/* Check that the TUN support is available */
+	int netfd = open("/dev/net/tun", O_RDWR);
+	if (netfd == -1) {
+		if (errno == ENODEV || errno == ENOENT)
+			tst_brkm(TCONF, NULL, "TUN support is missing?");
+
+		tst_brkm(TBROK | TERRNO, NULL, "opening /dev/net/tun failed");
+	}
+
 	tst_require_root();
 	check_iproute(IP_TUNTAP_MIN_VER);
 	check_netns();