All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Fuego] [PATCH] Add test cases for commands of at.
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of at Wang Mingyu
@ 2018-10-31  5:38   ` Tim.Bird
  0 siblings, 0 replies; 9+ messages in thread
From: Tim.Bird @ 2018-10-31  5:38 UTC (permalink / raw)
  To: wangmy, fuego

> -----Original Message-----
> From: Wang Mingyu
> 
> at
> atq
> atrm
> 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  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"
These should be:
assert_has_program at
assert_has_program atq
assert_has_program atrm

See http://fuegotest.org/wiki/function_assert_has_program

> +}
> +
> +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
Should check for useradd in test_pre_check with:
assert_has_program useradd

This is not guaranteed to be on a system.

> +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
I wish there was a way to do this without expect.

> +
> +sleep 5
> +
> +rm -fr /home/test_for_fuego
> +userdel -f test_for_fuego
Should use: assert_has_program userdel
to check that userdel is availale on the target board.

> +rm -f /etc/at.allow
> +rm -f /etc/at.deny
> +at -d $(at -l | cut -b 0-2)
This cut doesn't work on my system.  I get
"cut: byte/character positions are numbered from 1
Try 'cut --help' for more information."

> +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."
'is exist.' should be changed to 'exists.'

> +else
> +    echo " -> /var/run/atd.pid is not exist."
'is not exist.' should be changed to 'does 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


Most of this looks good. I wish this didn't require 'expect'.
Since it does, it needs an 'assert_has_program expect' in 
test_pre_check.

Please address my comments and re-submit.

Thanks for the patch.
 -- Tim


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Fuego] [PATCH] Add test cases of command syslog-ng.
@ 2018-10-31  8:44 Wang Mingyu
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of at Wang Mingyu
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Wang Mingyu @ 2018-10-31  8:44 UTC (permalink / raw)
  To: fuego

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 engine/tests/Functional.syslog-ng/fuego_test.sh    | 19 +++++++++++++
 engine/tests/Functional.syslog-ng/parser.py        | 22 +++++++++++++++
 engine/tests/Functional.syslog-ng/spec.json        |  7 +++++
 .../tests/Functional.syslog-ng/syslog-ng_test.sh   |  4 +++
 .../Functional.syslog-ng/tests/syslog-ng_log.sh    | 15 +++++++++++
 .../Functional.syslog-ng/tests/syslog-ng_share.sh  | 31 ++++++++++++++++++++++
 .../Functional.syslog-ng/tests/syslog-ng_start.sh  | 18 +++++++++++++
 7 files changed, 116 insertions(+)
 create mode 100644 engine/tests/Functional.syslog-ng/fuego_test.sh
 create mode 100644 engine/tests/Functional.syslog-ng/parser.py
 create mode 100644 engine/tests/Functional.syslog-ng/spec.json
 create mode 100755 engine/tests/Functional.syslog-ng/syslog-ng_test.sh
 create mode 100644 engine/tests/Functional.syslog-ng/tests/syslog-ng_log.sh
 create mode 100644 engine/tests/Functional.syslog-ng/tests/syslog-ng_share.sh
 create mode 100644 engine/tests/Functional.syslog-ng/tests/syslog-ng_start.sh

diff --git a/engine/tests/Functional.syslog-ng/fuego_test.sh b/engine/tests/Functional.syslog-ng/fuego_test.sh
new file mode 100644
index 0000000..b4cd7c1
--- /dev/null
+++ b/engine/tests/Functional.syslog-ng/fuego_test.sh
@@ -0,0 +1,19 @@
+function test_pre_check {
+    is_on_target_path syslog-ng PROGRAM_SYSLOGNG
+    assert_define PROGRAM_SYSLOGNG "Missing 'syslog-ng' program on target board"
+}
+
+function test_deploy {
+    put $TEST_HOME/syslog-ng_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/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./syslog-ng_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.syslog-ng/parser.py b/engine/tests/Functional.syslog-ng/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.syslog-ng/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.syslog-ng/spec.json b/engine/tests/Functional.syslog-ng/spec.json
new file mode 100644
index 0000000..ca078f6
--- /dev/null
+++ b/engine/tests/Functional.syslog-ng/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.syslog-ng",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.syslog-ng/syslog-ng_test.sh b/engine/tests/Functional.syslog-ng/syslog-ng_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.syslog-ng/syslog-ng_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.syslog-ng/tests/syslog-ng_log.sh b/engine/tests/Functional.syslog-ng/tests/syslog-ng_log.sh
new file mode 100644
index 0000000..6407abc
--- /dev/null
+++ b/engine/tests/Functional.syslog-ng/tests/syslog-ng_log.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In the target, run syslog-ng and check the message file.
+
+test="log"
+
+mgs="This is a test message $(date)"
+logger "$msg"
+if grep "$msg" /var/log/syslog
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo "  Didn't find test string in log"
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.syslog-ng/tests/syslog-ng_share.sh b/engine/tests/Functional.syslog-ng/tests/syslog-ng_share.sh
new file mode 100644
index 0000000..696f284
--- /dev/null
+++ b/engine/tests/Functional.syslog-ng/tests/syslog-ng_share.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+#  In the target, run syslog-ng
+#  check the process state and keyword "supervising syslog ng".
+
+test="share"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target syslog-ng stop
+
+if [ -e /usr/share/syslog-ng ]
+then
+    mv /usr/share/syslog-ng /usr/share/syslog-ng_bak
+fi
+
+exec_service_on_target syslog-ng restart
+
+if ps aux | grep "[/]usr/sbin/syslog-ng"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ -e /usr/share/syslog-ng_orig ]
+then
+    mv /usr/share/syslog-ng_bak /usr/share/syslog-ng
+fi
diff --git a/engine/tests/Functional.syslog-ng/tests/syslog-ng_start.sh b/engine/tests/Functional.syslog-ng/tests/syslog-ng_start.sh
new file mode 100644
index 0000000..bab81d2
--- /dev/null
+++ b/engine/tests/Functional.syslog-ng/tests/syslog-ng_start.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+#  In the target, run syslog-ng and check the status of process.
+
+test="start"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target syslog-ng restart
+
+if ps aux | grep "[/]usr/sbin/syslog-ng"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Fuego] [PATCH] Add test cases for commands of at.
  2018-10-31  8:44 [Fuego] [PATCH] Add test cases of command syslog-ng Wang Mingyu
@ 2018-10-31  8:44 ` Wang Mingyu
  2018-10-31  5:38   ` Tim.Bird
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of utillinux Wang Mingyu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Wang Mingyu @ 2018-10-31  8:44 UTC (permalink / raw)
  To: fuego

at
atq
atrm

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 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




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Fuego] [PATCH] Add test cases for commands of utillinux.
  2018-10-31  8:44 [Fuego] [PATCH] Add test cases of command syslog-ng Wang Mingyu
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of at Wang Mingyu
@ 2018-10-31  8:44 ` Wang Mingyu
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command vconfig Wang Mingyu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Wang Mingyu @ 2018-10-31  8:44 UTC (permalink / raw)
  To: fuego

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 engine/tests/Functional.utillinux/fuego_test.sh    | 51 ++++++++++++++++++++++
 engine/tests/Functional.utillinux/parser.py        | 22 ++++++++++
 engine/tests/Functional.utillinux/spec.json        |  7 +++
 .../tests/utillinux_blockdev.sh                    | 15 +++++++
 .../Functional.utillinux/tests/utillinux_cal.sh    | 12 +++++
 .../Functional.utillinux/tests/utillinux_col.sh    | 12 +++++
 .../Functional.utillinux/tests/utillinux_colcrt.sh | 15 +++++++
 .../Functional.utillinux/tests/utillinux_colrm.sh  | 15 +++++++
 .../Functional.utillinux/tests/utillinux_column.sh | 20 +++++++++
 .../tests/utillinux_ctrlaltdel.sh                  | 12 +++++
 .../Functional.utillinux/tests/utillinux_dmesg.sh  | 12 +++++
 .../Functional.utillinux/tests/utillinux_fdisk.sh  | 13 ++++++
 .../Functional.utillinux/tests/utillinux_getopt.sh | 12 +++++
 .../tests/utillinux_hexdump.sh                     | 19 ++++++++
 .../Functional.utillinux/tests/utillinux_ipcrm.sh  | 12 +++++
 .../Functional.utillinux/tests/utillinux_ipcs.sh   | 12 +++++
 .../Functional.utillinux/tests/utillinux_kill.sh   | 16 +++++++
 .../Functional.utillinux/tests/utillinux_logger.sh | 15 +++++++
 .../Functional.utillinux/tests/utillinux_look.sh   | 17 ++++++++
 .../tests/utillinux_mcookie.sh                     | 12 +++++
 .../Functional.utillinux/tests/utillinux_mkfs.sh   | 14 ++++++
 .../Functional.utillinux/tests/utillinux_more.sh   | 12 +++++
 .../Functional.utillinux/tests/utillinux_mount.sh  | 31 +++++++++++++
 .../Functional.utillinux/tests/utillinux_namei.sh  | 16 +++++++
 .../Functional.utillinux/tests/utillinux_rename.sh | 17 ++++++++
 .../Functional.utillinux/tests/utillinux_renice.sh | 15 +++++++
 .../Functional.utillinux/tests/utillinux_rev.sh    | 16 +++++++
 .../Functional.utillinux/tests/utillinux_script.sh | 25 +++++++++++
 .../Functional.utillinux/tests/utillinux_setsid.sh | 12 +++++
 .../tests/utillinux_setterm.sh                     | 12 +++++
 .../Functional.utillinux/tests/utillinux_sfdisk.sh | 13 ++++++
 .../Functional.utillinux/tests/utillinux_swap.sh   | 38 ++++++++++++++++
 .../Functional.utillinux/tests/utillinux_ul.sh     | 12 +++++
 .../Functional.utillinux/tests/utillinux_umount.sh | 16 +++++++
 .../tests/utillinux_whereis.sh                     | 12 +++++
 .../Functional.utillinux/tests/utillinux_write.sh  | 13 ++++++
 .../tests/Functional.utillinux/utillinux_test.sh   |  4 ++
 37 files changed, 599 insertions(+)
 create mode 100644 engine/tests/Functional.utillinux/fuego_test.sh
 create mode 100644 engine/tests/Functional.utillinux/parser.py
 create mode 100644 engine/tests/Functional.utillinux/spec.json
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_blockdev.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_cal.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_col.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_colcrt.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_colrm.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_column.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_ctrlaltdel.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_dmesg.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_fdisk.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_getopt.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_hexdump.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_ipcrm.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_ipcs.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_kill.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_logger.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_look.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_mcookie.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_mkfs.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_more.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_mount.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_namei.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_rename.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_renice.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_rev.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_script.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_setsid.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_setterm.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_sfdisk.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_swap.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_ul.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_umount.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_whereis.sh
 create mode 100644 engine/tests/Functional.utillinux/tests/utillinux_write.sh
 create mode 100755 engine/tests/Functional.utillinux/utillinux_test.sh

diff --git a/engine/tests/Functional.utillinux/fuego_test.sh b/engine/tests/Functional.utillinux/fuego_test.sh
new file mode 100644
index 0000000..d23d2d8
--- /dev/null
+++ b/engine/tests/Functional.utillinux/fuego_test.sh
@@ -0,0 +1,51 @@
+function test_pre_check {
+    assert_has_program blockdev
+    assert_has_program cal
+    assert_has_program colcrt
+    assert_has_program colrm
+    assert_has_program col
+    assert_has_program column
+    assert_has_program ctrlaltdel
+    assert_has_program dmesg
+    assert_has_program fdisk
+    assert_has_program getopt
+    assert_has_program hexdump
+    assert_has_program ipcrm
+    assert_has_program ipcs
+    assert_has_program kill
+    assert_has_program logger
+    assert_has_program look
+    assert_has_program mcookie
+    assert_has_program mkfs
+    assert_has_program more
+    assert_has_program mount
+    assert_has_program namei
+    assert_has_program rename
+    assert_has_program renice
+    assert_has_program rev
+    assert_has_program script
+    assert_has_program setsid
+    assert_has_program setterm
+    assert_has_program sfdisk
+    assert_has_program swapon
+    assert_has_program swapoff
+    assert_has_program ul
+    assert_has_program umount
+    assert_has_program whereis
+    assert_has_program write
+}
+
+function test_deploy {
+    put $TEST_HOME/utillinux_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 ramdiskdev=/dev/ram0;\
+    ./utillinux_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.utillinux/parser.py b/engine/tests/Functional.utillinux/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.utillinux/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.utillinux/spec.json b/engine/tests/Functional.utillinux/spec.json
new file mode 100644
index 0000000..d661b09
--- /dev/null
+++ b/engine/tests/Functional.utillinux/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.utillinux",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_blockdev.sh b/engine/tests/Functional.utillinux/tests/utillinux_blockdev.sh
new file mode 100644
index 0000000..60fb97f
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_blockdev.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command blockdev.
+#  option: --setrw
+
+test="help"
+
+modprobe brd
+
+if blockdev --setrw $ramdiskdev
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_cal.sh b/engine/tests/Functional.utillinux/tests/utillinux_cal.sh
new file mode 100644
index 0000000..c844624
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_cal.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command cal.
+
+test="cal"
+
+if cal
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_col.sh b/engine/tests/Functional.utillinux/tests/utillinux_col.sh
new file mode 100644
index 0000000..8ea276a
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_col.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command col.
+
+test="col"
+
+if echo -e "hello\tworld" | col -x | tr ' ' '~' | grep "hello~~~world"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_colcrt.sh b/engine/tests/Functional.utillinux/tests/utillinux_colcrt.sh
new file mode 100644
index 0000000..469da48
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_colcrt.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command colcrt.
+
+test="colcrt"
+
+echo "hello" > log
+echo "world" >> log
+if colcrt -2 log | grep -e "hello" -e "world"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f  log
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_colrm.sh b/engine/tests/Functional.utillinux/tests/utillinux_colrm.sh
new file mode 100644
index 0000000..b1a5877
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_colrm.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command colrm.
+
+test="colrm"
+
+echo "hello" > log
+echo "world" >> log
+if cat log | colrm 2 4 | grep -e "ho" -e "wd"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f  log
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_column.sh b/engine/tests/Functional.utillinux/tests/utillinux_column.sh
new file mode 100644
index 0000000..dcaf82b
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_column.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+#  In target, run command column.
+
+test="column"
+
+echo "This is a test file." > log
+echo "This file is used to test column command." >> log
+
+echo "This  is    a   test  file." > grepfile
+echo "This  file  is  used  to     test  column  command." >> grepfile
+
+if column -t log | grep -f grepfile
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f  log grepfile
+
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_ctrlaltdel.sh b/engine/tests/Functional.utillinux/tests/utillinux_ctrlaltdel.sh
new file mode 100644
index 0000000..dcaf3ba
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_ctrlaltdel.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command ctrlaltdel.
+
+test="ctrlaltdel"
+
+if ctrlaltdel soft
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_dmesg.sh b/engine/tests/Functional.utillinux/tests/utillinux_dmesg.sh
new file mode 100644
index 0000000..a026030
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_dmesg.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command dmesg.
+
+test="dmesg"
+
+if dmesg | grep "Linux version"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_fdisk.sh b/engine/tests/Functional.utillinux/tests/utillinux_fdisk.sh
new file mode 100644
index 0000000..1c08cfc
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_fdisk.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command fdisk.
+
+test="fdisk"
+
+modprobe brd
+if fdisk -s $ramdiskdev
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_getopt.sh b/engine/tests/Functional.utillinux/tests/utillinux_getopt.sh
new file mode 100644
index 0000000..fb30d26
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_getopt.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command getopt.
+
+test="getopt"
+
+if getopt aR -aR | grep "\-a.*\-R"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_hexdump.sh b/engine/tests/Functional.utillinux/tests/utillinux_hexdump.sh
new file mode 100644
index 0000000..ab3280e
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_hexdump.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+#  In target, run command hexdump.
+
+test="hexdump"
+
+mkdir test_dir
+echo "HELLO WORLD" > test_dir/test1
+
+hexdump -c test_dir/test1 > log
+
+if head -n 1 log | grep "0000000   H   E   L   L   O       W   O   R   L   D  \\\n" && tail -n 1 log | grep "000000c"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -rf test_dir
+rm -f log
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_ipcrm.sh b/engine/tests/Functional.utillinux/tests/utillinux_ipcrm.sh
new file mode 100644
index 0000000..d654d33
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_ipcrm.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command ipcrm.
+
+test="ipcrm"
+
+if ipcrm
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_ipcs.sh b/engine/tests/Functional.utillinux/tests/utillinux_ipcs.sh
new file mode 100644
index 0000000..23f3a08
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_ipcs.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command ipcs.
+
+test="ipcs"
+
+if ipcs | grep "Semaphore Arrays"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_kill.sh b/engine/tests/Functional.utillinux/tests/utillinux_kill.sh
new file mode 100644
index 0000000..2c517f7
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_kill.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run command kill.
+
+test="kill"
+
+sleep 1234 & pid=$!
+
+kill -9 $pid
+
+if ps | grep [s]leep
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_logger.sh b/engine/tests/Functional.utillinux/tests/utillinux_logger.sh
new file mode 100644
index 0000000..453fb0f
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_logger.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command logger.
+
+test="logger"
+
+mgs="This is a test message $(date)"
+logger "$msg"
+if grep "$msg" /var/log/syslog
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo "  Didn't find test string in log"
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_look.sh b/engine/tests/Functional.utillinux/tests/utillinux_look.sh
new file mode 100644
index 0000000..45a4cc6
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_look.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#  In target, run command look.
+
+test="look"
+
+mkdir test_dir
+echo "Line1 of test file" > test_dir/test1
+echo "Line2 of test file" >> test_dir/test1
+
+if look Line1 test_dir/test1 | grep "Line1 of test file"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -fr test_dir
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_mcookie.sh b/engine/tests/Functional.utillinux/tests/utillinux_mcookie.sh
new file mode 100644
index 0000000..29ca06a
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_mcookie.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command mcookie.
+
+test="mcookie"
+
+if mcookie | wc -c | grep 33
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_mkfs.sh b/engine/tests/Functional.utillinux/tests/utillinux_mkfs.sh
new file mode 100644
index 0000000..dc33dc5
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_mkfs.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+#  In target, run command mkfs.
+
+test="mkfs"
+
+modprobe brd
+
+if mkfs $ramdiskdev
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_more.sh b/engine/tests/Functional.utillinux/tests/utillinux_more.sh
new file mode 100644
index 0000000..2c0c410
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_more.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command more.
+
+test="more"
+
+if more -V | grep "more from util-linux"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_mount.sh b/engine/tests/Functional.utillinux/tests/utillinux_mount.sh
new file mode 100644
index 0000000..ec7218d
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_mount.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+#  In target, run command mount.
+
+test="mount"
+
+if [ -f /mnt/test-ram ]
+then
+    rm -rf /mnt/test-ram
+fi
+
+mkdir /mnt/test-ram
+
+if mount -t ramfs $ramdiskdev /mnt/test-ram
+then
+    echo " -> mount succeeded."
+else
+    echo " -> mount failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if mount | grep "$ramdiskdev on \/mnt\/test-ram type ramf"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+umount /mnt/test-ram
+rm -fr /mnt/test-ram
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_namei.sh b/engine/tests/Functional.utillinux/tests/utillinux_namei.sh
new file mode 100644
index 0000000..22f0ad5
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_namei.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run command namei.
+
+test="namei"
+
+mkdir test_dir
+namei test_dir > log
+if head -n 1 log | grep "f: test_dir" && tail -n 1 log | grep " d test_dir"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -fr test_dir
+rm -f  log
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_rename.sh b/engine/tests/Functional.utillinux/tests/utillinux_rename.sh
new file mode 100644
index 0000000..13c08a4
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_rename.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#  In target, run command rename.
+
+test="rename"
+
+mkdir test_dir
+touch test_dir/test1
+rename test_dir/test1 test_dir/rename_test1 test_dir/test1
+
+if [ ! -f test_dir/test1 ] && [ -f test_dir/rename_test1 ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -fr test_dir
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_renice.sh b/engine/tests/Functional.utillinux/tests/utillinux_renice.sh
new file mode 100644
index 0000000..2af39d6
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_renice.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command renice.
+
+test="renice"
+
+sleep 12345 & pid=$!
+
+if renice 12 -p $pid | grep "process ID"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+killall sleep
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_rev.sh b/engine/tests/Functional.utillinux/tests/utillinux_rev.sh
new file mode 100644
index 0000000..85b3b86
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_rev.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run command rev.
+
+test="rev"
+
+mkdir test_dir
+echo "hello world" > test_dir/test1
+
+if rev test_dir/test1 | grep "dlrow olleh"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -fr test_dir
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_script.sh b/engine/tests/Functional.utillinux/tests/utillinux_script.sh
new file mode 100644
index 0000000..2e693ca
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_script.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+#  In target, run command script.
+
+test="script"
+
+expect <<-EOF
+spawn script
+expect "Script started, file is typescript"
+send_user " -> start script succeeded.\n"
+send "echo \"hello world\"\r"
+expect "hello world"
+send "exit\r"
+expect "Script done, file is typescript"
+send_user " -> file typescript is created.\n"
+expect eof
+EOF
+
+if cat typescript | grep "hello world"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f typescript
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_setsid.sh b/engine/tests/Functional.utillinux/tests/utillinux_setsid.sh
new file mode 100644
index 0000000..ae9d130
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_setsid.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command setsid.
+
+test="setsid"
+
+if setsid ls
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_setterm.sh b/engine/tests/Functional.utillinux/tests/utillinux_setterm.sh
new file mode 100644
index 0000000..33e1f46
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_setterm.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command setterm.
+
+test="setterm"
+
+if setterm --help | grep "Usage"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_sfdisk.sh b/engine/tests/Functional.utillinux/tests/utillinux_sfdisk.sh
new file mode 100644
index 0000000..c692aab
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_sfdisk.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command sfdisk.
+
+test="sfdisk"
+
+modprobe brd
+if sfdisk -s $ramdiskdev
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_swap.sh b/engine/tests/Functional.utillinux/tests/utillinux_swap.sh
new file mode 100644
index 0000000..1f8a0a1
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_swap.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+#  In target, run command swapon&swapoff.
+
+test="swapon&swapoff"
+
+function check_if_succeeded {
+    if $1
+    then
+        echo " -> $test: $1 succeeded."
+    else
+        echo " -> $test: $1 failed."
+        echo " -> $test: TEST-FAIL"
+    fi
+}
+
+if [ $(cat /proc/swaps | wc -l) = 1 ]
+then
+    check_if_succeeded "swapon -a"
+    check_if_succeeded "swapoff -a"
+    if [ $(cat /proc/swaps | wc -l) = 1 ]
+    then
+        echo " -> $test: TEST-PASS"
+    else
+        echo " -> $test: TEST-FAIL"
+    fi
+else
+    swap_name=$(cat /proc/swaps | tail -n 1| tr -s " " | cut -d ' ' -f1)
+    check_if_succeeded "swapoff $swap_name"
+    check_if_succeeded "swapon $swap_name"
+    if cat /proc/swaps | grep $swap_name
+    then
+        echo " -> $test: TEST-PASS"
+    else
+        echo " -> $test: TEST-FAIL"
+    fi
+fi;
+
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_ul.sh b/engine/tests/Functional.utillinux/tests/utillinux_ul.sh
new file mode 100644
index 0000000..a92fcb3
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_ul.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command ul.
+
+test="ul"
+
+if echo "__" | ul
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_umount.sh b/engine/tests/Functional.utillinux/tests/utillinux_umount.sh
new file mode 100644
index 0000000..b161023
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_umount.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run command umount.
+
+test="umount"
+
+mount -n -t tmpfs none  /dev/shm
+
+umount /dev/shm
+if mount | grep "none on /dev/shm"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi;
+
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_whereis.sh b/engine/tests/Functional.utillinux/tests/utillinux_whereis.sh
new file mode 100644
index 0000000..e097175
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_whereis.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+#  In target, run command whereis.
+
+test="whereis"
+
+if whereis passwd | grep "passwd: "
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/tests/utillinux_write.sh b/engine/tests/Functional.utillinux/tests/utillinux_write.sh
new file mode 100644
index 0000000..8afe03f
--- /dev/null
+++ b/engine/tests/Functional.utillinux/tests/utillinux_write.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command write.
+
+test="write"
+
+mesg y
+if echo "testing write" | write root /dev/pts/0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.utillinux/utillinux_test.sh b/engine/tests/Functional.utillinux/utillinux_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.utillinux/utillinux_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Fuego] [PATCH] Add test cases of command vconfig.
  2018-10-31  8:44 [Fuego] [PATCH] Add test cases of command syslog-ng Wang Mingyu
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of at Wang Mingyu
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of utillinux Wang Mingyu
@ 2018-10-31  8:44 ` Wang Mingyu
  2018-10-31 18:31   ` Tim.Bird
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command samhain Wang Mingyu
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test case of command bc Wang Mingyu
  4 siblings, 1 reply; 9+ messages in thread
From: Wang Mingyu @ 2018-10-31  8:44 UTC (permalink / raw)
  To: fuego

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 engine/tests/Functional.vconfig/fuego_test.sh      | 19 ++++++++++++++++++
 engine/tests/Functional.vconfig/parser.py          | 22 +++++++++++++++++++++
 engine/tests/Functional.vconfig/spec.json          |  7 +++++++
 .../Functional.vconfig/tests/vconfig_VLAN_tag.sh   | 23 ++++++++++++++++++++++
 .../tests/Functional.vconfig/tests/vconfig_add.sh  | 16 +++++++++++++++
 .../Functional.vconfig/tests/vconfig_addaddr.sh    | 17 ++++++++++++++++
 .../tests/Functional.vconfig/tests/vconfig_help.sh | 13 ++++++++++++
 .../Functional.vconfig/tests/vconfig_remove.sh     | 15 ++++++++++++++
 .../Functional.vconfig/tests/vconfig_set_flag.sh   | 16 +++++++++++++++
 engine/tests/Functional.vconfig/vconfig_test.sh    |  4 ++++
 10 files changed, 152 insertions(+)
 create mode 100644 engine/tests/Functional.vconfig/fuego_test.sh
 create mode 100644 engine/tests/Functional.vconfig/parser.py
 create mode 100644 engine/tests/Functional.vconfig/spec.json
 create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh
 create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_add.sh
 create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh
 create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_help.sh
 create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_remove.sh
 create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh
 create mode 100755 engine/tests/Functional.vconfig/vconfig_test.sh

diff --git a/engine/tests/Functional.vconfig/fuego_test.sh b/engine/tests/Functional.vconfig/fuego_test.sh
new file mode 100644
index 0000000..cda39c7
--- /dev/null
+++ b/engine/tests/Functional.vconfig/fuego_test.sh
@@ -0,0 +1,19 @@
+function test_pre_check {
+    is_on_target_path vconfig PROGRAM_VCONFIG
+    assert_define PROGRAM_VCONFIG "Missing 'vconfig' program on target board"
+}
+
+function test_deploy {
+    put $TEST_HOME/vconfig_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 vcon_remote_ifeth=$IFETH;\
+    ./vconfig_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.vconfig/parser.py b/engine/tests/Functional.vconfig/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.vconfig/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.vconfig/spec.json b/engine/tests/Functional.vconfig/spec.json
new file mode 100644
index 0000000..e45af81
--- /dev/null
+++ b/engine/tests/Functional.vconfig/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.vconfig",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh b/engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh
new file mode 100644
index 0000000..14d1b86
--- /dev/null
+++ b/engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#  In target, run command vconfig.
+#  option: add/rem
+
+test="VLAN_tag"
+
+mkdir test_dir
+
+ifconfig $vcon_remote_ifeth up
+vconfig add $vcon_remote_ifeth 100
+ifconfig $vcon_remote_ifeth.100 inet 192.168.255.1 netmask 0xffffff00
+ping -q -c 50 -I $vcon_remote_ifeth.100 192.168.255.2 &
+tcpdump -c 10 -ex -i $vcon_remote_ifeth ether broadcast > test_dir/dumpdata
+
+if cat test_dir/dumpdata | grep "vlan 100"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm -f test_dir/dumpdata
+vconfig rem $vcon_remote_ifeth.100
diff --git a/engine/tests/Functional.vconfig/tests/vconfig_add.sh b/engine/tests/Functional.vconfig/tests/vconfig_add.sh
new file mode 100644
index 0000000..d2c5ad5
--- /dev/null
+++ b/engine/tests/Functional.vconfig/tests/vconfig_add.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run command vconfig.
+#  option: add
+
+test="add"
+
+vconfig add $vcon_remote_ifeth 4
+
+if ifconfig $vcon_remote_ifeth.4 | grep "$vcon_remote_ifeth.4"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+vconfig rem $vcon_remote_ifeth.4
diff --git a/engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh b/engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh
new file mode 100644
index 0000000..aa98b56
--- /dev/null
+++ b/engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#  In target, run command vconfig.
+#  option: add/rem
+
+test="addaddr"
+
+vconfig add $vcon_remote_ifeth 100
+ifconfig $vcon_remote_ifeth.100 inet 192.168.255.1 netmask 0xffffff00
+
+if ifconfig $vcon_remote_ifeth.100 | grep "192.168.255.1"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+vconfig rem $vcon_remote_ifeth.100
diff --git a/engine/tests/Functional.vconfig/tests/vconfig_help.sh b/engine/tests/Functional.vconfig/tests/vconfig_help.sh
new file mode 100644
index 0000000..43314f3
--- /dev/null
+++ b/engine/tests/Functional.vconfig/tests/vconfig_help.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command vconfig.
+#  option: none
+
+test="help"
+
+if vconfig | grep Usage
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.vconfig/tests/vconfig_remove.sh b/engine/tests/Functional.vconfig/tests/vconfig_remove.sh
new file mode 100644
index 0000000..d3696ef
--- /dev/null
+++ b/engine/tests/Functional.vconfig/tests/vconfig_remove.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  In target, run command vconfig.
+#  option: rem
+
+test="remove"
+
+vconfig add $vcon_remote_ifeth 4
+
+if vconfig rem $vcon_remote_ifeth.4 | grep "Removed VLAN"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh b/engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh
new file mode 100644
index 0000000..b8b11a5
--- /dev/null
+++ b/engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run command vconfig.
+#  option: set_flag
+
+test="set_flag"
+
+vconfig add $vcon_remote_ifeth 4
+
+if vconfig set_flag $vcon_remote_ifeth.4 1 | grep "Set flag on device"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+vconfig rem $vcon_remote_ifeth.4
diff --git a/engine/tests/Functional.vconfig/vconfig_test.sh b/engine/tests/Functional.vconfig/vconfig_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.vconfig/vconfig_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Fuego] [PATCH] Add test cases of command samhain.
  2018-10-31  8:44 [Fuego] [PATCH] Add test cases of command syslog-ng Wang Mingyu
                   ` (2 preceding siblings ...)
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command vconfig Wang Mingyu
@ 2018-10-31  8:44 ` Wang Mingyu
  2018-10-31 19:06   ` Tim.Bird
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test case of command bc Wang Mingyu
  4 siblings, 1 reply; 9+ messages in thread
From: Wang Mingyu @ 2018-10-31  8:44 UTC (permalink / raw)
  To: fuego

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 engine/tests/Functional.samhain/data/samhainrc     | 773 +++++++++++++++++++++
 engine/tests/Functional.samhain/fuego_test.sh      |  19 +
 engine/tests/Functional.samhain/parser.py          |  22 +
 engine/tests/Functional.samhain/samhain_test.sh    |   4 +
 engine/tests/Functional.samhain/spec.json          |   7 +
 .../Functional.samhain/tests/samhain_check.sh      |  58 ++
 .../tests/Functional.samhain/tests/samhain_help.sh |  13 +
 .../tests/Functional.samhain/tests/samhain_init.sh |  42 ++
 8 files changed, 938 insertions(+)
 create mode 100755 engine/tests/Functional.samhain/data/samhainrc
 create mode 100644 engine/tests/Functional.samhain/fuego_test.sh
 create mode 100644 engine/tests/Functional.samhain/parser.py
 create mode 100755 engine/tests/Functional.samhain/samhain_test.sh
 create mode 100644 engine/tests/Functional.samhain/spec.json
 create mode 100644 engine/tests/Functional.samhain/tests/samhain_check.sh
 create mode 100644 engine/tests/Functional.samhain/tests/samhain_help.sh
 create mode 100644 engine/tests/Functional.samhain/tests/samhain_init.sh

diff --git a/engine/tests/Functional.samhain/data/samhainrc b/engine/tests/Functional.samhain/data/samhainrc
new file mode 100755
index 0000000..e90926d
--- /dev/null
+++ b/engine/tests/Functional.samhain/data/samhainrc
@@ -0,0 +1,773 @@
+#####################################################################
+#
+# Configuration file template for samhain.
+#
+#####################################################################
+# 
+# -- empty lines and lines starting with '#', ';' or '//' are ignored
+# -- boolean options can be Yes/No or True/False or 1/0 
+# -- you can PGP clearsign this file -- samhain will check (if compiled
+#    with support) or otherwise ignore the signature
+# -- CHECK mail address
+#
+# To each log facility, you can assign a threshold severity. Only
+# reports with at least the threshold severity will be logged
+# to the respective facility (even further below).
+#
+#####################################################################
+#
+# SETUP for file system checking:
+# 
+# (i)   There are several policies, each has its own section. Put files
+#       into the section for the appropriate policy (see below).
+# (ii)  Section [EventSeverity]: 
+#       To each policy, you can assign a severity (further below).
+# (iii) Section [Log]: 
+#       To each log facility, you can assign a threshold severity. Only
+#       reports with at least the threshold severity will be logged
+#       to the respective facility (even further below).
+#
+#####################################################################
+
+#####################################################################
+#
+# Files are defined with: file = /absolute/path
+#
+# Directories are defined with:                  dir = /absolute/path
+# or with an optional recursion depth (N <= 99): dir = N/absolute/path
+#
+# Directory inodes are checked. If you only want to check files
+# in a directory, but not the directory inode itself, use (e.g.):
+#
+# [ReadOnly]
+# dir = /some/directory
+# [IgnoreAll]
+# file = /some/directory
+#
+# You can use shell-style globbing patterns, like: file = /path/foo*
+# 
+######################################################################
+
+[Misc]
+##
+## Add or subtract tests from the policies
+## - if you want to change their definitions,
+##   you need to do that before using the policies
+##
+# RedefReadOnly = (no default)
+# RedefAttributes=(no default)
+# RedefLogFiles=(no default)
+# RedefGrowingLogFiles=(no default)
+# RedefIgnoreAll=(no default)
+# RedefIgnoreNone=(no default)
+
+# RedefUser0=(no default)
+# RedefUser1=(no default)
+
+#
+# --------- / --------------
+#
+
+[ReadOnly]
+#dir = 0/
+
+[Attributes]
+file = /tmp
+file = /dev
+file = /media
+file = /proc
+file = /sys
+
+#
+# --------- /etc -----------
+#
+
+[ReadOnly]
+##
+## for these files, only access time is ignored
+##
+#dir = 99/etc
+
+[Attributes]
+##
+## check permission and ownership
+##
+#file = /etc/mtab
+#file = /etc/adjtime
+#file = /etc/motd
+#file = /etc/lvm/.cache
+
+# On Ubuntu, these are in /var/lib rather than /etc
+#file = /etc/cups/certs
+#file = /etc/cups/certs/0
+
+# managed by fstab-sync on Fedora Core
+#file = /etc/fstab
+
+# modified when booting 
+#file = /etc/sysconfig/hwconf
+
+# There are files in /etc that might change, thus changing the directory
+# timestamps. Put it here as 'file', and in the ReadOnly section as 'dir'.
+
+#file = /etc
+
+#
+# --------- /boot -----------
+#
+
+[ReadOnly]
+#dir = 99/boot
+
+#
+# --------- /bin, /sbin -----------
+#
+
+[ReadOnly]
+#dir = 99/bin
+#dir = 99/sbin
+
+#
+# --------- /lib -----------
+#
+
+[ReadOnly]
+#dir = 99/lib
+
+#
+# --------- /dev -----------
+#
+
+[Attributes]
+#dir = 99/dev
+
+[IgnoreAll]
+##
+## pseudo terminals are created/removed as needed
+##
+#dir = -1/dev/pts
+
+# dir = -1/dev/.udevdb
+
+#file = /dev/ppp
+
+#
+# --------- /usr -----------
+#
+
+[ReadOnly]
+#dir = 99/usr
+
+[ReadOnly]
+dir = 99$BOARD_TESTDIR/fuego.$TESTDIR/test_dir/samhain_test 
+
+#
+# --------- /var -----------
+#
+
+[ReadOnly]
+#dir = 99/var
+
+[IgnoreAll]
+dir = -1/var/cache
+dir = -1/var/backups
+dir = -1/var/games
+dir = -1/var/gdm
+dir = -1/var/lock
+dir = -1/var/mail
+dir = -1/var/run
+dir = -1/var/spool
+dir = -1/var/tmp
+dir = -1/var/lib/texmf
+dir = -1/var/lib/scrollkeeper
+
+
+[Attributes]
+
+dir = /var/lib/nfs
+dir = /var/lib/pcmcia
+
+# /var/lib/rpm changes if packets are installed;
+# /var/lib/rpm/__db.00[123] even more frequently
+file = /var/lib/rpm/__db.00?
+
+file = /var/lib/acpi-support/vbestate
+file = /var/lib/alsa/asound.state
+file = /var/lib/apt/lists/lock
+file = /var/lib/apt/lists/partial
+file = /var/lib/cups/certs
+file = /var/lib/cups/certs/0
+file = /var/lib/dpkg/lock
+file = /var/lib/gdm
+file = /var/lib/gdm/.cookie
+file = /var/lib/gdm/.gdmfifo
+file = /var/lib/gdm/:0.Xauth
+file = /var/lib/gdm/:0.Xservers
+file = /var/lib/logrotate/status
+file = /var/lib/mysql
+file = /var/lib/mysql/ib_logfile0
+file = /var/lib/mysql/ibdata1
+file = /var/lib/slocate
+file = /var/lib/slocate/slocate.db
+file = /var/lib/slocate/slocate.db.tmp
+file = /var/lib/urandom
+file = /var/lib/urandom/random-seed
+file = /var/lib/random-seed
+file = /var/lib/xkb
+
+
+[GrowingLogFiles]
+##
+## For these files, changes in signature, timestamps, and increase in size
+## are ignored. Logfile rotation will cause a report because of shrinking
+## size and different inode. 
+##
+#dir = 99/var/log
+
+[Attributes]
+#
+# rotated logs will change inode
+#
+#file = /var/log/*.[0-9].gz
+#file = /var/log/*.[0-9].log
+#file = /var/log/*.[0-9]
+#file = /var/log/*.old
+#file = /var/log/*/*.[0-9].gz
+#file = /var/log/*/*.[0-9][0-9].gz
+#file = /var/log/*/*.log.[0-9]
+
+[Misc]
+#
+# Various naming schemes for rotated logs
+#
+IgnoreAdded = /var/log/.*\.[0-9]+$
+IgnoreAdded = /var/log/.*\.[0-9]+\.gz$
+IgnoreAdded = /var/log/.*\.[0-9]+\.log$
+#
+# Subdirectories
+#
+IgnoreAdded = /var/log/[[:alnum:]]+/.*\.[0-9]+$
+IgnoreAdded = /var/log/[[:alnum:]]+/.*\.[0-9]+\.gz$
+IgnoreAdded = /var/log/[[:alnum:]]+/.*\.[0-9]+\.log$
+#
+IgnoreAdded = /var/lib/slocate/slocate.db.tmp
+IgnoreMissing = /var/lib/slocate/slocate.db.tmp
+
+#
+# --------- other policies -----------
+#
+
+[IgnoreNone]
+##
+## for these files, all modifications (even access time) are reported
+##    - you may create some interesting-looking file (like /etc/safe_passwd),
+##      just to watch whether someone will access it ...
+##
+
+[Prelink]
+##
+## Use for prelinked files or directories holding them
+##
+
+
+[User0]
+[User1]
+## User0 and User1 are sections for files/dirs with user-definable checking
+## (see the manual) 
+
+
+
+[EventSeverity]
+##
+## Here you can assign severities to policy violations.
+## If this severity exceeds the treshold of a log facility (see below),
+## a policy violation will be logged to that facility.
+##
+## Severity for verification failures.
+##
+# SeverityReadOnly=crit
+# SeverityLogFiles=crit
+# SeverityGrowingLogs=crit
+# SeverityIgnoreNone=crit
+# SeverityAttributes=crit
+# SeverityUser0=crit
+# SeverityUser1=crit
+# SeverityIgnoreAll=crit
+
+
+## Files : file access problems
+# SeverityFiles=crit
+
+## Dirs  : directory access problems
+# SeverityDirs=crit
+
+## Names : suspect (non-printable) characters in a pathname
+# SeverityNames=crit
+
+[Log]
+##
+## Switch on/OFF log facilities and set their threshold severity
+##
+## Values: debug, info, notice, warn, mark, err, crit, alert, none.
+## 'mark' is used for timestamps.
+##
+##
+## Use 'none' to SWITCH OFF a log facility
+## 
+## By default, everything equal to and above the threshold is logged.
+## The specifiers '*', '!', and '=' are interpreted as  
+## 'all', 'all but', and 'only', respectively (like syslogd(8) does, 
+## at least on Linux). Examples:
+## MailSeverity=*
+## MailSeverity=!warn
+## MailSeverity==crit
+
+## E-mail
+##
+# MailSeverity=none
+
+## Console
+##
+# PrintSeverity=info
+
+## Logfile
+##
+# LogSeverity=mark
+
+## Syslog
+##
+# SyslogSeverity=none
+
+## Remote server (yule)
+##
+# ExportSeverity=none
+
+## External script or program
+##
+# ExternalSeverity = none
+
+## Logging to a database
+##
+# DatabaseSeverity = none
+
+## Logging to a Prelude-IDS
+##
+# PreludeSeverity = crit
+
+
+
+#####################################################
+#
+# Optional modules
+#
+#####################################################
+
+# [SuidCheck]
+##
+## --- Check the filesystem for SUID/SGID binaries
+## 
+
+## Switch on
+#
+# SuidCheckActive = yes
+
+## Interval for check (seconds)
+#
+# SuidCheckInterval = 7200
+
+## Alternative: crontab-like schedule
+#
+# SuidCheckSchedule = NULL
+ 
+## Directory to exclude 
+#
+# SuidCheckExclude = NULL
+
+## Limit on files per second (0 == no limit)
+#
+# SuidCheckFps = 0
+
+## Alternative: yield after every file
+#
+# SuidCheckYield = no
+
+## Severity of a detection
+#
+# SeveritySuidCheck = crit
+
+## Quarantine SUID/SGID files if found
+#
+# SuidCheckQuarantineFiles = yes
+
+## Method for Quarantining files:
+#  0 - Delete or truncate the file.
+#  1 - Remove SUID/SGID permissions from file.
+#  2 - Move SUID/SGID file to quarantine dir.
+#
+# SuidCheckQuarantineMethod = 0
+
+## For method 1 and 3, really delete instead of truncating
+# 
+# SuidCheckQuarantineDelete = yes
+
+#[Kernel]
+##
+## --- Check for loadable kernel module rootkits (Linux/FreeBSD only) 
+##
+
+## Switch on/off
+#
+# KernelCheckActive = True
+
+## Check interval (seconds); btw., the check is VERY fast
+#
+# KernelCheckInterval = 300
+
+## Severity
+#
+# SeverityKernel = crit
+
+
+# [Utmp]
+##
+## --- Logging of login/logout events
+##
+
+## Switch on/off
+#
+# LoginCheckActive = True
+
+## Severity for logins, multiple logins, logouts
+# 
+# SeverityLogin=info
+# SeverityLoginMulti=warn
+# SeverityLogout=info
+
+## Interval for login/logout checks
+#
+# LoginCheckInterval = 300
+
+
+# [Database]
+##
+## --- Logging to a relational database
+##
+
+## Database name
+#
+# SetDBName = samhain
+
+## Database table
+#
+# SetDBTable = log
+
+## Database user
+#
+# SetDBUser = samhain
+
+## Database password
+#
+# SetDBPassword = (default: none)
+
+## Database host
+#
+# SetDBHost = localhost
+
+## Log the server timestamp for received messages
+#
+# SetDBServerTstamp = True
+
+## Use a persistent connection
+#
+# UsePersistent = True
+
+# [External]
+##
+## Interface to call external scripts/programs for logging
+##
+
+## The absolute path to the command
+## - Each invocation of this directive will end the definition of the
+##   preceding command, and start the definition of 
+##   an additional, new command
+#
+# OpenCommand = (no default)
+
+## Type (log or rv)
+## - log for log messages, srv for messages received by the server
+#
+# SetType = log
+
+## The command (full command line) to execute
+#
+# SetCommandLine = (no default)
+
+## The environment (KEY=value; repeat for more)
+#
+# SetEnviron = TZ=(your timezone)
+
+## The TIGER192 checksum (optional)
+#
+# SetChecksum = (no default)
+
+## User who runs the command
+#
+# SetCredentials = (default: samhain process uid)
+
+## Words not allowed in message
+#
+# SetFilterNot = (none)
+
+## Words required (ALL of them)
+#
+# SetFilterAnd = (none)
+
+## Words required (at least one)
+#
+# SetFilterOr = (none)
+
+## Deadtime between consecutive calls
+#
+# SetDeadtime = 0
+
+## Add default environment (HOME, PATH, SHELL)
+#
+# SetDefault = no
+
+
+#####################################################
+#
+# Miscellaneous configuration options
+#
+#####################################################
+
+[Misc]
+
+## whether to become a daemon process
+## (this is not honoured on database initialisation)
+#
+# Daemon = no
+Daemon = yes
+
+## whether to test signature of files (init/check/none)
+## - if 'none', then we have to decide this on the command line -
+#
+# ChecksumTest = none
+ChecksumTest=check
+
+## Set nice level (-19 to 19, see 'man nice'),
+## and I/O limit (kilobytes per second; 0 == off)
+## to reduce load on host.
+#
+# SetNiceLevel = 0
+# SetIOLimit = 0
+
+## The version string to embed in file signature databases
+#
+# VersionString = NULL
+
+## Interval between time stamp messages
+#
+# SetLoopTime = 60
+SetLoopTime = 600
+
+## Interval between file checks 
+#
+# SetFileCheckTime = 600
+SetFileCheckTime = 7200
+
+## Alternative: crontab-like schedule
+#
+# FileCheckScheduleOne = NULL
+
+## Alternative: crontab-like schedule(2)
+#
+# FileCheckScheduleTwo = NULL
+
+## Report only once on modified files 
+## Setting this to 'FALSE' will generate a report for any policy 
+## violation (old and new ones) each time the daemon checks the file system.
+#
+# ReportOnlyOnce = True
+
+## Report in full detail
+#
+# ReportFullDetail = False
+
+## Report file timestamps in local time rather than GMT
+#
+# UseLocalTime = No
+
+## The console device (can also be a file or named pipe)
+## - There are two console devices. Accordingly, you can use
+##   this directive a second time to set the second console device.
+##   If you have not defined the second device at compile time,
+##   and you don't want to use it, then:
+##   setting it to /dev/null is less effective than just leaving
+##   it alone (setting to /dev/null will waste time by opening
+##   /dev/null and writing to it)
+#
+# SetConsole = /dev/console
+
+## Activate the SysV IPC message queue
+#
+# MessageQueueActive = False
+
+
+## If false, skip reverse lookup when connecting to a host known 
+## by name rather than IP address (i.e. trust the DNS)
+#
+# SetReverseLookup = True
+
+## --- E-Mail ---
+
+# Only highest-level (alert) reports will be mailed immediately,
+# others will be queued. Here you can define, when the queue will
+# be flushed (Note: the queue is automatically flushed after
+# completing a file check).
+#
+# SetMailTime = 86400
+
+## Maximum number of mails to queue
+#
+# SetMailNum = 10
+
+## Recipient (max. 8)
+#
+# SetMailAddress=root@localhost
+
+## Mail relay (IP address)
+#
+# SetMailRelay = NULL
+
+## Custom subject format
+#
+# MailSubject = NULL
+
+## --- end E-Mail ---
+
+## Path to the prelink executable
+#
+# SetPrelinkPath = /usr/sbin/prelink
+
+## TIGER192 checksum of the prelink executable
+#
+# SetPrelinkChecksum = (no default)
+
+
+## Path to the executable. If set, will be checksummed after startup
+## and before exit.
+#
+# SamhainPath = (no default)
+
+
+## The IP address of the log server
+#
+# SetLogServer = (default: compiled-in)
+
+## The IP address of the time server
+#
+# SetTimeServer = (default: compiled-in)
+
+## Trusted Users (comma delimited list of user names) 
+#
+# TrustedUser = (no default; this adds to the compiled-in list)
+
+## Path to the file signature database
+#
+# SetDatabasePath = (default: compiled-in)
+
+## Path to the log file
+#
+# SetLogfilePath = (default: compiled-in)
+
+## Path to the PID file
+#
+# SetLockPath = (default: compiled-in)
+
+
+## The digest/checksum/hash algorithm
+#
+# DigestAlgo = TIGER192
+
+
+## Custom format for message header. 
+## CAREFUL if you use XML logfile format.
+##
+## %S severity
+## %T timestamp
+## %C class
+##
+## %F source file
+## %L source line
+#
+# MessageHeader="%S %T "
+
+
+## Don't log path to config/database file on startup
+#
+# HideSetup = False
+
+## The syslog facility, if you log to syslog
+#
+# SyslogFacility = LOG_AUTHPRIV
+SyslogFacility=LOG_LOCAL2
+
+## The message authentication method
+## - If you change this, you *must* change it
+##   on client *and* server
+#
+# MACType = HMAC-TIGER
+
+
+## The Prelude-IDS profile to use for reporting
+## default value is "samhain"
+#
+# PreludeProfile = samhain
+
+## Map these samhain severities to impact severity 'info' severity
+#
+# PreludeMapToInfo =
+
+## Map these samhain severities to impact severity 'low' severity
+#
+# PreludeMapToLow = debug info
+
+## Map these samhain severities to impact severity 'medium' severity
+#
+# PreludeMapToMedium = notice warn err
+
+## Map these samhain severities to impact severity 'high' severity
+#
+# PreludeMapToHigh = crit alert
+
+
+## everything below is ignored
+[EOF]
+
+#####################################################################
+# This would be the proper syntax for parts that should only be
+#    included for certain hosts.
+# You may enclose anything in a @HOSTNAME/@end bracket, as long as the
+#    result still has the proper syntax for the config file.
+# You may have any number of @HOSTNAME/@end brackets.
+# HOSTNAME should be the fully qualified 'official' name 
+#    (e.g. 'nixon.watergate.com', not 'nixon'), no aliases. 
+#    No IP number - except if samhain cannot determine the 
+#    fully qualified hostname.
+#
+# @HOSTNAME
+# file=/foo/bar
+# @end
+#
+# These are two examples for conditional inclusion/exclusion
+# of a machine based on the output from 'uname -srm'
+# $Linux:2.*.7:i666
+# file=/foo/bar3
+# $end
+#
+# !$Linux:2.*.7:i686
+# file=/foo/bar2
+# $end
+#
+#####################################################################
diff --git a/engine/tests/Functional.samhain/fuego_test.sh b/engine/tests/Functional.samhain/fuego_test.sh
new file mode 100644
index 0000000..dddf5ad
--- /dev/null
+++ b/engine/tests/Functional.samhain/fuego_test.sh
@@ -0,0 +1,19 @@
+function test_pre_check {
+    is_on_target_path samhain PROGRAM_SAMHAIN
+    assert_define PROGRAM_SAMHAIN "Missing 'samhain' program on target board"
+}
+
+function test_deploy {
+    put $TEST_HOME/samhain_test.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;\
+    ./samhain_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.samhain/parser.py b/engine/tests/Functional.samhain/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.samhain/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.samhain/samhain_test.sh b/engine/tests/Functional.samhain/samhain_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.samhain/samhain_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.samhain/spec.json b/engine/tests/Functional.samhain/spec.json
new file mode 100644
index 0000000..5e2f023
--- /dev/null
+++ b/engine/tests/Functional.samhain/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.samhain",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.samhain/tests/samhain_check.sh b/engine/tests/Functional.samhain/tests/samhain_check.sh
new file mode 100644
index 0000000..312466d
--- /dev/null
+++ b/engine/tests/Functional.samhain/tests/samhain_check.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+#  In target, run command samhain.
+#  option: -t
+
+test="check"
+
+umount /media/sda2 > /dev/null 2>&1
+umount /media/sda3 > /dev/null 2>&1
+umount /media/sda4 > /dev/null 2>&1
+umount /media/sda5 > /dev/null 2>&1
+umount /media/sda6 > /dev/null 2>&1
+umount /media/sda7 > /dev/null 2>&1
+umount /media/sda8 > /dev/null 2>&1
+umount /media/sda9 > /dev/null 2>&1
+
+mv /etc/samhainrc /etc/samhainrc_bak
+cp data/samhainrc /etc/samhainrc
+
+chown root.root /etc/samhainrc
+
+rm -fr /var/samhain/*
+rm -f /var/log/samhain_log
+
+sleep 1
+
+mkdir -p test_dir/samhain_test/
+touch test_dir/samhain_test/test.txt
+
+samhain -t init -p info > /dev/null 2&> 1
+
+sleep 1
+
+echo test > test_dir/samhain_test/test.txt
+
+sleep 1
+
+if samhain -t check
+then
+    echo " -> samhain -t check succeeded."
+else
+    echo " -> $test: TEST-FAIL"
+    rm -fr test_dir/samhain_test
+    mv /etc/samhainrc_bak /etc/samhainrc
+    exit
+fi
+
+sleep 2
+
+if cat /var/log/samhain_log | grep "path=</home/test/samhain_test/test.txt>, size_old=<0>, size_new=<5>"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+rm -fr test_dir/samhain_test
+mv /etc/samhainrc_bak /etc/samhainrc
diff --git a/engine/tests/Functional.samhain/tests/samhain_help.sh b/engine/tests/Functional.samhain/tests/samhain_help.sh
new file mode 100644
index 0000000..f16b680
--- /dev/null
+++ b/engine/tests/Functional.samhain/tests/samhain_help.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command samhain.
+#  option: --help
+
+test="help"
+
+if samhain --help | grep "Usage"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/engine/tests/Functional.samhain/tests/samhain_init.sh b/engine/tests/Functional.samhain/tests/samhain_init.sh
new file mode 100644
index 0000000..64a2f17
--- /dev/null
+++ b/engine/tests/Functional.samhain/tests/samhain_init.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+#  In target, run command samhain.
+#  option: -t
+
+test="init"
+
+umount /media/sda2 > /dev/null 2>&1
+umount /media/sda3 > /dev/null 2>&1
+umount /media/sda4 > /dev/null 2>&1
+umount /media/sda5 > /dev/null 2>&1
+umount /media/sda6 > /dev/null 2>&1
+umount /media/sda7 > /dev/null 2>&1
+umount /media/sda8 > /dev/null 2>&1
+umount /media/sda9 > /dev/null 2>&1
+
+mv /etc/samhainrc /etc/samhainrc_bak
+cp data/samhainrc /etc/samhainrc
+
+chown root.root /etc/samhainrc
+
+rm -fr /var/samhain/*
+rm -f /var/log/samhain_log
+
+sleep 1
+
+mkdir -p test_dir/samhain_test/
+touch test_dir/samhain_test/test.txt
+
+samhain -t init -p info > /dev/null 2&> 1
+
+sleep 1
+
+if cat /var/log/samhain_log | grep "ALRT.*-.*-.*T.*:.*:.*msg=\"EXIT\""
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+rm -fr test_dir/samhain_test
+mv /etc/samhainrc_bak /etc/samhainrc
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Fuego] [PATCH] Add test case of command bc.
  2018-10-31  8:44 [Fuego] [PATCH] Add test cases of command syslog-ng Wang Mingyu
                   ` (3 preceding siblings ...)
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command samhain Wang Mingyu
@ 2018-10-31  8:44 ` Wang Mingyu
  4 siblings, 0 replies; 9+ messages in thread
From: Wang Mingyu @ 2018-10-31  8:44 UTC (permalink / raw)
  To: fuego

Read the expression from the file and display the results.

Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
---
 engine/tests/Functional.bc/bc-script.tar.gz | Bin 270 -> 429 bytes
 engine/tests/Functional.bc/by2.tar.gz       | Bin 264 -> 390 bytes
 engine/tests/Functional.bc/fuego_test.sh    |   4 ++--
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/engine/tests/Functional.bc/bc-script.tar.gz b/engine/tests/Functional.bc/bc-script.tar.gz
index eaa468151e6d0aefe54f5d4057c1aa03298b712d..dd7331e22942f7dcafbe197300b878a6fe5b2efb 100644
GIT binary patch
literal 429
zcmV;e0aE@SiwFRBO}$$H1MSxDOTs`H2k^bVzvAiKtH|6>7vX{m1xYZhAc&~#Jl#OI
zx!ro@AK%S%X;c<yQaztH`*F|MZO^{Pd{)g^8YZHqY>g&4j$LeZr>-q;7ZlwzZO5?c
zwk_*)IczFmZ*NMk@=SOsfHKJWF#e=&-S{u%m;IM}ef|_OewYQDy~nKo_Q(C#9jENS
zW;wF|mTnmeXq%nJ`~G?VD|<CRjB37@1%#ZPKQwPId#<V%yS?VsP3PKG4MM^J+}*(=
zXF&|=yb7k^vqx}UplVr7;r^b8fJX$RSv~DuP{KzUUpmz~ZFeXcgk;x`|L?8je-Mr~
zpZ@jvH>|h$H|vIm`Tq&?{1@r30JI~JZ)3>C0i<~ZEFO=&s4sJVNQmH>aB1<0P(qj|
z-~?E44jK(;c3Z^WKO&Pn6r?yPRt%p(buzD+!Z76tP)noVSsv2y%k{WUY|Bdi13pT2
zk$?T||DVjiiTVEtU(UZAjS~^Z(J@qm#cEJ|FtiMNP{usZydnQq(s%tH5JCtcgb+dq
XA%qY@2qA<J`U{=`(w%Eq04M+es1VdQ

literal 270
zcmb2|=3uxNwJVH)`RzqV@52Tn>>uXcUtV!7ZfowPlI3zCY8}j}S{%tcmZoh{SZ#83
zviv=XrClAnb9y%Ze?Q^7hn&ij^{17iw|y-ZXP2IA!MwDlv@ZPqa;0!5wWI}~6g)5c
zbT(XlHt);Zqh+6`S!T>$_B%iC>d(GQwg1*to2)O*?91JH&pPbs`=akZpU(^mO4F;K
z={>!E)4lXRx#vII+jNxf?fH5q%w>5x|KZ=S3k8?Tzpbb!Hs7VI<QSq~Vf1jO=IXY^
z>ox0=W6$l-u;}^qa>DZ9S6Z7@%Kp?;luAyj-1O}DwVx-CYAkW}tvmlxyLR1{xAlw+
RXy69x`yBTdHVhgJ3;^hag17(x

diff --git a/engine/tests/Functional.bc/by2.tar.gz b/engine/tests/Functional.bc/by2.tar.gz
index a424d5b9cfe03497709a12d21d65886f43ba9730..676e82ba78de2153b8ce4124aa5bb369facba59c 100644
GIT binary patch
literal 390
zcmV;10eSu(iwFQsNxfSD1MSv9OT#b}2k@TrDV|vmDsD@YrUjt~l?mcNnF_)fuI;k6
zu(e}t1;Gz*s#E3;ZXUX!d%sIcn$VJ$f7;-Mw~d-H&6TohE!Sbo?I*($Lb}|xZATc)
zVp2CC>wd9HnHT;Xz!;Y*%6=HP?*1PY==uj?bEKY=P_^>7j%Tc^KWC1vzr}2+_kd&T
z`g2z}2CzC_X4Rh8zj4qGlC&N8c}&Rp#Z%|;w&$5vb=m9OJ#_CqlM|ARq2Gt03gZmu
zp}81$bj&HdLJ$tY^MIOPb0`c3q=;2YK>L_=b4`hw<Z7ww^6aWh$v7co*Q>C<zU80S
za{z3Xe<2;|*ur&n{sj{P^S=$4|NXYef2=06n!f%U<lkET|Km27nE!29<iARP1K=tJ
zy&91!PGDZ95N6Y<pN@3GTh-lcRwP+^3Qaw@P<i3eYTMBF;~@xjw>}J_xtakjb3an_
kH%Gv(*8w4f5JCtcgb+dqA%qY@2%-Pr4K000!2l=#07t{ZOaK4?

literal 264
zcmb2|=3w~0TPTu&`R&DnUd)C9Y!Bu<*F3g^U9@C!&SuNEj!T;&0#-EzbmeZ-+#R4b
zLyN<1&+d$+6&sejcKt7(X)sgK`PlxMAtgShbGGJQIk)QU4z-eHq36?%J&T-N?k9P0
z+v|f-`h}*oX=0mq{Medz`)}W;v;S%<ZMfH$O8O;TJt}?sTYkvCd;3c({Wb2U6dhdE
zomltl`S1Jpy=(XS{51)4Nq^q|w|#cv#24Qz-rT>(|E}wZz|~^8-U^{puR5PPehMwG
zNKx6pSzkRyL}&7Qxs#6#*RI;2l2=m}8}G^0EnyZUzI-~f=jT~3*4HyKpn(MQT81-L
KF)J7}7#IM@hkH)|

diff --git a/engine/tests/Functional.bc/fuego_test.sh b/engine/tests/Functional.bc/fuego_test.sh
index 5c9bbbd..b614951 100755
--- a/engine/tests/Functional.bc/fuego_test.sh
+++ b/engine/tests/Functional.bc/fuego_test.sh
@@ -12,11 +12,11 @@ function test_build {
 }
 
 function test_deploy {
-    put bc-device.sh  $BOARD_TESTDIR/fuego.$TESTDIR/
+    put ./* $BOARD_TESTDIR/fuego.$TESTDIR
 }
 
 function test_run {
-    report "cd $BOARD_TESTDIR/fuego.$TESTDIR; ./bc-device.sh $FUNCTIONAL_BC_EXPR $FUNCTIONAL_BC_RESULT"
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR; ./bc-device.sh; ./bc-file.sh; ./bc-help.sh $FUNCTIONAL_BC_EXPR $FUNCTIONAL_BC_RESULT"
 }
 
 function test_processing {
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Fuego] [PATCH] Add test cases of command vconfig.
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command vconfig Wang Mingyu
@ 2018-10-31 18:31   ` Tim.Bird
  0 siblings, 0 replies; 9+ messages in thread
From: Tim.Bird @ 2018-10-31 18:31 UTC (permalink / raw)
  To: wangmy, fuego

Please see comments inline below:

> -----Original Message-----
> From: Wang Mingyu
>
There is no description in the commit message.  The body of the
commit message should not be empty. Please at least describe
the test a little bit here.

 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  engine/tests/Functional.vconfig/fuego_test.sh      | 19
> ++++++++++++++++++
>  engine/tests/Functional.vconfig/parser.py          | 22
> +++++++++++++++++++++
>  engine/tests/Functional.vconfig/spec.json          |  7 +++++++
>  .../Functional.vconfig/tests/vconfig_VLAN_tag.sh   | 23
> ++++++++++++++++++++++
>  .../tests/Functional.vconfig/tests/vconfig_add.sh  | 16 +++++++++++++++
>  .../Functional.vconfig/tests/vconfig_addaddr.sh    | 17 ++++++++++++++++
>  .../tests/Functional.vconfig/tests/vconfig_help.sh | 13 ++++++++++++
>  .../Functional.vconfig/tests/vconfig_remove.sh     | 15 ++++++++++++++
>  .../Functional.vconfig/tests/vconfig_set_flag.sh   | 16 +++++++++++++++
>  engine/tests/Functional.vconfig/vconfig_test.sh    |  4 ++++
>  10 files changed, 152 insertions(+)
>  create mode 100644 engine/tests/Functional.vconfig/fuego_test.sh
>  create mode 100644 engine/tests/Functional.vconfig/parser.py
>  create mode 100644 engine/tests/Functional.vconfig/spec.json
>  create mode 100644
> engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh
>  create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_add.sh
>  create mode 100644
> engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh
>  create mode 100644 engine/tests/Functional.vconfig/tests/vconfig_help.sh
>  create mode 100644
> engine/tests/Functional.vconfig/tests/vconfig_remove.sh
>  create mode 100644
> engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh
>  create mode 100755 engine/tests/Functional.vconfig/vconfig_test.sh
> 
> diff --git a/engine/tests/Functional.vconfig/fuego_test.sh
> b/engine/tests/Functional.vconfig/fuego_test.sh
> new file mode 100644
> index 0000000..cda39c7
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/fuego_test.sh
> @@ -0,0 +1,19 @@
> +function test_pre_check {
> +    is_on_target_path vconfig PROGRAM_VCONFIG
> +    assert_define PROGRAM_VCONFIG "Missing 'vconfig' program on target
> board"
Should be:
assert_has_program vconfig

> +}
> +
> +function test_deploy {
> +    put $TEST_HOME/vconfig_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 vcon_remote_ifeth=$IFETH;\
Where does $IFETH come from?

If the test requires a variable defined in the board file, then this
should be documented in a test.yaml file.

> +    ./vconfig_test.sh"
> +}
> +
> +function test_processing {
> +    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/engine/tests/Functional.vconfig/parser.py
> b/engine/tests/Functional.vconfig/parser.py
> new file mode 100644
> index 0000000..d85abd7
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/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))
I'm still interested in adding a generic parser for this.

But that will likely have to wait until we do an overhaul of the parser
code for the 1.5 release.

> diff --git a/engine/tests/Functional.vconfig/spec.json
> b/engine/tests/Functional.vconfig/spec.json
> new file mode 100644
> index 0000000..e45af81
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/spec.json
> @@ -0,0 +1,7 @@
> +{
> +    "testName": "Functional.vconfig",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> +
> diff --git a/engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh
> b/engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh
> new file mode 100644
> index 0000000..14d1b86
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/tests/vconfig_VLAN_tag.sh
> @@ -0,0 +1,23 @@
> +#!/bin/sh
> +
> +#  In target, run command vconfig.
> +#  option: add/rem
> +
> +test="VLAN_tag"
> +
> +mkdir test_dir
> +
> +ifconfig $vcon_remote_ifeth up
I'm confused by the variable naming here.
Is 'vcon_remote_ifeth' the board's Ethernet device?
Why does it have 'remote' in the name?

> +vconfig add $vcon_remote_ifeth 100
> +ifconfig $vcon_remote_ifeth.100 inet 192.168.255.1 netmask 0xffffff00
These addresses look suspiciously hardcoded for a particular network.
Will this work in other people's labs, or does the board have to
already be on a 192.168.255 network?

Please explain what this test is actually doing (possibly by
putting something in a comment in this test).

> +ping -q -c 50 -I $vcon_remote_ifeth.100 192.168.255.2 &
> +tcpdump -c 10 -ex -i $vcon_remote_ifeth ether broadcast >
> test_dir/dumpdata
Should check that ping and tcpdump are on the board with 'assert_has_program'

> +
> +if cat test_dir/dumpdata | grep "vlan 100"

This is an intriguing test.  I look forward to adding it.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +rm -f test_dir/dumpdata
> +vconfig rem $vcon_remote_ifeth.100
> diff --git a/engine/tests/Functional.vconfig/tests/vconfig_add.sh
> b/engine/tests/Functional.vconfig/tests/vconfig_add.sh
> new file mode 100644
> index 0000000..d2c5ad5
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/tests/vconfig_add.sh
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +
> +#  In target, run command vconfig.
> +#  option: add
> +
> +test="add"
> +
> +vconfig add $vcon_remote_ifeth 4
> +
> +if ifconfig $vcon_remote_ifeth.4 | grep "$vcon_remote_ifeth.4"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +vconfig rem $vcon_remote_ifeth.4
> diff --git a/engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh
> b/engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh
> new file mode 100644
> index 0000000..aa98b56
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/tests/vconfig_addaddr.sh
> @@ -0,0 +1,17 @@
> +#!/bin/sh
> +
> +#  In target, run command vconfig.
> +#  option: add/rem
> +
> +test="addaddr"
> +
> +vconfig add $vcon_remote_ifeth 100
> +ifconfig $vcon_remote_ifeth.100 inet 192.168.255.1 netmask 0xffffff00
> +
> +if ifconfig $vcon_remote_ifeth.100 | grep "192.168.255.1"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +vconfig rem $vcon_remote_ifeth.100
> diff --git a/engine/tests/Functional.vconfig/tests/vconfig_help.sh
> b/engine/tests/Functional.vconfig/tests/vconfig_help.sh
> new file mode 100644
> index 0000000..43314f3
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/tests/vconfig_help.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  In target, run command vconfig.
> +#  option: none
> +
> +test="help"
> +
> +if vconfig | grep Usage
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.vconfig/tests/vconfig_remove.sh
> b/engine/tests/Functional.vconfig/tests/vconfig_remove.sh
> new file mode 100644
> index 0000000..d3696ef
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/tests/vconfig_remove.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +#  In target, run command vconfig.
> +#  option: rem
> +
> +test="remove"
> +
> +vconfig add $vcon_remote_ifeth 4
> +
> +if vconfig rem $vcon_remote_ifeth.4 | grep "Removed VLAN"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> diff --git a/engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh
> b/engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh
> new file mode 100644
> index 0000000..b8b11a5
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/tests/vconfig_set_flag.sh
> @@ -0,0 +1,16 @@
> +#!/bin/sh
> +
> +#  In target, run command vconfig.
> +#  option: set_flag
> +
> +test="set_flag"
> +
> +vconfig add $vcon_remote_ifeth 4
> +
> +if vconfig set_flag $vcon_remote_ifeth.4 1 | grep "Set flag on device"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +vconfig rem $vcon_remote_ifeth.4
> diff --git a/engine/tests/Functional.vconfig/vconfig_test.sh
> b/engine/tests/Functional.vconfig/vconfig_test.sh
> new file mode 100755
> index 0000000..dd5ce37
> --- /dev/null
> +++ b/engine/tests/Functional.vconfig/vconfig_test.sh
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +for i in tests/*.sh; do
> +    sh $i
> +done
> --
> 1.8.3.1


Most of this looks good.  But please address the comments above
and re-submit.

Thanks,
 -- Tim


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Fuego] [PATCH] Add test cases of command samhain.
  2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command samhain Wang Mingyu
@ 2018-10-31 19:06   ` Tim.Bird
  0 siblings, 0 replies; 9+ messages in thread
From: Tim.Bird @ 2018-10-31 19:06 UTC (permalink / raw)
  To: wangmy, fuego

See comments inline below.

> -----Original Message-----
> From: Wang Mingyu

The commit message body must not be empty.  Please describe
what 'samhain' is, and what this test is testing about it.

> 
> Signed-off-by: Wang Mingyu <wangmy@cn.fujitsu.com>
> ---
>  engine/tests/Functional.samhain/data/samhainrc     | 773
> +++++++++++++++++++++
>  engine/tests/Functional.samhain/fuego_test.sh      |  19 +
>  engine/tests/Functional.samhain/parser.py          |  22 +
>  engine/tests/Functional.samhain/samhain_test.sh    |   4 +
>  engine/tests/Functional.samhain/spec.json          |   7 +
>  .../Functional.samhain/tests/samhain_check.sh      |  58 ++
>  .../tests/Functional.samhain/tests/samhain_help.sh |  13 +
>  .../tests/Functional.samhain/tests/samhain_init.sh |  42 ++
>  8 files changed, 938 insertions(+)
>  create mode 100755 engine/tests/Functional.samhain/data/samhainrc
>  create mode 100644 engine/tests/Functional.samhain/fuego_test.sh
>  create mode 100644 engine/tests/Functional.samhain/parser.py
>  create mode 100755 engine/tests/Functional.samhain/samhain_test.sh
>  create mode 100644 engine/tests/Functional.samhain/spec.json
>  create mode 100644
> engine/tests/Functional.samhain/tests/samhain_check.sh
>  create mode 100644
> engine/tests/Functional.samhain/tests/samhain_help.sh
>  create mode 100644 engine/tests/Functional.samhain/tests/samhain_init.sh
> 
> diff --git a/engine/tests/Functional.samhain/data/samhainrc
> b/engine/tests/Functional.samhain/data/samhainrc
> new file mode 100755
> index 0000000..e90926d
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/data/samhainrc
> @@ -0,0 +1,773 @@
> +#########################################################
> ############
> +#
> +# Configuration file template for samhain.
> +#
> +#########################################################
> ############
> +#
> +# -- empty lines and lines starting with '#', ';' or '//' are ignored
> +# -- boolean options can be Yes/No or True/False or 1/0
> +# -- you can PGP clearsign this file -- samhain will check (if compiled
> +#    with support) or otherwise ignore the signature
> +# -- CHECK mail address
> +#
> +# To each log facility, you can assign a threshold severity. Only
> +# reports with at least the threshold severity will be logged
> +# to the respective facility (even further below).
> +#
> +#########################################################
> ############
> +#
> +# SETUP for file system checking:
> +#
> +# (i)   There are several policies, each has its own section. Put files
> +#       into the section for the appropriate policy (see below).
> +# (ii)  Section [EventSeverity]:
> +#       To each policy, you can assign a severity (further below).
> +# (iii) Section [Log]:
> +#       To each log facility, you can assign a threshold severity. Only
> +#       reports with at least the threshold severity will be logged
> +#       to the respective facility (even further below).
> +#
> +#########################################################
> ############
> +
> +#########################################################
> ############
> +#
> +# Files are defined with: file = /absolute/path
> +#
> +# Directories are defined with:                  dir = /absolute/path
> +# or with an optional recursion depth (N <= 99): dir = N/absolute/path
> +#
> +# Directory inodes are checked. If you only want to check files
> +# in a directory, but not the directory inode itself, use (e.g.):
> +#
> +# [ReadOnly]
> +# dir = /some/directory
> +# [IgnoreAll]
> +# file = /some/directory
> +#
> +# You can use shell-style globbing patterns, like: file = /path/foo*
> +#
> +#########################################################
> #############
> +
> +[Misc]
> +##
> +## Add or subtract tests from the policies
> +## - if you want to change their definitions,
> +##   you need to do that before using the policies
> +##
> +# RedefReadOnly = (no default)
> +# RedefAttributes=(no default)
> +# RedefLogFiles=(no default)
> +# RedefGrowingLogFiles=(no default)
> +# RedefIgnoreAll=(no default)
> +# RedefIgnoreNone=(no default)
> +
> +# RedefUser0=(no default)
> +# RedefUser1=(no default)
> +
> +#
> +# --------- / --------------
> +#
> +
> +[ReadOnly]
> +#dir = 0/
> +
> +[Attributes]
> +file = /tmp
> +file = /dev
> +file = /media
> +file = /proc
> +file = /sys
> +
> +#
> +# --------- /etc -----------
> +#
> +
> +[ReadOnly]
> +##
> +## for these files, only access time is ignored
> +##
> +#dir = 99/etc
> +
> +[Attributes]
> +##
> +## check permission and ownership
> +##
> +#file = /etc/mtab
> +#file = /etc/adjtime
> +#file = /etc/motd
> +#file = /etc/lvm/.cache
> +
> +# On Ubuntu, these are in /var/lib rather than /etc
> +#file = /etc/cups/certs
> +#file = /etc/cups/certs/0
> +
> +# managed by fstab-sync on Fedora Core
> +#file = /etc/fstab
> +
> +# modified when booting
> +#file = /etc/sysconfig/hwconf
> +
> +# There are files in /etc that might change, thus changing the directory
> +# timestamps. Put it here as 'file', and in the ReadOnly section as 'dir'.
> +
> +#file = /etc
> +
> +#
> +# --------- /boot -----------
> +#
> +
> +[ReadOnly]
> +#dir = 99/boot
> +
> +#
> +# --------- /bin, /sbin -----------
> +#
> +
> +[ReadOnly]
> +#dir = 99/bin
> +#dir = 99/sbin
> +
> +#
> +# --------- /lib -----------
> +#
> +
> +[ReadOnly]
> +#dir = 99/lib
> +
> +#
> +# --------- /dev -----------
> +#
> +
> +[Attributes]
> +#dir = 99/dev
> +
> +[IgnoreAll]
> +##
> +## pseudo terminals are created/removed as needed
> +##
> +#dir = -1/dev/pts
> +
> +# dir = -1/dev/.udevdb
> +
> +#file = /dev/ppp
> +
> +#
> +# --------- /usr -----------
> +#
> +
> +[ReadOnly]
> +#dir = 99/usr
> +
> +[ReadOnly]
> +dir = 99$BOARD_TESTDIR/fuego.$TESTDIR/test_dir/samhain_test
> +
> +#
> +# --------- /var -----------
> +#
> +
> +[ReadOnly]
> +#dir = 99/var
> +
> +[IgnoreAll]
> +dir = -1/var/cache
> +dir = -1/var/backups
> +dir = -1/var/games
> +dir = -1/var/gdm
> +dir = -1/var/lock
> +dir = -1/var/mail
> +dir = -1/var/run
> +dir = -1/var/spool
> +dir = -1/var/tmp
> +dir = -1/var/lib/texmf
> +dir = -1/var/lib/scrollkeeper
> +
> +
> +[Attributes]
> +
> +dir = /var/lib/nfs
> +dir = /var/lib/pcmcia
> +
> +# /var/lib/rpm changes if packets are installed;
> +# /var/lib/rpm/__db.00[123] even more frequently
> +file = /var/lib/rpm/__db.00?
> +
> +file = /var/lib/acpi-support/vbestate
> +file = /var/lib/alsa/asound.state
> +file = /var/lib/apt/lists/lock
> +file = /var/lib/apt/lists/partial
> +file = /var/lib/cups/certs
> +file = /var/lib/cups/certs/0
> +file = /var/lib/dpkg/lock
> +file = /var/lib/gdm
> +file = /var/lib/gdm/.cookie
> +file = /var/lib/gdm/.gdmfifo
> +file = /var/lib/gdm/:0.Xauth
> +file = /var/lib/gdm/:0.Xservers
> +file = /var/lib/logrotate/status
> +file = /var/lib/mysql
> +file = /var/lib/mysql/ib_logfile0
> +file = /var/lib/mysql/ibdata1
> +file = /var/lib/slocate
> +file = /var/lib/slocate/slocate.db
> +file = /var/lib/slocate/slocate.db.tmp
> +file = /var/lib/urandom
> +file = /var/lib/urandom/random-seed
> +file = /var/lib/random-seed
> +file = /var/lib/xkb
> +
> +
> +[GrowingLogFiles]
> +##
> +## For these files, changes in signature, timestamps, and increase in size
> +## are ignored. Logfile rotation will cause a report because of shrinking
> +## size and different inode.
> +##
> +#dir = 99/var/log
> +
> +[Attributes]
> +#
> +# rotated logs will change inode
> +#
> +#file = /var/log/*.[0-9].gz
> +#file = /var/log/*.[0-9].log
> +#file = /var/log/*.[0-9]
> +#file = /var/log/*.old
> +#file = /var/log/*/*.[0-9].gz
> +#file = /var/log/*/*.[0-9][0-9].gz
> +#file = /var/log/*/*.log.[0-9]
> +
> +[Misc]
> +#
> +# Various naming schemes for rotated logs
> +#
> +IgnoreAdded = /var/log/.*\.[0-9]+$
> +IgnoreAdded = /var/log/.*\.[0-9]+\.gz$
> +IgnoreAdded = /var/log/.*\.[0-9]+\.log$
> +#
> +# Subdirectories
> +#
> +IgnoreAdded = /var/log/[[:alnum:]]+/.*\.[0-9]+$
> +IgnoreAdded = /var/log/[[:alnum:]]+/.*\.[0-9]+\.gz$
> +IgnoreAdded = /var/log/[[:alnum:]]+/.*\.[0-9]+\.log$
> +#
> +IgnoreAdded = /var/lib/slocate/slocate.db.tmp
> +IgnoreMissing = /var/lib/slocate/slocate.db.tmp
> +
> +#
> +# --------- other policies -----------
> +#
> +
> +[IgnoreNone]
> +##
> +## for these files, all modifications (even access time) are reported
> +##    - you may create some interesting-looking file (like /etc/safe_passwd),
> +##      just to watch whether someone will access it ...
> +##
> +
> +[Prelink]
> +##
> +## Use for prelinked files or directories holding them
> +##
> +
> +
> +[User0]
> +[User1]
> +## User0 and User1 are sections for files/dirs with user-definable checking
> +## (see the manual)
> +
> +
> +
> +[EventSeverity]
> +##
> +## Here you can assign severities to policy violations.
> +## If this severity exceeds the treshold of a log facility (see below),
> +## a policy violation will be logged to that facility.
> +##
> +## Severity for verification failures.
> +##
> +# SeverityReadOnly=crit
> +# SeverityLogFiles=crit
> +# SeverityGrowingLogs=crit
> +# SeverityIgnoreNone=crit
> +# SeverityAttributes=crit
> +# SeverityUser0=crit
> +# SeverityUser1=crit
> +# SeverityIgnoreAll=crit
> +
> +
> +## Files : file access problems
> +# SeverityFiles=crit
> +
> +## Dirs  : directory access problems
> +# SeverityDirs=crit
> +
> +## Names : suspect (non-printable) characters in a pathname
> +# SeverityNames=crit
> +
> +[Log]
> +##
> +## Switch on/OFF log facilities and set their threshold severity
> +##
> +## Values: debug, info, notice, warn, mark, err, crit, alert, none.
> +## 'mark' is used for timestamps.
> +##
> +##
> +## Use 'none' to SWITCH OFF a log facility
> +##
> +## By default, everything equal to and above the threshold is logged.
> +## The specifiers '*', '!', and '=' are interpreted as
> +## 'all', 'all but', and 'only', respectively (like syslogd(8) does,
> +## at least on Linux). Examples:
> +## MailSeverity=*
> +## MailSeverity=!warn
> +## MailSeverity==crit
> +
> +## E-mail
> +##
> +# MailSeverity=none
> +
> +## Console
> +##
> +# PrintSeverity=info
> +
> +## Logfile
> +##
> +# LogSeverity=mark
> +
> +## Syslog
> +##
> +# SyslogSeverity=none
> +
> +## Remote server (yule)
> +##
> +# ExportSeverity=none
> +
> +## External script or program
> +##
> +# ExternalSeverity = none
> +
> +## Logging to a database
> +##
> +# DatabaseSeverity = none
> +
> +## Logging to a Prelude-IDS
> +##
> +# PreludeSeverity = crit
> +
> +
> +
> +#####################################################
> +#
> +# Optional modules
> +#
> +#####################################################
> +
> +# [SuidCheck]
> +##
> +## --- Check the filesystem for SUID/SGID binaries
> +##
> +
> +## Switch on
> +#
> +# SuidCheckActive = yes
> +
> +## Interval for check (seconds)
> +#
> +# SuidCheckInterval = 7200
> +
> +## Alternative: crontab-like schedule
> +#
> +# SuidCheckSchedule = NULL
> +
> +## Directory to exclude
> +#
> +# SuidCheckExclude = NULL
> +
> +## Limit on files per second (0 == no limit)
> +#
> +# SuidCheckFps = 0
> +
> +## Alternative: yield after every file
> +#
> +# SuidCheckYield = no
> +
> +## Severity of a detection
> +#
> +# SeveritySuidCheck = crit
> +
> +## Quarantine SUID/SGID files if found
> +#
> +# SuidCheckQuarantineFiles = yes
> +
> +## Method for Quarantining files:
> +#  0 - Delete or truncate the file.
> +#  1 - Remove SUID/SGID permissions from file.
> +#  2 - Move SUID/SGID file to quarantine dir.
> +#
> +# SuidCheckQuarantineMethod = 0
> +
> +## For method 1 and 3, really delete instead of truncating
> +#
> +# SuidCheckQuarantineDelete = yes
> +
> +#[Kernel]
> +##
> +## --- Check for loadable kernel module rootkits (Linux/FreeBSD only)
> +##
> +
> +## Switch on/off
> +#
> +# KernelCheckActive = True
> +
> +## Check interval (seconds); btw., the check is VERY fast
> +#
> +# KernelCheckInterval = 300
> +
> +## Severity
> +#
> +# SeverityKernel = crit
> +
> +
> +# [Utmp]
> +##
> +## --- Logging of login/logout events
> +##
> +
> +## Switch on/off
> +#
> +# LoginCheckActive = True
> +
> +## Severity for logins, multiple logins, logouts
> +#
> +# SeverityLogin=info
> +# SeverityLoginMulti=warn
> +# SeverityLogout=info
> +
> +## Interval for login/logout checks
> +#
> +# LoginCheckInterval = 300
> +
> +
> +# [Database]
> +##
> +## --- Logging to a relational database
> +##
> +
> +## Database name
> +#
> +# SetDBName = samhain
> +
> +## Database table
> +#
> +# SetDBTable = log
> +
> +## Database user
> +#
> +# SetDBUser = samhain
> +
> +## Database password
> +#
> +# SetDBPassword = (default: none)
> +
> +## Database host
> +#
> +# SetDBHost = localhost
> +
> +## Log the server timestamp for received messages
> +#
> +# SetDBServerTstamp = True
> +
> +## Use a persistent connection
> +#
> +# UsePersistent = True
> +
> +# [External]
> +##
> +## Interface to call external scripts/programs for logging
> +##
> +
> +## The absolute path to the command
> +## - Each invocation of this directive will end the definition of the
> +##   preceding command, and start the definition of
> +##   an additional, new command
> +#
> +# OpenCommand = (no default)
> +
> +## Type (log or rv)
> +## - log for log messages, srv for messages received by the server
> +#
> +# SetType = log
> +
> +## The command (full command line) to execute
> +#
> +# SetCommandLine = (no default)
> +
> +## The environment (KEY=value; repeat for more)
> +#
> +# SetEnviron = TZ=(your timezone)
> +
> +## The TIGER192 checksum (optional)
> +#
> +# SetChecksum = (no default)
> +
> +## User who runs the command
> +#
> +# SetCredentials = (default: samhain process uid)
> +
> +## Words not allowed in message
> +#
> +# SetFilterNot = (none)
> +
> +## Words required (ALL of them)
> +#
> +# SetFilterAnd = (none)
> +
> +## Words required (at least one)
> +#
> +# SetFilterOr = (none)
> +
> +## Deadtime between consecutive calls
> +#
> +# SetDeadtime = 0
> +
> +## Add default environment (HOME, PATH, SHELL)
> +#
> +# SetDefault = no
> +
> +
> +#####################################################
> +#
> +# Miscellaneous configuration options
> +#
> +#####################################################
> +
> +[Misc]
> +
> +## whether to become a daemon process
> +## (this is not honoured on database initialisation)
> +#
> +# Daemon = no
> +Daemon = yes
> +
> +## whether to test signature of files (init/check/none)
> +## - if 'none', then we have to decide this on the command line -
> +#
> +# ChecksumTest = none
> +ChecksumTest=check
> +
> +## Set nice level (-19 to 19, see 'man nice'),
> +## and I/O limit (kilobytes per second; 0 == off)
> +## to reduce load on host.
> +#
> +# SetNiceLevel = 0
> +# SetIOLimit = 0
> +
> +## The version string to embed in file signature databases
> +#
> +# VersionString = NULL
> +
> +## Interval between time stamp messages
> +#
> +# SetLoopTime = 60
> +SetLoopTime = 600
> +
> +## Interval between file checks
> +#
> +# SetFileCheckTime = 600
> +SetFileCheckTime = 7200
> +
> +## Alternative: crontab-like schedule
> +#
> +# FileCheckScheduleOne = NULL
> +
> +## Alternative: crontab-like schedule(2)
> +#
> +# FileCheckScheduleTwo = NULL
> +
> +## Report only once on modified files
> +## Setting this to 'FALSE' will generate a report for any policy
> +## violation (old and new ones) each time the daemon checks the file
> system.
> +#
> +# ReportOnlyOnce = True
> +
> +## Report in full detail
> +#
> +# ReportFullDetail = False
> +
> +## Report file timestamps in local time rather than GMT
> +#
> +# UseLocalTime = No
> +
> +## The console device (can also be a file or named pipe)
> +## - There are two console devices. Accordingly, you can use
> +##   this directive a second time to set the second console device.
> +##   If you have not defined the second device at compile time,
> +##   and you don't want to use it, then:
> +##   setting it to /dev/null is less effective than just leaving
> +##   it alone (setting to /dev/null will waste time by opening
> +##   /dev/null and writing to it)
> +#
> +# SetConsole = /dev/console
> +
> +## Activate the SysV IPC message queue
> +#
> +# MessageQueueActive = False
> +
> +
> +## If false, skip reverse lookup when connecting to a host known
> +## by name rather than IP address (i.e. trust the DNS)
> +#
> +# SetReverseLookup = True
> +
> +## --- E-Mail ---
> +
> +# Only highest-level (alert) reports will be mailed immediately,
> +# others will be queued. Here you can define, when the queue will
> +# be flushed (Note: the queue is automatically flushed after
> +# completing a file check).
> +#
> +# SetMailTime = 86400
> +
> +## Maximum number of mails to queue
> +#
> +# SetMailNum = 10
> +
> +## Recipient (max. 8)
> +#
> +# SetMailAddress=root@localhost
> +
> +## Mail relay (IP address)
> +#
> +# SetMailRelay = NULL
> +
> +## Custom subject format
> +#
> +# MailSubject = NULL
> +
> +## --- end E-Mail ---
> +
> +## Path to the prelink executable
> +#
> +# SetPrelinkPath = /usr/sbin/prelink
> +
> +## TIGER192 checksum of the prelink executable
> +#
> +# SetPrelinkChecksum = (no default)
> +
> +
> +## Path to the executable. If set, will be checksummed after startup
> +## and before exit.
> +#
> +# SamhainPath = (no default)
> +
> +
> +## The IP address of the log server
> +#
> +# SetLogServer = (default: compiled-in)
> +
> +## The IP address of the time server
> +#
> +# SetTimeServer = (default: compiled-in)
> +
> +## Trusted Users (comma delimited list of user names)
> +#
> +# TrustedUser = (no default; this adds to the compiled-in list)
> +
> +## Path to the file signature database
> +#
> +# SetDatabasePath = (default: compiled-in)
> +
> +## Path to the log file
> +#
> +# SetLogfilePath = (default: compiled-in)
> +
> +## Path to the PID file
> +#
> +# SetLockPath = (default: compiled-in)
> +
> +
> +## The digest/checksum/hash algorithm
> +#
> +# DigestAlgo = TIGER192
> +
> +
> +## Custom format for message header.
> +## CAREFUL if you use XML logfile format.
> +##
> +## %S severity
> +## %T timestamp
> +## %C class
> +##
> +## %F source file
> +## %L source line
> +#
> +# MessageHeader="%S %T "
> +
> +
> +## Don't log path to config/database file on startup
> +#
> +# HideSetup = False
> +
> +## The syslog facility, if you log to syslog
> +#
> +# SyslogFacility = LOG_AUTHPRIV
> +SyslogFacility=LOG_LOCAL2
> +
> +## The message authentication method
> +## - If you change this, you *must* change it
> +##   on client *and* server
> +#
> +# MACType = HMAC-TIGER
> +
> +
> +## The Prelude-IDS profile to use for reporting
> +## default value is "samhain"
> +#
> +# PreludeProfile = samhain
> +
> +## Map these samhain severities to impact severity 'info' severity
> +#
> +# PreludeMapToInfo =
> +
> +## Map these samhain severities to impact severity 'low' severity
> +#
> +# PreludeMapToLow = debug info
> +
> +## Map these samhain severities to impact severity 'medium' severity
> +#
> +# PreludeMapToMedium = notice warn err
> +
> +## Map these samhain severities to impact severity 'high' severity
> +#
> +# PreludeMapToHigh = crit alert
> +
> +
> +## everything below is ignored
> +[EOF]
> +
> +#########################################################
> ############
> +# This would be the proper syntax for parts that should only be
> +#    included for certain hosts.
> +# You may enclose anything in a @HOSTNAME/@end bracket, as long as the
> +#    result still has the proper syntax for the config file.
> +# You may have any number of @HOSTNAME/@end brackets.
> +# HOSTNAME should be the fully qualified 'official' name
> +#    (e.g. 'nixon.watergate.com', not 'nixon'), no aliases.
> +#    No IP number - except if samhain cannot determine the
> +#    fully qualified hostname.
> +#
> +# @HOSTNAME
> +# file=/foo/bar
> +# @end
> +#
> +# These are two examples for conditional inclusion/exclusion
> +# of a machine based on the output from 'uname -srm'
> +# $Linux:2.*.7:i666
> +# file=/foo/bar3
> +# $end
> +#
> +# !$Linux:2.*.7:i686
> +# file=/foo/bar2
> +# $end
> +#
> +#########################################################
> ############

Does this configuration file require a specific distribution of Linux?
I see mentions of Fedora and Ubuntu.  Will this configuration work
on other distributions (like from Yocto Project), or does it need
additional customizations to apply to those.

This raises the issue of whether Fuego should support
checking for a dependency on the board distribution.

It's possible that the comments about distribution-specific
configuration items are irrelevant for the operations performed
by this test, but I'm not familiar with 'samhain', so I don't really
know what it does, or whether these config items are relevant
for the test or not.

> diff --git a/engine/tests/Functional.samhain/fuego_test.sh
> b/engine/tests/Functional.samhain/fuego_test.sh
> new file mode 100644
> index 0000000..dddf5ad
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/fuego_test.sh
> @@ -0,0 +1,19 @@
> +function test_pre_check {
> +    is_on_target_path samhain PROGRAM_SAMHAIN
> +    assert_define PROGRAM_SAMHAIN "Missing 'samhain' program on
> target board"
> +}
> +
> +function test_deploy {
> +    put $TEST_HOME/samhain_test.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;\
> +    ./samhain_test.sh"
> +}
> +
> +function test_processing {
> +    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/engine/tests/Functional.samhain/parser.py
> b/engine/tests/Functional.samhain/parser.py
> new file mode 100644
> index 0000000..d85abd7
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/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.samhain/samhain_test.sh
> b/engine/tests/Functional.samhain/samhain_test.sh
> new file mode 100755
> index 0000000..dd5ce37
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/samhain_test.sh
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +for i in tests/*.sh; do
> +    sh $i
> +done
> diff --git a/engine/tests/Functional.samhain/spec.json
> b/engine/tests/Functional.samhain/spec.json
> new file mode 100644
> index 0000000..5e2f023
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/spec.json
> @@ -0,0 +1,7 @@
> +{
> +    "testName": "Functional.samhain",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> +
> diff --git a/engine/tests/Functional.samhain/tests/samhain_check.sh
> b/engine/tests/Functional.samhain/tests/samhain_check.sh
> new file mode 100644
> index 0000000..312466d
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/tests/samhain_check.sh
> @@ -0,0 +1,58 @@
> +#!/bin/sh
> +
> +#  In target, run command samhain.
> +#  option: -t
> +
> +test="check"
> +
> +umount /media/sda2 > /dev/null 2>&1
> +umount /media/sda3 > /dev/null 2>&1
> +umount /media/sda4 > /dev/null 2>&1
> +umount /media/sda5 > /dev/null 2>&1
> +umount /media/sda6 > /dev/null 2>&1
> +umount /media/sda7 > /dev/null 2>&1
> +umount /media/sda8 > /dev/null 2>&1
> +umount /media/sda9 > /dev/null 2>&1

OK - Please explain what is going on here.  This looks like something
that changes the status of mounted filesystems on the board, with no
mechanism to restore state (nothing is preserved about the state before
unmounting this filesystems).

If some other program has a filesystem mounted on /media/sda[1-9] then
this will pull the rug out from under it.

If this is cleaning up from possible leftover stuff from a previous
run of the test, then that should be mentioned in a comment
(and possibly the cleanup should happen at the end of the test
rather than at the beginning).

I any case, please tell me why these umounts are here, and add
a comment about them in the code.

> +
> +mv /etc/samhainrc /etc/samhainrc_bak
> +cp data/samhainrc /etc/samhainrc
> +
> +chown root.root /etc/samhainrc
> +
> +rm -fr /var/samhain/*
> +rm -f /var/log/samhain_log
> +
> +sleep 1
> +
> +mkdir -p test_dir/samhain_test/
> +touch test_dir/samhain_test/test.txt
> +
> +samhain -t init -p info > /dev/null 2&> 1
> +
> +sleep 1
> +
> +echo test > test_dir/samhain_test/test.txt
> +
> +sleep 1
> +
> +if samhain -t check
> +then
> +    echo " -> samhain -t check succeeded."
> +else
> +    echo " -> $test: TEST-FAIL"
> +    rm -fr test_dir/samhain_test
> +    mv /etc/samhainrc_bak /etc/samhainrc

OK - I like that this restores the board's existing Samhain config file.
Thanks.

> +    exit
> +fi
> +
> +sleep 2
> +
> +if cat /var/log/samhain_log | grep
> "path=</home/test/samhain_test/test.txt>, size_old=<0>, size_new=<5>"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +rm -fr test_dir/samhain_test
> +mv /etc/samhainrc_bak /etc/samhainrc
> diff --git a/engine/tests/Functional.samhain/tests/samhain_help.sh
> b/engine/tests/Functional.samhain/tests/samhain_help.sh
> new file mode 100644
> index 0000000..f16b680
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/tests/samhain_help.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  In target, run command samhain.
> +#  option: --help
> +
> +test="help"
> +
> +if samhain --help | grep "Usage"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> diff --git a/engine/tests/Functional.samhain/tests/samhain_init.sh
> b/engine/tests/Functional.samhain/tests/samhain_init.sh
> new file mode 100644
> index 0000000..64a2f17
> --- /dev/null
> +++ b/engine/tests/Functional.samhain/tests/samhain_init.sh
> @@ -0,0 +1,42 @@
> +#!/bin/sh
> +
> +#  In target, run command samhain.
> +#  option: -t
> +
> +test="init"
> +
> +umount /media/sda2 > /dev/null 2>&1
> +umount /media/sda3 > /dev/null 2>&1
> +umount /media/sda4 > /dev/null 2>&1
> +umount /media/sda5 > /dev/null 2>&1
> +umount /media/sda6 > /dev/null 2>&1
> +umount /media/sda7 > /dev/null 2>&1
> +umount /media/sda8 > /dev/null 2>&1
> +umount /media/sda9 > /dev/null 2>&1
Same comment here as above.

> +
> +mv /etc/samhainrc /etc/samhainrc_bak
> +cp data/samhainrc /etc/samhainrc
> +
> +chown root.root /etc/samhainrc
> +
> +rm -fr /var/samhain/*
> +rm -f /var/log/samhain_log
> +
> +sleep 1
> +
> +mkdir -p test_dir/samhain_test/
> +touch test_dir/samhain_test/test.txt
> +
> +samhain -t init -p info > /dev/null 2&> 1
> +
> +sleep 1
> +
> +if cat /var/log/samhain_log | grep "ALRT.*-.*-.*T.*:.*:.*msg=\"EXIT\""
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +rm -fr test_dir/samhain_test
> +mv /etc/samhainrc_bak /etc/samhainrc
> --
> 1.8.3.1
Most of this looks good.  Please address my comments and re-submit.

Thanks,
 -- Tim


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-10-31 19:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-31  8:44 [Fuego] [PATCH] Add test cases of command syslog-ng Wang Mingyu
2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of at Wang Mingyu
2018-10-31  5:38   ` Tim.Bird
2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases for commands of utillinux Wang Mingyu
2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command vconfig Wang Mingyu
2018-10-31 18:31   ` Tim.Bird
2018-10-31  8:44 ` [Fuego] [PATCH] Add test cases of command samhain Wang Mingyu
2018-10-31 19:06   ` Tim.Bird
2018-10-31  8:44 ` [Fuego] [PATCH] Add test case of command bc Wang Mingyu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.