[Fuego] [PATCH v2] bluez_utils: add test cases for bluez_utils.

Zheng Ruoqin zhengrq.fnst at cn.fujitsu.com
Fri Dec 21 01:20:48 UTC 2018


Signed-off-by: Zheng Ruoqin <zhengrq.fnst at cn.fujitsu.com>
---
 .../Functional.bluez_utils/bluez_utils_test.sh     |  4 +
 .../tests/Functional.bluez_utils/datas/testfunc.sh | 15 ++++
 engine/tests/Functional.bluez_utils/fuego_test.sh  | 23 ++++++
 engine/tests/Functional.bluez_utils/parser.py      | 22 ++++++
 engine/tests/Functional.bluez_utils/spec.json      |  6 ++
 .../Functional.bluez_utils/tests/bluez_utils_01.sh | 13 ++++
 .../Functional.bluez_utils/tests/bluez_utils_02.sh | 13 ++++
 .../Functional.bluez_utils/tests/bluez_utils_03.sh | 37 ++++++++++
 .../Functional.bluez_utils/tests/bluez_utils_04.sh | 86 ++++++++++++++++++++++
 9 files changed, 219 insertions(+)
 create mode 100644 engine/tests/Functional.bluez_utils/bluez_utils_test.sh
 create mode 100644 engine/tests/Functional.bluez_utils/datas/testfunc.sh
 create mode 100644 engine/tests/Functional.bluez_utils/fuego_test.sh
 create mode 100644 engine/tests/Functional.bluez_utils/parser.py
 create mode 100644 engine/tests/Functional.bluez_utils/spec.json
 create mode 100644 engine/tests/Functional.bluez_utils/tests/bluez_utils_01.sh
 create mode 100644 engine/tests/Functional.bluez_utils/tests/bluez_utils_02.sh
 create mode 100644 engine/tests/Functional.bluez_utils/tests/bluez_utils_03.sh
 create mode 100644 engine/tests/Functional.bluez_utils/tests/bluez_utils_04.sh

diff --git a/engine/tests/Functional.bluez_utils/bluez_utils_test.sh b/engine/tests/Functional.bluez_utils/bluez_utils_test.sh
new file mode 100644
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/bluez_utils_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.bluez_utils/datas/testfunc.sh b/engine/tests/Functional.bluez_utils/datas/testfunc.sh
new file mode 100644
index 0000000..e3cacd6
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/datas/testfunc.sh
@@ -0,0 +1,15 @@
+#$1: Specify the service_name
+#$2: Specify the action
+
+function exec_service_on_target { 
+    local service_name="$1"
+    local action="$2"
+    if [ "$init_manager" = "sysvinit" ]
+    then 
+        service $service_name $action
+    elif [ "$init_manager" = "systemd" ]
+    then
+        systemctl $action $service_name
+    fi
+    return
+}
diff --git a/engine/tests/Functional.bluez_utils/fuego_test.sh b/engine/tests/Functional.bluez_utils/fuego_test.sh
new file mode 100644
index 0000000..ec00752
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/fuego_test.sh
@@ -0,0 +1,23 @@
+function test_pre_check {
+    assert_has_program ciptool
+    assert_has_program hcitool
+    assert_has_program dfu-util
+    assert_has_program l2ping
+    assert_has_program rfcomm
+}
+
+function test_deploy {
+    put $TEST_HOME/bluez_utils_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/engine/scripts/fuego_board_function_lib.sh $BOARD_TESTDIR/fuego.$TESTDIR
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/datas $BOARD_TESTDIR/fuego.$TESTDIR/ 
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    sh bluez_utils_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.bluez_utils/parser.py b/engine/tests/Functional.bluez_utils/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/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.bluez_utils/spec.json b/engine/tests/Functional.bluez_utils/spec.json
new file mode 100644
index 0000000..a3cea8e
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.bluez_utils",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/engine/tests/Functional.bluez_utils/tests/bluez_utils_01.sh b/engine/tests/Functional.bluez_utils/tests/bluez_utils_01.sh
new file mode 100644
index 0000000..8751202
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/tests/bluez_utils_01.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# In target, run comannd ciptool.
+# To make sure that the string "Usage" is in output.
+
+test="bluez_utils01"
+
+if ciptool --help | grep .*Usage.*
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.bluez_utils/tests/bluez_utils_02.sh b/engine/tests/Functional.bluez_utils/tests/bluez_utils_02.sh
new file mode 100644
index 0000000..6abbead
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/tests/bluez_utils_02.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# In target, run comannd hcitool.
+# To make sure that the string "Usage" is in output.
+
+test="bluez_utils02"
+
+if hcitool --help | grep ".*Usage.*"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.bluez_utils/tests/bluez_utils_03.sh b/engine/tests/Functional.bluez_utils/tests/bluez_utils_03.sh
new file mode 100644
index 0000000..d127950
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/tests/bluez_utils_03.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# In target, run comannd dfu-util
+# To make sure that the string "dfu-util" is in output.
+
+# In target, run comannd l2ping, rfcomm, sdptool.
+# To make sure that the string "Usage" is in output.
+
+test="bluez_utils03"
+
+if dfu-util -V | grep ".*dfu-util.*"
+then
+    echo " -> execute dfu-util succedded."
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+
+if l2ping --help | grep ".*Usage.*"
+then
+    echo " -> execute l2ping succedded."
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+
+if rfcomm --help | grep ".*Usage.*"
+then
+    echo " -> execute rfcomm succedded."
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+
+if sdptool --help | grep ".*Usage.*"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.bluez_utils/tests/bluez_utils_04.sh b/engine/tests/Functional.bluez_utils/tests/bluez_utils_04.sh
new file mode 100644
index 0000000..6548f26
--- /dev/null
+++ b/engine/tests/Functional.bluez_utils/tests/bluez_utils_04.sh
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+#  In the target start bluetooth, and confirm the process condition by command ps.
+#  check the keyword "bluetooth".
+
+test="bluez_utils04"
+
+source "datas/testfunc.sh"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+dbus_status=$(exec_service_on_target dbus is-active)
+
+if exec_service_on_target dbus restart
+then
+    echo " -> restart of dbus succedded."
+else
+    echo " -> restart of dbus failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ps aux | grep [d]bus
+then
+    echo " -> get dbus succedded."
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+#Restore the service status of bluetooth
+if [ "$dbus_status" != "active" ]
+then
+   if exec_service_on_target dbus stop
+   then
+       echo " -> stop of dbus succedded."
+   else
+       echo " -> stop of dbus failed."
+       echo " -> $test: TEST-FAIL"
+       exit
+   fi
+fi
+
+bluetooth_status=`exec_service_on_target bluetooth is-active`
+
+exec_service_on_target bluetooth stop
+
+if exec_service_on_target bluetooth start
+then
+    echo " -> start of bluetooth succedded."
+else
+    echo " -> start of bluetooth failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ps aux | grep [b]luetooth
+then
+    echo " -> get bluetooth succedded."
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+exec_service_on_target bluetooth stop
+
+if ps aux | grep [b]luetooth
+then
+    echo " -> $test: TEST-FAIL"
+fi
+
+#Restore the service status of bluetooth
+if [ "$bluetooth_status" = "active" ]
+then
+   if exec_service_on_target bluetooth start
+   then
+       echo " -> start of bluetooth succedded."
+       echo " -> $test: TEST-PASS"
+   else
+       echo " -> start of bluetooth failed."
+       echo " -> $test: TEST-FAIL"
+       exit
+   fi
+else
+   echo " -> $test: TEST-PASS"
+fi
-- 
1.8.3.1





More information about the Fuego mailing list