diff --git a/.github/workflows/fsanitize-check.yml b/.github/workflows/fsanitize-check.yml index ee87798ef..543e55420 100644 --- a/.github/workflows/fsanitize-check.yml +++ b/.github/workflows/fsanitize-check.yml @@ -15,15 +15,36 @@ jobs: WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1 steps: + - name: Install dependencies + run: | + # Don't prompt for anything + export DEBIAN_FRONTEND=noninteractive + sudo apt-get update + # Install mosquitto + sudo apt-get install -y mosquitto bubblewrap + + - name: Setup mosquitto broker + run: | + # Disable default broker daemon + sudo service mosquitto stop + sleep 1 + + # This is some debug info useful if something goes wrong + - name: Show network status + run: | + sudo ifconfig + sudo route + sudo netstat -tulpan + - uses: actions/checkout@master with: repository: wolfssl/wolfssl path: wolfssl - name: wolfssl autogen - working-directory: ./wolfssl + working-directory: ./wolfssl run: ./autogen.sh - name: wolfssl configure - working-directory: ./wolfssl + working-directory: ./wolfssl run: ./configure --enable-enckeys - name: wolfssl make working-directory: ./wolfssl @@ -34,27 +55,37 @@ jobs: - uses: actions/checkout@master - name: autogen run: ./autogen.sh + - name: configure run: ./configure CC="gcc -fsanitize=address" - name: make run: make - name: make check run: make check + - name: configure with SN Enabled run: ./configure --enable-sn CC="gcc -fsanitize=address" - name: make run: make - name: make check run: make check + - name: configure with Non-Block run: ./configure --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK" CC="gcc -fsanitize=address" - name: make run: make - name: make check run: make check + - name: configure with Non-Block and Multi-threading run: ./configure --enable-mt --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK" CC="gcc -fsanitize=address" - name: make run: make - name: make check run: make check + + # capture logs on failure + - name: Show logs on failure + if: failure() || cancelled() + run: | + more test-suite.log diff --git a/.github/workflows/macos-check.yml b/.github/workflows/macos-check.yml index 1474e1f26..c748881f8 100644 --- a/.github/workflows/macos-check.yml +++ b/.github/workflows/macos-check.yml @@ -19,12 +19,13 @@ jobs: repository: wolfssl/wolfssl path: wolfssl - name: brew - run: brew install automake libtool + run: brew install automake libtool md5sha1sum + - name: wolfssl autogen - working-directory: ./wolfssl + working-directory: ./wolfssl run: ./autogen.sh - name: wolfssl configure - working-directory: ./wolfssl + working-directory: ./wolfssl run: ./configure --enable-enckeys - name: wolfssl make working-directory: ./wolfssl @@ -32,30 +33,41 @@ jobs: - name: wolfssl make install working-directory: ./wolfssl run: make install + - uses: actions/checkout@master - name: autogen run: ./autogen.sh + - name: configure run: ./configure - name: make run: make - name: make check run: make check + - name: configure with SN Enabled run: ./configure --enable-sn - name: make run: make - name: make check run: make check + - name: configure with Non-Block run: ./configure --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK" - name: make run: make - name: make check run: make check + - name: configure with Non-Block and Multi-threading run: ./configure --enable-mt --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK" - name: make run: make - name: make check run: make check + + # capture logs on failure + - name: Show logs on failure + if: failure() || cancelled() + run: | + cat test-suite.log diff --git a/.github/workflows/ubuntu-check.yml b/.github/workflows/ubuntu-check.yml index d8bd3107f..811233988 100644 --- a/.github/workflows/ubuntu-check.yml +++ b/.github/workflows/ubuntu-check.yml @@ -13,6 +13,27 @@ jobs: timeout-minutes: 5 steps: + - name: Install dependencies + run: | + # Don't prompt for anything + export DEBIAN_FRONTEND=noninteractive + sudo apt-get update + # Install mosquitto + sudo apt-get install -y mosquitto bubblewrap + + - name: Setup mosquitto broker + run: | + # Disable default broker daemon + sudo service mosquitto stop + sleep 1 + + # This is some debug info useful if something goes wrong + - name: Show network status + run: | + sudo ifconfig + sudo route + sudo netstat -tulpan + - uses: actions/checkout@master with: repository: wolfssl/wolfssl @@ -29,63 +50,51 @@ jobs: - name: wolfssl make install working-directory: ./wolfssl run: sudo make install + - uses: actions/checkout@master - - name: autogen + - name: wolfmqtt autogen run: ./autogen.sh - - name: configure + + - name: wolfmqtt configure run: ./configure - - name: make + - name: wolfmqtt make run: make - - name: make check - id: make-check + - name: wolfmqtt make check run: make check - - name: Show logs on failure - if: ${{ failure() && steps.make-check.outcome == 'failure' }} - run: | - more test-suite.log + env: WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1 - - name: configure with SN Enabled + + - name: wolfmqtt configure with SN Enabled run: ./configure --enable-sn - - name: make + - name: wolfmqtt make run: make - - name: make check - id: make-check-sn + - name: wolfmqtt make check run: make check - - name: Show logs on failure - if: ${{ failure() && steps.make-check-sn.outcome == 'failure' }} - run: | - more test-suite.log - - name: configure with Non-Block + + - name: wolfmqtt configure with Non-Block run: ./configure --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK" - - name: make + - name: wolfmqtt make run: make - - name: make check - id: make-check-nonblock + - name: wolfmqtt make check run: make check - - name: Show logs on failure - if: ${{ failure() && steps.make-check-nonblock.outcome == 'failure' }} - run: | - more test-suite.log - - name: configure with Non-Block and Multi-threading + + - name: wolfmqtt configure with Non-Block and Multi-threading run: ./configure --enable-mt --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK" - - name: make + - name: wolfmqtt make run: make - - name: make check - id: make-check-nonblock-mt + - name: wolfmqtt make check run: make check - - name: Show logs on failure - if: ${{ failure() && steps.make-check-nonblock-mt.outcome == 'failure' }} - run: | - more test-suite.log + - name: configure with Multi-threading and WOLFMQTT_DYN_PROP run: ./configure --enable-mt CFLAGS="-DWOLFMQTT_DYN_PROP" - name: make run: make - name: make check - id: make-check-mt-dynprop run: make check + + # capture logs on failure - name: Show logs on failure - if: ${{ failure() && steps.make-check-mt-dynprop.outcome == 'failure' }} + if: failure() || cancelled() run: | more test-suite.log diff --git a/.github/workflows/zephyr.yml b/.github/workflows/zephyr.yml index eb81835c0..8501ea4f2 100644 --- a/.github/workflows/zephyr.yml +++ b/.github/workflows/zephyr.yml @@ -1,4 +1,6 @@ name: Zephyr tests +env: + WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1 on: push: @@ -17,6 +19,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 20 steps: + - name: Install dependencies run: | # Don't prompt for anything @@ -86,7 +89,7 @@ jobs: sudo service mosquitto stop mosquitto -c scripts/broker_test/mosquitto.conf &> broker.log & sleep 1 # let the broker set everything up - mosquitto_sub -t sensors &> sub.log & + mosquitto_sub -p 11883 -t sensors &> sub.log & # This is some debug info useful if something goes wrong - name: Show network status diff --git a/scripts/broker_test/mosquitto.conf b/scripts/broker_test/mosquitto.conf index 23e3be18e..7e27dc735 100644 --- a/scripts/broker_test/mosquitto.conf +++ b/scripts/broker_test/mosquitto.conf @@ -7,7 +7,7 @@ # ================================================================= # Port to use for the default listener. -listener 1883 +listener 11883 allow_anonymous true # ----------------------------------------------------------------- @@ -19,7 +19,7 @@ allow_anonymous true # # See also the mosquitto-tls man page. -listener 8883 +listener 18883 allow_anonymous true # At least one of cafile or capath must be defined. They both diff --git a/scripts/client.test b/scripts/client.test index fc241e1e2..482427790 100755 --- a/scripts/client.test +++ b/scripts/client.test @@ -8,9 +8,11 @@ broker_pid=$no_pid do_cleanup() { if [ $broker_pid != $no_pid ] then - kill -6 $broker_pid + kill -9 $broker_pid + echo "Killed broker PID $broker_pid" + broker_pid=$no_pid fi - + if [ $1 -ne 0 ] then exit 1 @@ -29,6 +31,7 @@ then if [ "${AM_BWRAPPED-}" != "yes" ]; then bwrap_path="$(command -v bwrap)" if [ -n "$bwrap_path" ]; then + echo "Client test using bwrap" export AM_BWRAPPED=yes exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@" fi @@ -36,42 +39,45 @@ then # Run mosquitto broker mosquitto -c scripts/broker_test/mosquitto.conf & broker_pid=$! + echo "Broker PID is $broker_pid" def_args="${def_args} -h localhost" - mutual_auth_args="${mutual_auth_args} -c certs/client-cert.pem -K certs/client-key.pem" - ecc_mutual_auth_args="${mutual_auth_args} -c certs/client-ecc-cert.pem -K certs/ecc-client-key.pem" + tls_port_args="-p 18883" + port_args="-p 11883" + 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 # Run with and without TLS and QoS 0-2 -./examples/mqttclient/mqttclient $def_args -q 0 $1 +./examples/mqttclient/mqttclient $def_args $port_args -q 0 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=Off, QoS=0" && do_cleanup "-1" -./examples/mqttclient/mqttclient $def_args -q 1 $1 +./examples/mqttclient/mqttclient $def_args $port_args -q 1 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=Off, QoS=1" && do_cleanup "-1" -./examples/mqttclient/mqttclient $def_args -q 2 $1 +./examples/mqttclient/mqttclient $def_args $port_args -q 2 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=Off, QoS=2" && do_cleanup "-1" -./examples/mqttclient/mqttclient $def_args -t -q 0 $1 +./examples/mqttclient/mqttclient $def_args $tls_port_args -t -q 0 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=On, QoS=0" && do_cleanup "-1" -./examples/mqttclient/mqttclient $def_args -t -q 1 $1 +./examples/mqttclient/mqttclient $def_args $tls_port_args -t -q 1 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=On, QoS=1" && do_cleanup "-1" -./examples/mqttclient/mqttclient $def_args -t -q 2 $1 +./examples/mqttclient/mqttclient $def_args $tls_port_args -t -q 2 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=On, QoS=2" && do_cleanup "-1" -./examples/mqttclient/mqttclient $def_args $mutual_auth_args -t -q 0 $1 +./examples/mqttclient/mqttclient $def_args $mutual_auth_args $tls_port_args -t -q 0 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=On, QoS=0, RSA mutual auth" && do_cleanup "-1" -./examples/mqttclient/mqttclient $def_args $ecc_mutual_auth_args -t -q 0 $1 +./examples/mqttclient/mqttclient $def_args $ecc_mutual_auth_args $tls_port_args -t -q 0 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nMQTT Client failed! TLS=On, QoS=0, ECC mutual auth" && do_cleanup "-1" diff --git a/scripts/firmware.test b/scripts/firmware.test index a8c3cfb1e..6f2ce615f 100755 --- a/scripts/firmware.test +++ b/scripts/firmware.test @@ -6,9 +6,16 @@ no_pid=-1 broker_pid=$no_pid do_cleanup() { + if [ $ENABLE_MQTT_TLS -ne 1 ]; then + # Delete file + rm $fileout + fi + if [ $broker_pid != $no_pid ] then - kill -6 $broker_pid + kill -9 $broker_pid + echo "Killed broker PID $broker_pid" + broker_pid=$no_pid fi if [ $1 -ne 0 ] @@ -32,6 +39,7 @@ then if [ "${AM_BWRAPPED-}" != "yes" ]; then bwrap_path="$(command -v bwrap)" if [ -n "$bwrap_path" ]; then + echo "Firmware test using bwrap" export AM_BWRAPPED=yes exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@" fi @@ -39,9 +47,13 @@ then # Run mosquitto broker mosquitto -c scripts/broker_test/mosquitto.conf & broker_pid=$! - def_args="${def_args} -h localhost" + echo "Broker PID is $broker_pid" + def_args="${def_args} -h localhost -p 18883" fi +grep -F -e 'ENABLE_MQTT_TLS' ./wolfmqtt/options.h +ENABLE_MQTT_TLS=$? + # Start firmware push ./examples/firmware/fwpush $def_args -r -f $filein $1 server_result=$? @@ -52,13 +64,13 @@ server_result=$? client_result=$? [ $client_result -ne 0 ] && echo -e "\n\nMQTT Example fwclient failed!" && do_cleanup "-1" -# Compare files -md5sum -b $filein $fileout -compare_result=$? -[ $client_result -ne 0 ] && echo -e "\n\nMQTT Example firmware compare failed!" && do_cleanup "-1" - -# Delete file -rm $fileout +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 # End broker do_cleanup "0" diff --git a/scripts/multithread.test b/scripts/multithread.test index 0cf80148d..72f671df1 100755 --- a/scripts/multithread.test +++ b/scripts/multithread.test @@ -1,6 +1,6 @@ #!/bin/bash -# MQTT Client test +# MQTT Multithread Client test no_pid=-1 broker_pid=$no_pid @@ -8,7 +8,9 @@ broker_pid=$no_pid do_cleanup() { if [ $broker_pid != $no_pid ] then - kill -6 $broker_pid + kill -9 $broker_pid + echo "Killed broker PID $broker_pid" + broker_pid=$no_pid fi if [ $1 -ne 0 ] @@ -29,6 +31,7 @@ then 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 @@ -36,32 +39,35 @@ then # 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 # Run with and without TLS and QoS 0-2 -./examples/multithread/multithread $def_args -q 0 $1 +./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 -q 1 $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 -q 2 $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" -./examples/multithread/multithread $def_args -t -q 0 $1 +./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 -t -q 1 $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 -t -q 2 $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" diff --git a/scripts/nbclient.test b/scripts/nbclient.test index 940dab8a9..8d760d083 100755 --- a/scripts/nbclient.test +++ b/scripts/nbclient.test @@ -8,7 +8,9 @@ broker_pid=$no_pid do_cleanup() { if [ $broker_pid != $no_pid ] then - kill -6 $broker_pid + kill -9 $broker_pid + echo "Killed broker PID $broker_pid" + broker_pid=$no_pid fi if [ $1 -ne 0 ] @@ -31,6 +33,7 @@ then if [ "${AM_BWRAPPED-}" != "yes" ]; then bwrap_path="$(command -v bwrap)" if [ -n "$bwrap_path" ]; then + echo "nbclient test using bwrap" export AM_BWRAPPED=yes exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@" fi @@ -38,32 +41,35 @@ then # 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 # Run with and without TLS and QoS 0-2 -./examples/nbclient/nbclient $def_args -q 0 $1 +./examples/nbclient/nbclient $def_args $port_args -q 0 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nNon-blocking Client failed! TLS=Off, QoS=0" && do_cleanup "-1" -./examples/nbclient/nbclient $def_args -q 1 $1 +./examples/nbclient/nbclient $def_args $port_args -q 1 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nNon-blocking Client failed! TLS=Off, QoS=1" && do_cleanup "-1" -./examples/nbclient/nbclient $def_args -q 2 $1 +./examples/nbclient/nbclient $def_args $port_args -q 2 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nNon-blocking Client failed! TLS=Off, QoS=2" && do_cleanup "-1" -./examples/nbclient/nbclient $def_args -t -q 0 $1 +./examples/nbclient/nbclient $def_args $tls_port_args -t -q 0 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nNon-blocking Client failed! TLS=On, QoS=0" && do_cleanup "-1" -./examples/nbclient/nbclient $def_args -t -q 1 $1 +./examples/nbclient/nbclient $def_args $tls_port_args -t -q 1 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nNon-blocking Client failed! TLS=On, QoS=1" && do_cleanup "-1" -./examples/nbclient/nbclient $def_args -t -q 2 $1 +./examples/nbclient/nbclient $def_args $tls_port_args -t -q 2 $1 RESULT=$? [ $RESULT -ne 0 ] && echo -e "\n\nNon-blocking Client failed! TLS=On, QoS=2" && do_cleanup "-1" diff --git a/zephyr/samples/client.c b/zephyr/samples/client.c index c85f1fde3..07f71e76e 100644 --- a/zephyr/samples/client.c +++ b/zephyr/samples/client.c @@ -32,6 +32,13 @@ int main(void) mqttCtx.test_mode = 1; + /* Set port as configured in scripts/broker_test/mosquitto.conf */ +#if defined(WOLFMQTT_DEFAULT_TLS) && (WOLFMQTT_DEFAULT_TLS == 1) + mqttCtx.port = 18883; +#else + mqttCtx.port = 11883; +#endif + rc = mqttclient_test(&mqttCtx); mqtt_free_ctx(&mqttCtx);