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

Wang Mingyu wangmy at cn.fujitsu.com
Wed Nov 14 09:30:23 UTC 2018


This test set is used to check the service ntpd and command ntpdate/ntpdc/ntpq/ntptime/tickadj.

Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
---
 engine/tests/Functional.ntp/data/hosts            |  4 ++
 engine/tests/Functional.ntp/data/ntp.conf         | 82 +++++++++++++++++++++++
 engine/tests/Functional.ntp/fuego_test.sh         | 24 +++++++
 engine/tests/Functional.ntp/ntp_test.sh           |  4 ++
 engine/tests/Functional.ntp/parser.py             | 22 ++++++
 engine/tests/Functional.ntp/spec.json             |  7 ++
 engine/tests/Functional.ntp/test.yaml             | 34 ++++++++++
 engine/tests/Functional.ntp/tests/ntp_ntpdate1.sh | 13 ++++
 engine/tests/Functional.ntp/tests/ntp_ntpdate2.sh | 20 ++++++
 engine/tests/Functional.ntp/tests/ntp_ntpdc.sh    | 46 +++++++++++++
 engine/tests/Functional.ntp/tests/ntp_ntpq.sh     | 46 +++++++++++++
 engine/tests/Functional.ntp/tests/ntp_ntptime.sh  | 40 +++++++++++
 engine/tests/Functional.ntp/tests/ntp_pid.sh      | 52 ++++++++++++++
 engine/tests/Functional.ntp/tests/ntp_ps.sh       | 49 ++++++++++++++
 engine/tests/Functional.ntp/tests/ntp_syslog.sh   | 37 ++++++++++
 engine/tests/Functional.ntp/tests/ntp_tickadj.sh  | 26 +++++++
 16 files changed, 506 insertions(+)
 create mode 100644 engine/tests/Functional.ntp/data/hosts
 create mode 100644 engine/tests/Functional.ntp/data/ntp.conf
 create mode 100644 engine/tests/Functional.ntp/fuego_test.sh
 create mode 100755 engine/tests/Functional.ntp/ntp_test.sh
 create mode 100644 engine/tests/Functional.ntp/parser.py
 create mode 100644 engine/tests/Functional.ntp/spec.json
 create mode 100644 engine/tests/Functional.ntp/test.yaml
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_ntpdate1.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_ntpdate2.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_ntpdc.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_ntpq.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_ntptime.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_pid.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_ps.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_syslog.sh
 create mode 100644 engine/tests/Functional.ntp/tests/ntp_tickadj.sh

diff --git a/engine/tests/Functional.ntp/data/hosts b/engine/tests/Functional.ntp/data/hosts
new file mode 100644
index 0000000..3c8d41d
--- /dev/null
+++ b/engine/tests/Functional.ntp/data/hosts
@@ -0,0 +1,4 @@
+#
+#Template of /etc/hosts
+#
+127.0.0.1       localhost
diff --git a/engine/tests/Functional.ntp/data/ntp.conf b/engine/tests/Functional.ntp/data/ntp.conf
new file mode 100644
index 0000000..99f8d02
--- /dev/null
+++ b/engine/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/engine/tests/Functional.ntp/fuego_test.sh b/engine/tests/Functional.ntp/fuego_test.sh
new file mode 100644
index 0000000..28933bf
--- /dev/null
+++ b/engine/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/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;\
+    export test_tcpip_host=$SRV_IP;\
+    ./ntp_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.ntp/ntp_test.sh b/engine/tests/Functional.ntp/ntp_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.ntp/ntp_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.ntp/parser.py b/engine/tests/Functional.ntp/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.ntp/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.ntp/spec.json b/engine/tests/Functional.ntp/spec.json
new file mode 100644
index 0000000..642048d
--- /dev/null
+++ b/engine/tests/Functional.ntp/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.ntp",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.ntp/test.yaml b/engine/tests/Functional.ntp/test.yaml
new file mode 100644
index 0000000..8deb2f5
--- /dev/null
+++ b/engine/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 <wangmy at cn.fujitsu.com>
+maintainer: Tim Bird <tim.bird at sony.com>
+version: 1.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/engine/tests/Functional.ntp/tests/ntp_ntpdate1.sh b/engine/tests/Functional.ntp/tests/ntp_ntpdate1.sh
new file mode 100644
index 0000000..8b0b18a
--- /dev/null
+++ b/engine/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/engine/tests/Functional.ntp/tests/ntp_ntpdate2.sh b/engine/tests/Functional.ntp/tests/ntp_ntpdate2.sh
new file mode 100644
index 0000000..703d5fd
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_ntpdate2.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+#  In target, run command netpdate.
+#  option: -q.
+
+test="ntpdate2"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+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
+
+exec_service_on_target ntpd stop
diff --git a/engine/tests/Functional.ntp/tests/ntp_ntpdc.sh b/engine/tests/Functional.ntp/tests/ntp_ntpdc.sh
new file mode 100644
index 0000000..acba24a
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_ntpdc.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+#  In target, run command ntpdc.
+#  option: -p
+
+test="ntpdc"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+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
+
+if exec_service_on_target ntpd restart
+then
+    echo " -> $test: ntpd restart succeeded."
+else
+    echo " -> $test: ntpd restart failed."
+    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
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ntpdc -p 127.0.0.1 | grep "$test_tcpip_host"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+exec_service_on_target ntpd stop
+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
diff --git a/engine/tests/Functional.ntp/tests/ntp_ntpq.sh b/engine/tests/Functional.ntp/tests/ntp_ntpq.sh
new file mode 100644
index 0000000..f3c324e
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_ntpq.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+#  In target, run command ntpq.
+#  option: -p.
+
+test="ntpq"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+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
+
+if exec_service_on_target ntpd restart
+then
+    echo " -> $test: ntpd restart succeeded."
+else
+    echo " -> $test: ntpd restart failed."
+    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
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ntpq -p 127.0.0.1 | grep "$test_tcpip_host"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+exec_service_on_target ntpd stop
+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
diff --git a/engine/tests/Functional.ntp/tests/ntp_ntptime.sh b/engine/tests/Functional.ntp/tests/ntp_ntptime.sh
new file mode 100644
index 0000000..9caf62c
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_ntptime.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+#  In target, run command ntptime.
+#  option: none
+
+test="ntptime"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+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
+
+if exec_service_on_target ntpd restart
+then
+    echo " -> $test: ntpd restart succeeded."
+else
+    echo " -> $test: ntpd restart failed."
+    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
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ntptime | grep OK
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+exec_service_on_target ntpd stop
+mv /etc/ntp.conf_bak /etc/ntp.conf
+rm data/ntp.conf_$test_tcpip_host
diff --git a/engine/tests/Functional.ntp/tests/ntp_pid.sh b/engine/tests/Functional.ntp/tests/ntp_pid.sh
new file mode 100644
index 0000000..52f1e91
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_pid.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+#  In target start ntpd and verify the process of creating the process ID file by ntpd.
+#  option: none.
+
+test="pid"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+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"
+    exec_service_on_target ntpd stop
+    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
diff --git a/engine/tests/Functional.ntp/tests/ntp_ps.sh b/engine/tests/Functional.ntp/tests/ntp_ps.sh
new file mode 100644
index 0000000..f35a06e
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_ps.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+#  In target, start ntpd and check the process state with the PS command.
+#  option: none.
+
+test="ps"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target ntpd stop
+
+sleep 5
+
+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 ps aux | grep "[/]usr/sbin/ntpd"
+then
+    echo " -> $test: ntpd stop succeeded."
+else
+    echo " -> $test: ntpd stop failed."
+    echo " -> $test: TEST-FAIL"
+    exec_service_on_target ntpd stop
+    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 ! ps aux | grep "[/]usr/sbin/ntpd"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
diff --git a/engine/tests/Functional.ntp/tests/ntp_syslog.sh b/engine/tests/Functional.ntp/tests/ntp_syslog.sh
new file mode 100644
index 0000000..91800a6
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_syslog.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+#  In target, start ntpd and verify the ntpd syslog.
+#  option: none
+
+test="syslog"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+logger_service=$(detect_logger_service)
+
+exec_service_on_target ntpd stop
+exec_service_on_target $logger_service stop
+rm -f /var/log/syslog
+
+exec_service_on_target $logger_service restart
+
+if exec_service_on_target ntpd restart
+then
+    echo " -> $test: ntpd restart succeeded."
+else
+    echo " -> $test: ntpd restart failed."
+    mv /etc/ntp.conf_bak /etc/ntp.conf
+    rm data/ntp.conf_$test_tcpip_host
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if cat /var/log/syslog | grep ntpd
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+exec_service_on_target ntpd stop
diff --git a/engine/tests/Functional.ntp/tests/ntp_tickadj.sh b/engine/tests/Functional.ntp/tests/ntp_tickadj.sh
new file mode 100644
index 0000000..c801aca
--- /dev/null
+++ b/engine/tests/Functional.ntp/tests/ntp_tickadj.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+#  In target, run command tickadj.
+#  option: none
+
+test="tickadj"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+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
-- 
1.8.3.1





More information about the Fuego mailing list