[Fuego] [PATCH] nicstat: Add test cases of command nicstat.

Yuan Chao yuanc.fnst at cn.fujitsu.com
Wed Jun 12 00:56:00 UTC 2019


This is a simple test to check the option extended/help/interface/list/parseable/tcp/times/udp/version of command nicstat.

Signed-off-by: Yuan Chao <yuanc.fnst at cn.fujitsu.com>
---
 tests/Functional.nicstat/fuego_test.sh              | 17 +++++++++++++++++
 tests/Functional.nicstat/nicstat_test.sh            |  4 ++++
 tests/Functional.nicstat/parser.py                  | 20 ++++++++++++++++++++
 tests/Functional.nicstat/spec.json                  |  6 ++++++
 tests/Functional.nicstat/test.yaml                  | 19 +++++++++++++++++++
 tests/Functional.nicstat/tests/nicstat_extended.sh  | 15 +++++++++++++++
 tests/Functional.nicstat/tests/nicstat_help.sh      | 15 +++++++++++++++
 tests/Functional.nicstat/tests/nicstat_interface.sh | 15 +++++++++++++++
 tests/Functional.nicstat/tests/nicstat_list.sh      | 13 +++++++++++++
 tests/Functional.nicstat/tests/nicstat_parseable.sh | 15 +++++++++++++++
 tests/Functional.nicstat/tests/nicstat_tcp.sh       | 13 +++++++++++++
 tests/Functional.nicstat/tests/nicstat_times.sh     | 15 +++++++++++++++
 tests/Functional.nicstat/tests/nicstat_udp.sh       | 13 +++++++++++++
 tests/Functional.nicstat/tests/nicstat_version.sh   | 13 +++++++++++++
 14 files changed, 193 insertions(+)
 create mode 100644 tests/Functional.nicstat/fuego_test.sh
 create mode 100644 tests/Functional.nicstat/nicstat_test.sh
 create mode 100644 tests/Functional.nicstat/parser.py
 create mode 100644 tests/Functional.nicstat/spec.json
 create mode 100644 tests/Functional.nicstat/test.yaml
 create mode 100644 tests/Functional.nicstat/tests/nicstat_extended.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_help.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_interface.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_list.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_parseable.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_tcp.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_times.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_udp.sh
 create mode 100644 tests/Functional.nicstat/tests/nicstat_version.sh

diff --git a/tests/Functional.nicstat/fuego_test.sh b/tests/Functional.nicstat/fuego_test.sh
new file mode 100644
index 0000000..38d79fa
--- /dev/null
+++ b/tests/Functional.nicstat/fuego_test.sh
@@ -0,0 +1,17 @@
+function test_pre_check {
+    assert_has_program nicstat
+}
+
+function test_deploy {
+    put $TEST_HOME/nicstat_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./nicstat_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/tests/Functional.nicstat/nicstat_test.sh b/tests/Functional.nicstat/nicstat_test.sh
new file mode 100644
index 0000000..dd5ce37
--- /dev/null
+++ b/tests/Functional.nicstat/nicstat_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/tests/Functional.nicstat/parser.py b/tests/Functional.nicstat/parser.py
new file mode 100644
index 0000000..f25a608
--- /dev/null
+++ b/tests/Functional.nicstat/parser.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+# See common.py for description of command-line arguments
+
+import os, sys, collections
+import common as plib
+
+measurements = {}
+measurements = collections.OrderedDict()
+
+regex_string = '^ -> (.*): TEST-(.*)$'
+matches = plib.parse_log(regex_string)
+
+if matches:
+    for m in matches:
+        measurements['default.' + m[0]] = 'PASS' if m[1] == 'PASS' else 'FAIL'
+
+# split the output for each testcase
+plib.split_output_per_testcase(regex_string, measurements)
+
+sys.exit(plib.process(measurements))
diff --git a/tests/Functional.nicstat/spec.json b/tests/Functional.nicstat/spec.json
new file mode 100644
index 0000000..43c3796
--- /dev/null
+++ b/tests/Functional.nicstat/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.nicstat",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/tests/Functional.nicstat/test.yaml b/tests/Functional.nicstat/test.yaml
new file mode 100644
index 0000000..df1deba
--- /dev/null
+++ b/tests/Functional.nicstat/test.yaml
@@ -0,0 +1,19 @@
+fuego_package_version: 1
+name: Functional.nicstat
+description: |
+        Nicstat a tool for printing network traffic statistics.
+        This is a simple test to check the option extended/help/interface/list/parseable/tcp/times/udp/version of command nicstat.
+license: BSD-3-Clause
+author: Yuan Chao <yuanc.fnst at cn.fujitsu.com>
+maintainer: Wang Mingyu <wangmy at cn.fujitsu.com>
+version: 1.00
+fuego_release: 1
+type: Functional
+tags: ['nic']
+data_files:
+ - nicstat_test.sh
+ - fuego_test.sh
+ - parser.py
+ - spec.json
+ - test.yaml
+ - tests
diff --git a/tests/Functional.nicstat/tests/nicstat_extended.sh b/tests/Functional.nicstat/tests/nicstat_extended.sh
new file mode 100644
index 0000000..16fa6e4
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_extended.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if extended option can execute.
+#  1) Option: -x
+
+test="nicstat"
+
+test_nic=$(nicstat -l | cut -d ' ' -f 1 | sed -n '2p')
+
+if nicstat -x | grep "$test_nic"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.nicstat/tests/nicstat_help.sh b/tests/Functional.nicstat/tests/nicstat_help.sh
new file mode 100644
index 0000000..a8fc86c
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_help.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if help option can execute.
+#  1) Option: -h
+
+test="nicstat"
+nicstat -h > help.txt 2>&1
+
+if cat help.txt | grep "USAGE"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f help.txt
diff --git a/tests/Functional.nicstat/tests/nicstat_interface.sh b/tests/Functional.nicstat/tests/nicstat_interface.sh
new file mode 100644
index 0000000..0cdce0b
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_interface.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if interface option can execute.
+#  1) Option: -i
+
+test="nicstat"
+
+test_nic=$(nicstat -l | cut -d ' ' -f 1 | sed -n '2p')
+
+if nicstat -i $test_nic | grep "Time"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.nicstat/tests/nicstat_list.sh b/tests/Functional.nicstat/tests/nicstat_list.sh
new file mode 100644
index 0000000..0c80903
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_list.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if list option can execute.
+#  1) Option: -l
+
+test="nicstat"
+
+if nicstat -l | grep "Int"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.nicstat/tests/nicstat_parseable.sh b/tests/Functional.nicstat/tests/nicstat_parseable.sh
new file mode 100644
index 0000000..b3655de
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_parseable.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if parseable option can execute.
+#  1) Option: -p
+
+test="nicstat"
+
+test_nic=$(nicstat -l | cut -d ' ' -f 1 | sed -n '2p')
+
+if nicstat -p | grep ":${test_nic}:"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.nicstat/tests/nicstat_tcp.sh b/tests/Functional.nicstat/tests/nicstat_tcp.sh
new file mode 100644
index 0000000..ba909ed
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_tcp.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if tcp option can execute.
+#  1) Option: -t
+
+test="nicstat"
+
+if nicstat -t | grep "TCP"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.nicstat/tests/nicstat_times.sh b/tests/Functional.nicstat/tests/nicstat_times.sh
new file mode 100644
index 0000000..cabe392
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_times.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if right output can be print when set times.
+#  1) Option: none
+
+test="nicstat"
+
+test_times="3"
+
+if [ "$(nicstat 1 $test_times | grep "Time" | wc -l)" = "$test_times" ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.nicstat/tests/nicstat_udp.sh b/tests/Functional.nicstat/tests/nicstat_udp.sh
new file mode 100644
index 0000000..2c3b066
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_udp.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if udp option can execute.
+#  1) Option: -u
+
+test="nicstat"
+
+if nicstat -u | grep "UDP"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.nicstat/tests/nicstat_version.sh b/tests/Functional.nicstat/tests/nicstat_version.sh
new file mode 100644
index 0000000..f2a708b
--- /dev/null
+++ b/tests/Functional.nicstat/tests/nicstat_version.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command nicstat, and check if version option can execute.
+#  1) Option: -v
+
+test="nicstat"
+
+if nicstat -v | grep "version"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
-- 
1.8.3.1





More information about the Fuego mailing list