Return-Path: From: Wang Mingyu Date: Wed, 31 Oct 2018 01:44:02 -0700 Message-ID: <1540975446-17301-2-git-send-email-wangmy@cn.fujitsu.com> In-Reply-To: <1540975446-17301-1-git-send-email-wangmy@cn.fujitsu.com> References: <1540975446-17301-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH] Add test cases for commands of at. List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org at atq atrm Signed-off-by: Wang Mingyu --- engine/tests/Functional.at/at_test.sh | 4 ++ engine/tests/Functional.at/data/at_no.allow | 2 + engine/tests/Functional.at/data/at_no.deny | 0 engine/tests/Functional.at/data/at_test.allow | 2 + engine/tests/Functional.at/data/at_test.deny | 2 + engine/tests/Functional.at/data/test_add.sh | 3 + engine/tests/Functional.at/fuego_test.sh | 24 ++++++++ engine/tests/Functional.at/parser.py | 22 +++++++ engine/tests/Functional.at/spec.json | 7 +++ engine/tests/Functional.at/tests/atd_allow_deny.sh | 47 +++++++++++++++ .../Functional.at/tests/atd_allow_deny_no_user.sh | 48 +++++++++++++++ .../tests/Functional.at/tests/atd_allow_no_user.sh | 46 +++++++++++++++ engine/tests/Functional.at/tests/atd_atq.sh | 39 +++++++++++++ engine/tests/Functional.at/tests/atd_atrm.sh | 39 +++++++++++++ .../tests/Functional.at/tests/atd_deny_no_user.sh | 46 +++++++++++++++ engine/tests/Functional.at/tests/atd_job.sh | 68 ++++++++++++++++++++++ engine/tests/Functional.at/tests/atd_pidfile.sh | 55 +++++++++++++++++ engine/tests/Functional.at/tests/atd_ps.sh | 51 ++++++++++++++++ engine/tests/Functional.at/tests/atd_syslog.sh | 49 ++++++++++++++++ 19 files changed, 554 insertions(+) create mode 100755 engine/tests/Functional.at/at_test.sh create mode 100644 engine/tests/Functional.at/data/at_no.allow create mode 100644 engine/tests/Functional.at/data/at_no.deny create mode 100644 engine/tests/Functional.at/data/at_test.allow create mode 100644 engine/tests/Functional.at/data/at_test.deny create mode 100755 engine/tests/Functional.at/data/test_add.sh create mode 100644 engine/tests/Functional.at/fuego_test.sh create mode 100644 engine/tests/Functional.at/parser.py create mode 100644 engine/tests/Functional.at/spec.json create mode 100644 engine/tests/Functional.at/tests/atd_allow_deny.sh create mode 100644 engine/tests/Functional.at/tests/atd_allow_deny_no_user.sh create mode 100644 engine/tests/Functional.at/tests/atd_allow_no_user.sh create mode 100644 engine/tests/Functional.at/tests/atd_atq.sh create mode 100644 engine/tests/Functional.at/tests/atd_atrm.sh create mode 100644 engine/tests/Functional.at/tests/atd_deny_no_user.sh create mode 100644 engine/tests/Functional.at/tests/atd_job.sh create mode 100644 engine/tests/Functional.at/tests/atd_pidfile.sh create mode 100644 engine/tests/Functional.at/tests/atd_ps.sh create mode 100644 engine/tests/Functional.at/tests/atd_syslog.sh diff --git a/engine/tests/Functional.at/at_test.sh b/engine/tests/Functional.at/at_test.sh new file mode 100755 index 0000000..dd5ce37 --- /dev/null +++ b/engine/tests/Functional.at/at_test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done diff --git a/engine/tests/Functional.at/data/at_no.allow b/engine/tests/Functional.at/data/at_no.allow new file mode 100644 index 0000000..139597f --- /dev/null +++ b/engine/tests/Functional.at/data/at_no.allow @@ -0,0 +1,2 @@ + + diff --git a/engine/tests/Functional.at/data/at_no.deny b/engine/tests/Functional.at/data/at_no.deny new file mode 100644 index 0000000..e69de29 diff --git a/engine/tests/Functional.at/data/at_test.allow b/engine/tests/Functional.at/data/at_test.allow new file mode 100644 index 0000000..cf79c53 --- /dev/null +++ b/engine/tests/Functional.at/data/at_test.allow @@ -0,0 +1,2 @@ +test_for_fuego + diff --git a/engine/tests/Functional.at/data/at_test.deny b/engine/tests/Functional.at/data/at_test.deny new file mode 100644 index 0000000..cf79c53 --- /dev/null +++ b/engine/tests/Functional.at/data/at_test.deny @@ -0,0 +1,2 @@ +test_for_fuego + diff --git a/engine/tests/Functional.at/data/test_add.sh b/engine/tests/Functional.at/data/test_add.sh new file mode 100755 index 0000000..3fb66d4 --- /dev/null +++ b/engine/tests/Functional.at/data/test_add.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +/usr/bin/logger -i "hello fuego autotest! from at" diff --git a/engine/tests/Functional.at/fuego_test.sh b/engine/tests/Functional.at/fuego_test.sh new file mode 100644 index 0000000..0054017 --- /dev/null +++ b/engine/tests/Functional.at/fuego_test.sh @@ -0,0 +1,24 @@ +function test_pre_check { + is_on_target_path at PROGRAM_AT + assert_define PROGRAM_AT "Missing 'at' program on target board" + is_on_target_path atq PROGRAM_ATQ + assert_define PROGRAM_ATQ "Missing 'atq' program on target board" + is_on_target_path atrm PROGRAM_ATRM + assert_define PROGRAM_ATRM "Missing 'atrm' program on target board" +} + +function test_deploy { + put $TEST_HOME/at_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/data $BOARD_TESTDIR/fuego.$TESTDIR/ +} + +function test_run { + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\ + ./at_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +} diff --git a/engine/tests/Functional.at/parser.py b/engine/tests/Functional.at/parser.py new file mode 100644 index 0000000..d85abd7 --- /dev/null +++ b/engine/tests/Functional.at/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.at/spec.json b/engine/tests/Functional.at/spec.json new file mode 100644 index 0000000..2a9d359 --- /dev/null +++ b/engine/tests/Functional.at/spec.json @@ -0,0 +1,7 @@ +{ + "testName": "Functional.at", + "specs": { + "default": {} + } +} + diff --git a/engine/tests/Functional.at/tests/atd_allow_deny.sh b/engine/tests/Functional.at/tests/atd_allow_deny.sh new file mode 100644 index 0000000..ea48268 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_allow_deny.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# In the target start atd, check the operation allow and deny. + +test="allow_deny" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +cp data/at_test.allow /etc/at.allow +cp data/at_test.deny /etc/at.deny + +useradd test_for_fuego +cp data/test_add.sh /home/test_for_fuego/ + +expect <<-EOF +spawn su test_for_fuego +send "at -f /home/test_for_fuego/test_add.sh now + 5 minutes\r" +expect { + -re ".*job.*" { + send_user " -> $test: TEST-PASS\n" + } + default { send_user " -> $test: TEST-FAIL\n" } } +send "exit\r" +expect eof +EOF + +sleep 5 + +rm -fr /home/test_for_fuego +userdel -f test_for_fuego +rm -f /etc/at.allow +rm -f /etc/at.deny +at -d $(at -l | cut -b 0-2) +exec_service_on_target atd stop diff --git a/engine/tests/Functional.at/tests/atd_allow_deny_no_user.sh b/engine/tests/Functional.at/tests/atd_allow_deny_no_user.sh new file mode 100644 index 0000000..c8a4757 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_allow_deny_no_user.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# In the target start atd, check the operation if no user . + +test="allow_deny_no_user" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +cp data/at_no.allow /etc/at.allow +cp data/at_no.deny /etc/at.deny + +useradd test_for_fuego +cp data/test_add.sh /home/test_for_fuego/ + +expect <<-EOF +spawn su test_for_fuego +send "at -f /home/test_for_fuego/test_add.sh now + 5 minutes || echo error\r" +expect { + -re ".*error.*" { + send_user " -> $test: TEST-PASS\n" + } + default { send_user " -> $test: TEST-FAIL\n" } } +send "exit\r" +expect eof +EOF + +sleep 5 + +rm -fr /home/test_for_fuego +userdel -f test_for_fuego +rm -f /etc/at.allow +rm -f /etc/at.deny +at -d $(at -l | cut -b 0-2) + +exec_service_on_target atd stop diff --git a/engine/tests/Functional.at/tests/atd_allow_no_user.sh b/engine/tests/Functional.at/tests/atd_allow_no_user.sh new file mode 100644 index 0000000..8fadf1c --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_allow_no_user.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# In the target start atd, check the operation if no user . + +test="allow_no_user" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +cp data/at_no.allow /etc/at.allow + +useradd test_for_fuego +cp data/test_add.sh /home/test_for_fuego/ + +expect <<-EOF +spawn su test_for_fuego +send "at -f /home/test_for_fuego/test_add.sh now + 5 minutes || echo error\r" +expect { + -re ".*error.*" { + send_user " -> $test: TEST-PASS\n" + } + default { send_user " -> $test: TEST-FAIL\n" } } +send "exit\r" +expect eof +EOF + +sleep 5 + +rm -fr /home/test_for_fuego +userdel -f test_for_fuego +rm -f /etc/at.allow +at -d $(at -l | cut -b 0-2) + +exec_service_on_target atd stop diff --git a/engine/tests/Functional.at/tests/atd_atq.sh b/engine/tests/Functional.at/tests/atd_atq.sh new file mode 100644 index 0000000..8755ed2 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_atq.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# In the target start atd, check the status of job. + +test="atq" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +mkdir test_dir +cp data/test_add.sh test_dir/ + +at -f test_dir/test_add.sh now + 5 minutes + +if atq +then + echo " -> $test: TEST-PASS" +else + echo " -> list job failed." + echo " -> $test: TEST-FAIL" +fi + +rm -fr test_dir + +at -d $(at -l | cut -b 0-2) + +exec_service_on_target atd stop diff --git a/engine/tests/Functional.at/tests/atd_atrm.sh b/engine/tests/Functional.at/tests/atd_atrm.sh new file mode 100644 index 0000000..01c3490 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_atrm.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# In the target start atd, check the status of job. + +test="atrm" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +mkdir test_dir +cp data/test_add.sh test_dir/ + +at -f test_dir/test_add.sh now + 5 minutes + +if atrm $(at -l | cut -b 0-2) +then + echo " -> $test: TEST-PASS" +else + echo " -> remove the job failed." + echo " -> $test: TEST-FAIL" +fi + +rm -fr test_dir + +at -d $(at -l | cut -b 0-2) + +exec_service_on_target atd stop diff --git a/engine/tests/Functional.at/tests/atd_deny_no_user.sh b/engine/tests/Functional.at/tests/atd_deny_no_user.sh new file mode 100644 index 0000000..b49d12e --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_deny_no_user.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# In the target start atd, check the operation if no user . + +test="deny_no_user" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +cp data/at_no.deny /etc/at.deny + +useradd test_for_fuego +cp data/test_add.sh /home/test_for_fuego/ + +expect <<-EOF +spawn su test_for_fuego +send "at -f /home/test_for_fuego/test_add.sh now + 5 minutes\r" +expect { + -re ".*job.*" { + send_user " -> $test: TEST-PASS\n" + } + default { send_user " -> $test: TEST-FAIL\n" } } +send "exit\r" +expect eof +EOF + +sleep 5 + +rm -fr /home/test_for_fuego +userdel -f test_for_fuego +rm -f /etc/at.deny +at -d $(at -l | cut -b 0-2) + +exec_service_on_target atd stop diff --git a/engine/tests/Functional.at/tests/atd_job.sh b/engine/tests/Functional.at/tests/atd_job.sh new file mode 100644 index 0000000..aae8311 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_job.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# In the target start atd, check the operation of add, list and remove job. + +test="job" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +mkdir test_dir +cp data/test_add.sh test_dir/ + +if at -f test_dir/test_add.sh now + 5 minutes +then + echo " -> add job succeeded." +else + echo " -> add job failed." + echo " -> $test: TEST-FAIL" + rm -fr test_dir + exec_service_on_target atd stop + exit +fi + +if at -c $(at -l | cut -b 0-2) | grep "fuego autotest" +then + echo " -> cats the jobs listed on the command line succeeded." +else + echo " -> cats the jobs listed on the command line failed." + echo " -> $test: TEST-FAIL" + rm -fr test_dir + exec_service_on_target atd stop + exit +fi + +if at -l +then + echo " -> list job succeeded." +else + echo " -> list job failed." + echo " -> $test: TEST-FAIL" + rm -fr test_dir + exec_service_on_target atd stop + exit +fi + +rm -fr test_dir + +if at -d $(at -l | cut -b 0-2) +then + echo " -> $test: TEST-PASS" +else + echo " -> remove job failed." + echo " -> $test: TEST-FAIL" +fi + +exec_service_on_target atd stop diff --git a/engine/tests/Functional.at/tests/atd_pidfile.sh b/engine/tests/Functional.at/tests/atd_pidfile.sh new file mode 100644 index 0000000..19ea377 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_pidfile.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# In the target start atd, and check if the /var/run/atd.pid is exist. + +test="pidfile" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if [ -f /var/run/atd.pid ] +then + rm -f /var/run/atd.pid +fi + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if ls /var/run/atd.pid +then + echo " -> /var/run/atd.pid is exist." +else + echo " -> /var/run/atd.pid is not exist." + echo " -> $test: TEST-FAIL" + exec_service_on_target atd stop + exit +fi + +if exec_service_on_target atd stop +then + echo " -> stop atd succeeded." +else + echo " -> stop atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if test -f /var/run/atd.pid +then + echo " -> $test: TEST-FAIL" +else + echo " -> $test: TEST-PASS" +fi diff --git a/engine/tests/Functional.at/tests/atd_ps.sh b/engine/tests/Functional.at/tests/atd_ps.sh new file mode 100644 index 0000000..57674c3 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_ps.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# In the target start atd, and confirm the process condition by command ps. +# check the keyword "atd". + +test="ps" + +. ./fuego_board_function_lib.sh + +set_init_manager + +exec_service_on_target atd stop + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if ps -N a | grep "[/]usr/sbin/atd" +then + echo " -> get the pid of atd." +else + echo " -> can't get the pid of atd." + echo " -> $test: TEST-FAIL" + exec_service_on_target atd stop + exit +fi + +if exec_service_on_target atd stop +then + echo " -> stop atd succeeded." +else + echo " -> stop atd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if ps -N a | grep "[/]usr/sbin/atd" +then + echo " -> $test: TEST-FAIL" +else + echo " -> $test: TEST-PASS" +fi diff --git a/engine/tests/Functional.at/tests/atd_syslog.sh b/engine/tests/Functional.at/tests/atd_syslog.sh new file mode 100644 index 0000000..23e3efe --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_syslog.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# In the target start atd, add job and verify job completion. +# Check the syslog string "fuego autotest". + +test="syslog" + +. ./fuego_board_function_lib.sh + +set_init_manager + +logger_service=$(detect_logger_service) + +exec_service_on_target $logger_service stop +exec_service_on_target atd stop + +if [ -f /var/log/syslog ] +then + mv /var/log/syslog /var/log/syslog_bak +fi +exec_service_on_target $logger_service restart + +if exec_service_on_target atd start +then + echo " -> start atd succeeded." +else + echo " -> start atd failed." +fi + +mkdir test_dir +cp data/test_add.sh test_dir/ + +at -f test_dir/test_add.sh now + 1 minutes + +echo "sleep 60s!" +sleep 60 + +if cat /var/log/syslog | grep "hello fuego autotest" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +rm -fr test_dir + +at -d $(at -l | cut -b 0-2) +exec_service_on_target atd stop +exec_service_on_target $logger_service stop -- 1.8.3.1