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 #!/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 # 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 # 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}" BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}"
BIN_DIR="${BASE_DIR}/bin" BIN_DIR="${BASE_DIR}/bin"
DEST_DIR="${DEST_DIR}"
GROUP="${GROUP:-scenarios}" GROUP="${GROUP:-scenarios}"
CHECK_TYPE=all
function usage function usage
{ {
echo "Usage: generate_tests_tt2.sh [-h] [-x GROUP] scenario [id1] [id2]" echo "Usage: generate_tests_tt2.sh [-h] [-x GROUP] scenario [id1] [id2]"
echo "Options:" echo "Options:"
echo -e "\\tx: group of scenarios. Default: scenarios" echo -e "\\tx: group of scenarios. Default: scenarios"
echo -e "\\t-S check type. Default: all (cfgt, sipp)"
echo -e "\\th: this help" echo -e "\\th: this help"
echo "Args:" echo "Args:"
echo -e "\\tscenario: name of the scenario in GROUP" 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" 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 case $opt in
h) usage; exit 0;; h) usage; exit 0;;
x) GROUP=${OPTARG};; x) GROUP=${OPTARG};;
S) CHECK_TYPE=${OPTARG};;
*) usage; exit 1;; *) usage; exit 1;;
esac esac
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
SCEN="$1" SCEN="$1"
shift 1
if [[ $# -lt 1 ]]; then if [ -z "${SCEN}" ]; then
echo "Wrong number or arguments" >&2 echo "Wrong number or arguments" >&2
usage usage
exit 1 exit 1
@ -73,29 +76,53 @@ elif [ ! -f "${LOG_DIR}/scenario_ids.yml" ] ; then
exit 2 exit 2
fi fi
if [ ! -x "${BIN_DIR}/generate_test_tt2.pl" ]; then gen_cfgt() {
echo "Cannot exec ${BIN_DIR}/generate_test_tt2.pl" >&2 if [ ! -x "${BIN_DIR}/generate_test_tt2.pl" ]; then
usage echo "Cannot exec ${BIN_DIR}/generate_test_tt2.pl" >&2
exit 3 usage
fi exit 3
if [[ $# -eq 1 ]]; then fi
mapfile -t IDS < <(find "${LOG_DIR}" -maxdepth 1 -name '*.json' -exec basename {} \;| sort) if [[ $# -eq 0 ]]; then
else mapfile -t IDS < <(find "${LOG_DIR}" -maxdepth 1 -name '*.json' -exec basename {} \;| sort)
shift 1 else
IDS=() IDS=()
for t in "${@}"; do for t in "${@}"; do
file=$(printf "%04d.json" "${t}") file=$(printf "%04d.json" "${t}")
if [ ! -f "${LOG_DIR}/${file}" ]; then if [ ! -f "${LOG_DIR}/${file}" ]; then
echo "${LOG_DIR}/${file} not found" >&2 echo "${LOG_DIR}/${file} not found" >&2
exit 4 exit 4
fi fi
IDS+=( "${file}" ) IDS+=( "${file}" )
done done
fi fi
CMD="${BIN_DIR}/generate_test_tt2.pl -F -i ${LOG_DIR}/scenario_ids.yml" CMD="${BIN_DIR}/generate_test_tt2.pl -F -i ${LOG_DIR}/scenario_ids.yml"
CMD+=" -n ${SCEN_DIR}/scenario.yml " CMD+=" -n ${SCEN_DIR}/scenario.yml "
for t in "${IDS[@]}" ; do for t in "${IDS[@]}" ; do
file="${SCEN_DIR}/$(basename "${t}" .json)"_test.yml.tt2 file="${SCEN_DIR}/$(basename "${t}" .json)"_test.yml.tt2
echo "generating: ${file}" echo "generating: ${file}"
${CMD} "${LOG_DIR}/${t}" > "${file}" ${CMD} "${LOG_DIR}/${t}" > "${file}"
done 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