#!/bin/sh
# This regression test is a part of SIPp.
# Turning the messages log off and on again with the "trace" control
# command opens the messages log again, not the logs one.
. "`dirname "$0"`/../functions"; init

command -v python3 >/dev/null || skip "no python3"

sippfg -sf uac.xml -i 127.0.0.1 -p 25873 -cp 8898 -m 1 127.0.0.1:25872 \
    -trace_msg -timeout 10 >/dev/null 2>&1 &
sipp=$!
sleep 0.5
python3 -c '
import socket, time
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(b"ctrace messages off", ("127.0.0.1", 8898))
time.sleep(0.2)
s.sendto(b"ctrace messages on", ("127.0.0.1", 8898))'
wait $sipp
status=$?
messages=`cat uac_*_messages.log 2>/dev/null`
rm -f uac_*_messages.log uac_*_logs.log

if test $status -ne 0; then
    fail "exit status $status"
elif ! echo "$messages" | grep -q OPTIONS; then
    fail "no message logged after the log was turned on again"
else
    ok
fi
