[Fuego] [PATCH] Add test cases for commands of sysvinit.

Tim.Bird at sony.com Tim.Bird at sony.com
Wed Nov 14 17:19:59 UTC 2018



> -----Original Message-----
> From: Tim.Bird at sony.com
> > -----Original Message-----
> > From: Wang Mingyu on Wednesday, November 14, 2018 1:30 AM
> >
> > 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 <wangmy at cn.fujitsu.com>
> > ---
> >  engine/tests/Functional.sysvinit/fuego_test.sh     | 24
> > ++++++++++++++++++++++
> >  engine/tests/Functional.sysvinit/parser.py         | 22
> > ++++++++++++++++++++
> >  engine/tests/Functional.sysvinit/spec.json         |  7 +++++++
> >  engine/tests/Functional.sysvinit/sysvinit_test.sh  |  4 ++++
> >  .../Functional.sysvinit/tests/sysvinit_halt.sh     | 12 +++++++++++
> >  .../Functional.sysvinit/tests/sysvinit_last.sh     | 12 +++++++++++
> >  .../Functional.sysvinit/tests/sysvinit_mesg.sh     | 13 ++++++++++++
> >  .../Functional.sysvinit/tests/sysvinit_runlevel.sh | 12 +++++++++++
> >  .../Functional.sysvinit/tests/sysvinit_shutdown.sh | 12 +++++++++++
> >  .../Functional.sysvinit/tests/sysvinit_sulogin.sh  | 18 ++++++++++++++++
> >  .../Functional.sysvinit/tests/sysvinit_utmpdump.sh | 12 +++++++++++
> >  .../Functional.sysvinit/tests/sysvinit_wall.sh     | 12 +++++++++++
> >  12 files changed, 160 insertions(+)
> >  create mode 100644 engine/tests/Functional.sysvinit/fuego_test.sh
> >  create mode 100644 engine/tests/Functional.sysvinit/parser.py
> >  create mode 100644 engine/tests/Functional.sysvinit/spec.json
> >  create mode 100755 engine/tests/Functional.sysvinit/sysvinit_test.sh
> >  create mode 100644
> engine/tests/Functional.sysvinit/tests/sysvinit_halt.sh
> >  create mode 100644 engine/tests/Functional.sysvinit/tests/sysvinit_last.sh
> >  create mode 100644
> > engine/tests/Functional.sysvinit/tests/sysvinit_mesg.sh
> >  create mode 100644
> > engine/tests/Functional.sysvinit/tests/sysvinit_runlevel.sh
> >  create mode 100644
> > engine/tests/Functional.sysvinit/tests/sysvinit_shutdown.sh
> >  create mode 100644
> > engine/tests/Functional.sysvinit/tests/sysvinit_sulogin.sh
> >  create mode 100644
> > engine/tests/Functional.sysvinit/tests/sysvinit_utmpdump.sh
> >  create mode 100644
> engine/tests/Functional.sysvinit/tests/sysvinit_wall.sh
> >
> > diff --git a/engine/tests/Functional.sysvinit/fuego_test.sh
> > b/engine/tests/Functional.sysvinit/fuego_test.sh
> > new file mode 100644
> > index 0000000..1ac7b1d
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/fuego_test.sh
> > @@ -0,0 +1,24 @@
> > +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

Also, this is missing "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;\
> > +    ./sysvinit_test.sh"
> > +}
> > +
> > +function test_processing {
> > +    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> > +}
> > diff --git a/engine/tests/Functional.sysvinit/parser.py
> > b/engine/tests/Functional.sysvinit/parser.py
> > new file mode 100644
> > index 0000000..d85abd7
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/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.sysvinit/spec.json
> > b/engine/tests/Functional.sysvinit/spec.json
> > new file mode 100644
> > index 0000000..49f2afb
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/spec.json
> > @@ -0,0 +1,7 @@
> > +{
> > +    "testName": "Functional.sysvinit",
> > +    "specs": {
> > +        "default": {}
> > +    }
> > +}
> > +
> > diff --git a/engine/tests/Functional.sysvinit/sysvinit_test.sh
> > b/engine/tests/Functional.sysvinit/sysvinit_test.sh
> > new file mode 100755
> > index 0000000..dd5ce37
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/sysvinit_test.sh
> > @@ -0,0 +1,4 @@
> > +#!/bin/sh
> > +for i in tests/*.sh; do
> > +    sh $i
> > +done
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_halt.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_halt.sh
> > new file mode 100644
> > index 0000000..765a45e
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_halt.sh
> > @@ -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;
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_last.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_last.sh
> > new file mode 100644
> > index 0000000..dd37235
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_last.sh
> > @@ -0,0 +1,12 @@
> > +#!/bin/sh
> > +
> > +#  In target, run command last.
> > +
> > +test="last"
> > +
> > +if last | grep "root.*still logged in"
> 
> The test user might not be 'root', so this might fail.
> 
> Doing something like this might work around this:
> 
> USER_NAME=$(id -u -n)
> if last | grep "$USER_NAME.*still logged in"
> 
> > +then
> > +    echo " -> $test: TEST-PASS"
> > +else
> > +    echo " -> $test: TEST-FAIL"
> > +fi;
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_mesg.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_mesg.sh
> > new file mode 100644
> > index 0000000..a47c8ab
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_mesg.sh
> > @@ -0,0 +1,13 @@
> > +#!/bin/sh
> > +
> > +#  In target, run command mesg.
> > +
> > +test="mesg"
> > +
> > +mesg n
> > +if echo $? = 1
> > +then
> > +    echo " -> $test: TEST-PASS"
> > +else
> > +    echo " -> $test: TEST-FAIL"
> > +fi
> 
> There is no attempt here to preserve the current status of the mesg flag.
> You should save the previous value, and reset it when this test is over.
> 
> Note that 'mesg' returns 0 when the status is 'y' and 1 when the status is 'n'.
> 
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_runlevel.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_runlevel.sh
> > new file mode 100644
> > index 0000000..22e107e
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_runlevel.sh
> > @@ -0,0 +1,12 @@
> > +#!/bin/sh
> > +
> > +#  In target, run command runlevel.
> > +
> > +test="runlevel"
> > +
> > +if runlevel | grep "N "
> 
> This assumes that the runlevel has never been changed since boot,
> which is not a great assumption.  I'm not sure how to work around this one,
> though.
> 
> > +then
> > +    echo " -> $test: TEST-PASS"
> > +else
> > +    echo " -> $test: TEST-FAIL"
> > +fi;
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_shutdown.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_shutdown.sh
> > new file mode 100644
> > index 0000000..4847db1
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_shutdown.sh
> > @@ -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;
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_sulogin.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_sulogin.sh
> > new file mode 100644
> > index 0000000..8b56d17
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_sulogin.sh
> > @@ -0,0 +1,18 @@
> > +#!/bin/sh
> > +
> > +#  In target, run command sulogin.
> > +
> > +test="sulogin"
> > +
> > +expect <<-EOF
> > +spawn sulogin
> > +expect ":"
> > +send "$PASSWORD\r"
> > +expect {
> > +"#" {
> > +          send_user " -> $test: TEST-PASS\n"
> > +          }
> > +default { send_user " -> $test: TEST-FAIL\n" }  }
> > +send "exit\r"
> > +expect eof
> > +EOF
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_utmpdump.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_utmpdump.sh
> > new file mode 100644
> > index 0000000..a5b20f1
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_utmpdump.sh
> > @@ -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;
> > diff --git a/engine/tests/Functional.sysvinit/tests/sysvinit_wall.sh
> > b/engine/tests/Functional.sysvinit/tests/sysvinit_wall.sh
> > new file mode 100644
> > index 0000000..ae22656
> > --- /dev/null
> > +++ b/engine/tests/Functional.sysvinit/tests/sysvinit_wall.sh
> > @@ -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;
> > --
> > 1.8.3.1
> 
> Please fix the commented-on issues, and re-submit.
> 
> Thanks!
>  -- Tim
> _______________________________________________
> Fuego mailing list
> Fuego at lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/fuego


More information about the Fuego mailing list