123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #!/bin/sh
- # -*- coding: utf-8 -*-
- basedir="$(realpath "$0" | xargs dirname)"
- basedir="$basedir/.."
- info()
- {
- echo "--- $*"
- }
- error()
- {
- echo "=== ERROR: $*" >&2
- }
- warning()
- {
- echo "=== WARNING: $*" >&2
- }
- die()
- {
- error "$*"
- exit 1
- }
- build_project()
- {
- info "Building project..."
- cd "$basedir" || die "cd failed"
- ./build.sh || die "Build failed"
- }
- cargo_clippy()
- {
- cargo clippy -- --deny warnings || die "cargo clippy failed"
- cargo clippy --tests -- --deny warnings || die "cargo clippy --tests failed"
- }
- build_stubs()
- {
- info "Building stubs..."
- mkdir -p "$tmpbin" \
- || die "Failed to create tmpbin directory"
- rustc --edition 2021 -o "$tmpbin/nft" "$stubdir/nft.rs" \
- || die "Failed to build nft stub"
- }
- run_tests()
- {
- local test_type="$1"
- info "### Running test: $test_type ###"
- rm -rf "$rundir"
- local conf="$testdir/conf/$test_type.conf"
- info "Starting letmeinfwd..."
- "$target/letmeinfwd" \
- --test-mode \
- --no-systemd \
- --rundir "$rundir" \
- --config "$conf" &
- pid_letmeinfwd=$!
- info "Starting letmeind..."
- "$target/letmeind" \
- --no-systemd \
- --rundir "$rundir" \
- --config "$conf" &
- pid_letmeind=$!
- wait_for_pidfile letmeinfwd "$pid_letmeinfwd"
- wait_for_pidfile letmeind "$pid_letmeind"
- info "Knocking..."
- "$target/letmein" \
- --verbose \
- --config "$conf" \
- knock \
- --user 12345678 \
- localhost 42 \
- || die "letmein knock failed"
- kill_all_and_wait
- }
- wait_for_pidfile()
- {
- local name="$1"
- local pid="$2"
- for i in $(seq 0 29); do
- if [ -r "$rundir/$name/$name.pid" ]; then
- if [ "$pid" != "$(cat "$rundir/$name/$name.pid")" ]; then
- die "$name: Invalid PID-file."
- fi
- return
- fi
- sleep 0.1
- done
- die "$name PID-file is missing. Did $name fail to start?"
- }
- kill_all()
- {
- kill_letmeind
- kill_letmeinfwd
- }
- kill_all_and_wait()
- {
- kill_all
- wait
- }
- kill_letmeinfwd()
- {
- if [ -n "$pid_letmeinfwd" ]; then
- kill -TERM "$pid_letmeinfwd" >/dev/null 2>&1
- pid_letmeinfwd=
- fi
- }
- kill_letmeind()
- {
- if [ -n "$pid_letmeind" ]; then
- kill -TERM "$pid_letmeind" >/dev/null 2>&1
- pid_letmeind=
- fi
- }
- cleanup()
- {
- kill_all
- if [ -n "$tmpdir" ]; then
- rm -rf "$tmpdir"
- tmpdir=
- fi
- }
- cleanup_and_exit()
- {
- cleanup
- exit 1
- }
-
- pid_letmeinfwd=
- pid_letmeind=
- [ -n "$TMPDIR" ] || export TMPDIR=/tmp
- tmpdir="$(mktemp --tmpdir="$TMPDIR" -d letmein-test.XXXXXXXXXX)"
- [ -d "$tmpdir" ] || die "Failed to create temporary directory"
- tmpbin="$tmpdir/bin"
- rundir="$tmpdir/run"
- target="$basedir/target/debug"
- testdir="$basedir/tests"
- stubdir="$testdir/stubs"
- export PATH="$tmpbin:$PATH"
- trap cleanup_and_exit INT TERM
- trap cleanup EXIT
- info "Temporary directory is: $tmpdir"
- build_project
- cargo_clippy
- build_stubs
- run_tests tcp
- run_tests udp
- info "All tests Ok."
- # vim: ts=4 sw=4 expandtab
|