Return-Path: From: Wang Mingyu Date: Tue, 21 Aug 2018 06:38:07 -0700 Message-ID: <1534858691-25071-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCHv2] Add test cases for command acpid. List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org Signed-off-by: Wang Mingyu --- engine/tests/Functional.acpid/acpid_test.sh | 4 ++ engine/tests/Functional.acpid/datas/test_action.sh | 6 ++ engine/tests/Functional.acpid/datas/testfunc.sh | 13 ++++ engine/tests/Functional.acpid/datas/testhkey | 2 + engine/tests/Functional.acpid/fuego_test.sh | 20 +++++++ engine/tests/Functional.acpid/parser.py | 22 +++++++ engine/tests/Functional.acpid/spec.json | 7 +++ engine/tests/Functional.acpid/tests/acpid_help.sh | 13 ++++ .../tests/Functional.acpid/tests/acpid_logfile.sh | 47 +++++++++++++++ engine/tests/Functional.acpid/tests/acpid_ps.sh | 41 +++++++++++++ .../tests/Functional.acpid/tests/acpid_reload.sh | 70 ++++++++++++++++++++++ .../Functional.acpid/tests/acpid_socketfile.sh | 47 +++++++++++++++ 12 files changed, 292 insertions(+) create mode 100644 engine/tests/Functional.acpid/acpid_test.sh create mode 100644 engine/tests/Functional.acpid/datas/test_action.sh create mode 100644 engine/tests/Functional.acpid/datas/testfunc.sh create mode 100644 engine/tests/Functional.acpid/datas/testhkey create mode 100644 engine/tests/Functional.acpid/fuego_test.sh create mode 100644 engine/tests/Functional.acpid/parser.py create mode 100644 engine/tests/Functional.acpid/spec.json create mode 100644 engine/tests/Functional.acpid/tests/acpid_help.sh create mode 100644 engine/tests/Functional.acpid/tests/acpid_logfile.sh create mode 100644 engine/tests/Functional.acpid/tests/acpid_ps.sh create mode 100644 engine/tests/Functional.acpid/tests/acpid_reload.sh create mode 100644 engine/tests/Functional.acpid/tests/acpid_socketfile.sh diff --git a/engine/tests/Functional.acpid/acpid_test.sh b/engine/tests/Functional.acpid/acpid_test.sh new file mode 100644 index 0000000..dd5ce37 --- /dev/null +++ b/engine/tests/Functional.acpid/acpid_test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done diff --git a/engine/tests/Functional.acpid/datas/test_action.sh b/engine/tests/Functional.acpid/datas/test_action.sh new file mode 100644 index 0000000..904dba8 --- /dev/null +++ b/engine/tests/Functional.acpid/datas/test_action.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +sync +sync +sleep 2 +echo "acpi test" diff --git a/engine/tests/Functional.acpid/datas/testfunc.sh b/engine/tests/Functional.acpid/datas/testfunc.sh new file mode 100644 index 0000000..b13041c --- /dev/null +++ b/engine/tests/Functional.acpid/datas/testfunc.sh @@ -0,0 +1,13 @@ +# $1: Used to determine whether the command line execution result is correct or not +function exec_service_on_target { +local service_name="$1" +local action="$2" +if [ "$init_manager" = "sysvinit" ] +then + $service_name $action +elif [ "$init_manager" = "systemd" ] +then + systemctl $action $service_name +fi +return +} diff --git a/engine/tests/Functional.acpid/datas/testhkey b/engine/tests/Functional.acpid/datas/testhkey new file mode 100644 index 0000000..6e234fc --- /dev/null +++ b/engine/tests/Functional.acpid/datas/testhkey @@ -0,0 +1,2 @@ +event=button/sleep * +action=/etc/acpi/actions/test_action.sh diff --git a/engine/tests/Functional.acpid/fuego_test.sh b/engine/tests/Functional.acpid/fuego_test.sh new file mode 100644 index 0000000..56b5d7f --- /dev/null +++ b/engine/tests/Functional.acpid/fuego_test.sh @@ -0,0 +1,20 @@ +function test_pre_check { + is_on_target_path acpid PROGRAM_ACPID + assert_define PROGRAM_ACPID "Missing 'acpid' program on target board" +} + +function test_deploy { + put $TEST_HOME/acpid_test.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;\ + export init_manager=systemd;\ + sh -v acpid_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +} diff --git a/engine/tests/Functional.acpid/parser.py b/engine/tests/Functional.acpid/parser.py new file mode 100644 index 0000000..d85abd7 --- /dev/null +++ b/engine/tests/Functional.acpid/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.acpid/spec.json b/engine/tests/Functional.acpid/spec.json new file mode 100644 index 0000000..1a7630e --- /dev/null +++ b/engine/tests/Functional.acpid/spec.json @@ -0,0 +1,7 @@ +{ + "testName": "Functional.acpid", + "specs": { + "default": {} + } +} + diff --git a/engine/tests/Functional.acpid/tests/acpid_help.sh b/engine/tests/Functional.acpid/tests/acpid_help.sh new file mode 100644 index 0000000..c0ad586 --- /dev/null +++ b/engine/tests/Functional.acpid/tests/acpid_help.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, run comannd acpi_listen. +# To make sure that there is string "Usage" in output. + +test="help" + +if acpi_listen -h | grep Usage +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi; diff --git a/engine/tests/Functional.acpid/tests/acpid_logfile.sh b/engine/tests/Functional.acpid/tests/acpid_logfile.sh new file mode 100644 index 0000000..981ee44 --- /dev/null +++ b/engine/tests/Functional.acpid/tests/acpid_logfile.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# In the target to start acpid acpid, to confirm the acquisition of the log. +# check the keyword "acpid". + +test="logfile" +service_name="" + +source "datas/testfunc.sh" + +if [ "$init_manager" = "systemd" ] +then + service_name="syslog-ng" +else + service_name="syslog.syslog-ng" +fi + +exec_service_on_target $service_name stop +if [ -f /var/log/messages ] +then + rm -f /var/log/messages +fi + +exec_service_on_target acpid stop +if [ -f /var/log/acpid ] +then + rm -f /var/log/acpid +fi + +exec_service_on_target $service_name restart +if exec_service_on_target acpid start +then + echo " -> start of acpid succeeded." +else + echo " -> start of acpid failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if tail /var/log/messages | grep "starting up" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +exec_service_on_target acpid stop diff --git a/engine/tests/Functional.acpid/tests/acpid_ps.sh b/engine/tests/Functional.acpid/tests/acpid_ps.sh new file mode 100644 index 0000000..8e42e7c --- /dev/null +++ b/engine/tests/Functional.acpid/tests/acpid_ps.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# In the target start acpid, and confirm the process condition by command ps. +# check the keyword "acpid". + +test="ps" + +source "datas/testfunc.sh" + +exec_service_on_target acpid stop +if exec_service_on_target acpid start +then + echo " -> start of acpid succeeded." +else + echo " -> start of acpid failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if [ -z "$(ps aux | grep acpid | grep "/usr/sbin/acpid" | grep -v grep)" ] +then + echo " -> can't get the pid of acpid." + echo " -> $test: TEST-FAIL" + exit +fi + +if exec_service_on_target acpid stop +then + echo " -> stop of acpid succeeded." +else + echo " -> stop of acpid failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if ps aux | grep acpid | grep "/usr/sbin/acpid" | grep -v grep +then + echo " -> $test: TEST-FAIL" +else + echo " -> $test: TEST-PASS" +fi diff --git a/engine/tests/Functional.acpid/tests/acpid_reload.sh b/engine/tests/Functional.acpid/tests/acpid_reload.sh new file mode 100644 index 0000000..09e1046 --- /dev/null +++ b/engine/tests/Functional.acpid/tests/acpid_reload.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# If the target start the acpid. +# Add the action file and event file to /etc/acpid to reload acpid. +# Check the log file. + +test="reload" +service_name="" + +source "datas/testfunc.sh" + +if [ "$init_manager" = "systemd" ] +then + service_name="syslog-ng" +else + service_name="syslog.syslog-ng" +fi + +if [ ! -f /etc/acpi/actions ] +then + mkdir -p /etc/acpi/actions +fi + +if [ ! -f /etc/acpi/events/testhkey ] +then + touch /etc/acpi/events/testhkey +fi + +if [ ! -f /etc/acpi/actions/test_action.sh ] +then + touch /etc/acpi/actions/test_action.sh +fi + +cp datas/testhkey /etc/acpi/events/testhkey +cp datas/test_action.sh /etc/acpi/actions/test_action.sh + +chmod +x /etc/acpi/actions/test_action.sh +if [ -f /var/log/acpid ] +then + rm -f /var/log/acpid +fi + +exec_service_on_target $service_name stop +if [ -f /var/log/messages ] +then + rm -f /var/log/messages +fi + +sleep 5 + +exec_service_on_target $service_name restart + +if exec_service_on_target acpid restart +then + echo " -> restart of acpid succeeded." +else + echo " -> restart of acpid failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if tail /var/log/messages | grep "starting up" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi +exec_service_on_target acpid stop +rm -f /etc/acpi/events/testhkey +rm -f /etc/acpi/actions/test_action.sh diff --git a/engine/tests/Functional.acpid/tests/acpid_socketfile.sh b/engine/tests/Functional.acpid/tests/acpid_socketfile.sh new file mode 100644 index 0000000..4643ffb --- /dev/null +++ b/engine/tests/Functional.acpid/tests/acpid_socketfile.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# In target, start the acpid and check if the Unix domain socket is created or not. + +test="socketfile" + +source "datas/testfunc.sh" + +exec_service_on_target acpid stop +if [ -f /var/run/acpid.socket ] +then + rm -f /var/run/acpid.socket +fi + +if exec_service_on_target acpid start +then + echo " -> start of acpid succeeded." +else + echo " -> start of acpid failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if ls /var/run/acpid.socket +then + echo " -> ls /var/run/acpid.socket succeeded." +else + echo " -> ls /var/run/acpid.socket failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if exec_service_on_target acpid stop +then + echo " -> stop of acpid succeeded." +else + echo " -> stop of acpid failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if test -f /var/run/acpid.socket +then + echo " -> $test: TEST-FAIL" +else + echo " -> $test: TEST-PASS" +fi -- 1.8.3.1