Browse Source

[3422] Cleanup in the dhcp_test_lib.sh script.

Marcin Siodelski 11 years ago
parent
commit
b0142552a1

+ 9 - 11
src/bin/dhcp4/tests/dhcp4_reconfigure_test.sh

@@ -12,8 +12,6 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 # PERFORMANCE OF THIS SOFTWARE.
 
 
-# Test name
-TEST_NAME="DHCPv4.dynamicReconfiguration"
 # Path to the temporary configuration file.
 # Path to the temporary configuration file.
 CFG_FILE="test_config.json"
 CFG_FILE="test_config.json"
 # Path to the Kea log file.
 # Path to the Kea log file.
@@ -61,14 +59,14 @@ CONFIG_INVALID="{
 }"
 }"
 
 
 # Set the location of the executable.
 # Set the location of the executable.
-BIN="b10-dhcp4"
-BIN_PATH=".."
+bin="b10-dhcp4"
+bin_path=".."
 
 
 # Import common test library.
 # Import common test library.
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 
 
 # Log the start of the test and print test name.
 # Log the start of the test and print test name.
-test_start
+test_start "dhcpv4_srv.dynamic_reconfiguration"
 # Remove dangling Kea instances and remove log files.
 # Remove dangling Kea instances and remove log files.
 cleanup
 cleanup
 # Create new configuration file.
 # Create new configuration file.
@@ -76,7 +74,7 @@ create_config "${CONFIG}"
 # Instruct Kea to log to the specific file.
 # Instruct Kea to log to the specific file.
 set_logger
 set_logger
 # Start Kea.
 # Start Kea.
-start_kea
+start_kea ${bin_path}/${bin}
 # Wait up to 20s for Kea to start.
 # Wait up to 20s for Kea to start.
 wait_for_kea 20
 wait_for_kea 20
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
@@ -86,7 +84,7 @@ fi
 
 
 # Check if it is still running. It could have terminated (e.g. as a result
 # Check if it is still running. It could have terminated (e.g. as a result
 # of configuration failure).
 # of configuration failure).
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: expected one Kea process to be started. Found %d processes\
     printf "ERROR: expected one Kea process to be started. Found %d processes\
  started.\n" ${_GET_PIDS_NUM}
  started.\n" ${_GET_PIDS_NUM}
@@ -107,7 +105,7 @@ fi
 create_config "${CONFIG_INVALID}"
 create_config "${CONFIG_INVALID}"
 
 
 # Try to reconfigure by sending SIGHUP
 # Try to reconfigure by sending SIGHUP
-send_signal 1 ${BIN}
+send_signal 1 ${bin}
 
 
 # The configuration should fail and the error message should be there.
 # The configuration should fail and the error message should be there.
 wait_for_message 10 "DHCP4_CONFIG_LOAD_FAIL" 1
 wait_for_message 10 "DHCP4_CONFIG_LOAD_FAIL" 1
@@ -126,7 +124,7 @@ elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
 fi
 fi
 
 
 # Make sure the server is still operational.
 # Make sure the server is still operational.
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     clean_exit 1
     clean_exit 1
@@ -136,7 +134,7 @@ fi
 create_config "${CONFIG}"
 create_config "${CONFIG}"
 
 
 # Reconfigure the server with SIGHUP.
 # Reconfigure the server with SIGHUP.
-send_signal 1 ${BIN}
+send_signal 1 ${bin}
 
 
 # There should be two occurrences of the DHCP4_CONFIG_COMPLETE messages.
 # There should be two occurrences of the DHCP4_CONFIG_COMPLETE messages.
 # Wait for it up to 10s.
 # Wait for it up to 10s.
@@ -153,7 +151,7 @@ else
 fi
 fi
 
 
 # Make sure the server is still operational.
 # Make sure the server is still operational.
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     clean_exit 1
     clean_exit 1

+ 8 - 8
src/bin/dhcp4/tests/dhcp4_shutdown_test.sh

@@ -18,7 +18,7 @@ if [ $# -ne 2 ]; then
 fi
 fi
 
 
 # Test name
 # Test name
-TEST_NAME=$1
+test_name=${1}
 # Signal number to be used for this test.
 # Signal number to be used for this test.
 SIG_NUM=$2
 SIG_NUM=$2
 # Path to the temporary configuration file.
 # Path to the temporary configuration file.
@@ -47,14 +47,14 @@ CONFIG="{
 }"
 }"
 
 
 # Set the location of the executable.
 # Set the location of the executable.
-BIN="b10-dhcp4"
-BIN_PATH=".."
+bin="b10-dhcp4"
+bin_path=".."
 
 
 # Import common test library.
 # Import common test library.
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 
 
 # Log the start of the test and print test name.
 # Log the start of the test and print test name.
-test_start
+test_start ${test_name}
 # Remove dangling Kea instances and remove log files.
 # Remove dangling Kea instances and remove log files.
 cleanup
 cleanup
 # Create new configuration file.
 # Create new configuration file.
@@ -62,7 +62,7 @@ create_config "${CONFIG}"
 # Instruct Kea to log to the specific file.
 # Instruct Kea to log to the specific file.
 set_logger
 set_logger
 # Start Kea.
 # Start Kea.
-start_kea
+start_kea ${bin_path}/${bin}
 # Wait up to 20s for Kea to start.
 # Wait up to 20s for Kea to start.
 wait_for_kea 20
 wait_for_kea 20
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
@@ -72,7 +72,7 @@ fi
 
 
 # Check if it is still running. It could have terminated (e.g. as a result
 # Check if it is still running. It could have terminated (e.g. as a result
 # of configuration failure).
 # of configuration failure).
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: expected one Kea process to be started. Found %d processes\
     printf "ERROR: expected one Kea process to be started. Found %d processes\
  started.\n" ${_GET_PIDS_NUM}
  started.\n" ${_GET_PIDS_NUM}
@@ -90,7 +90,7 @@ else
 fi
 fi
 
 
 # Send signal to Kea (SIGTERM, SIGINT etc.)
 # Send signal to Kea (SIGTERM, SIGINT etc.)
-send_signal ${SIG_NUM} ${BIN}
+send_signal ${SIG_NUM} ${bin}
 
 
 # Wait up to 10s for the server's graceful shutdown. The graceful shut down
 # Wait up to 10s for the server's graceful shutdown. The graceful shut down
 # should be recorded in the log file with the appropriate message.
 # should be recorded in the log file with the appropriate message.
@@ -101,7 +101,7 @@ if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
 fi
 fi
 
 
 # Server should have shut down.
 # Server should have shut down.
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 0 ]; then
 if [ ${_GET_PIDS_NUM} -ne 0 ]; then
     printf "ERROR: Kea did not shut down after receiving signal.\n"\
     printf "ERROR: Kea did not shut down after receiving signal.\n"\
  ${_GET_PIDS_NUM}
  ${_GET_PIDS_NUM}

+ 1 - 1
src/bin/dhcp4/tests/dhcp4_sigint_test.sh

@@ -13,4 +13,4 @@
 # PERFORMANCE OF THIS SOFTWARE.
 # PERFORMANCE OF THIS SOFTWARE.
 
 
 # Run a test that sends SIGINT to Kea and checks if it shuts down gracefully.
 # Run a test that sends SIGINT to Kea and checks if it shuts down gracefully.
-$(dirname $0)/dhcp4_shutdown_test.sh "DHCPv4.sigint" 2
+$(dirname $0)/dhcp4_shutdown_test.sh "dhcpv4_srv.sigint" 2

+ 1 - 1
src/bin/dhcp4/tests/dhcp4_sigterm_test.sh

@@ -13,4 +13,4 @@
 # PERFORMANCE OF THIS SOFTWARE.
 # PERFORMANCE OF THIS SOFTWARE.
 
 
 # Run a test that sends SIGTERM to Kea and checks if it shuts down gracefully.
 # Run a test that sends SIGTERM to Kea and checks if it shuts down gracefully.
-$(dirname $0)/dhcp4_shutdown_test.sh "DHCPv4.sigterm" 15
+$(dirname $0)/dhcp4_shutdown_test.sh "dhcpv4_srv.sigterm" 15

+ 9 - 11
src/bin/dhcp6/tests/dhcp6_reconfigure_test.sh

@@ -12,8 +12,6 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 # PERFORMANCE OF THIS SOFTWARE.
 
 
-# Test name
-TEST_NAME="DHCPv6.dynamicReconfiguration"
 # Path to the temporary configuration file.
 # Path to the temporary configuration file.
 CFG_FILE="test_config.json"
 CFG_FILE="test_config.json"
 # Path to the Kea log file.
 # Path to the Kea log file.
@@ -63,14 +61,14 @@ CONFIG_INVALID="{
 }"
 }"
 
 
 # Set the location of the executable.
 # Set the location of the executable.
-BIN="b10-dhcp6"
-BIN_PATH=".."
+bin="b10-dhcp6"
+bin_path=".."
 
 
 # Import common test library.
 # Import common test library.
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 
 
 # Log the start of the test and print test name.
 # Log the start of the test and print test name.
-test_start
+test_start "dhcpv6_srv.dynamic_reconfiguration"
 # Remove dangling Kea instances and remove log files.
 # Remove dangling Kea instances and remove log files.
 cleanup
 cleanup
 # Create new configuration file.
 # Create new configuration file.
@@ -78,7 +76,7 @@ create_config "${CONFIG}"
 # Instruct Kea to log to the specific file.
 # Instruct Kea to log to the specific file.
 set_logger
 set_logger
 # Start Kea.
 # Start Kea.
-start_kea
+start_kea ${bin_path}/${bin}
 # Wait up to 20s for Kea to start.
 # Wait up to 20s for Kea to start.
 wait_for_kea 20
 wait_for_kea 20
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
@@ -88,7 +86,7 @@ fi
 
 
 # Check if it is still running. It could have terminated (e.g. as a result
 # Check if it is still running. It could have terminated (e.g. as a result
 # of configuration failure).
 # of configuration failure).
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: expected one Kea process to be started. Found %d processes\
     printf "ERROR: expected one Kea process to be started. Found %d processes\
  started.\n" ${_GET_PIDS_NUM}
  started.\n" ${_GET_PIDS_NUM}
@@ -109,7 +107,7 @@ fi
 create_config "${CONFIG_INVALID}"
 create_config "${CONFIG_INVALID}"
 
 
 # Try to reconfigure by sending SIGHUP
 # Try to reconfigure by sending SIGHUP
-send_signal 1 ${BIN}
+send_signal 1 ${bin}
 
 
 # The configuration should fail and the error message should be there.
 # The configuration should fail and the error message should be there.
 wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
 wait_for_message 10 "DHCP6_CONFIG_LOAD_FAIL" 1
@@ -128,7 +126,7 @@ elif [ ${_GET_RECONFIG_ERRORS} -ne 1 ]; then
 fi
 fi
 
 
 # Make sure the server is still operational.
 # Make sure the server is still operational.
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     clean_exit 1
     clean_exit 1
@@ -138,7 +136,7 @@ fi
 create_config "${CONFIG}"
 create_config "${CONFIG}"
 
 
 # Reconfigure the server with SIGHUP.
 # Reconfigure the server with SIGHUP.
-send_signal 1 ${BIN}
+send_signal 1 ${bin}
 
 
 # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
 # There should be two occurrences of the DHCP6_CONFIG_COMPLETE messages.
 # Wait for it up to 10s.
 # Wait for it up to 10s.
@@ -155,7 +153,7 @@ else
 fi
 fi
 
 
 # Make sure the server is still operational.
 # Make sure the server is still operational.
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
     clean_exit 1
     clean_exit 1

+ 8 - 8
src/bin/dhcp6/tests/dhcp6_shutdown_test.sh

@@ -18,7 +18,7 @@ if [ $# -ne 2 ]; then
 fi
 fi
 
 
 # Test name
 # Test name
-TEST_NAME=$1
+test_name=${1}
 # Signal number to be used for this test.
 # Signal number to be used for this test.
 SIG_NUM=$2
 SIG_NUM=$2
 # Path to the temporary configuration file.
 # Path to the temporary configuration file.
@@ -48,14 +48,14 @@ CONFIG="{
 }"
 }"
 
 
 # Set the location of the executable.
 # Set the location of the executable.
-BIN="b10-dhcp6"
-BIN_PATH=".."
+bin="b10-dhcp6"
+bin_path=".."
 
 
 # Import common test library.
 # Import common test library.
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 . $(dirname $0)/../../../lib/testutils/dhcp_test_lib.sh
 
 
 # Log the start of the test and print test name.
 # Log the start of the test and print test name.
-test_start
+test_start ${test_name}
 # Remove dangling Kea instances and remove log files.
 # Remove dangling Kea instances and remove log files.
 cleanup
 cleanup
 # Create new configuration file.
 # Create new configuration file.
@@ -63,7 +63,7 @@ create_config "${CONFIG}"
 # Instruct Kea to log to the specific file.
 # Instruct Kea to log to the specific file.
 set_logger
 set_logger
 # Start Kea.
 # Start Kea.
-start_kea
+start_kea ${bin_path}/${bin}
 # Wait up to 20s for Kea to start.
 # Wait up to 20s for Kea to start.
 wait_for_kea 20
 wait_for_kea 20
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
 if [ ${_WAIT_FOR_KEA} -eq 0 ]; then
@@ -73,7 +73,7 @@ fi
 
 
 # Check if it is still running. It could have terminated (e.g. as a result
 # Check if it is still running. It could have terminated (e.g. as a result
 # of configuration failure).
 # of configuration failure).
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
 if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     printf "ERROR: expected one Kea process to be started. Found %d processes\
     printf "ERROR: expected one Kea process to be started. Found %d processes\
  started.\n" ${_GET_PIDS_NUM}
  started.\n" ${_GET_PIDS_NUM}
@@ -91,7 +91,7 @@ else
 fi
 fi
 
 
 # Send signal to Kea (SIGTERM, SIGINT etc.)
 # Send signal to Kea (SIGTERM, SIGINT etc.)
-send_signal ${SIG_NUM} ${BIN}
+send_signal ${SIG_NUM} ${bin}
 
 
 # Wait up to 10s for the server's graceful shutdown. The graceful shut down
 # Wait up to 10s for the server's graceful shutdown. The graceful shut down
 # should be recorded in the log file with the appropriate message.
 # should be recorded in the log file with the appropriate message.
@@ -102,7 +102,7 @@ if [ ${_WAIT_FOR_MESSAGE} -eq 0 ]; then
 fi
 fi
 
 
 # Server should have shut down.
 # Server should have shut down.
-get_pids ${BIN}
+get_pids ${bin}
 if [ ${_GET_PIDS_NUM} -ne 0 ]; then
 if [ ${_GET_PIDS_NUM} -ne 0 ]; then
     printf "ERROR: Kea did not shut down after receiving signal.\n"\
     printf "ERROR: Kea did not shut down after receiving signal.\n"\
  ${_GET_PIDS_NUM}
  ${_GET_PIDS_NUM}

+ 1 - 1
src/bin/dhcp6/tests/dhcp6_sigint_test.sh

@@ -13,4 +13,4 @@
 # PERFORMANCE OF THIS SOFTWARE.
 # PERFORMANCE OF THIS SOFTWARE.
 
 
 # Run a test that sends SIGINT to Kea and checks if it shuts down gracefully.
 # Run a test that sends SIGINT to Kea and checks if it shuts down gracefully.
-$(dirname $0)/dhcp6_shutdown_test.sh "DHCPv6.sigint" 2
+$(dirname $0)/dhcp6_shutdown_test.sh "dhcpv6_srv.sigint" 2

+ 1 - 1
src/bin/dhcp6/tests/dhcp6_sigterm_test.sh

@@ -13,4 +13,4 @@
 # PERFORMANCE OF THIS SOFTWARE.
 # PERFORMANCE OF THIS SOFTWARE.
 
 
 # Run a test that sends SIGTERM to Kea and checks if it shuts down gracefully.
 # Run a test that sends SIGTERM to Kea and checks if it shuts down gracefully.
-$(dirname $0)/dhcp6_shutdown_test.sh "DHCPv6.sigterm" 15
+$(dirname $0)/dhcp6_shutdown_test.sh "dhcpv6_srv.sigterm" 15

+ 5 - 15
src/bin/keactrl/tests/keactrl_tests.sh.in

@@ -71,13 +71,11 @@ config="{
 # This test checks that both DHCPv4 and DHCPv6 server can be started and
 # This test checks that both DHCPv4 and DHCPv6 server can be started and
 # shut down.
 # shut down.
 start_both_servers_test() {
 start_both_servers_test() {
-    # Test name.
-    TEST_NAME="keactrl.start_both_servers_test"
     # Create configuration file for keactrl. This configuration enables
     # Create configuration file for keactrl. This configuration enables
     # both DHCPv4 and DHCPv6 server.
     # both DHCPv4 and DHCPv6 server.
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=yes\n"
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=yes\n"
 
 
-    test_start
+    test_start "keactrl.start_both_servers_test"
 
 
     # Create configuration file for Kea and for keactrl.
     # Create configuration file for Kea and for keactrl.
     create_config "${config}"
     create_config "${config}"
@@ -150,13 +148,11 @@ Expected wait_for_message return %d, returned %d."
 # This test checks that only DHCPv4 server can be started and that the DHCPv6
 # This test checks that only DHCPv4 server can be started and that the DHCPv6
 # server is not started.
 # server is not started.
 start_v4_server_test() {
 start_v4_server_test() {
-    # Test name.
-    TEST_NAME="keactrl.start_v4_server_test"
     # Create configuration file for keactrl. This configuration enables
     # Create configuration file for keactrl. This configuration enables
     # DHCPv4 server but disables DHCPv6 server.
     # DHCPv4 server but disables DHCPv6 server.
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=no\n"
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=no\n"
 
 
-    test_start
+    test_start "keactrl.start_v4_server_test"
 
 
     # Create configuration file for Kea and for keactrl.
     # Create configuration file for Kea and for keactrl.
     create_config "${config}"
     create_config "${config}"
@@ -228,13 +224,11 @@ Expected wait_for_message return %d, returned %d."
 # This test checks that only DHCPv6 server can be started and that the DHCPv4
 # This test checks that only DHCPv6 server can be started and that the DHCPv4
 # server is not started.
 # server is not started.
 start_v6_server_test() {
 start_v6_server_test() {
-    # Test name.
-    TEST_NAME="keactrl.start_v6_server_test"
     # Create configuration file for keactrl. This configuration enables
     # Create configuration file for keactrl. This configuration enables
     # DHCPv6 server but disables DHCPv4 server.
     # DHCPv6 server but disables DHCPv4 server.
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=no\nkea6=yes\n"
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=no\nkea6=yes\n"
 
 
-    test_start
+    test_start "keactrl.start_v6_server_test"
 
 
     # Create configuration file for Kea and for keactrl.
     # Create configuration file for Kea and for keactrl.
     create_config "${config}"
     create_config "${config}"
@@ -307,13 +301,11 @@ Expected wait_for_message return %d, returned %d."
 # DHCPv4 server can be started while DHCPv6 server is already running.
 # DHCPv4 server can be started while DHCPv6 server is already running.
 # Also check that both servers can be reconfigured.
 # Also check that both servers can be reconfigured.
 late_start_v4_server_test() {
 late_start_v4_server_test() {
-    # Test name.
-    TEST_NAME="keactrl.late_start_v4_server_test"
     # Create configuration file for keactrl. This configuration enables
     # Create configuration file for keactrl. This configuration enables
     # DHCPv6 server but disables DHCPv4 server.
     # DHCPv6 server but disables DHCPv4 server.
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=no\nkea6=yes\n"
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=no\nkea6=yes\n"
 
 
-    test_start
+    test_start "keactrl.late_start_v4_server_test"
 
 
     # Create configuration file for Kea and for keactrl.
     # Create configuration file for Kea and for keactrl.
     create_config "${config}"
     create_config "${config}"
@@ -435,13 +427,11 @@ Expected wait_for_message return %d, returned %d."
 # DHCPv6 server can be started while DHCPv4 server is already running.
 # DHCPv6 server can be started while DHCPv4 server is already running.
 # Also check that both servers can be reconfigured.
 # Also check that both servers can be reconfigured.
 late_start_v6_server_test() {
 late_start_v6_server_test() {
-    # Test name.
-    TEST_NAME="keactrl.late_start_v6_server_test"
     # Create configuration file for keactrl. This configuration enables
     # Create configuration file for keactrl. This configuration enables
     # DHCPv4 server but disables DHCPv6 server.
     # DHCPv4 server but disables DHCPv6 server.
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=no\n"
     keactrl_config="kea_config_file=${CFG_FILE}\nkea4=yes\nkea6=no\n"
 
 
-    test_start
+    test_start "keactrl.late_start_v6_server_test"
 
 
     # Create configuration file for Kea and for keactrl.
     # Create configuration file for Kea and for keactrl.
     create_config "${config}"
     create_config "${config}"

+ 151 - 47
src/lib/testutils/dhcp_test_lib.sh

@@ -12,15 +12,23 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 # PERFORMANCE OF THIS SOFTWARE.
 
 
-# The following two parameters must to be specified in a script
-# including this library.
-# - BIN - Name of the Kea executable (excluding a path), e.g. b10-dhcp6
-# - BIN_PATH - Path to the Kea executable (excluding an executable name),
-#              e.g. ../
-
 # A list of Kea processes, mainly used by the cleanup functions.
 # A list of Kea processes, mainly used by the cleanup functions.
 KEA_PROCS="b10-dhcp4 b10-dhcp6 b10-dhcp-ddns"
 KEA_PROCS="b10-dhcp4 b10-dhcp6 b10-dhcp-ddns"
 
 
+### Logging functions ###
+
+# Prints error message.
+test_lib_error() {
+    printf "ERROR/test_lib: %s\n" "${1}"
+}
+
+# Prints info message.
+test_lib_info() {
+    printf "INFO/test_lib: %s\n" "${1}"
+}
+
+### Assertions ###
+
 # Assertion that checks if two numbers are equal.
 # Assertion that checks if two numbers are equal.
 # If numbers are not equal, the mismatched values are presented and the
 # If numbers are not equal, the mismatched values are presented and the
 # detailed error is printed. The detailed error must use the printf
 # detailed error is printed. The detailed error must use the printf
@@ -59,14 +67,18 @@ assert_string_contains() {
 }
 }
 
 
 # Begins a test by prining its name.
 # Begins a test by prining its name.
-# It requires the ${TEST_NAME} variable to hold the test name.
 test_start() {
 test_start() {
+    TEST_NAME=${1}
+    if [ -z ${TEST_NAME} ]; then
+        test_lib_error "test_start requires test name as an argument"
+        clean_exit 1
+    fi
     printf "\nSTART TEST ${TEST_NAME}\n"
     printf "\nSTART TEST ${TEST_NAME}\n"
 }
 }
 
 
+# Prints test result an cleans up after the test.
 test_finish() {
 test_finish() {
-    local error_code=${1}
-    exit_code=${1}  # Exit code to be returned by the exit function.
+    local exit_code=${1}  # Exit code to be returned by the exit function.
     if [ ${exit_code} -eq 0 ]; then
     if [ ${exit_code} -eq 0 ]; then
         cleanup
         cleanup
         printf "PASSED ${TEST_NAME}\n\n"
         printf "PASSED ${TEST_NAME}\n\n"
@@ -84,39 +96,78 @@ test_finish() {
 # Stores the configuration specified as a parameter in the configuration
 # Stores the configuration specified as a parameter in the configuration
 # file which name has been set in the ${CFG_FILE} variable.
 # file which name has been set in the ${CFG_FILE} variable.
 create_config() {
 create_config() {
+    local cfg=${1}  # Configuration string.
+    if [ -z ${CFG_FILE} ]; then
+        test_lib_error "create_config requires CFG_FILE variable be set"
+        clean_exit 1
+
+    elif [ -z "${cfg}" ]; then
+        test_lib_error "create_config requires argument holding a configuration"
+        clean_exit 1
+    fi
     printf "Creating Kea configuration file: %s.\n" ${CFG_FILE}
     printf "Creating Kea configuration file: %s.\n" ${CFG_FILE}
-    printf "%b" ${1} > ${CFG_FILE}
+    printf "%b" ${cfg} > ${CFG_FILE}
 }
 }
 
 
+# Stores the keactrl configuration specified as a parameter in the
+# configuration file which name has been set in the ${KEACTRL_CFG_FILE}
+# variable.
 create_keactrl_config() {
 create_keactrl_config() {
+    local cfg=${1} # Configuration string.
+    if [ -z ${KEACTRL_CFG_FILE} ]; then
+        test_lib_error "create_keactrl_config requires KEACTRL_CFG_FILE \
+variable be set"
+        clean_exit 1
+
+    elif [ -z "${cfg}" ]; then
+        test_lib_error "create_keactrl_config requires argument holding a \
+configuration"
+        clean_exit 1
+    fi
     printf "Creating keactrl configuration file: %s.\n" ${KEACTRL_CFG_FILE}
     printf "Creating keactrl configuration file: %s.\n" ${KEACTRL_CFG_FILE}
-    printf "%b" ${1} > ${KEACTRL_CFG_FILE}
+    printf "%b" ${cfg} > ${KEACTRL_CFG_FILE}
 }
 }
 
 
 # Sets Kea logger to write to the file specified by the global value
 # Sets Kea logger to write to the file specified by the global value
 # ${LOG_FILE}.
 # ${LOG_FILE}.
 set_logger() {
 set_logger() {
+    if [ -z ${LOG_FILE} ]; then
+        test_lib_error "set_logger requies LOG_FILE variable be set"
+        clean_exit 1
+    fi
     printf "Kea log will be stored in %s.\n" ${LOG_FILE}
     printf "Kea log will be stored in %s.\n" ${LOG_FILE}
     export B10_LOGGER_DESTINATION=${LOG_FILE}
     export B10_LOGGER_DESTINATION=${LOG_FILE}
 }
 }
 
 
 # Returns the number of running process pids and the list of pids.
 # Returns the number of running process pids and the list of pids.
-_GET_PIDS=     # Return value: holds space separated list of DHCPv6 pids.
-_GET_PIDS_NUM= # Return value: holds the number of DHCPv6 server pids.
+# Return values:
+#   _GET_PIDS: holds space separated list of pids.
+#   _GET_PIDS_NUM: holds the number pids.
 get_pids() {
 get_pids() {
-    proc_name=${1} # Process name
-    _GET_PIDS=`ps axwwo pid,command | grep ${proc_name} | grep -v grep | awk '{print $1}'`
-    _GET_PIDS_NUM=`printf "%s" "${_GET_PIDS}" | wc -w | awk '{print $1}'`
+    local proc_name=${1} # Process name
+    if [ -z ${proc_name} ]; then
+        test_lib_error "get_pids requires process name"
+        clean_exit 1
+    fi
+    _GET_PIDS=$( ps axwwo pid,command | grep ${proc_name} \
+        | grep -v grep | awk '{print $1}' )
+    _GET_PIDS_NUM=$( printf "%s" "${_GET_PIDS}" | wc -w | awk '{print $1}' )
 }
 }
 
 
-# Returns the number of occurrences of the Kea log message in the
-# log file.
-_GET_LOG_MESSAGES=0 # Holds the number of log message occurrences.
+# Returns the number of occurrences of the Kea log message in the log file.
+# Return value:
+#   _GET_LOG_MESSAGES: number of log message occurrences.
 get_log_messages() {
 get_log_messages() {
+    local msg=${1}  # Message id, e.g. DHCP6_SHUTDOWN
+    if [ -z ${msg} ]; then
+        test_lib_error "get_log_messages require message identifier"
+        clean_exit 1
+    fi
     _GET_LOG_MESSAGES=0
     _GET_LOG_MESSAGES=0
+    # If log file is not present, the number of occurrences is 0.
     if [ -s ${LOG_FILE} ]; then
     if [ -s ${LOG_FILE} ]; then
         # Grep log file for the logger message occurrences.
         # Grep log file for the logger message occurrences.
-        _GET_LOG_MESSAGES=`grep -o ${1} ${LOG_FILE} | wc -w`
+        _GET_LOG_MESSAGES=$( grep -o ${msg} ${LOG_FILE} | wc -w )
         # Remove whitespaces.
         # Remove whitespaces.
         ${_GET_LOG_MESSAGES##*[! ]}
         ${_GET_LOG_MESSAGES##*[! ]}
     fi
     fi
@@ -124,26 +175,29 @@ get_log_messages() {
 
 
 # Returns the number of server configurations performed so far. Also
 # Returns the number of server configurations performed so far. Also
 # returns the number of configuration errors.
 # returns the number of configuration errors.
-_GET_RECONFIGS=        # Return value: number of configurations so far.
-_GET_RECONFIG_ERRORS=  # Return value: number of configuration errors.
+# Return values:
+#   _GET_RECONFIGS: number of configurations so far.
+#   _GET_RECONFIG_ERRORS: number of configuration errors.
 get_reconfigs() {
 get_reconfigs() {
-    # Grep log file for DHCP6_CONFIG_COMPLETE occurences. There should
+    # Grep log file for CONFIG_COMPLETE occurences. There should
     # be one occurence per (re)configuration.
     # be one occurence per (re)configuration.
-    _GET_RECONFIGS=`grep -o CONFIG_COMPLETE ${LOG_FILE} | wc -w`
-    # Grep log file for DHCP6_CONFIG_LOAD_FAIL to check for configuration
+    _GET_RECONFIGS=$( grep -o CONFIG_COMPLETE ${LOG_FILE} | wc -w )
+    # Grep log file for CONFIG_LOAD_FAIL to check for configuration
     # failures.
     # failures.
-    _GET_RECONFIG_ERRORS=`grep -o CONFIG_LOAD_FAIL ${LOG_FILE} | wc -w`
+    _GET_RECONFIG_ERRORS=$( grep -o CONFIG_LOAD_FAIL ${LOG_FILE} | wc -w )
     # Remove whitespaces
     # Remove whitespaces
     ${_GET_RECONFIGS##*[! ]}
     ${_GET_RECONFIGS##*[! ]}
     ${_GET_RECONFIG_ERRORS##*[! ]}
     ${_GET_RECONFIG_ERRORS##*[! ]}
 }
 }
 
 
-# Performs cleanup for a test.
+# Performs cleanup after test.
 # It shuts down running Kea processes and removes temporary files.
 # It shuts down running Kea processes and removes temporary files.
-# The location of the log file and the configuration file should be set
+# The location of the log file and the configuration files should be set
 # in the ${LOG_FILE}, ${CFG_FILE} and ${KEACTRL_CFG_FILE} variables
 # in the ${LOG_FILE}, ${CFG_FILE} and ${KEACTRL_CFG_FILE} variables
 # recpectively, prior to calling this function.
 # recpectively, prior to calling this function.
 cleanup() {
 cleanup() {
+    # KEA_PROCS holds the name of all Kea processes. Shut down each
+    # of them if running.
     for proc_name in ${KEA_PROCS}
     for proc_name in ${KEA_PROCS}
     do
     do
         get_pids ${proc_name}
         get_pids ${proc_name}
@@ -153,7 +207,6 @@ cleanup() {
             printf "Shutting down Kea proccess having pid %d.\n" ${pid}
             printf "Shutting down Kea proccess having pid %d.\n" ${pid}
             kill -9 ${pid}
             kill -9 ${pid}
         done
         done
-        shift
     done
     done
     # Remove temporary files.
     # Remove temporary files.
     rm -rf ${LOG_FILE}
     rm -rf ${LOG_FILE}
@@ -166,19 +219,28 @@ cleanup() {
 # If a test fails, the Kea log is dumped.
 # If a test fails, the Kea log is dumped.
 clean_exit() {
 clean_exit() {
     exit_code=${1}  # Exit code to be returned by the exit function.
     exit_code=${1}  # Exit code to be returned by the exit function.
+    case ${exit_code} in
+        ''|*[!0-9]*)
+            test_lib_error "argument passed to clean_exit must be a number" ;;
+    esac
     # Print test result and perform a cleanup
     # Print test result and perform a cleanup
     test_finish ${exit_code}
     test_finish ${exit_code}
     exit ${exit_code}
     exit ${exit_code}
 }
 }
 
 
 # Starts Kea process in background using a configuration file specified
 # Starts Kea process in background using a configuration file specified
-# in the global variable ${CFG_FILE}
+# in the global variable ${CFG_FILE}.
 start_kea() {
 start_kea() {
-    printf "Running command %s.\n" "\"${BIN_PATH}/${BIN} -c ${CFG_FILE}\""
-    ${BIN_PATH}/$BIN -c ${CFG_FILE} &
+    bin=${1}
+    if [ -z ${bin} ]; then
+        test_lib_error "binary name must be specified for start_kea"
+        clean_exit 1
+    fi
+    printf "Running command %s.\n" "\"${bin} -c ${CFG_FILE}\""
+    ${bin} -c ${CFG_FILE} &
 }
 }
 
 
-# Waits for Kea to startup with timeout.
+# Waits with timeout for Kea to start.
 # This function repeatedly checs if the Kea log file has been created
 # This function repeatedly checs if the Kea log file has been created
 # and is non-empty. If it is, the function assumes that Kea has started.
 # and is non-empty. If it is, the function assumes that Kea has started.
 # It doesn't check the contents of the log file though.
 # It doesn't check the contents of the log file though.
@@ -186,15 +248,21 @@ start_kea() {
 # checks again. This is repeated until timeout is reached or non-empty
 # checks again. This is repeated until timeout is reached or non-empty
 # log file is found. If timeout is reached, the function reports an
 # log file is found. If timeout is reached, the function reports an
 # error.
 # error.
-_WAIT_FOR_KEA=0  # Return value: Holds 0 if Kea hasn't started, 1 otherwise
+# Return value:
+#    _WAIT_FOR_KEA: 0 if Kea hasn't started, 1 otherwise
 wait_for_kea() {
 wait_for_kea() {
-    timeout=${1} # Desired timeout in seconds.
-    loops=0 # Loops counter
+    local timeout=${1} # Desired timeout in seconds.
+    case ${timeout} in
+        ''|*[!0-9]*)
+            test_lib_error "argument passed to wait_for_kea must be a number"
+            clean_exit 1 ;;
+    esac
+    local loops=0 # Loops counter
     _WAIT_FOR_KEA=0
     _WAIT_FOR_KEA=0
     while [ ! -s ${LOG_FILE} ] && [ ${loops} -le ${timeout} ]; do
     while [ ! -s ${LOG_FILE} ] && [ ${loops} -le ${timeout} ]; do
         printf "."
         printf "."
         sleep 1
         sleep 1
-        loops=`expr $loops + 1`
+        loops=$( expr $loops + 1 )
     done
     done
     printf "\n"
     printf "\n"
     if [ ${loops} -le ${timeout} ]; then
     if [ ${loops} -le ${timeout} ]; then
@@ -211,27 +279,50 @@ wait_for_kea() {
 # This function waits a specified number of seconds for the number
 # This function waits a specified number of seconds for the number
 # of message occurrences to show up. If the expected number of
 # of message occurrences to show up. If the expected number of
 # message doesn't occur, the error status is returned.
 # message doesn't occur, the error status is returned.
-_WAIT_FOR_MESSAGE=0  # Return value: holds 0 if the message hasn't occured,
-                     # 1 otherwise.
+# Return value:
+#    _WAIT_FOR_MESSAGE: 0 if the message hasn't occured, 1 otherwise.
 wait_for_message() {
 wait_for_message() {
-    timeout=${1}     # Expecte timeout value in seconds.
-    message=${2}     # Expected message id.
-    occurrences=${3} # Number of expected occurrences.
-    loops=0          # Number of loops performed so far.
+    local timeout=${1}     # Expected timeout value in seconds.
+    local message=${2}     # Expected message id.
+    local occurrences=${3} # Number of expected occurrences.
+
+    # Validate timeout
+    case ${timeout} in
+        ''|*[!0-9]*)
+            test_lib_error "argument timeout passed to wait_for_message must \
+be a number"
+        clean_exit 1 ;;
+    esac
+
+    # Validate message
+    if [ -z ${message} ]; then
+        test_lib_error "message id is a required argument for wait_for_message"
+        clean_exit 1
+    fi
+
+    # Validate occurrences
+    case ${occurrences} in
+        ''|*[!0-9]*)
+            test_lib_error "argument occurrences passed to wait_for_message \
+must be a number"
+        clean_exit 1 ;;
+    esac
+
+    local loops=0          # Number of loops performed so far.
     _WAIT_FOR_MESSAGE=0
     _WAIT_FOR_MESSAGE=0
     # Check if log file exists and if we reached timeout.
     # Check if log file exists and if we reached timeout.
     while [ ${loops} -le ${timeout} ]; do
     while [ ${loops} -le ${timeout} ]; do
         printf "."
         printf "."
         # Check if the message has been logged.
         # Check if the message has been logged.
         get_log_messages ${message}
         get_log_messages ${message}
-        if [ ${_GET_LOG_MESSAGES} -eq ${occurrences} ]; then
+        if [ ${_GET_LOG_MESSAGES} -ge ${occurrences} ]; then
             printf "\n"
             printf "\n"
             _WAIT_FOR_MESSAGE=1
             _WAIT_FOR_MESSAGE=1
             return
             return
         fi
         fi
         # Message not recorded. Keep going.
         # Message not recorded. Keep going.
         sleep 1
         sleep 1
-        loops=`expr ${loops} + 1`
+        loops=$( expr ${loops} + 1 )
     done
     done
     printf "\n"
     printf "\n"
     # Timeout.
     # Timeout.
@@ -239,8 +330,21 @@ wait_for_message() {
 
 
 # Sends specified signal to the Kea process.
 # Sends specified signal to the Kea process.
 send_signal() {
 send_signal() {
-    sig=${1}       # Signal number.
-    proc_name=${2} # Process name
+    local sig=${1}       # Signal number.
+    local proc_name=${2} # Process name
+
+    # Validate signal
+    case ${sig} in
+        ''|*[!0-9]*)
+            test_lib_error "signal number passed to send_signal \
+must bea number"
+        clean_exit 1 ;;
+    esac
+    # Validate process name
+    if [ -z ${proc_name} ]; then
+        test_lib_error "send_signal requires process name be passed as argument"
+        clean_exit 1
+    fi
     # Get Kea pid.
     # Get Kea pid.
     get_pids ${proc_name}
     get_pids ${proc_name}
     if [ ${_GET_PIDS_NUM} -ne 1 ]; then
     if [ ${_GET_PIDS_NUM} -ne 1 ]; then