# if so notifies the user and provides them the opportunity
# to abort the current command.
check_file_overwrite () {
- local file=$1
+ local file="${1}"
if [ -e "${file}" ]
then
echo "Output file, $file, exists and will be overwritten."
# SQL text needed to dump the lease data for the current backend
# and protocol
get_dump_query() {
- local version=$1
+ local version="${1}"
case ${backend} in
mysql)
# Print location of CSV file. Accepts 4 or 6 as parameter.
csv_file() {
- local v=${1}
+ local v="${1}"
printf '%s' "@abs_top_builddir@/src/bin/admin/tests/kea-dhcp${v}.csv"
}
# Print location of kea-dhcp[46] binaries. Accepts 4 or 6 as parameter.
kea_dhcp() {
- local v=${1}
+ local v="${1}"
printf '%s' "@abs_top_builddir@/src/bin/dhcp${v}/kea-dhcp${v}"
}
# Starts Kea and sets PID. It logs to stdout and stderr if DEBUG is enabled.
# Accepts 4 or 6 as parameter.
start_kea_dhcp() {
- local v=${1}
+ local v="${1}"
if test -n "${DEBUG+x}"; then
"$(kea_dhcp "${v}")" -c "${config_file}" &
else
# This test verifies that DHCPv4 server is shut down gracefully when it
# receives a SIGINT or SIGTERM signal.
shutdown_test() {
- local test_name=${1} # Test name
- local signum=${2} # Signal number
+ local test_name="${1}" # Test name
+ local signum="${2}" # Signal number
# Log the start of the test and print test name.
test_start "${test_name}"
# Create new configuration file.
# This test verifies that DHCPv6 server is shut down gracefully when it
# receives a SIGINT or SIGTERM signal.
shutdown_test() {
- local test_name=${1} # Test name
- local signum=${2} # Signal number
+ local test_name="${1}" # Test name
+ local signum="${2}" # Signal number
# Log the start of the test and print test name.
test_start "${test_name}"
#
# shellcheck disable=SC2154
get_pid_from_file() {
- local proc_name=${1} # Process name.
+ local proc_name="${1}" # Process name.
local kea_config_file=
case ${proc_name} in
# PID file and checking the PID it contains. If the file does
# not exist, the process is assumed to not be running.
check_running() {
- local proc_name=${1} # Process name.
+ local proc_name="${1}" # Process name.
# Initially mark the process as not running.
_running=0
# Sends a signal to a process based on its PID file
send_signal() {
- local sig=${1} # Signal number
- local proc_name=${2} # Process name.
+ local sig="${1}" # Signal number
+ local proc_name="${2}" # Process name.
get_pid_from_file "${proc_name}"
if [ "${_pid}" -eq 0 ]; then
# Check if the Kea configuration file location has been specified in the
# keactrl configuration file. If not, it is a warning or a fatal error.
check_kea_conf() {
- local conf_file=${1-} # Kea config file name.
+ local conf_file="${1-}" # Kea config file name.
if [ -z "${conf_file}" ]; then
log_error "Configuration file for Kea not specified."
exit 1
# and be set to yes, e.g. ${dhcp4} should be equal to yes if server name
# is dhcp4
run_conditional() {
- local server=${1} # Server name: dhcp4, dhcp6, dhcp_ddns, ctrl_agent, netconf
- local commands="${2}" # Commands to execute
- local check_file_cfg=${3} # Check if server enabled in the configuration file
- local is_all=0 # is all servers or a specific one
+ local server="${1}" # Server name: dhcp4, dhcp6, dhcp_ddns, ctrl_agent, netconf
+ local commands="${2}" # Commands to execute
+ local check_file_cfg="${3}" # Check if server enabled in the configuration file
+ local is_all=0 # is all servers or a specific one
# If keyword "all" is not on the list of servers we will have to check
# if our specific server is on the list. If, not return.
# Prints error message.
test_lib_error() {
- local s=${1-} # Error message.
- local no_new_line=${2-} # If specified, the message not terminated with
- # new line.
+ local s="${1-}" # Error message.
+ local no_new_line="${2-}" # If specified, the message is not terminated
+ # with new line.
printf "ERROR/test_lib: %s" "${s}"
if [ -z "${no_new_line}" ]; then
printf '\n'
# Prints info message.
test_lib_info() {
- local s=${1-} # Info message.
- local no_new_line=${2-} # If specified, the message is not terminated with
- # new line.
+ local s="${1-}" # Info message.
+ local no_new_line="${2-}" # If specified, the message is not terminated
+ # with new line.
printf "INFO/test_lib: %s" "${s}"
if [ -z "${no_new_line}" ]; then
printf '\n'
# Prints test result an cleans up after the test.
test_finish() {
# Exit code to be returned by the exit function
- local exit_code=${1}
+ local exit_code="${1}"
# Stop timer and set duration.
FINISH_TIME=$(get_current_time)
# _GET_PID: holds a PID if process is running
# _GET_PIDS_NUM: holds 1 if process is running, 0 otherwise
get_pid() {
- local proc_name=${1-} # Process name
- local cfg_file_name=${2-} # Configuration file name without extension.
+ local proc_name="${1-}" # Process name
+ local cfg_file_name="${2-}" # Configuration file name without extension.
# Reset PID results.
_GET_PID=0
# Get the name of the process identified by PID.
get_process_name() {
- local pid=${1-}
+ local pid="${1-}"
if test -z "${pid}"; then
test_lib_error 'expected PID parameter in get_process_name'
clean_exit 1
# Wait for file to be created.
wait_for_file() {
- local file=${1-}
+ local file="${1-}"
if test -z "${file}"; then
test_lib_error 'expected file parameter in wait_for_file'
clean_exit 1
fi
local timeout='4' # seconds
- local deadline=$(($(date +%s) + timeout))
+ local deadline="$(($(date +%s) + timeout))"
while ! test -f "${file}"; do
if test "${deadline}" -lt "$(date +%s)"; then
# Time is up.
# Wait for process identified by PID to die.
wait_for_process_to_stop() {
- local pid=${1-}
+ local pid="${1-}"
if test -z "${pid}"; then
test_lib_error 'expected PID parameter in wait_for_process_to_stop'
clean_exit 1
fi
local timeout='4' # seconds
- local deadline=$(($(date +%s) + timeout))
+ local deadline="$(($(date +%s) + timeout))"
while ps "${pid}" >/dev/null; do
if test "${deadline}" -lt "$(date +%s)"; then
# Time is up.
# names, add this before pgrep:
# proc_name=$(printf '%s' "${proc_name}" | cut -c1-15)
kill_processes_by_name() {
- local proc_name=${1-} # Process name
+ local proc_name="${1-}" # Process name
if [ -z "${proc_name}" ]; then
test_lib_error "kill_processes_by_name requires process name"
clean_exit 1
# Starts Kea process in background using a configuration file specified
# in the global variable ${CFG_FILE}.
start_kea() {
- local bin=${1-}
+ local bin="${1-}"
if [ -z "${bin}" ]; then
test_lib_error "binary name must be specified for start_kea"
clean_exit 1
# Return value:
# _WAIT_FOR_KEA: 0 if Kea hasn't started, 1 otherwise
wait_for_kea() {
- local timeout=${1-} # Desired timeout in seconds.
+ local timeout="${1-}" # Desired timeout in seconds.
if test -z "${timeout}"; then
test_lib_error 'expected timeout parameter in wait_for_kea'
clean_exit 1
# Sends specified signal to the Kea process.
send_signal() {
- local sig=${1-} # Signal number.
- local proc_name=${2-} # Process name
+ local sig="${1-}" # Signal number.
+ local proc_name="${2-}" # Process name
# Validate signal
case ${sig} in
fi
# Declarations
- local test_name=${1}; shift
- local exit_code=${1}; shift
- local duration=${1}; shift # milliseconds
+ local test_name="${1}"; shift
+ local exit_code="${1}"; shift
+ local duration="${1}"; shift # milliseconds
local now
local test_case
local test_suite
# Add ${string} after ${reference} in ${file}.
_add_after() {
- local string=${1}; shift
- local reference=${1}; shift
- local file=${1}; shift
+ local string="${1}"; shift
+ local reference="${1}"; shift
+ local file="${1}"; shift
# Escape all slashes.
string=$(printf '%s' "${string}" | sed 's#\/#\\\/#g')
# Add ${string} before ${reference} in ${file}.
_add_before() {
- local string=${1}; shift
- local reference=${1}; shift
- local file=${1}; shift
+ local string="${1}"; shift
+ local reference="${1}"; shift
+ local file="${1}"; shift
# Get the line number of the reference line.
local line_number
}
_add_failure_tag() {
- local test_case_tag=${1}; shift
- local xml=${1}; shift
+ local test_case_tag="${1}"; shift
+ local xml="${1}"; shift
local closing_tag=' </testcase>'
local failure_tag
# Add test result if not in file.
_add_test_case() {
- local test_suite=${1}; shift
- local test_case=${1}; shift
- local result=${1}; shift
- local duration=${1}; shift
- local xml=${1}; shift
- local now=${1}; shift
+ local test_suite="${1}"; shift
+ local test_case="${1}"; shift
+ local result="${1}"; shift
+ local duration="${1}"; shift
+ local xml="${1}"; shift
+ local now="${1}"; shift
# Determine the test case tag.
local closing_backslash
# Add a set of test suite tags if not already present in the XML.
_add_test_suite() {
- local test_suite=${1}; shift
- local xml=${1}; shift
- local now=${1}; shift
+ local test_suite="${1}"; shift
+ local xml="${1}"; shift
+ local now="${1}"; shift
local test_suite_line
local all_test_suites
return;
fi
- local xml=${1}; shift
- local now=${1}; shift
+ local xml="${1}"; shift
+ local now="${1}"; shift
mkdir -p "$(dirname "${xml}")"
printf \
# Print the lines between two matching regex patterns from a file. Excludes the
# lines that contain the patterns themselves. Matches only the first occurrence.
_print_lines_between_matching_patterns() {
- local start_pattern=${1}; shift
- local end_pattern=${1}; shift
- local file=${1}; shift
+ local start_pattern="${1}"; shift
+ local end_pattern="${1}"; shift
+ local file="${1}"; shift
# Escape all slashes.
start_pattern=$(printf '%s' "${start_pattern}" | sed 's#\/#\\\/#g')
# Update the test suite XML attributes with metrics collected from the child
# test cases.
_update_test_suite_metrics() {
- local test_suite=${1}; shift
- local all_test_cases=${1}; shift
- local xml=${1}; shift
- local now=${1}; shift
+ local test_suite="${1}"; shift
+ local all_test_cases="${1}"; shift
+ local xml="${1}"; shift
+ local now="${1}"; shift
# Get the metrics on the parent test suite.
local duration
print_lines_between_matching_patterns() {
mandatory_commands sed
- local start_pattern=${1}; shift
- local end_pattern=${1}; shift
- local file=${1}; shift
+ local start_pattern="${1}"; shift
+ local end_pattern="${1}"; shift
+ local file="${1}"; shift
# Escape all slashes.
start_pattern=$(printf '%s' "${start_pattern}" | sed 's#\/#\\\/#g')
# Print file name if a file with that name exists.
print_file_name() {
- local file_name=${1}
+ local file_name="${1}"
if test -f "${file_name}"; then
printf '%s\n' "${file_name}" | cut -d '/' -f '2-'
fi
# SC1003: Want to escape a single quote? echo 'This is how it'\''s done'
# reason: No, we don't want to escape a single quote, we want a backslash.
print_generated_messages() {
- local makefile_am=${1}; shift
- local directory=${1}; shift
+ local makefile_am="${1}"; shift
+ local directory="${1}"; shift
for j in $(grep -F 'messages:' "${makefile_am}" | cut -d ':' -f '2-' | \
cut -d '\' -f 1); do
# Generated parsers
print_generated_parsers() {
- local makefile_am=${1}; shift
- local directory=${1}; shift
+ local makefile_am="${1}"; shift
+ local directory="${1}"; shift
for j in $(grep -F 'parser:' "${makefile_am}" | cut -d ':' -f '2-'); do
print_file_name "${directory}/${j}"
# Other generated files
print_built_sources() {
- local makefile_am=${1}; shift
- local directory=${1}; shift
+ local makefile_am="${1}"; shift
+ local directory="${1}"; shift
for j in $(grep -E 'BUILT_SOURCES (=|\+=)' "${makefile_am}" | cut -d '=' -f '2-'); do
print_file_name "${directory}/${j}"
# Print all files of interest sorted alphabetically.
print_all_sorted() {
- local built_sources=${1-true}
+ local built_sources="${1-true}"
for i in $(find . -type f -name 'Makefile.am'); do
directory=$(dirname "${i}")