[Skiboot] [PATCH 8/8] gard: Add tests
Oliver O'Halloran
oohall at gmail.com
Thu Nov 30 16:31:29 AEDT 2017
I hear Stewart likes these for some reason. Dunno why.
Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
external/gard/test/add_test.sh | 67 +++++++++++++++++++++
external/gard/test/files/blank.bin | Bin 0 -> 20480 bytes
.../gard/test/results/04-create-bad-instance.err | 2 +
.../gard/test/results/04-create-bad-instance.out | 0
external/gard/test/results/05-create-bad-unit.err | 2 +
external/gard/test/results/05-create-bad-unit.out | 0
external/gard/test/results/06-create-long-path.err | 2 +
external/gard/test/results/06-create-long-path.out | 0
external/gard/test/results/07-create-slash.err | 2 +
external/gard/test/results/07-create-slash.out | 0
external/gard/test/results/08-create-duplicate.err | 1 +
external/gard/test/results/08-create-duplicate.out | 0
external/gard/test/results/09-create-last-unit.err | 0
external/gard/test/results/09-create-last-unit.out | 4 ++
external/gard/test/tests/00-list | 2 +-
external/gard/test/tests/01-show_1 | 2 +-
external/gard/test/tests/04-create-bad-instance | 10 +++
external/gard/test/tests/05-create-bad-unit | 10 +++
external/gard/test/tests/06-create-long-path | 10 +++
external/gard/test/tests/07-create-slash | 10 +++
external/gard/test/tests/08-create-duplicate | 10 +++
external/gard/test/tests/09-create-last-unit | 16 +++++
22 files changed, 148 insertions(+), 2 deletions(-)
create mode 100755 external/gard/test/add_test.sh
create mode 100644 external/gard/test/files/blank.bin
create mode 100644 external/gard/test/results/04-create-bad-instance.err
create mode 100644 external/gard/test/results/04-create-bad-instance.out
create mode 100644 external/gard/test/results/05-create-bad-unit.err
create mode 100644 external/gard/test/results/05-create-bad-unit.out
create mode 100644 external/gard/test/results/06-create-long-path.err
create mode 100644 external/gard/test/results/06-create-long-path.out
create mode 100644 external/gard/test/results/07-create-slash.err
create mode 100644 external/gard/test/results/07-create-slash.out
create mode 100644 external/gard/test/results/08-create-duplicate.err
create mode 100644 external/gard/test/results/08-create-duplicate.out
create mode 100644 external/gard/test/results/09-create-last-unit.err
create mode 100644 external/gard/test/results/09-create-last-unit.out
create mode 100644 external/gard/test/tests/04-create-bad-instance
create mode 100644 external/gard/test/tests/05-create-bad-unit
create mode 100644 external/gard/test/tests/06-create-long-path
create mode 100644 external/gard/test/tests/07-create-slash
create mode 100644 external/gard/test/tests/08-create-duplicate
create mode 100644 external/gard/test/tests/09-create-last-unit
diff --git a/external/gard/test/add_test.sh b/external/gard/test/add_test.sh
new file mode 100755
index 000000000000..8e7736096414
--- /dev/null
+++ b/external/gard/test/add_test.sh
@@ -0,0 +1,67 @@
+#!/bin/bash -uex
+#
+# this is a really dumb script for auto-generating test cases from known good-data
+#
+# usage: ./add_test <pass|fail> <inputfile> <testname> [gard subcommand]
+#
+# e.g.
+# ./add_test.sh fail blank.bin create-bad-instance create /sys256
+# ./add_test.sh pass blank.bin create-normal create /sys0/node0/proc0
+#
+# this will generate a test script file and writes the stdout/stderr of the command
+# to the respective files.
+#
+
+cd $(dirname $(realpath $0))/../
+echo $PWD
+
+if [ "$1" = "pass" ]; then
+ check='if [ "$?" -ne 0 ]; then'
+ test_type="pass"
+else
+ check='if [ "$?" -eq 0 ]; then'
+ test_type="fails"
+fi
+shift
+
+file="test/files/$1"
+if [ ! -f "$file" ]; then
+ echo "test file not found!"
+ exit 1;
+fi
+shift
+
+name="$1"
+shift
+
+max="$(ls test/tests/ -1|sort -n | sed 's@\(..\).*@\1@' | tail -1 | sed s@^0*@@)"
+num="$(printf %02d $((max + 1)))"
+
+echo "Adding: $num-$name"
+
+# where we will write the script file
+script_file="test/tests/$num-$name"
+
+echo "making $num-$name: f=$script_file, normally $test_type, cmd='$*'"
+
+cat > $script_file <<EOF
+#! /bin/sh
+
+run_binary "./gard" "-9 -p -e -f $file $*"
+$check
+ fail_test
+fi
+
+diff_with_result
+
+pass_test
+EOF
+
+# generate the .out and .err files
+stdout_file="test/results/$num-$name.out"
+stderr_file="test/results/$num-$name.err"
+
+test_input="$name-$num-input"
+cp $file $test_input
+./gard -f $test_input -p -e $* 2>$stderr_file >$stdout_file
+rm -f $test_input
diff --git a/external/gard/test/files/blank.bin b/external/gard/test/files/blank.bin
new file mode 100644
index 0000000000000000000000000000000000000000..c6cc6b8c239e484ec62bbc701ccf4c733a792a36
GIT binary patch
literal 20480
zcmeIxu?YYG2m?X)Upfjpg5}x7`r(qjx{YT_h#&$N6i`3`1r$&~0R<FLKmi35P(T3%
z6i`3`1r$&~0R<FLKmi35P(T3%6i`3`1r$&~0R<FLKmi35P(T3%6i`3`1r$&~0R<FL
cKmi35P(T3%6i`3`1r$&~0R<FLK*6tq28;XI{r~^~
literal 0
HcmV?d00001
diff --git a/external/gard/test/results/04-create-bad-instance.err b/external/gard/test/results/04-create-bad-instance.err
new file mode 100644
index 000000000000..2a8da501a9da
--- /dev/null
+++ b/external/gard/test/results/04-create-bad-instance.err
@@ -0,0 +1,2 @@
+Instance 256 is invalid. Must be 0 to 255
+Unable to parse path
diff --git a/external/gard/test/results/04-create-bad-instance.out b/external/gard/test/results/04-create-bad-instance.out
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/external/gard/test/results/05-create-bad-unit.err b/external/gard/test/results/05-create-bad-unit.err
new file mode 100644
index 000000000000..aa1af82f5afb
--- /dev/null
+++ b/external/gard/test/results/05-create-bad-unit.err
@@ -0,0 +1,2 @@
+Unknown unit at: 'doesnt_exist0'
+Unable to parse path
diff --git a/external/gard/test/results/05-create-bad-unit.out b/external/gard/test/results/05-create-bad-unit.out
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/external/gard/test/results/06-create-long-path.err b/external/gard/test/results/06-create-long-path.err
new file mode 100644
index 000000000000..f79a3bda988f
--- /dev/null
+++ b/external/gard/test/results/06-create-long-path.err
@@ -0,0 +1,2 @@
+Path has more than 10 components!
+Unable to parse path
diff --git a/external/gard/test/results/06-create-long-path.out b/external/gard/test/results/06-create-long-path.out
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/external/gard/test/results/07-create-slash.err b/external/gard/test/results/07-create-slash.err
new file mode 100644
index 000000000000..6fd6876043d8
--- /dev/null
+++ b/external/gard/test/results/07-create-slash.err
@@ -0,0 +1,2 @@
+Unknown unit at: ''
+Unable to parse path
diff --git a/external/gard/test/results/07-create-slash.out b/external/gard/test/results/07-create-slash.out
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/external/gard/test/results/08-create-duplicate.err b/external/gard/test/results/08-create-duplicate.err
new file mode 100644
index 000000000000..4c4073953744
--- /dev/null
+++ b/external/gard/test/results/08-create-duplicate.err
@@ -0,0 +1 @@
+Unit /Sys0/Node0/Membuf0 is already GARDed by record 0x000002
diff --git a/external/gard/test/results/08-create-duplicate.out b/external/gard/test/results/08-create-duplicate.out
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/external/gard/test/results/09-create-last-unit.err b/external/gard/test/results/09-create-last-unit.err
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/external/gard/test/results/09-create-last-unit.out b/external/gard/test/results/09-create-last-unit.out
new file mode 100644
index 000000000000..62cfcbbd0a66
--- /dev/null
+++ b/external/gard/test/results/09-create-last-unit.out
@@ -0,0 +1,4 @@
+ ID | Error | Type | Path
+----------------------------------------------------------------------------------------------------------------------------------------------------------------
+ 00000001 | 00000000 | Manual | /MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255
+================================================================================================================================================================
diff --git a/external/gard/test/tests/00-list b/external/gard/test/tests/00-list
index 8e285c43473c..aa38fc3cf671 100644
--- a/external/gard/test/tests/00-list
+++ b/external/gard/test/tests/00-list
@@ -1,6 +1,6 @@
#! /bin/sh
-run_binary "./gard" "-p -e -f test/files/data1.bin list"
+run_binary "./gard" "-p -e -8 -f test/files/data1.bin list"
if [ "$?" -ne 0 ] ; then
fail_test
fi
diff --git a/external/gard/test/tests/01-show_1 b/external/gard/test/tests/01-show_1
index 66ee7321fc93..dc67b93e0e3b 100644
--- a/external/gard/test/tests/01-show_1
+++ b/external/gard/test/tests/01-show_1
@@ -1,6 +1,6 @@
#! /bin/sh
-run_binary "./gard" "-p -e -f test/files/data1.bin show 1"
+run_binary "./gard" "-p -e -8 -f test/files/data1.bin show 1"
if [ "$?" -ne 0 ] ; then
fail_test
fi
diff --git a/external/gard/test/tests/04-create-bad-instance b/external/gard/test/tests/04-create-bad-instance
new file mode 100644
index 000000000000..29e08bd16e1a
--- /dev/null
+++ b/external/gard/test/tests/04-create-bad-instance
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+run_binary "./gard" "-p -e -8 -f test/files/blank.bin create /sys256"
+if [ "$?" -eq 0 ]; then
+ fail_test
+fi
+
+diff_with_result
+
+pass_test
diff --git a/external/gard/test/tests/05-create-bad-unit b/external/gard/test/tests/05-create-bad-unit
new file mode 100644
index 000000000000..cfe4b71e8189
--- /dev/null
+++ b/external/gard/test/tests/05-create-bad-unit
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+run_binary "./gard" "-p -e -f test/files/blank.bin create /doesnt_exist0"
+if [ "$?" -eq 0 ]; then
+ fail_test
+fi
+
+diff_with_result
+
+pass_test
diff --git a/external/gard/test/tests/06-create-long-path b/external/gard/test/tests/06-create-long-path
new file mode 100644
index 000000000000..7eb197b60c1d
--- /dev/null
+++ b/external/gard/test/tests/06-create-long-path
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+run_binary "./gard" "-p -e -8 -f test/files/blank.bin create /sys0/sys0/sys0/sys0/sys0/sys0/sys0/sys0/sys0/sys0/sys0/sys0/"
+if [ "$?" -eq 0 ]; then
+ fail_test
+fi
+
+diff_with_result
+
+pass_test
diff --git a/external/gard/test/tests/07-create-slash b/external/gard/test/tests/07-create-slash
new file mode 100644
index 000000000000..3897a7b55622
--- /dev/null
+++ b/external/gard/test/tests/07-create-slash
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+run_binary "./gard" "-p -e -f test/files/blank.bin create /"
+if [ "$?" -eq 0 ]; then
+ fail_test
+fi
+
+diff_with_result
+
+pass_test
diff --git a/external/gard/test/tests/08-create-duplicate b/external/gard/test/tests/08-create-duplicate
new file mode 100644
index 000000000000..7179a1468fba
--- /dev/null
+++ b/external/gard/test/tests/08-create-duplicate
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+run_binary "./gard" "-p -e -8 -f test/files/data1.bin create /Sys0/Node0/Membuf0"
+if [ "$?" -eq 0 ]; then
+ fail_test
+fi
+
+diff_with_result
+
+pass_test
diff --git a/external/gard/test/tests/09-create-last-unit b/external/gard/test/tests/09-create-last-unit
new file mode 100644
index 000000000000..d293057d947f
--- /dev/null
+++ b/external/gard/test/tests/09-create-last-unit
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+cp test/files/blank.bin $DATA_DIR/input
+run_binary "./gard" "-9 -p -e -f $DATA_DIR/input create /MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255/MFREFCLK255"
+if [ "$?" -ne 0 ]; then
+ fail_test
+fi
+
+run_binary "./gard" "-9 -p -e -f $DATA_DIR/input list"
+if [ "$?" -ne 0 ]; then
+ fail_test
+fi
+
+diff_with_result
+
+pass_test
--
2.9.5
More information about the Skiboot
mailing list