Return-Path: From: Wang Mingyu Date: Mon, 25 Mar 2019 02:19:23 -0700 Message-ID: <1553505567-3221-5-git-send-email-wangmy@cn.fujitsu.com> In-Reply-To: <1553505567-3221-1-git-send-email-wangmy@cn.fujitsu.com> References: <1553505567-3221-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH v2] ntp: Add test cases for commands of ntp. List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org This test set is used to check the service ntpd and command ntpdate/ntpdc/ntpq/ntptime/tickadj. Signed-off-by: Wang Mingyu --- tests/Functional.ntp/data/hosts | 4 ++ tests/Functional.ntp/data/ntp.conf | 82 +++++++++++++++++++++++++++ tests/Functional.ntp/fuego_test.sh | 24 ++++++++ tests/Functional.ntp/ntp_test.sh | 7 +++ tests/Functional.ntp/parser.py | 20 +++++++ tests/Functional.ntp/spec.json | 6 ++ tests/Functional.ntp/test.yaml | 34 +++++++++++ tests/Functional.ntp/tests/ntp_ntpdate1.sh | 13 +++++ tests/Functional.ntp/tests/ntp_ntpdate2.sh | 21 +++++++ tests/Functional.ntp/tests/ntp_ntpdc.sh | 50 ++++++++++++++++ tests/Functional.ntp/tests/ntp_ntpq.sh | 49 ++++++++++++++++ tests/Functional.ntp/tests/ntp_ntptime.sh_bak | 28 +++++++++ tests/Functional.ntp/tests/ntp_pid.sh | 57 +++++++++++++++++++ tests/Functional.ntp/tests/ntp_ps.sh | 47 +++++++++++++++ tests/Functional.ntp/tests/ntp_syslog.sh | 51 +++++++++++++++++ tests/Functional.ntp/tests/ntp_tickadj.sh | 28 +++++++++ 16 files changed, 521 insertions(+) create mode 100644 tests/Functional.ntp/data/hosts create mode 100644 tests/Functional.ntp/data/ntp.conf create mode 100644 tests/Functional.ntp/fuego_test.sh create mode 100755 tests/Functional.ntp/ntp_test.sh create mode 100644 tests/Functional.ntp/parser.py create mode 100644 tests/Functional.ntp/spec.json create mode 100644 tests/Functional.ntp/test.yaml create mode 100644 tests/Functional.ntp/tests/ntp_ntpdate1.sh create mode 100644 tests/Functional.ntp/tests/ntp_ntpdate2.sh create mode 100644 tests/Functional.ntp/tests/ntp_ntpdc.sh create mode 100644 tests/Functional.ntp/tests/ntp_ntpq.sh create mode 100644 tests/Functional.ntp/tests/ntp_ntptime.sh_bak create mode 100644 tests/Functional.ntp/tests/ntp_pid.sh create mode 100644 tests/Functional.ntp/tests/ntp_ps.sh create mode 100644 tests/Functional.ntp/tests/ntp_syslog.sh create mode 100644 tests/Functional.ntp/tests/ntp_tickadj.sh diff --git a/tests/Functional.ntp/data/hosts b/tests/Functional.ntp/data/hosts new file mode 100644 index 0000000..3c8d41d --- /dev/null +++ b/tests/Functional.ntp/data/hosts @@ -0,0 +1,4 @@ +# +#Template of /etc/hosts +# +127.0.0.1 localhost diff --git a/tests/Functional.ntp/data/ntp.conf b/tests/Functional.ntp/data/ntp.conf new file mode 100644 index 0000000..99f8d02 --- /dev/null +++ b/tests/Functional.ntp/data/ntp.conf @@ -0,0 +1,82 @@ +# Prohibit general access to this service. +restrict default ignore + +# Permit all access over the loopback interface. This could +# be tightened as well, but to do so would effect some of +# the administrative functions. +restrict 127.0.0.1 + + +# -- CLIENT NETWORK ------- +# Permit systems on this network to synchronize with this +# time service. Do not permit those systems to modify the +# configuration of this service. Also, do not use those +# systems as peers for synchronization. +# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap + + +# --- OUR TIMESERVERS ----- +# or remove the default restrict line +# Permit time synchronization with our time source, but do not +# permit the source to query or modify the service on this system. + +# restrict mytrustedtimeserverip mask 255.255.255.255 nomodify notrap noquery +# server mytrustedtimeserverip + + + +# --- NTP MULTICASTCLIENT --- +#multicastclient # listen on default 224.0.1.1 +# restrict 224.0.1.1 mask 255.255.255.255 notrust nomodify notrap +# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap + + + +# --- GENERAL CONFIGURATION --- +# +# Undisciplined Local Clock. This is a fake driver intended for backup +# and when no outside source of synchronized time is available. The +# default stratum is usually 3, but in this case we elect to use stratum +# 0. Since the server line does not have the prefer keyword, this driver +# is never used for synchronization, unless no other other +# synchronization source is available. In case the local host is +# controlled by some external source, such as an external oscillator or +# another protocol, the prefer keyword would cause the local host to +# disregard all other synchronization sources, unless the kernel +# modifications are in use and declare an unsynchronized condition. +# +server 127.127.1.0 # local clock +fudge 127.127.1.0 stratum 10 + +# +# Drift file. Put this in a directory which the daemon can write to. +# No symbolic links allowed, either, since the daemon updates the file +# by creating a temporary in the same directory and then rename()'ing +# it to the file. +# +driftfile /var/lib/ntp/drift +broadcastdelay 0.008 + +# +# Authentication delay. If you use, or plan to use someday, the +# authentication facility you should make the programs in the auth_stuff +# directory and figure out what this number should be on your machine. +# +## authenticate yes + +# +# Keys file. If you want to diddle your server at run time, make a +# keys file (mode 600 for sure) and define the key number to be +# used for making requests. +# +# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote +# systems might be able to reset your clock at will. Note also that +# ntpd is started with a -A flag, disabling authentication, that +# will have to be removed as well. +# +keys /etc/ntp/keys +# server 192.168.0.1 +#server 192.168.246.1 +#server 192.168.0.2 +restrict 192.68.0.2 mask 255.255.255.255 nomodify notrap noquery + diff --git a/tests/Functional.ntp/fuego_test.sh b/tests/Functional.ntp/fuego_test.sh new file mode 100644 index 0000000..c5ac056 --- /dev/null +++ b/tests/Functional.ntp/fuego_test.sh @@ -0,0 +1,24 @@ +function test_pre_check { + assert_has_program ntpdate + assert_has_program ntpdc + assert_has_program ntpq + assert_has_program ntptime + assert_has_program tickadj +} + +function test_deploy { + put $TEST_HOME/ntp_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/ + put $FUEGO_CORE/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;\ + export test_tcpip_host=$SRV_IP;\ + ./ntp_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +} diff --git a/tests/Functional.ntp/ntp_test.sh b/tests/Functional.ntp/ntp_test.sh new file mode 100755 index 0000000..95c34db --- /dev/null +++ b/tests/Functional.ntp/ntp_test.sh @@ -0,0 +1,7 @@ +#!/bin/sh +. ./fuego_board_function_lib.sh +set_init_manager + +for i in tests/*.sh; do + source $i +done diff --git a/tests/Functional.ntp/parser.py b/tests/Functional.ntp/parser.py new file mode 100644 index 0000000..f25a608 --- /dev/null +++ b/tests/Functional.ntp/parser.py @@ -0,0 +1,20 @@ +#!/usr/bin/python +# See common.py for description of command-line arguments + +import os, sys, collections +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/tests/Functional.ntp/spec.json b/tests/Functional.ntp/spec.json new file mode 100644 index 0000000..c537ede --- /dev/null +++ b/tests/Functional.ntp/spec.json @@ -0,0 +1,6 @@ +{ + "testName": "Functional.ntp", + "specs": { + "default": {} + } +} diff --git a/tests/Functional.ntp/test.yaml b/tests/Functional.ntp/test.yaml new file mode 100644 index 0000000..e331e1e --- /dev/null +++ b/tests/Functional.ntp/test.yaml @@ -0,0 +1,34 @@ +fuego_package_version: 1 +name: Functional.ntp +description: | + The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer + systems over packet-switched, variable-latency data networks. + This is a simple test to check the service and commands of ntp. +license: Unknown +author: Wang Mingyu +maintainer: Tim Bird +version: 2.00 +fuego_release: 1 +type: Functional +tags: ['time'] +params: + SRV_IP="The IP address of host" Defined in board file +data_files: + - ntp_test.sh + - fuego_test.sh + - parser.py + - spec.json + - test.yaml + - data + hosts + ntp.data + - tests + ntp_ntpdate1.sh + ntp_ntpdate2.sh + ntp_ntpdc.sh + ntp_ntpq.sh + ntp_ntptime.sh + ntp_pid.sh + ntp_ps.sh + ntp_syslog.sh + ntp_tickadj.sh diff --git a/tests/Functional.ntp/tests/ntp_ntpdate1.sh b/tests/Functional.ntp/tests/ntp_ntpdate1.sh new file mode 100644 index 0000000..8b0b18a --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_ntpdate1.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# In target, run command netpdate. +# option: -q + +test="ntpdate1" + +if ntpdate -q $test_tcpip_host | grep "server $test_tcpip_host" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi diff --git a/tests/Functional.ntp/tests/ntp_ntpdate2.sh b/tests/Functional.ntp/tests/ntp_ntpdate2.sh new file mode 100644 index 0000000..c6d1b81 --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_ntpdate2.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# In target, run command netpdate. +# option: -q. + +test="ntpdate2" + +service_status=$(get_service_status ntpd) + +exec_service_on_target ntpd start +if ntpdate -q $test_tcpip_host | grep "server $test_tcpip_host" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +if [ "$service_status" = "inactive" ] +then + exec_service_on_target ntpd stop +fi diff --git a/tests/Functional.ntp/tests/ntp_ntpdc.sh b/tests/Functional.ntp/tests/ntp_ntpdc.sh new file mode 100644 index 0000000..bdbbfeb --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_ntpdc.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +# In target, run command ntpdc. +# option: -p + +test="ntpdc" + +service_status=$(get_service_status ntpd) + +cp data/hosts data/hosts_$test_tcpip_host +echo "$test_tcpip_host $test_tcpip_host" >> data/hosts_$test_tcpip_host +mv /etc/hosts /etc/hosts_bak +cp data/hosts_$test_tcpip_host /etc/hosts + +exec_service_on_target ntpd stop + +cp data/ntp.conf data/ntp.conf_$test_tcpip_host +echo "server $test_tcpip_host" >> data/ntp.conf_$test_tcpip_host +mv /etc/ntp.conf /etc/ntp.conf_bak +cp data/ntp.conf_$test_tcpip_host /etc/ntp.conf +echo enable mode7 >> /etc/ntp.conf + +restore_target() { + mv /etc/ntp.conf_bak /etc/ntp.conf + mv /etc/hosts_bak /etc/hosts + rm data/hosts_$test_tcpip_host data/ntp.conf_$test_tcpip_host +} + +if exec_service_on_target ntpd restart +then + echo " -> $test: ntpd restart succeeded." +else + echo " -> $test: ntpd restart failed." + echo " -> $test: TEST-FAIL" + restore_target + exit +fi + +if ntpdc -p 127.0.0.1 | grep "$test_tcpip_host" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +if [ "$service_status" = "inactive" ] +then + exec_service_on_target ntpd stop +fi +restore_target diff --git a/tests/Functional.ntp/tests/ntp_ntpq.sh b/tests/Functional.ntp/tests/ntp_ntpq.sh new file mode 100644 index 0000000..cdf816b --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_ntpq.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# In target, run command ntpq. +# option: -p. + +test="ntpq" + +service_status=$(get_service_status ntpd) + +cp data/hosts data/hosts_$test_tcpip_host +echo "$test_tcpip_host $test_tcpip_host" >> data/hosts_$test_tcpip_host +mv /etc/hosts /etc/hosts_bak +cp data/hosts_$test_tcpip_host /etc/hosts + +exec_service_on_target ntpd stop + +cp data/ntp.conf data/ntp.conf_$test_tcpip_host +echo "server $test_tcpip_host" >> data/ntp.conf_$test_tcpip_host +mv /etc/ntp.conf /etc/ntp.conf_bak +cp data/ntp.conf_$test_tcpip_host /etc/ntp.conf +echo enable mode7 >> /etc/ntp.conf + +restore_target() { + mv /etc/ntp.conf_bak /etc/ntp.conf + mv /etc/hosts_bak /etc/hosts + rm data/hosts_$test_tcpip_host data/ntp.conf_$test_tcpip_host +} + +if exec_service_on_target ntpd restart +then + echo " -> $test: ntpd restart succeeded." +else + echo " -> $test: ntpd restart failed." + echo " -> $test: TEST-FAIL" + restore_target + exit +fi + +if ntpq -p 127.0.0.1 | grep "$test_tcpip_host" +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi +if [ "$service_status" = "inactive" ] +then + exec_service_on_target ntpd stop +fi +restore_target diff --git a/tests/Functional.ntp/tests/ntp_ntptime.sh_bak b/tests/Functional.ntp/tests/ntp_ntptime.sh_bak new file mode 100644 index 0000000..4d5f961 --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_ntptime.sh_bak @@ -0,0 +1,28 @@ +#!/bin/sh + +# In target, run command ntptime. +# option: none + +test="ntptime" + +service_status=$(get_service_status ntpd) + +if exec_service_on_target ntpd restart +then + echo " -> $test: ntpd restart succeeded." +else + echo " -> $test: ntpd restart failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if ntptime | grep OK +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi; +if [ "$service_status" = "inactive" ] +then + exec_service_on_target ntpd stop +fi diff --git a/tests/Functional.ntp/tests/ntp_pid.sh b/tests/Functional.ntp/tests/ntp_pid.sh new file mode 100644 index 0000000..61e5a9a --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_pid.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# In target start ntpd and verify the process of creating the process ID file by ntpd. +# option: none. + +test="pid" + +service_status=$(get_service_status ntpd) + +exec_service_on_target ntpd stop + +if [ -f /var/run/ntpd.pid ] +then + rm -f /var/run/ntpd.pid +fi + +if exec_service_on_target ntpd start +then + echo " -> $test: ntpd start succeeded." +else + echo " -> $test: ntpd start failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if ls /var/run/ntpd.pid +then + echo " -> $test: ntpd pid is exist." +else + echo " -> $test: ntpd pid is not exist." + echo " -> $test: TEST-FAIL" + if [ "$service_status" = "inactive" ] + then + exec_service_on_target ntpd stop + fi + exit +fi + +if exec_service_on_target ntpd stop +then + echo " -> $test: ntpd stop succeeded." +else + echo " -> $test: ntpd stop failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if test ! -f /var/run/ntpd.pid +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi +if [ "$service_status" = "active" -o "$service_status" = "unknown" ] +then + exec_service_on_target ntpd start +fi diff --git a/tests/Functional.ntp/tests/ntp_ps.sh b/tests/Functional.ntp/tests/ntp_ps.sh new file mode 100644 index 0000000..0c3e4fb --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_ps.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# In the target start ntpd, and confirm the process condition by command ps. + +test="ps" + +service_status=$(get_service_status ntpd) + +exec_service_on_target ntpd stop + +if exec_service_on_target ntpd start +then + echo " -> start of ntpd succeeded." +else + echo " -> start of ntpd failed." + echo " -> $test: TEST-FAIL" + exit +fi + +sleep 5 + +if ps aux | grep "[/]usr/sbin/ntpd" +then + echo " -> get the process of ntpd." +else + echo " -> can't get the process of ntpd." + echo " -> $test: TEST-FAIL" + if [ "$service_status" = "inactive" ] + then + exec_service_on_target ntpd stop + fi + exit +fi + +exec_service_on_target ntpd stop + +if ps aux | grep "[/]usr/sbin/ntpd" +then + echo " -> $test: TEST-FAIL" +else + echo " -> $test: TEST-PASS" +fi + +if [ "$service_status" = "active" -o "$service_status" = "unknown" ] +then + exec_service_on_target ntpd start +fi diff --git a/tests/Functional.ntp/tests/ntp_syslog.sh b/tests/Functional.ntp/tests/ntp_syslog.sh new file mode 100644 index 0000000..c6c778a --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_syslog.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# In target, start ntpd and verify the ntpd syslog. +# option: none + +test="syslog" + +service_status=$(get_service_status ntpd) +logger_service=$(detect_logger_service) + +exec_service_on_target ntpd stop +exec_service_on_target $logger_service stop + +if [ -f /var/log/syslog ] +then + mv /var/log/syslog /var/log/syslog_bak +fi + +restore_target() { + if [ -f /var/log/syslog_bak ] + then + mv /var/log/syslog_bak /var/log/syslog + fi +} + +exec_service_on_target $logger_service restart + +if exec_service_on_target ntpd start +then + echo " -> $test: ntpd start succeeded." +else + echo " -> $test: ntpd start failed." + echo " -> $test: TEST-FAIL" + restore_target + exit +fi + +sleep 10 + +if cat /var/log/syslog | grep ntpd +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +if [ "$service_status" = "inactive" ] +then + exec_service_on_target ntpd stop +fi +restore_target diff --git a/tests/Functional.ntp/tests/ntp_tickadj.sh b/tests/Functional.ntp/tests/ntp_tickadj.sh new file mode 100644 index 0000000..27e6e62 --- /dev/null +++ b/tests/Functional.ntp/tests/ntp_tickadj.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# In target, run command tickadj. +# option: none + +test="tickadj" + +service_status=$(get_service_status ntpd ) +if exec_service_on_target ntpd stop +then + echo " -> $test: ntpd stop succeeded." +else + echo " -> $test: ntpd stop failed." + echo " -> $test: TEST-FAIL" + exit +fi + +if tickadj | grep tick +then + echo " -> $test: TEST-PASS" +else + echo " -> $test: TEST-FAIL" +fi + +if [ "$service_status" = "active" -o "$service_status" = "unknown" ] +then + exec_service_on_target ntpd start +fi -- 1.8.3.1