TT#116101 bin/generate_test_tt2.sh add sipp option

* default: generate all
  so it can generate sipp checks too

Change-Id: I9881d1b0aa2bd4d8397e1189f28c579b6073c53b
mr10.0
Victor Seva 5 years ago
parent e7b9a38eff
commit 4742b3c90b

@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright: 2020 Sipwise Development Team <support@sipwise.com>
# Copyright: 2020-2021 Sipwise Development Team <support@sipwise.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -20,14 +20,15 @@
#
BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}"
BIN_DIR="${BASE_DIR}/bin"
DEST_DIR="${DEST_DIR}"
GROUP="${GROUP:-scenarios}"
CHECK_TYPE=all
function usage
{
echo "Usage: generate_tests_tt2.sh [-h] [-x GROUP] scenario [id1] [id2]"
echo "Options:"
echo -e "\\tx: group of scenarios. Default: scenarios"
echo -e "\\t-S check type. Default: all (cfgt, sipp)"
echo -e "\\th: this help"
echo "Args:"
echo -e "\\tscenario: name of the scenario in GROUP"
@ -40,17 +41,19 @@ function usage
echo -e "\\t\$ generate_tests_tt2.sh incoming 1 7 12"
}
while getopts 'hx:' opt; do
while getopts 'hx:S:' opt; do
case $opt in
h) usage; exit 0;;
x) GROUP=${OPTARG};;
S) CHECK_TYPE=${OPTARG};;
*) usage; exit 1;;
esac
done
shift $((OPTIND - 1))
SCEN="$1"
shift 1
if [[ $# -lt 1 ]]; then
if [ -z "${SCEN}" ]; then
echo "Wrong number or arguments" >&2
usage
exit 1
@ -73,29 +76,53 @@ elif [ ! -f "${LOG_DIR}/scenario_ids.yml" ] ; then
exit 2
fi
if [ ! -x "${BIN_DIR}/generate_test_tt2.pl" ]; then
echo "Cannot exec ${BIN_DIR}/generate_test_tt2.pl" >&2
usage
exit 3
fi
if [[ $# -eq 1 ]]; then
mapfile -t IDS < <(find "${LOG_DIR}" -maxdepth 1 -name '*.json' -exec basename {} \;| sort)
else
shift 1
IDS=()
for t in "${@}"; do
file=$(printf "%04d.json" "${t}")
if [ ! -f "${LOG_DIR}/${file}" ]; then
echo "${LOG_DIR}/${file} not found" >&2
exit 4
fi
IDS+=( "${file}" )
done
fi
CMD="${BIN_DIR}/generate_test_tt2.pl -F -i ${LOG_DIR}/scenario_ids.yml"
CMD+=" -n ${SCEN_DIR}/scenario.yml "
for t in "${IDS[@]}" ; do
file="${SCEN_DIR}/$(basename "${t}" .json)"_test.yml.tt2
echo "generating: ${file}"
${CMD} "${LOG_DIR}/${t}" > "${file}"
done
gen_cfgt() {
if [ ! -x "${BIN_DIR}/generate_test_tt2.pl" ]; then
echo "Cannot exec ${BIN_DIR}/generate_test_tt2.pl" >&2
usage
exit 3
fi
if [[ $# -eq 0 ]]; then
mapfile -t IDS < <(find "${LOG_DIR}" -maxdepth 1 -name '*.json' -exec basename {} \;| sort)
else
IDS=()
for t in "${@}"; do
file=$(printf "%04d.json" "${t}")
if [ ! -f "${LOG_DIR}/${file}" ]; then
echo "${LOG_DIR}/${file} not found" >&2
exit 4
fi
IDS+=( "${file}" )
done
fi
CMD="${BIN_DIR}/generate_test_tt2.pl -F -i ${LOG_DIR}/scenario_ids.yml"
CMD+=" -n ${SCEN_DIR}/scenario.yml "
for t in "${IDS[@]}" ; do
file="${SCEN_DIR}/$(basename "${t}" .json)"_test.yml.tt2
echo "generating: ${file}"
${CMD} "${LOG_DIR}/${t}" > "${file}"
done
}
gen_sipp() {
if [ ! -x "${BIN_DIR}/generate_test_tt2.py" ]; then
echo "Cannot exec ${BIN_DIR}/generate_test_tt2.py" >&2
usage
exit 3
fi
mapfile -t IDS < <(find "${LOG_DIR}" -maxdepth 1 -name '*.msg' -exec basename {} \;| sort)
CMD="${BIN_DIR}/generate_test_tt2.py ${LOG_DIR}/scenario_ids.yml"
for t in "${IDS[@]}" ; do
file="${SCEN_DIR}/$(basename "${t}" .msg)"_test.yml.tt2
echo "generating: ${file}"
${CMD} "${LOG_DIR}/${t}" > "${file}"
done
}
case "${CHECK_TYPE}" in
all) gen_cfgt "$@"; gen_sipp;;
cfgt) gen_cfgt "$@";;
sipp) gen_sipp;;
*) echo "unknown check type"; exit 1;;
esac

Loading…
Cancel
Save