[Fuego] [PATCH] Add test cases for command cryptsetup.

Wang Mingyu wangmy at cn.fujitsu.com
Tue Sep 18 15:57:30 UTC 2018


Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
---
 .../tests/Functional.cryptsetup/cryptsetup_test.sh |  4 +++
 engine/tests/Functional.cryptsetup/fuego_test.sh   | 18 ++++++++++++
 engine/tests/Functional.cryptsetup/parser.py       | 22 +++++++++++++++
 engine/tests/Functional.cryptsetup/spec.json       |  7 +++++
 .../tests/cryptsetup_create.sh                     | 32 ++++++++++++++++++++++
 .../Functional.cryptsetup/tests/cryptsetup_help.sh | 13 +++++++++
 6 files changed, 96 insertions(+)
 create mode 100755 engine/tests/Functional.cryptsetup/cryptsetup_test.sh
 create mode 100644 engine/tests/Functional.cryptsetup/fuego_test.sh
 create mode 100644 engine/tests/Functional.cryptsetup/parser.py
 create mode 100644 engine/tests/Functional.cryptsetup/spec.json
 create mode 100644 engine/tests/Functional.cryptsetup/tests/cryptsetup_create.sh
 create mode 100644 engine/tests/Functional.cryptsetup/tests/cryptsetup_help.sh

diff --git a/engine/tests/Functional.cryptsetup/cryptsetup_test.sh b/engine/tests/Functional.cryptsetup/cryptsetup_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.cryptsetup/cryptsetup_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.cryptsetup/fuego_test.sh b/engine/tests/Functional.cryptsetup/fuego_test.sh
new file mode 100644
index 0000000..7354b01
--- /dev/null
+++ b/engine/tests/Functional.cryptsetup/fuego_test.sh
@@ -0,0 +1,18 @@
+function test_pre_check {
+    is_on_target_path cryptsetup PROGRAM_CRYPTSETUP
+    assert_define PROGRAM_CRYPTSETUP "Missing 'cryptsetup' program on target board"
+}
+
+function test_deploy {
+    put $TEST_HOME/cryptsetup_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./cryptsetup_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.cryptsetup/parser.py b/engine/tests/Functional.cryptsetup/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.cryptsetup/parser.py
@@ -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))
diff --git a/engine/tests/Functional.cryptsetup/spec.json b/engine/tests/Functional.cryptsetup/spec.json
new file mode 100644
index 0000000..ec65501
--- /dev/null
+++ b/engine/tests/Functional.cryptsetup/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.cryptsetup",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.cryptsetup/tests/cryptsetup_create.sh b/engine/tests/Functional.cryptsetup/tests/cryptsetup_create.sh
new file mode 100644
index 0000000..98eb5d2
--- /dev/null
+++ b/engine/tests/Functional.cryptsetup/tests/cryptsetup_create.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command cryptsetup
+#  option: create
+
+test="create"
+
+modprobe loop
+
+dd if=/dev/zero of=/tmp/cryptloop bs=1k count=1000
+losetup -f
+losetup /dev/loop0 /tmp/cryptloop
+
+expect <<-EOF
+spawn cryptsetup create loop_test /dev/loop0
+expect {                
+ -re "Enter passphrase:" { 
+           send "test\n" 
+           send_user " -> $test: create loop_test succeeded.\n"
+          }
+ default { send_user " -> $test: TEST-FAIL\n" }  }
+expect eof
+EOF
+
+if ls /dev/mapper | grep loop_test
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+cryptsetup remove loop_test
+losetup -d /dev/loop0
diff --git a/engine/tests/Functional.cryptsetup/tests/cryptsetup_help.sh b/engine/tests/Functional.cryptsetup/tests/cryptsetup_help.sh
new file mode 100644
index 0000000..caa625d
--- /dev/null
+++ b/engine/tests/Functional.cryptsetup/tests/cryptsetup_help.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command cryptsetup
+#  option: --help
+
+test="help"
+
+if cryptsetup --help | grep Usage
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
-- 
1.8.3.1





More information about the Fuego mailing list