wolfMQTT/scripts/multithread.test

92 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# MQTT Multithread Client test
no_pid=-1
broker_pid=$no_pid
do_cleanup() {
if [ $broker_pid != $no_pid ]
then
kill -9 $broker_pid
echo "Killed broker PID $broker_pid"
broker_pid=$no_pid
fi
if [ $1 -ne 0 ]
then
exit 1
fi
}
# Check for application
[ ! -x ./examples/multithread/multithread ] && echo -e "\n\nMultithread Client doesn't exist" && exit 1
# Check for TLS support
has_tls=no
./examples/multithread/multithread -? 2>&1 | grep -- 'Enable TLS'
if [ $? -eq 0 ]; then
has_tls=yes
fi
def_args="-T -C 2000"
# Check for mosquitto
if command -v mosquitto
then
# bwrap only if using a local mosquitto instance
if [ "${AM_BWRAPPED-}" != "yes" ]; then
bwrap_path="$(command -v bwrap)"
if [ -n "$bwrap_path" ]; then
echo "multithread test using bwrap"
export AM_BWRAPPED=yes
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
fi
fi
# Run mosquitto broker
mosquitto -c scripts/broker_test/mosquitto.conf &
broker_pid=$!
echo "Broker PID is $broker_pid"
def_args="${def_args} -h localhost"
tls_port_args="-p 18883"
port_args="-p 11883"
fi
echo -e "Base args: $def_args $port_args"
# Run without TLS and QoS 0-2
./examples/multithread/multithread $def_args $port_args -q 0 $1
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nMultithread Client failed! TLS=Off, QoS=0" && do_cleanup "-1"
./examples/multithread/multithread $def_args $port_args -q 1 $1
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nMultithread Client failed! TLS=Off, QoS=1" && do_cleanup "-1"
./examples/multithread/multithread $def_args $port_args -q 2 $1
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nMultithread Client failed! TLS=Off, QoS=2" && do_cleanup "-1"
if test $has_tls == yes
then
# Run with TLS and QoS 0-2
./examples/multithread/multithread $def_args $tls_port_args -t -q 0 $1
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nMultithread Client failed! TLS=On, QoS=0" && do_cleanup "-1"
./examples/multithread/multithread $def_args $tls_port_args -t -q 1 $1
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nMultithread Client failed! TLS=On, QoS=1" && do_cleanup "-1"
./examples/multithread/multithread $def_args $tls_port_args -t -q 2 $1
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nMultithread Client failed! TLS=On, QoS=2" && do_cleanup "-1"
fi
# End broker
do_cleanup "0"
echo -e "\n\nMultithread MQTT Client Tests Passed"
exit 0