Skip to content

Commit

Permalink
Merge pull request #376 from embhorn/sn-workflow
Browse files Browse the repository at this point in the history
Add MQTT-SN CI tests
  • Loading branch information
dgarske authored Nov 29, 2023
2 parents 3b93bdb + b4badfd commit 85ddcd1
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 7 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/mqtt-sn-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: MQTT-SN Build Test

on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]

jobs:
build:

runs-on: ubuntu-latest
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
mosquitto -v &> ~/broker.log &
sleep 1
- uses: actions/checkout@master
with:
repository: eclipse/paho.mqtt-sn.embedded-c
path: gateway
- name: Build gateway
working-directory: ./gateway/MQTTSNGateway
run: ./build.sh udp -DDEBUG -DDEBUG_NW
- name: Write config to change broker
working-directory: ./gateway/MQTTSNGateway/bin
run: |
printf "GatewayID=1\nGatewayName=PahoGateway-01\nMaxNumberOfClients=30\nKeepAlive=60\nBrokerName=localhost\nBrokerPortNo=1883\nAggregatingGateway=NO\nQoS-1=NO\nForwarder=NO\nPredefinedTopic=NO\nClientAuthentication=NO\nGatewayPortNo=10000\nMulticastPortNo=1883\nMulticastIP=225.1.1.1\nMulticastTTL=1\n" > gateway.conf
- name: Display gateway config
working-directory: ./gateway/MQTTSNGateway/bin
run: more gateway.conf
- name: Run gateway
working-directory: ./gateway/MQTTSNGateway/bin
run: sudo ./MQTT-SNGateway &> ~/gateway.log &
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
run: ./autogen.sh
- name: wolfssl configure
working-directory: ./wolfssl
run: ./configure --enable-enckeys
- name: wolfssl make
working-directory: ./wolfssl
run: make
- name: wolfssl make install
working-directory: ./wolfssl
run: sudo make install

- uses: actions/checkout@master
- name: wolfmqtt autogen
run: ./autogen.sh

- name: wolfmqtt configure with SN Enabled
run: |
export WOLFMQTT_NO_EXTERNAL_BROKER_TESTS=1
./configure --enable-sn
- name: wolfmqtt make
run: make

- name: test SN Client
run: ./examples/sn-client/sn-client -T

# Cleanup
- name: Stop gateway
if: failure() || cancelled()
run: |
sudo kill -2 $(pgrep -f "MQTT-SNGateway")
sleep 3
sudo kill -2 $(pgrep -f "mosquitto")
sleep 1
# capture logs on failure
- name: Show logs on failure
if: failure() || cancelled()
run: |
sudo cat ~/gateway.log
sudo cat ~/broker.log
15 changes: 8 additions & 7 deletions examples/sn-client/sn-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,20 +509,20 @@ int sn_test(MQTTCtx *mqttCtx)
PRINTF("MQTT Waiting for message...");

do {
/* Try and read packet */
rc = SN_Client_WaitMessage(&mqttCtx->client,
mqttCtx->cmd_timeout_ms);

/* check for test mode */
if (mStopRead) {
rc = MQTT_CODE_SUCCESS;
PRINTF("MQTT Exiting...");
break;
}

/* Try and read packet */
rc = SN_Client_WaitMessage(&mqttCtx->client,
mqttCtx->cmd_timeout_ms);

/* check return code */
#ifdef WOLFMQTT_ENABLE_STDIN_CAP
else if (rc == MQTT_CODE_STDIN_WAKE) {
if (rc == MQTT_CODE_STDIN_WAKE) {
XMEMSET(mqttCtx->rx_buf, 0, MAX_BUFFER_SIZE);
if (XFGETS((char*)mqttCtx->rx_buf, MAX_BUFFER_SIZE - 1,
stdin) != NULL)
Expand Down Expand Up @@ -556,8 +556,9 @@ int sn_test(MQTTCtx *mqttCtx)
}
}
}
else
#endif
else if (rc == MQTT_CODE_ERROR_TIMEOUT) {
if (rc == MQTT_CODE_ERROR_TIMEOUT) {
/* Keep Alive */
PRINTF("Keep-alive timeout, sending ping");

Expand Down Expand Up @@ -743,6 +744,6 @@ int main(int argc, char** argv)
#endif


return (rc == 0) ? 0 : EXIT_FAILURE;
return (rc == MQTT_CODE_SUCCESS) ? 0 : EXIT_FAILURE;
}

0 comments on commit 85ddcd1

Please sign in to comment.