blob: a4ac0dfd8ce8c581d4cc3bec486b91b29192dadb [file] [log] [blame]
set -eux
export UBSAN_OPTIONS=halt_on_error=1 # UBSan doesn't stop on errors by default.
if [[ $(dirname "$(dirname "$(realpath "$SYSREPO_REPOSITORY_PATH")")") != "@CMAKE_CURRENT_BINARY_DIR@" ]]; then
echo "\$SYSREPO_REPOSITORY_PATH is not inside the build dir! Aborting. ($SYSREPO_REPOSITORY_PATH)"
exit 1
fi
if [[ -z "$SYSREPO_SHM_PREFIX" ]]; then
echo '$SYSREPO_SHM_PREFIX is empty! Aborting.'
exit 1
fi
rm -rf "$SYSREPO_REPOSITORY_PATH"
rm -rf "/dev/shm/$SYSREPO_SHM_PREFIX"*
cp -r "@SYSREPO_SR_REPO_PATH@" "$SYSREPO_REPOSITORY_PATH"
SYSREPOCTL="@SYSREPOCTL_EXECUTABLE@"
SYSREPOCFG="@SYSREPOCFG_EXECUTABLE@"
MODULE="$1"
YANG_DIR=$(dirname "$1")
shift
# Install the module
"$SYSREPOCTL" --search-dirs "$YANG_DIR" --install "$MODULE" -a
BACKEND="$1"
shift
if [[ "$BACKEND" = "netconf" ]]; then
NETOPEER2="@NETOPEER2_EXECUTABLE@"
# Setup netopeer config
"$SYSREPOCFG" --import --datastore=running --format=xml --module=ietf-netconf-server <<< ""
# Disable nacm
for datastore in startup running; do
"$SYSREPOCFG" --import="@CMAKE_CURRENT_SOURCE_DIR@/tests/disable-nacm.xml" --datastore="$datastore" --format=xml --module=ietf-netconf-acm
done
# I need to run netopeer in the foreground, because I want to get its standard outputs. However, ctest doesn't like
# when child processes don't exit and always waits fot them. The `setsid` command runs a program in a separate
# session and also forks, which means it becomes invisible to ctest. I want the name of the process to be
# recognizable. For that `exec -a` can be used. Unfortunately `exec` is shell-builtin, so I need to run bash instead
# of running `exec` directly. Finally, I redirect its stdout and stderr to a file.
NETOPEER_PIDFILE="@CMAKE_CURRENT_BINARY_DIR@/test_netopeer_files/$SYSREPO_SHM_PREFIX.pid"
setsid -f \
bash -c "exec -a '${SYSREPO_SHM_PREFIX}_netopeer2-server' '$NETOPEER2' -d -v2 '-U$NETOPEER_SOCKET' -p'$NETOPEER_PIDFILE'" \
< /dev/null &> "@CMAKE_CURRENT_BINARY_DIR@/test_netopeer_outputs/$SYSREPO_SHM_PREFIX.out"
sleep 5
fi