Skip to content

Commit 165c831

Browse files
committed
For systems without bwrap use a random port and no TLS.
1 parent f7d1a1b commit 165c831

File tree

4 files changed

+120
-32
lines changed

4 files changed

+120
-32
lines changed

scripts/client.test

+30-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ do_cleanup() {
1919
fi
2020
}
2121

22+
generate_port() { # function to produce a random port number
23+
if [[ "$OSTYPE" == "linux"* ]]; then
24+
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
25+
elif [[ "$OSTYPE" == "darwin"* ]]; then
26+
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
27+
else
28+
echo "Unknown OS TYPE"
29+
exit 1
30+
fi
31+
echo -e "Using port $port"
32+
}
33+
34+
2235
# Check for application
2336
[ ! -x ./examples/mqttclient/mqttclient ] && echo -e "\n\nMQTT Client doesn't exist" && exit 1
2437

@@ -34,22 +47,31 @@ def_args="-T -C 2000"
3447
# Check for mosquitto
3548
if command -v mosquitto
3649
then
37-
# bwrap only if using a local mosquitto instance
38-
if [ "${AM_BWRAPPED-}" != "yes" ]; then
39-
bwrap_path="$(command -v bwrap)"
40-
if [ -n "$bwrap_path" ]; then
41-
echo "Client test using bwrap"
50+
bwrap_path="$(command -v bwrap)"
51+
if [ -n "$bwrap_path" ]; then
52+
# bwrap only if using a local mosquitto instance
53+
if [ "${AM_BWRAPPED-}" != "yes" ]; then
54+
echo "Using bwrap"
4255
export AM_BWRAPPED=yes
4356
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
4457
fi
58+
59+
broker_args="-c scripts/broker_test/mosquitto.conf"
60+
port=11883
61+
else
62+
# mosquitto broker custom port non-TLS only
63+
has_tls=no
64+
generate_port
65+
broker_args="-p $port"
4566
fi
46-
# Run mosquitto broker
47-
mosquitto -c scripts/broker_test/mosquitto.conf &
67+
mosquitto $broker_args &
4868
broker_pid=$!
4969
echo "Broker PID is $broker_pid"
70+
sleep 0.1
71+
5072
def_args="${def_args} -h localhost"
5173
tls_port_args="-p 18883"
52-
port_args="-p 11883"
74+
port_args="-p ${port}"
5375
mutual_auth_args="-c certs/client-cert.pem -K certs/client-key.pem"
5476
ecc_mutual_auth_args="-c certs/client-ecc-cert.pem -K certs/ecc-client-key.pem"
5577
fi

scripts/firmware.test

+30-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ do_cleanup() {
2424
fi
2525
}
2626

27+
generate_port() { # function to produce a random port number
28+
if [[ "$OSTYPE" == "linux"* ]]; then
29+
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
30+
elif [[ "$OSTYPE" == "darwin"* ]]; then
31+
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
32+
else
33+
echo "Unknown OS TYPE"
34+
exit 1
35+
fi
36+
echo -e "Using port $port"
37+
}
38+
39+
2740
# Check for application
2841
[ ! -x ./examples/firmware/fwpush ] && echo -e "\n\nMQTT Example fwpush doesn't exist" && exit 1
2942
[ ! -x ./examples/firmware/fwclient ] && echo -e "\n\nMQTT Example fwclient doesn't exist" && exit 1
@@ -47,20 +60,29 @@ fileout=./examples/publish.dat.trs
4760
# Check for mosquitto
4861
if command -v mosquitto
4962
then
50-
# bwrap only if using a local mosquitto instance
51-
if [ "${AM_BWRAPPED-}" != "yes" ]; then
52-
bwrap_path="$(command -v bwrap)"
53-
if [ -n "$bwrap_path" ]; then
54-
echo "Firmware test using bwrap"
63+
bwrap_path="$(command -v bwrap)"
64+
if [ -n "$bwrap_path" ]; then
65+
# bwrap only if using a local mosquitto instance
66+
if [ "${AM_BWRAPPED-}" != "yes" ]; then
67+
echo "Using bwrap"
5568
export AM_BWRAPPED=yes
5669
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
5770
fi
71+
72+
broker_args="-c scripts/broker_test/mosquitto.conf"
73+
port=11883
74+
else
75+
# mosquitto broker custom port non-TLS only
76+
has_tls=no
77+
generate_port
78+
broker_args="-p $port"
5879
fi
59-
# Run mosquitto broker
60-
mosquitto -c scripts/broker_test/mosquitto.conf &
80+
mosquitto $broker_args &
6181
broker_pid=$!
6282
echo "Broker PID is $broker_pid"
63-
def_args="${def_args} -h localhost -p 18883"
83+
sleep 0.1
84+
85+
def_args="${def_args} -h localhost -p ${port}"
6486
fi
6587

6688
grep -F -e 'ENABLE_MQTT_TLS' ./wolfmqtt/options.h

scripts/multithread.test

+29-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ do_cleanup() {
1919
fi
2020
}
2121

22+
generate_port() { # function to produce a random port number
23+
if [[ "$OSTYPE" == "linux"* ]]; then
24+
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
25+
elif [[ "$OSTYPE" == "darwin"* ]]; then
26+
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
27+
else
28+
echo "Unknown OS TYPE"
29+
exit 1
30+
fi
31+
echo -e "Using port $port"
32+
}
33+
2234
# Check for application
2335
[ ! -x ./examples/multithread/multithread ] && echo -e "\n\nMultithread Client doesn't exist" && exit 1
2436

@@ -34,22 +46,31 @@ def_args="-T -C 2000"
3446
# Check for mosquitto
3547
if command -v mosquitto
3648
then
37-
# bwrap only if using a local mosquitto instance
38-
if [ "${AM_BWRAPPED-}" != "yes" ]; then
39-
bwrap_path="$(command -v bwrap)"
40-
if [ -n "$bwrap_path" ]; then
41-
echo "multithread test using bwrap"
49+
bwrap_path="$(command -v bwrap)"
50+
if [ -n "$bwrap_path" ]; then
51+
# bwrap only if using a local mosquitto instance
52+
if [ "${AM_BWRAPPED-}" != "yes" ]; then
53+
echo "Using bwrap"
4254
export AM_BWRAPPED=yes
4355
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
4456
fi
57+
58+
broker_args="-c scripts/broker_test/mosquitto.conf"
59+
port=11883
60+
else
61+
# mosquitto broker custom port non-TLS only
62+
has_tls=no
63+
generate_port
64+
broker_args="-p $port"
4565
fi
46-
# Run mosquitto broker
47-
mosquitto -c scripts/broker_test/mosquitto.conf &
66+
mosquitto $broker_args &
4867
broker_pid=$!
4968
echo "Broker PID is $broker_pid"
69+
sleep 0.1
70+
5071
def_args="${def_args} -h localhost"
5172
tls_port_args="-p 18883"
52-
port_args="-p 11883"
73+
port_args="-p ${port}"
5374
fi
5475

5576
echo -e "Base args: $def_args $port_args"

scripts/nbclient.test

+31-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ do_cleanup() {
1919
fi
2020
}
2121

22+
generate_port() { # function to produce a random port number
23+
if [[ "$OSTYPE" == "linux"* ]]; then
24+
port=$(($(od -An -N2 /dev/urandom) % (65535-49152) + 49152))
25+
elif [[ "$OSTYPE" == "darwin"* ]]; then
26+
port=$(($(od -An -N2 /dev/random) % (65535-49152) + 49152))
27+
else
28+
echo "Unknown OS TYPE"
29+
exit 1
30+
fi
31+
echo -e "Using port $port"
32+
}
33+
2234
# Check for application
2335
[ ! -x ./examples/nbclient/nbclient ] && echo -e "\n\nNon-blocking Client doesn't exist" && exit 1
2436

@@ -36,27 +48,38 @@ def_args="-T -C 2000"
3648
# Check for mosquitto
3749
if command -v mosquitto
3850
then
39-
# bwrap only if using a local mosquitto instance
40-
if [ "${AM_BWRAPPED-}" != "yes" ]; then
41-
bwrap_path="$(command -v bwrap)"
42-
if [ -n "$bwrap_path" ]; then
43-
echo "nbclient test using bwrap"
51+
bwrap_path="$(command -v bwrap)"
52+
if [ -n "$bwrap_path" ]; then
53+
# bwrap only if using a local mosquitto instance
54+
if [ "${AM_BWRAPPED-}" != "yes" ]; then
55+
echo "Using bwrap"
4456
export AM_BWRAPPED=yes
4557
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
4658
fi
59+
60+
broker_args="-c scripts/broker_test/mosquitto.conf"
61+
port=11883
62+
else
63+
# mosquitto broker custom port non-TLS only
64+
has_tls=no
65+
generate_port
66+
broker_args="-p $port"
4767
fi
48-
# Run mosquitto broker
49-
mosquitto -c scripts/broker_test/mosquitto.conf &
68+
echo -e "mosquitto $broker_args"
69+
mosquitto $broker_args &
5070
broker_pid=$!
5171
echo "Broker PID is $broker_pid"
72+
sleep 0.1
73+
5274
def_args="${def_args} -h localhost"
5375
tls_port_args="-p 18883"
54-
port_args="-p 11883"
76+
port_args="-p ${port}"
5577
fi
5678

5779
echo -e "Base args: $def_args $port_args"
5880

5981
# Run without TLS and QoS 0-2
82+
echo -e "./examples/nbclient/nbclient $def_args $port_args -q 0 $1"
6083
./examples/nbclient/nbclient $def_args $port_args -q 0 $1
6184
RESULT=$?
6285
[ $RESULT -ne 0 ] && echo -e "\n\nNon-blocking Client failed! TLS=Off, QoS=0" && do_cleanup "-1"

0 commit comments

Comments
 (0)