Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MQTT-SN CI tests #376

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

Loading