Return-Path: From: Wang Mingyu Date: Tue, 6 Nov 2018 05:56:05 -0800 Message-ID: <1541512565-7858-4-git-send-email-wangmy@cn.fujitsu.com> In-Reply-To: <1541512565-7858-1-git-send-email-wangmy@cn.fujitsu.com> References: <1541512565-7858-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH v2] 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 commands list: at atq atrm This test set is to check the service atd and command at/atq/atrm that if they can examine or delete jobs for later execution successfully. 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 | 23 ++++++++ engine/tests/Functional.at/parser.py | 22 +++++++ engine/tests/Functional.at/spec.json | 7 +++ engine/tests/Functional.at/tests/atd_allow_deny.sh | 44 ++++++++++++++ .../Functional.at/tests/atd_allow_deny_no_user.sh | 45 ++++++++++++++ .../tests/Functional.at/tests/atd_allow_no_user.sh | 43 ++++++++++++++ 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 | 43 ++++++++++++++ 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, 541 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..6d523c9 --- /dev/null +++ b/engine/tests/Functional.at/fuego_test.sh @@ -0,0 +1,23 @@ +function test_pre_check { + assert_has_program at + assert_has_program atq + assert_has_program atrm + assert_has_program useradd + assert_has_program userdel +} + +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..21c930e --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_allow_deny.sh @@ -0,0 +1,44 @@ +#!/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/ + +su - test_for_fuego -c "at -f /home/test_for_fuego/test_add.sh now + 5 minutes" > log 2>&1 +if cat log | grep "job" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi +rm log + +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 1-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..9040e93 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_allow_deny_no_user.sh @@ -0,0 +1,45 @@ +#!/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/ + +su - test_for_fuego -c "at -f /home/test_for_fuego/test_add.sh now + 5 minutes || echo error" > log 2>&1 +if cat log | grep "error" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi +rm log + +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 1-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..e368ee5 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_allow_no_user.sh @@ -0,0 +1,43 @@ +#!/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/ + +su - test_for_fuego -c "at -f /home/test_for_fuego/test_add.sh now + 5 minutes || echo error" > log 2>&1 +if cat log | grep "error" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi +rm log + +sleep 5 + +rm -fr /home/test_for_fuego +userdel -f test_for_fuego +rm -f /etc/at.allow +at -d $(at -l | cut -b 1-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..aefe284 --- /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 1-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..f23a94d --- /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 1-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 1-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..13ebae8 --- /dev/null +++ b/engine/tests/Functional.at/tests/atd_deny_no_user.sh @@ -0,0 +1,43 @@ +#!/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/ + +su - test_for_fuego -c "at -f /home/test_for_fuego/test_add.sh now + 5 minutes" > log 2>&1 +if cat log | grep "job" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi +rm log + +sleep 5 + +rm -fr /home/test_for_fuego +userdel -f test_for_fuego +rm -f /etc/at.deny +at -d $(at -l | cut -b 1-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..ce8078f --- /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 1-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 1-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..3e4d191 --- /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 exists." +else + echo " -> /var/run/atd.pid dose 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..ddf9794 --- /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 1-2) +exec_service_on_target atd stop +exec_service_on_target $logger_service stop -- 1.8.3.1