sysvinit: Add test cases for commands of sysvinit.
PATCH v2 1/1 sysvinit: Add test cases for commands of sysvinit.
The sysvinit is the default init program used by some system.
This test set is used to check the programs for controlling the startup, running, and shutdown of the system.
--- tests/Functional.sysvinit/fuego_test.sh | 26 +++++++++++++++++++ tests/Functional.sysvinit/spec.json | 6 +++++ tests/Functional.sysvinit/sysvinit_test.sh | 4 +++ tests/Functional.sysvinit/test.yaml | 21 +++++++++++++++ .../tests/sysvinit_halt.sh | 12 +++++++++ .../tests/sysvinit_last.sh | 13 ++++++++++ .../tests/sysvinit_mesg.sh | 21 +++++++++++++++ .../tests/sysvinit_shutdown.sh | 12 +++++++++ .../tests/sysvinit_sulogin.sh | 18 +++++++++++++ .../tests/sysvinit_utmpdump.sh | 12 +++++++++ .../tests/sysvinit_wall.sh | 12 +++++++++ 11 files changed, 157 insertions(+) create mode 100644 tests/Functional.sysvinit/fuego_test.sh create mode 100644 tests/Functional.sysvinit/spec.json create mode 100755 tests/Functional.sysvinit/sysvinit_test.sh create mode 100644 tests/Functional.sysvinit/test.yaml create mode 100644 tests/Functional.sysvinit/tests/sysvinit_halt.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_last.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_mesg.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_shutdown.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_sulogin.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_utmpdump.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_wall.sh
tests/Functional.sysvinit/fuego_test.sh new file +26 -0
@@ -0,0 +1,26 @@ +function test_pre_check { + assert_has_program halt + assert_has_program last + assert_has_program mesg + assert_has_program runlevel + assert_has_program shutdown + assert_has_program sulogin + assert_has_program utmpdump + assert_has_program wall + assert_has_program expect +} + +function test_deploy { + put $TEST_HOME/sysvinit_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/ +} + +function test_run { + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\ + export test_passwd=$PASSWORD;\ + ./sysvinit_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +}
tests/Functional.sysvinit/spec.json new file +6 -0
@@ -0,0 +1,6 @@ +{ + "testName": "Functional.sysvinit", + "specs": { + "default": {} + } +}
tests/Functional.sysvinit/sysvinit_test.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done
tests/Functional.sysvinit/test.yaml new file +21 -0
@@ -0,0 +1,21 @@ +fuego_package_version: 1 +name: Functional.sysvinit +description: | + Sysvinit is a collection of System init programs originally. + This is a simple test to check the program of sysvinit. +license: BSD-3-Clause +author: Wang Mingyu <[email protected]> +maintainer: Wang Mingyu <[email protected]> +version: 1.00 +fuego_release: 1 +type: Functional +tags: ['sysvinit'] +params: + PASSWORD: + description: the password to login to your host - Defined in board file +data_files: + - sysvinit_test.sh + - fuego_test.sh + - spec.json + - test.yaml + - tests
tests/Functional.sysvinit/tests/sysvinit_halt.sh new file +12 -0
@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command halt. + +test="halt" + +if halt -w +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
tests/Functional.sysvinit/tests/sysvinit_last.sh new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, run command last. + +test="last" + +USER_NAME=$(id -u -n) +if last | grep "$USER_NAME.*still logged in" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
tests/Functional.sysvinit/tests/sysvinit_mesg.sh new file +21 -0
@@ -0,0 +1,21 @@ +#!/bin/sh + +# In target, run command mesg. + +test="mesg" + +mesg +mesg_status=$(echo $?) + +mesg n +if echo $? = 1 +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +if [ $mesg_status = 0 ] +then + mesg y +fi
tests/Functional.sysvinit/tests/sysvinit_shutdown.sh new file +12 -0
@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command shutdown. + +test="shutdown" + +if shutdown -k now +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
tests/Functional.sysvinit/tests/sysvinit_sulogin.sh new file +18 -0
@@ -0,0 +1,18 @@ +#!/bin/sh + +# In target, run command sulogin. + +test="sulogin" + +expect <<-EOF +spawn sulogin +expect ":" +send "$test_passwd\r" +expect { +"#" { + send_user " -> $test: TEST-PASS\n" + } +default { send_user " -> $test: TEST-FAIL\n" } } +send "exit\r" +expect eof +EOF
tests/Functional.sysvinit/tests/sysvinit_utmpdump.sh new file +12 -0
@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command utmpdump. + +test="utmpdump" + +if utmpdump /var/log/wtmp +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
tests/Functional.sysvinit/tests/sysvinit_wall.sh new file +12 -0
@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command wall. + +test="wall" + +if wall "Testing wall command" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
Signature · 1 line
2.17.1
PATCH v3 1/1 initscripts: Add test cases for commands of initscripts.
This test set is used to check che inittab command halt, ifdown-ifup and sendsigs.
--- tests/Functional.initscripts/fuego_test.sh | 18 ++++++++++++ .../initscripts_test.sh | 4 +++ tests/Functional.initscripts/spec.json | 6 ++++ .../tests/initscripts_halt.sh | 13 +++++++++ .../tests/initscripts_ifdown-ifup.sh | 29 +++++++++++++++++++ .../tests/initscripts_sendsigs.sh | 13 +++++++++ 6 files changed, 83 insertions(+) create mode 100644 tests/Functional.initscripts/fuego_test.sh create mode 100755 tests/Functional.initscripts/initscripts_test.sh create mode 100644 tests/Functional.initscripts/spec.json create mode 100644 tests/Functional.initscripts/tests/initscripts_halt.sh create mode 100644 tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh create mode 100644 tests/Functional.initscripts/tests/initscripts_sendsigs.sh
tests/Functional.initscripts/fuego_test.sh new file +18 -0
@@ -0,0 +1,18 @@ +function test_pre_check { + assert_has_program ifup + assert_has_program ifdown +} + +function test_deploy { + put $TEST_HOME/initscripts_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/ +} + +function test_run { + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\ + ./initscripts_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +}
tests/Functional.initscripts/initscripts_test.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done
tests/Functional.initscripts/spec.json new file +6 -0
@@ -0,0 +1,6 @@ +{ + "testName": "Functional.initscripts", + "specs": { + "default": {} + } +}
tests/Functional.initscripts/tests/initscripts_halt.sh new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, verify that the file is executable. +# option: none + +test="halt" + +if [ -x /etc/init.d/halt ] +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh new file +29 -0
@@ -0,0 +1,29 @@ +#!/bin/sh + +# In target, run command ifdown/ifup. +# option: none + +test="ifdown/ifup" + +if [ ! -f /etc/sysconfig/network-scripts/ifcfg-lo ] +then + echo " -> $test: ifcfg file is not exist." + echo " -> $test: TEST-SKIP" + exit 0 +fi + +if ifdown lo +then + echo " -> $test: ifdown lo succeeded." +else + echo " -> $test: ifdown lo failed." + echo " -> $test: TEST-FAIL" + exit 0 +fi + +if ifup lo +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
tests/Functional.initscripts/tests/initscripts_sendsigs.sh new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, verify that the file is executable. +# option: none + +test="sendsigs" + +if [ -x /etc/init.d/sendsigs ] +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
Signature · 1 line
2.17.1
Re: [Fuego] [PATCH v3] initscripts: Add test cases for commands of initscripts.
See comments inline below.
Quoted 9 lines
-----Original Message-----
From: [email protected] [mailto:fuego- [email protected]] On Behalf Of Wang Mingyu
Sent: Wednesday, September 18, 2019 9:21 PM
To: [email protected]
Subject: [Fuego] [PATCH v3] initscripts: Add test cases for commands of initscripts.This test set is used to check che inittab command halt, ifdown-ifup and
che-> the
Quoted 78 lines
sendsigs.
Signed-off-by Wang Mingyu <[email protected]>--- tests/Functional.initscripts/fuego_test.sh | 18 ++++++++++++ .../initscripts_test.sh | 4 +++ tests/Functional.initscripts/spec.json | 6 ++++ .../tests/initscripts_halt.sh | 13 +++++++++ .../tests/initscripts_ifdown-ifup.sh | 29 +++++++++++++++++++ .../tests/initscripts_sendsigs.sh | 13 +++++++++ 6 files changed, 83 insertions(+) create mode 100644 tests/Functional.initscripts/fuego_test.sh create mode 100755 tests/Functional.initscripts/initscripts_test.sh create mode 100644 tests/Functional.initscripts/spec.json create mode 100644 tests/Functional.initscripts/tests/initscripts_halt.sh create mode 100644 tests/Functional.initscripts/tests/initscripts_ifdown- ifup.sh create mode 100644 tests/Functional.initscripts/tests/initscripts_sendsigs.shtests/Functional.initscripts/fuego_test.sh new file +18
-0@@ -0,0 +1,18 @@ +function test_pre_check { + assert_has_program ifup + assert_has_program ifdown +} + +function test_deploy { + put $TEST_HOME/initscripts_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/ +} + +function test_run { + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\ + ./initscripts_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +}tests/Functional.initscripts/initscripts_test.sh new file +4
-0@@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +donetests/Functional.initscripts/spec.json new file +6
-0@@ -0,0 +1,6 @@ +{ + "testName": "Functional.initscripts", + "specs": { + "default": {} + } +}tests/Functional.initscripts/tests/initscripts_halt.sh new file +3
-0@@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, verify that the file is executable.
tests/Functional.initscripts/tests/initscripts_halt.sh line 13
Quoted 10 lines
tests/Functional.initscripts/tests/initscripts_halt.sh new file +10
-0+# option: none + +test="halt" + +if [ -x /etc/init.d/halt ] +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi
Would be nice to actually test if the program can halt the machine here. But that could be an enhancement for the future.
Quoted 7 lines
tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh new file +0
-0
tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh line 10
Quoted 10 lines
tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh new file +10
-0@@ -0,0 +1,29 @@ +#!/bin/sh + +# In target, run command ifdown/ifup. +# option: none + +test="ifdown/ifup" + +if [ ! -f /etc/sysconfig/network-scripts/ifcfg-lo ] +then + echo " -> $test: ifcfg file is not exist."
is not exist -> was not found
tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh line 22
Quoted 12 lines
tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh new file +12
-0+ echo " -> $test: TEST-SKIP" + exit 0 +fi + +if ifdown lo +then + echo " -> $test: ifdown lo succeeded." +else + echo " -> $test: ifdown lo failed." + echo " -> $test: TEST-FAIL" + exit 0 +fi
Should check here that the 'lo' interface (loopback) is no longer present in the output of 'ifconfig'
I added some lines to do this.
Quoted 28 lines
tests/Functional.initscripts/tests/initscripts_ifdown-ifup.sh new file +7
-0+ +if ifup lo +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fitests/Functional.initscripts/tests/initscripts_sendsigs.sh new file +13
-1@@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, verify that the file is executable. +# option: none + +test="sendsigs" + +if [ -x /etc/init.d/sendsigs ] +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi --
Quoted 1 line
2.17.1
OK - just checking that the program is present and executable is not very deep testing.
However, I'll accept this as a starting point for this test.
I'm applying this, but will re-word a few items, and I have added some extra checking for the correct status of the loopback device,
as described above.
-- Tim
Quoted 104 lines
-----Original Message-----
From: Wang Mingyu on Wednesday, September 18, 2019 9:21 PMThe sysvinit is the default init program used by some system. This test set is used to check the programs for controlling the startup, running, and shutdown of the system.
Signed-off-by Wang Mingyu <[email protected]>--- tests/Functional.sysvinit/fuego_test.sh | 26 +++++++++++++++++++ tests/Functional.sysvinit/spec.json | 6 +++++ tests/Functional.sysvinit/sysvinit_test.sh | 4 +++ tests/Functional.sysvinit/test.yaml | 21 +++++++++++++++ .../tests/sysvinit_halt.sh | 12 +++++++++ .../tests/sysvinit_last.sh | 13 ++++++++++ .../tests/sysvinit_mesg.sh | 21 +++++++++++++++ .../tests/sysvinit_shutdown.sh | 12 +++++++++ .../tests/sysvinit_sulogin.sh | 18 +++++++++++++ .../tests/sysvinit_utmpdump.sh | 12 +++++++++ .../tests/sysvinit_wall.sh | 12 +++++++++ 11 files changed, 157 insertions(+) create mode 100644 tests/Functional.sysvinit/fuego_test.sh create mode 100644 tests/Functional.sysvinit/spec.json create mode 100755 tests/Functional.sysvinit/sysvinit_test.sh create mode 100644 tests/Functional.sysvinit/test.yaml create mode 100644 tests/Functional.sysvinit/tests/sysvinit_halt.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_last.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_mesg.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_shutdown.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_sulogin.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_utmpdump.sh create mode 100644 tests/Functional.sysvinit/tests/sysvinit_wall.shtests/Functional.sysvinit/fuego_test.sh new file +26
-0@@ -0,0 +1,26 @@ +function test_pre_check { + assert_has_program halt + assert_has_program last + assert_has_program mesg + assert_has_program runlevel + assert_has_program shutdown + assert_has_program sulogin + assert_has_program utmpdump + assert_has_program wall + assert_has_program expect +} + +function test_deploy { + put $TEST_HOME/sysvinit_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/ +} + +function test_run { + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\ + export test_passwd=$PASSWORD;\ + ./sysvinit_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +}tests/Functional.sysvinit/spec.json new file +6
-0@@ -0,0 +1,6 @@ +{ + "testName": "Functional.sysvinit", + "specs": { + "default": {} + } +}tests/Functional.sysvinit/sysvinit_test.sh new file +4
-0@@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +donetests/Functional.sysvinit/test.yaml new file +5
-0@@ -0,0 +1,21 @@ +fuego_package_version: 1 +name: Functional.sysvinit +description: | + Sysvinit is a collection of System init programs originally. + This is a simple test to check the program of sysvinit.
tests/Functional.sysvinit/test.yaml line 15
Quoted 10 lines
tests/Functional.sysvinit/test.yaml new file +10
-0+license: BSD-3-Clause +author: Wang Mingyu <[email protected]> +maintainer: Wang Mingyu <[email protected]> +version: 1.00 +fuego_release: 1 +type: Functional +tags: ['sysvinit'] +params: + PASSWORD: + description: the password to login to your host - Defined in board file
This parameter is common to all tests, and normally does not need to be mentioned in the test-specific yaml file.
However, since this is explicitly used in the test, this is good to document. Nice job. :-)
tests/Functional.sysvinit/test.yaml line 21
Quoted 6 lines
tests/Functional.sysvinit/test.yaml new file +6
-0+data_files: + - sysvinit_test.sh + - fuego_test.sh + - spec.json + - test.yaml + - tests
There's no parser.py listed. Is there one for this test?
Quoted 26 lines
tests/Functional.sysvinit/tests/sysvinit_halt.sh new file +12
-0@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command halt. + +test="halt" + +if halt -w +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fitests/Functional.sysvinit/tests/sysvinit_last.sh new file +0
-0
tests/Functional.sysvinit/tests/sysvinit_last.sh line 8
Quoted 8 lines
tests/Functional.sysvinit/tests/sysvinit_last.sh new file +8
-0@@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, run command last. + +test="last" + +USER_NAME=$(id -u -n) +if last | grep "$USER_NAME.*still logged in"
Nice - I like the data validation.
Quoted 116 lines
tests/Functional.sysvinit/tests/sysvinit_last.sh new file +5
-0+then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fitests/Functional.sysvinit/tests/sysvinit_mesg.sh new file +21
-0@@ -0,0 +1,21 @@ +#!/bin/sh + +# In target, run command mesg. + +test="mesg" + +mesg +mesg_status=$(echo $?) + +mesg n +if echo $? = 1 +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +if [ $mesg_status = 0 ] +then + mesg y +fitests/Functional.sysvinit/tests/sysvinit_shutdown.sh new file +12
-0@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command shutdown. + +test="shutdown" + +if shutdown -k now +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fitests/Functional.sysvinit/tests/sysvinit_sulogin.sh new file +18
-0@@ -0,0 +1,18 @@ +#!/bin/sh + +# In target, run command sulogin. + +test="sulogin" + +expect <<-EOF +spawn sulogin +expect ":" +send "$test_passwd\r" +expect { +"#" { + send_user " -> $test: TEST-PASS\n" + } +default { send_user " -> $test: TEST-FAIL\n" } } +send "exit\r" +expect eof +EOFtests/Functional.sysvinit/tests/sysvinit_utmpdump.sh new file +12
-0@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command utmpdump. + +test="utmpdump" + +if utmpdump /var/log/wtmp +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fitests/Functional.sysvinit/tests/sysvinit_wall.sh new file +12
-1@@ -0,0 +1,12 @@ +#!/bin/sh + +# In target, run command wall. + +test="wall" + +if wall "Testing wall command" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi --
Quoted 1 line
2.17.1
Well, some of these (for example 'wall', and 'mesg') will return success (exit code 0) even if the action they perform has no effect. A test of actual functionality would be good, rather than just execution of the binary and looking at the return code.
However, this is a start.
I'm applying this, to the master branch of fuego-core on bitbucket.org.
-- Tim