Skip to contentSkip to conversation

ethtool: Add test cases for command ethtool.

PATCH In review Wang Mingyu 2 participants 2 messages Sep 6, 2018 – Sep 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ethtool: Add test cases for command ethtool.

---
 engine/tests/Functional.ethtool/ethtool_test.sh    |  4 ++++
 engine/tests/Functional.ethtool/fuego_test.sh      | 18 ++++++++++++++++++
 engine/tests/Functional.ethtool/parser.py          | 22 ++++++++++++++++++++++
 engine/tests/Functional.ethtool/spec.json          |  7 +++++++
 .../Functional.ethtool/tests/ethtool_driver.sh     | 13 +++++++++++++
 .../tests/Functional.ethtool/tests/ethtool_help.sh | 13 +++++++++++++
 .../tests/Functional.ethtool/tests/ethtool_show.sh | 13 +++++++++++++
 7 files changed, 90 insertions(+)
 create mode 100644 engine/tests/Functional.ethtool/ethtool_test.sh
 create mode 100644 engine/tests/Functional.ethtool/fuego_test.sh
 create mode 100644 engine/tests/Functional.ethtool/parser.py
 create mode 100644 engine/tests/Functional.ethtool/spec.json
 create mode 100644 engine/tests/Functional.ethtool/tests/ethtool_driver.sh
 create mode 100644 engine/tests/Functional.ethtool/tests/ethtool_help.sh
 create mode 100644 engine/tests/Functional.ethtool/tests/ethtool_show.sh
engine/tests/Functional.ethtool/ethtool_test.sh new file +4 -0
new file mode 100644
index 0000000..dd5ce37
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
engine/tests/Functional.ethtool/fuego_test.sh new file +18 -0
new file mode 100644
index 0000000..73193cb
@@ -0,0 +1,18 @@
+function test_pre_check {
+    is_on_target_path ethtool PROGRAM_ETHTOOL
+    assert_define PROGRAM_ETHTOOL "Missing 'ethtool' program on target board"
+}
+
+function test_deploy {
+    put $TEST_HOME/ethtool_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    sh -v ethtool_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
engine/tests/Functional.ethtool/parser.py new file +22 -0
new file mode 100644
index 0000000..d85abd7
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+# See common.py for description of command-line arguments
+
+import os, sys, collections
+
+sys.path.insert(0, os.environ['FUEGO_CORE'] + '/engine/scripts/parser')
+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))
engine/tests/Functional.ethtool/spec.json new file +7 -0
new file mode 100644
index 0000000..c16b2d5
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.ethtool",
+    "specs": {
+        "default": {}
+    }
+}
+
engine/tests/Functional.ethtool/tests/ethtool_driver.sh new file +13 -0
new file mode 100644
index 0000000..4be4aba
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run comannd ethtool.
+#  option: -i
+
+test="driver"
+
+if ethtool -i eth0 | grep driver
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.ethtool/tests/ethtool_help.sh new file +13 -0
new file mode 100644
index 0000000..cb3a72f
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run comannd ethtool.
+#  option: help
+
+test="help"
+
+if ethtool -h | grep Usage
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.ethtool/tests/ethtool_show.sh new file +13 -0
new file mode 100644
index 0000000..63c1ae0
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run comannd ethtool.
+#  option: none
+
+test="show"
+
+if ethtool eth0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
Signature · 1 line
1.8.3.1
#1 lore raw

See comments inline below.

Quoted 47 lines

-----Original Message-----
From: Wang Mingyu

---
 engine/tests/Functional.ethtool/ethtool_test.sh    |  4 ++++
 engine/tests/Functional.ethtool/fuego_test.sh      | 18
++++++++++++++++++
 engine/tests/Functional.ethtool/parser.py          | 22
++++++++++++++++++++++
 engine/tests/Functional.ethtool/spec.json          |  7 +++++++
 .../Functional.ethtool/tests/ethtool_driver.sh     | 13 +++++++++++++
 .../tests/Functional.ethtool/tests/ethtool_help.sh | 13 +++++++++++++
 .../tests/Functional.ethtool/tests/ethtool_show.sh | 13 +++++++++++++
 7 files changed, 90 insertions(+)
 create mode 100644 engine/tests/Functional.ethtool/ethtool_test.sh
 create mode 100644 engine/tests/Functional.ethtool/fuego_test.sh
 create mode 100644 engine/tests/Functional.ethtool/parser.py
 create mode 100644 engine/tests/Functional.ethtool/spec.json
 create mode 100644
engine/tests/Functional.ethtool/tests/ethtool_driver.sh
 create mode 100644 engine/tests/Functional.ethtool/tests/ethtool_help.sh
 create mode 100644

engine/tests/Functional.ethtool/tests/ethtool_show.sh

engine/tests/Functional.ethtool/ethtool_test.sh new file +4 -0
new file mode 100644
index 0000000..dd5ce37
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
engine/tests/Functional.ethtool/fuego_test.sh new file +3 -0
new file mode 100644
index 0000000..73193cb
@@ -0,0 +1,18 @@
+function test_pre_check {
+    is_on_target_path ethtool PROGRAM_ETHTOOL
+    assert_define PROGRAM_ETHTOOL "Missing 'ethtool' program on target

board"

engine/tests/Functional.ethtool/fuego_test.sh line 13

Quoted 10 lines
engine/tests/Functional.ethtool/fuego_test.sh new file +10 -0
+}
+
+function test_deploy {
+    put $TEST_HOME/ethtool_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    sh -v ethtool_test.sh"

You should use "./ethtool_test.sh" instead of 'sh -v ethtool_test.sh'.

If you really want the '-v' argument, you can add it to the ethtool_test.sh invocation line (the so-called 'shebang'), like so:
#!/bin/sh -v

It's a bit better if Fuego doesn't know whether the test program it's executing is a script or a program.

Quoted 24 lines
engine/tests/Functional.ethtool/fuego_test.sh new file +5 -0
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
engine/tests/Functional.ethtool/parser.py new file +12 -0
new file mode 100644
index 0000000..d85abd7
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+# See common.py for description of command-line arguments
+
+import os, sys, collections
+
+sys.path.insert(0, os.environ['FUEGO_CORE'] + '/engine/scripts/parser')
+import common as plib
+
+measurements = {}
+measurements = collections.OrderedDict()
+
+regex_string = '^ -> (.*): TEST-(.*)$'

engine/tests/Functional.ethtool/parser.py line 22

Quoted 10 lines
engine/tests/Functional.ethtool/parser.py new file +10 -0
+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))

This can be simplified if we add a new routine to handle this in the common.py module. See what I wrote Zheng on this issue.

Quoted 21 lines
engine/tests/Functional.ethtool/spec.json new file +7 -0
new file mode 100644
index 0000000..c16b2d5
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.ethtool",
+    "specs": {
+        "default": {}
+    }
+}
+
engine/tests/Functional.ethtool/tests/ethtool_driver.sh new file +0 -0
new file mode 100644
index 0000000..4be4aba

engine/tests/Functional.ethtool/tests/ethtool_driver.sh line 8

Quoted 8 lines
engine/tests/Functional.ethtool/tests/ethtool_driver.sh new file +8 -0
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run comannd ethtool.
+#  option: -i
+
+test="driver"
+
+if ethtool -i eth0 | grep driver

eth0 is board-specific. Other boards may have different network device names. I have a machine here where the wired ethernet device is called 'eno1'

You could add this to the board file, as:
ETHERNET_DEVICE_NAME="eth0",
and document it in a test.yaml file.
(It is good practice to document all data required from the board file and all spec variables in a test's test.yaml file.)

And then this line would become:
ethtool -I $ETHERNET_DEVICE_NAME

However, another approach is to auto-detect it.
I think it would be pretty easy to detect it by running ifconfig or looking in /proc/net/dev. You might need sed or awk to extract the network device names, and you'd have to check to see if the the particular ethtool test you want to run makes sense on that device.
You could probably check for the string "0baseT" in 'ethtool $device' output to see if this was really an Ethernet device, as opposed to some other kind of network device.

It is always much nicer when a test autodetects the data or devices it needs to use, rather than requiring the user to specify them. So I would recommend this approach.

Quoted 32 lines
engine/tests/Functional.ethtool/tests/ethtool_driver.sh new file +5 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.ethtool/tests/ethtool_help.sh new file +13 -0
new file mode 100644
index 0000000..cb3a72f
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run comannd ethtool.
+#  option: help
+
+test="help"
+
+if ethtool -h | grep Usage
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.ethtool/tests/ethtool_show.sh new file +0 -0
new file mode 100644
index 0000000..63c1ae0

engine/tests/Functional.ethtool/tests/ethtool_show.sh line 8

Quoted 8 lines
engine/tests/Functional.ethtool/tests/ethtool_show.sh new file +8 -0
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run comannd ethtool.
+#  option: none
+
+test="show"
+
+if ethtool eth0

'eth0' should be turned into a parameter here.

Also, you should check the output with grep, rather than just see if the command returned.

Quoted 7 lines
engine/tests/Functional.ethtool/tests/ethtool_show.sh new file +5 -1
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
--

1.8.3.1

Please at least convert to a parameterized (if not auto-detected) network device name for this test.
-- Tim