Skip to contentSkip to conversation

tests: Move tests from files to shell.

PATCH In review Varsha Rao 2 participants 13 messages Oct 11, 2017 – Oct 17, 2017 netfilter

lore
Share & tools
lore

Varsha Rao

author
#0 lore raw

cover tests: Move tests from files to shell.

Test files of tests/files/ are moved to tests/shell.

Varsha Rao (9):
tests: files: Remove jump chain tests.
tests: shell: Add test case for jump chain.
tests: shell: Add test case for sets.
tests: files: Remove tests for set.
tests: shell: Add tests for variable definition.
tests: files: Remove test cases for variable definition.
tests: files: Remove tests for chain.
tests: files: Remove tests for table.
tests: files: Remove tests for verdict maps.

 tests/files/loop-detect.1                          |  8 -------
 tests/files/loop-detect.2                          |  7 ------
 tests/files/loop-detect.3                          |  7 ------
 tests/files/loop-detect.4                          |  7 ------
 tests/files/obj-chain                              | 22 -------------------
 tests/files/obj-table                              |  9 --------
 tests/files/set                                    | 14 ------------
 tests/files/symbolic-define.1                      |  7 ------
 tests/files/symbolic-define.2                      |  7 ------
 tests/files/symbolic-define.3                      |  6 ------
 tests/files/verdict-maps                           | 20 -----------------
 tests/shell/testcases/chains/0015check_jump_loop_1 | 11 ++++++++++
 tests/shell/testcases/nft-f/0013defines_1          | 25 ++++++++++++++++++++++
 tests/shell/testcases/nft-f/0014defines_1          | 25 ++++++++++++++++++++++
 tests/shell/testcases/nft-f/0015defines_1          | 24 +++++++++++++++++++++
 tests/shell/testcases/sets/0025anonymous_set_0     | 17 +++++++++++++++
 16 files changed, 102 insertions(+), 114 deletions(-)
 delete mode 100644 tests/files/loop-detect.1
 delete mode 100644 tests/files/loop-detect.2
 delete mode 100644 tests/files/loop-detect.3
 delete mode 100644 tests/files/loop-detect.4
 delete mode 100644 tests/files/obj-chain
 delete mode 100644 tests/files/obj-table
 delete mode 100644 tests/files/set
 delete mode 100644 tests/files/symbolic-define.1
 delete mode 100644 tests/files/symbolic-define.2
 delete mode 100644 tests/files/symbolic-define.3
 delete mode 100644 tests/files/verdict-maps
 create mode 100755 tests/shell/testcases/chains/0015check_jump_loop_1
 create mode 100755 tests/shell/testcases/nft-f/0013defines_1
 create mode 100755 tests/shell/testcases/nft-f/0014defines_1
 create mode 100755 tests/shell/testcases/nft-f/0015defines_1
 create mode 100755 tests/shell/testcases/sets/0025anonymous_set_0
Signature · 1 line
2.13.6
author
#1 lore raw

PATCH 1/9 tests: files: Remove jump chain tests.

Tests for loop-detect 1, 2 and 3 are already there in tests/shell file. New test for loop-detect.4 has been added to tests/shell file. So, remove them.

---
 tests/files/loop-detect.1 | 8 --------
 tests/files/loop-detect.2 | 7 -------
 tests/files/loop-detect.3 | 7 -------
 tests/files/loop-detect.4 | 7 -------
 4 files changed, 29 deletions(-)
 delete mode 100644 tests/files/loop-detect.1
 delete mode 100644 tests/files/loop-detect.2
 delete mode 100644 tests/files/loop-detect.3
 delete mode 100644 tests/files/loop-detect.4
tests/files/loop-detect.1 deleted +0 -8
deleted file mode 100644
index e55864c..0000000
@@ -1,8 +0,0 @@
-#! nft -f
-
-# Create table and empty chains for loop detection tests
-add table filter
-
-add chain filter chain1
-add chain filter chain2
-add chain filter chain3
tests/files/loop-detect.2 deleted +0 -7
deleted file mode 100644
index 88a95e0..0000000
@@ -1,7 +0,0 @@
-#! nft -f
-
-# Circular regular jumps: chain1 -> chain2 -> chain3 -> chain1
-flush table filter
-add filter chain1 jump chain2
-add filter chain2 jump chain3
-add filter chain3 jump chain1
tests/files/loop-detect.3 deleted +0 -7
deleted file mode 100644
index 80f7fc5..0000000
@@ -1,7 +0,0 @@
-#! nft -f
-
-# Circular jump when creating an anonymous verdict map: chain1 -> chain2 -> chain3 -> chain1
-flush table filter
-add filter chain1 jump chain2
-add filter chain2 jump chain3
-add filter chain3 ip daddr vmap { 10.0.0.1 : continue, 192.168.0.1 : jump chain1 }
tests/files/loop-detect.4 deleted +0 -7
deleted file mode 100644
index acd9a34..0000000
@@ -1,7 +0,0 @@
-#! nft -f
-
-# Circular jump with an intermediate anonymous verdict map: chain1 -> chain2 -> chain3 -> chain1
-flush table filter
-add filter chain1 jump chain2
-add filter chain2 ip daddr vmap { 10.0.0.1 : continue, 192.168.0.1 : jump chain3 }
-add filter chain3 jump chain1
Signature · 1 line
2.13.6
author
#2 lore raw

PATCH 2/9 tests: shell: Add test case for jump chain.

In reply to Varsha Rao

This patch adds test case for checking jump to non existing chain.

---
 tests/shell/testcases/chains/0015check_jump_loop_1 | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100755 tests/shell/testcases/chains/0015check_jump_loop_1
tests/shell/testcases/chains/0015check_jump_loop_1 new file +11 -0
new file mode 100755
index 0000000..059cfaa
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+set -e
+
+$NFT add table t
+$NFT add chain t c1
+$NFT add chain t c2
+$NFT add t c1 jump c2
+# kernel should return ENOENT
+$NFT add t c2 ip daddr vmap { 1 : jump c3 }
+echo "E: Jumped to non existing chain" >&2
Signature · 1 line
2.13.6
author
#3 lore raw

PATCH 3/9 tests: shell: Add test case for sets.

In reply to Varsha Rao

This patch adds test case for anonymous sets.

---
 tests/shell/testcases/sets/0025anonymous_set_0 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 tests/shell/testcases/sets/0025anonymous_set_0
tests/shell/testcases/sets/0025anonymous_set_0 new file +17 -0
new file mode 100755
index 0000000..93a7c02
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# Adding anonymous sets
+
+set -e
+
+$NFT add table t
+$NFT add chain t c { type filter hook output priority 0 \; }
+# set: IP addresses
+$NFT add rule t c ip daddr { \
+        192.168.0.1, \
+        192.168.0.2, \
+        192.168.0.3, \
+}
+
+#set : tcp ports
+$NFT add rule t c tcp dport { 22, 23 } counter
Signature · 1 line
2.13.6
author
#4 lore raw

PATCH 4/9 tests: files: Remove tests for set.

In reply to Varsha Rao

This patch removes test case for set. As new test case is added to tests/shell file.

---
 tests/files/set | 14 --------------
 1 file changed, 14 deletions(-)
 delete mode 100644 tests/files/set
tests/files/set deleted +0 -14
deleted file mode 100644
index 3c040b0..0000000
@@ -1,14 +0,0 @@
-#! nft -f
-
-add table filter
-add chain filter output { type filter hook output priority 0 ; }
-
-# set: IP addresses
-add rule filter output ip daddr { \
-	192.168.0.1, \
-	192.168.0.2, \
-	192.168.0.3, \
-}
-
-# set: tcp ports
-add rule filter output tcp dport { 22, 23 } counter
Signature · 1 line
2.13.6
author
#5 lore raw

PATCH 5/9 tests: shell: Add tests for variable definition.

In reply to Varsha Rao

This patch adds test cases for a variable definition and redefinition.

---
 tests/shell/testcases/nft-f/0013defines_1 | 25 +++++++++++++++++++++++++
 tests/shell/testcases/nft-f/0014defines_1 | 25 +++++++++++++++++++++++++
 tests/shell/testcases/nft-f/0015defines_1 | 24 ++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100755 tests/shell/testcases/nft-f/0013defines_1
 create mode 100755 tests/shell/testcases/nft-f/0014defines_1
 create mode 100755 tests/shell/testcases/nft-f/0015defines_1
tests/shell/testcases/nft-f/0013defines_1 new file +25 -0
new file mode 100755
index 0000000..5519703
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Tests use of variable before definition.
+
+set -e
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+	echo "Failed to create tmp file" >&2
+	exit 0
+fi
+
+trap "rm -rf $tmpfile" EXIT # cleanup if aborted
+
+echo "
+define var2 = \$var1
+define var1 = lo
+
+table ip t {
+	chain c {
+		iif \$var2
+	}
+}" >> $tmpfile
+
+$NFT -f $tmpfile
tests/shell/testcases/nft-f/0014defines_1 new file +25 -0
new file mode 100755
index 0000000..914d910
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Tests redefinition of an existing variable.
+
+set -e
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+	echo "Failed to create tmp file" >&2
+	exit 0
+fi
+
+trap "rm -rf $tmpfile" EXIT # cleanup if aborted
+
+echo "
+define var1 = lo
+define var1 = lo
+
+table ip t {
+	chain c {
+		iif \$var1
+	}
+}" >> $tmpfile
+
+$NFT -f $tmpfile
tests/shell/testcases/nft-f/0015defines_1 new file +24 -0
new file mode 100755
index 0000000..1f9db11
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Tests recursive definition of a variable.
+
+set -e
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+	echo "Failed to create tmp file" >&2
+	exit 0
+fi
+
+trap "rm -rf $tmpfile" EXIT # cleanup if aborted
+
+echo "
+define var1 = \$var1
+
+table ip t {
+	chain c {
+		iif \$var1
+	}
+}" >> $tmpfile
+
+$NFT -f $tmpfile
Signature · 1 line
2.13.6
author
#6 lore raw

PATCH 6/9 tests: files: Remove test cases for variable definition.

In reply to Varsha Rao

New test cases for variable definition are added in tests/shell file. So, remove these test cases.

---
 tests/files/symbolic-define.1 | 7 -------
 tests/files/symbolic-define.2 | 7 -------
 tests/files/symbolic-define.3 | 6 ------
 3 files changed, 20 deletions(-)
 delete mode 100644 tests/files/symbolic-define.1
 delete mode 100644 tests/files/symbolic-define.2
 delete mode 100644 tests/files/symbolic-define.3
tests/files/symbolic-define.1 deleted +0 -7
deleted file mode 100644
index 712ef71..0000000
@@ -1,7 +0,0 @@
-#! nft -f
-
-# error: variable use before definition
-define var2 = $var1
-define var1 = eth0
-
-filter input iif $var2
tests/files/symbolic-define.2 deleted +0 -7
deleted file mode 100644
index cd3c23c..0000000
@@ -1,7 +0,0 @@
-#! nft -f
-
-# error: redefinition of an existing variable
-define var1 = eth0
-define var1 = eth0
-
-filter input iif $var1
tests/files/symbolic-define.3 deleted +0 -6
deleted file mode 100644
index ba224df..0000000
@@ -1,6 +0,0 @@
-#! nft -f
-
-# error: recursive definition of a variable
-define var1 = $var1
-
-filter input iif $var1
Signature · 1 line
2.13.6
author
#7 lore raw

PATCH 7/9 tests: files: Remove tests for chain.

In reply to Varsha Rao

Test cases for chain are there in tests/shell file. So, remove these testcases.

---
 tests/files/obj-chain | 22 ----------------------
 1 file changed, 22 deletions(-)
 delete mode 100644 tests/files/obj-chain
tests/files/obj-chain deleted +0 -22
deleted file mode 100644
index 2bce026..0000000
@@ -1,22 +0,0 @@
-#! nft -f
-
-add table filter
-
-# chains: add and delete chain
-add chain filter testchain
-delete chain filter testchain
-
-# chains: add and delete base chain
-add chain filter input { type filter hook input priority 0 ; }
-delete chain filter input
-
-# chains: can not delete chain while referenced
-add chain filter testchain
-add chain filter testchain2
-
-add rule filter testchain handle 1 jump testchain2
-delete chain filter testchain2
-delete rule filter testchain handle 1
-
-delete chain filter testchain2
-delete chain filter testchain
Signature · 1 line
2.13.6
author
#8 lore raw

PATCH 8/9 tests: files: Remove tests for table.

In reply to Varsha Rao

This patch removes test case for table. As test case for it is present in tests/shell file.

---
 tests/files/obj-table | 9 ---------
 1 file changed, 9 deletions(-)
 delete mode 100644 tests/files/obj-table
tests/files/obj-table deleted +0 -9
deleted file mode 100644
index 8b264cf..0000000
@@ -1,9 +0,0 @@
-#! nft -f
-
-# table: add and delete table
-add table filter
-table delete filter
-
-# table: deleting table with chain must fail
-add chain filter output
-table delete filter
Signature · 1 line
2.13.6
author
#9 lore raw

PATCH 9/9 tests: files: Remove tests for verdict maps.

In reply to Varsha Rao

Remove test cases for verdict maps. As they are already there in tests/shell file.

---
 tests/files/verdict-maps | 20 --------------------
 1 file changed, 20 deletions(-)
 delete mode 100644 tests/files/verdict-maps
tests/files/verdict-maps deleted +0 -20
deleted file mode 100644
index c1630ce..0000000
@@ -1,20 +0,0 @@
-#! nft -f
-#
-
-add table ip filter
-add chain ip filter input { type filter hook input priority 0; }
-
-add chain ip filter chain1
-add filter chain1 counter
-
-add chain ip filter chain2
-add filter chain2 counter
-
-add chain ip filter chain3
-add filter chain3 counter
-
-add filter input ip saddr vmap { \
-	10.0.0.0/24 : jump chain1, \
-	10.0.0.0/8  : jump chain2, \
-	8.8.8.8 : jump chain3 \
-}
Signature · 1 line
2.13.6
#10 lore raw
In reply to Varsha Rao

Hi Varsha,

Quoted 1 line · Varsha Rao

Test files of tests/files/ are moved to tests/shell.

We have more than 100 tests these days, could you have a look at the repository to see if this is adding redundant tests for what we have? If we already have a test covering the same configuration, we should just remove them from tests/files/.

Thanks.

author
#11 lore raw

Hello Pablo,

Quoted 10 lines · Pablo Neira Ayuso

Hi Varsha,

Quoted 1 line · Varsha Rao

Test files of tests/files/ are moved to tests/shell.

We have more than 100 tests these days, could you have a look at the repository to see if this is adding redundant tests for what we have? If we already have a test covering the same configuration, we should just remove them from tests/files/.

Sorry, the cover letter title and commit message looks misleading. But I have removed the redundant ones and added tests which were not there.

Thanks,
Varsha

#12 lore raw
Quoted 8 lines · Varsha Rao

Hello Pablo,

Quoted 5 lines · Pablo Neira Ayuso

Hi Varsha,

Quoted 1 line · Varsha Rao

Test files of tests/files/ are moved to tests/shell.

Quoted 8 lines
Quoted 5 lines

We have more than 100 tests these days, could you have a look at the repository to see if this is adding redundant tests for what we have? If we already have a test covering the same configuration, we should just remove them from tests/files/.

Sorry, the cover letter title and commit message looks misleading. But I have removed the redundant ones and added tests which were not there.

Thanks for clarifying, I have applied this.