Skip to content

Commit

Permalink
For systems without bwrap use a random port and no TLS.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Nov 21, 2023
1 parent bffe15c commit e46c2e9
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 49 deletions.
38 changes: 30 additions & 8 deletions scripts/client.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ do_cleanup() {
fi
}

generate_port() { # function to produce a random port number
if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
else
echo "Unknown OS TYPE"
exit 1
fi
echo -e "Using port $port"
}


# Check for application
[ ! -x ./examples/mqttclient/mqttclient ] && echo -e "\n\nMQTT Client doesn't exist" && exit 1

Expand All @@ -34,22 +47,31 @@ 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 "Client test using bwrap"
bwrap_path="$(command -v bwrap)"
if [ -n "$bwrap_path" ]; then
# bwrap only if using a local mosquitto instance
if [ "${AM_BWRAPPED-}" != "yes" ]; then
echo "Using bwrap"
export AM_BWRAPPED=yes
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
fi

broker_args="-c scripts/broker_test/mosquitto.conf"
port=11883
else
# mosquitto broker custom port non-TLS only
has_tls=no
generate_port
broker_args="-p $port"
fi
# Run mosquitto broker
mosquitto -c scripts/broker_test/mosquitto.conf &
mosquitto $broker_args &
broker_pid=$!
echo "Broker PID is $broker_pid"
sleep 0.1

def_args="${def_args} -h localhost"
tls_port_args="-p 18883"
port_args="-p 11883"
port_args="-p ${port}"
mutual_auth_args="-c certs/client-cert.pem -K certs/client-key.pem"
ecc_mutual_auth_args="-c certs/client-ecc-cert.pem -K certs/ecc-client-key.pem"
fi
Expand Down
66 changes: 41 additions & 25 deletions scripts/firmware.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ no_pid=-1
broker_pid=$no_pid

do_cleanup() {
if [ $ENABLE_MQTT_TLS -ne 1 ]; then
# Delete file
rm $fileout
fi
# Delete file
rm $fileout

if [ $broker_pid != $no_pid ]
then
Expand All @@ -24,6 +22,19 @@ do_cleanup() {
fi
}

generate_port() { # function to produce a random port number
if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
else
echo "Unknown OS TYPE"
exit 1
fi
echo -e "Using port $port"
}


# Check for application
[ ! -x ./examples/firmware/fwpush ] && echo -e "\n\nMQTT Example fwpush doesn't exist" && exit 1
[ ! -x ./examples/firmware/fwclient ] && echo -e "\n\nMQTT Example fwclient doesn't exist" && exit 1
Expand All @@ -36,35 +47,42 @@ if [ $? -eq 0 ]; then
fi

def_args="-T -C 5000 -n wolfMQTT/example/firmware_$((RANDOM))"
if test $has_tls == yes
then
def_args="${def_args} -t"
fi
filein=./examples/publish.dat
fileout=./examples/publish.dat.trs


# 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 "Firmware test using bwrap"
bwrap_path="$(command -v bwrap)"
if [ -n "$bwrap_path" ]; then
# bwrap only if using a local mosquitto instance
if [ "${AM_BWRAPPED-}" != "yes" ]; then
echo "Using bwrap"
export AM_BWRAPPED=yes
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
fi

broker_args="-c scripts/broker_test/mosquitto.conf"
port=11883
else
# mosquitto broker custom port non-TLS only
has_tls=no
generate_port
broker_args="-p $port"
fi
# Run mosquitto broker
mosquitto -c scripts/broker_test/mosquitto.conf &
mosquitto $broker_args &
broker_pid=$!
echo "Broker PID is $broker_pid"
def_args="${def_args} -h localhost -p 18883"
sleep 0.1

def_args="${def_args} -h localhost -p ${port}"
fi

grep -F -e 'ENABLE_MQTT_TLS' ./wolfmqtt/options.h
ENABLE_MQTT_TLS=$?
if test $has_tls == yes
then
def_args="${def_args} -t"
fi

echo -e "Base args: $def_args"

Expand All @@ -84,13 +102,11 @@ server_result=$?
# give some time for the client complete
sleep 0.5

if [ $ENABLE_MQTT_TLS -ne 1 ]; then
# Compare files
echo "Comparing files"
md5sum -b $filein $fileout
compare_result=$?
[ $compare_result -ne 0 ] && echo -e "\n\nMQTT Example firmware compare failed!" && do_cleanup "-1"
fi
# Compare files
echo "Comparing files"
md5sum -b $filein $fileout
compare_result=$?
[ $compare_result -ne 0 ] && echo -e "\n\nMQTT Example firmware compare failed!" && do_cleanup "-1"

# End broker
do_cleanup "0"
Expand Down
37 changes: 29 additions & 8 deletions scripts/multithread.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ do_cleanup() {
fi
}

generate_port() { # function to produce a random port number
if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
else
echo "Unknown OS TYPE"
exit 1
fi
echo -e "Using port $port"
}

# Check for application
[ ! -x ./examples/multithread/multithread ] && echo -e "\n\nMultithread Client doesn't exist" && exit 1

Expand All @@ -34,22 +46,31 @@ 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"
bwrap_path="$(command -v bwrap)"
if [ -n "$bwrap_path" ]; then
# bwrap only if using a local mosquitto instance
if [ "${AM_BWRAPPED-}" != "yes" ]; then
echo "Using bwrap"
export AM_BWRAPPED=yes
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
fi

broker_args="-c scripts/broker_test/mosquitto.conf"
port=11883
else
# mosquitto broker custom port non-TLS only
has_tls=no
generate_port
broker_args="-p $port"
fi
# Run mosquitto broker
mosquitto -c scripts/broker_test/mosquitto.conf &
mosquitto $broker_args &
broker_pid=$!
echo "Broker PID is $broker_pid"
sleep 0.1

def_args="${def_args} -h localhost"
tls_port_args="-p 18883"
port_args="-p 11883"
port_args="-p ${port}"
fi

echo -e "Base args: $def_args $port_args"
Expand Down
37 changes: 29 additions & 8 deletions scripts/nbclient.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ do_cleanup() {
fi
}

generate_port() { # function to produce a random port number
if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
else
echo "Unknown OS TYPE"
exit 1
fi
echo -e "Using port $port"
}

# Check for application
[ ! -x ./examples/nbclient/nbclient ] && echo -e "\n\nNon-blocking Client doesn't exist" && exit 1

Expand All @@ -36,22 +48,31 @@ 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 "nbclient test using bwrap"
bwrap_path="$(command -v bwrap)"
if [ -n "$bwrap_path" ]; then
# bwrap only if using a local mosquitto instance
if [ "${AM_BWRAPPED-}" != "yes" ]; then
echo "Using bwrap"
export AM_BWRAPPED=yes
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
fi

broker_args="-c scripts/broker_test/mosquitto.conf"
port=11883
else
# mosquitto broker custom port non-TLS only
has_tls=no
generate_port
broker_args="-p $port"
fi
# Run mosquitto broker
mosquitto -c scripts/broker_test/mosquitto.conf &
mosquitto $broker_args &
broker_pid=$!
echo "Broker PID is $broker_pid"
sleep 0.1

def_args="${def_args} -h localhost"
tls_port_args="-p 18883"
port_args="-p 11883"
port_args="-p ${port}"
fi

echo -e "Base args: $def_args $port_args"
Expand Down

0 comments on commit e46c2e9

Please sign in to comment.