Return-Path: From: Wang Mingyu Date: Tue, 21 Aug 2018 06:38:08 -0700 Message-ID: <1534858691-25071-2-git-send-email-wangmy@cn.fujitsu.com> In-Reply-To: <1534858691-25071-1-git-send-email-wangmy@cn.fujitsu.com> References: <1534858691-25071-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH] Add test cases for command dovecot. List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org Signed-off-by: Wang Mingyu --- engine/tests/Functional.dovecot/datas/testfunc.sh | 13 +++++++ engine/tests/Functional.dovecot/dovecot_test.sh | 4 ++ engine/tests/Functional.dovecot/fuego_test.sh | 20 ++++++++++ engine/tests/Functional.dovecot/parser.py | 22 +++++++++++ engine/tests/Functional.dovecot/spec.json | 7 ++++ .../Functional.dovecot/tests/dovecot_listen.sh | 27 +++++++++++++ .../Functional.dovecot/tests/dovecot_logfile.sh | 38 +++++++++++++++++++ .../Functional.dovecot/tests/dovecot_pidfile.sh | 39 +++++++++++++++++++ .../tests/Functional.dovecot/tests/dovecot_ps.sh | 44 ++++++++++++++++++++++ 9 files changed, 214 insertions(+) create mode 100644 engine/tests/Functional.dovecot/datas/testfunc.sh create mode 100644 engine/tests/Functional.dovecot/dovecot_test.sh create mode 100644 engine/tests/Functional.dovecot/fuego_test.sh create mode 100644 engine/tests/Functional.dovecot/parser.py create mode 100644 engine/tests/Functional.dovecot/spec.json create mode 100644 engine/tests/Functional.dovecot/tests/dovecot_listen.sh create mode 100644 engine/tests/Functional.dovecot/tests/dovecot_logfile.sh create mode 100644 engine/tests/Functional.dovecot/tests/dovecot_pidfile.sh create mode 100644 engine/tests/Functional.dovecot/tests/dovecot_ps.sh diff --git a/engine/tests/Functional.dovecot/datas/testfunc.sh b/engine/tests/Functional.dovecot/datas/testfunc.sh new file mode 100644 index 0000000..b13041c --- /dev/null +++ b/engine/tests/Functional.dovecot/datas/testfunc.sh @@ -0,0 +1,13 @@ +# $1: Used to determine whether the command line execution result is correct or not +function exec_service_on_target { +local service_name="$1" +local action="$2" +if [ "$init_manager" = "sysvinit" ] +then + $service_name $action +elif [ "$init_manager" = "systemd" ] +then + systemctl $action $service_name +fi +return +} diff --git a/engine/tests/Functional.dovecot/dovecot_test.sh b/engine/tests/Functional.dovecot/dovecot_test.sh new file mode 100644 index 0000000..dd5ce37 --- /dev/null +++ b/engine/tests/Functional.dovecot/dovecot_test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done diff --git a/engine/tests/Functional.dovecot/fuego_test.sh b/engine/tests/Functional.dovecot/fuego_test.sh new file mode 100644 index 0000000..c998246 --- /dev/null +++ b/engine/tests/Functional.dovecot/fuego_test.sh @@ -0,0 +1,20 @@ +function test_pre_check { + is_on_target_path dovecot PROGRAM_DOVECOT + assert_define PROGRAM_DOVECOT "Missing 'dovecot' program on target board" +} + +function test_deploy { + put $TEST_HOME/dovecot_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/datas $BOARD_TESTDIR/fuego.$TESTDIR/ +} + +function test_run { + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\ + export init_manager=systemd;\ + sh -v dovecot_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +} diff --git a/engine/tests/Functional.dovecot/parser.py b/engine/tests/Functional.dovecot/parser.py new file mode 100644 index 0000000..d85abd7 --- /dev/null +++ b/engine/tests/Functional.dovecot/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.dovecot/spec.json b/engine/tests/Functional.dovecot/spec.json new file mode 100644 index 0000000..3a71a30 --- /dev/null +++ b/engine/tests/Functional.dovecot/spec.json @@ -0,0 +1,7 @@ +{ + "testName": "Functional.dovecot", + "specs": { + "default": {} + } +} + diff --git a/engine/tests/Functional.dovecot/tests/dovecot_listen.sh b/engine/tests/Functional.dovecot/tests/dovecot_listen.sh new file mode 100644 index 0000000..f4e3897 --- /dev/null +++ b/engine/tests/Functional.dovecot/tests/dovecot_listen.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# In the target to start dovecot dovecot, to confirm the acquisition of the log. +# check the keyword "LISTEN". + +test="listen" + +source "datas/testfunc.sh" + +exec_service_on_target dovecot stop + +if exec_service_on_target dovecot start +then + echo " -> start of dovecot succeeded." +else + echo " -> start of dovecot failed." + echo " -> $test: TEST-FAIL" +fi + +if netstat -a --tcp | grep LISTEN +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +exec_service_on_target dovecot stop diff --git a/engine/tests/Functional.dovecot/tests/dovecot_logfile.sh b/engine/tests/Functional.dovecot/tests/dovecot_logfile.sh new file mode 100644 index 0000000..304ea7a --- /dev/null +++ b/engine/tests/Functional.dovecot/tests/dovecot_logfile.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# In the target to start dovecot dovecot, to confirm the acquisition of the log. +# check the keyword "dovecot". + +test="logfile" +service_name="" + +source "datas/testfunc.sh" + +if [ "$init_manager" = "systemd" ] +then + service_name="syslog-ng" +else + service_name="syslog.syslog-ng" +fi + +exec_service_on_target dovecot stop +rm -f /var/log/mail.log + +exec_service_on_target $service_name restart + +if exec_service_on_target dovecot start +then + echo " -> start of dovecot succeeded." +else + echo " -> start of dovecot failed." + echo " -> $test: TEST-FAIL" +fi + +if tail /var/log/mail.log | grep "dovecot" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +exec_service_on_target dovecot stop diff --git a/engine/tests/Functional.dovecot/tests/dovecot_pidfile.sh b/engine/tests/Functional.dovecot/tests/dovecot_pidfile.sh new file mode 100644 index 0000000..e3577cb --- /dev/null +++ b/engine/tests/Functional.dovecot/tests/dovecot_pidfile.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# In the target to start dovecot dovecot, to confirm the acquisition of the log. +# check the file master.pid. + +test="pidfile" + +source "datas/testfunc.sh" + +exec_service_on_target dovecot stop + +if exec_service_on_target dovecot start +then + echo " -> start of dovecot succeeded." +else + echo " -> start of dovecot failed." + echo " -> $test: TEST-FAIL" +fi + +sleep 5 + +if ls /var/run/dovecot/master.pid +then + echo " -> ls /var/run/dovecot/master.pid succeeded." +else + echo " -> ls /var/run/dovecot/master.pid failed." + echo " -> $test: TEST-FAIL" + exec_service_on_target dovecot stop + exit +fi + +exec_service_on_target dovecot stop + +if test ! -f /var/run/dovecot/master.pid +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi diff --git a/engine/tests/Functional.dovecot/tests/dovecot_ps.sh b/engine/tests/Functional.dovecot/tests/dovecot_ps.sh new file mode 100644 index 0000000..7ad190a --- /dev/null +++ b/engine/tests/Functional.dovecot/tests/dovecot_ps.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# In the target start dovecot, and confirm the process condition by command ps. +# check the keyword "dovecot". + +test="ps" + +source "datas/testfunc.sh" + +exec_service_on_target dovecot stop +if exec_service_on_target dovecot start +then + echo " -> start of dovecot succeeded." +else + echo " -> start of dovecot failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if ps -N a | grep dovecot | grep "[/]usr/sbin/dovecot" +then + echo " -> get the pid of dovecot." +else + echo " -> can't get the pid of dovecot." + echo " -> $test: TEST-FAIL" + exec_service_on_target dovecot stop + exit +fi + +if exec_service_on_target dovecot stop +then + echo " -> stop of dovecot succeeded." +else + echo " -> stop of dovecot failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if ps -N a | grep dovecot | grep "[/]usr/sbin/dovecot" +then + echo " -> $test: TEST-FAIL" +else + echo " -> $test: TEST-PASS" +fi -- 1.8.3.1