Skip to content

Commit

Permalink
Merge pull request wolfSSL#369 from dgarske/thread_tests
Browse files Browse the repository at this point in the history
Improvements to multithread locking and tests.
  • Loading branch information
embhorn authored Nov 22, 2023
2 parents f2a0ac3 + f5b05e4 commit 8ba1cea
Show file tree
Hide file tree
Showing 22 changed files with 882 additions and 571 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/fsanitize-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,29 @@ jobs:
- name: make check
run: make check

- name: configure without TLS
run: ./configure CC="gcc -fsanitize=address" --enable-all --disable-tls
- name: make
run: make
- name: make check
run: make check

- name: configure with SN Enabled
run: ./configure --enable-sn CC="gcc -fsanitize=address"
run: ./configure CC="gcc -fsanitize=address" --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" CC="gcc -fsanitize=address"
run: ./configure CC="gcc -fsanitize=address" --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" CC="gcc -fsanitize=address"
run: ./configure CC="gcc -fsanitize=address" --enable-mt --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK"
- name: make
run: make
- name: make check
Expand All @@ -89,3 +96,4 @@ jobs:
if: failure() || cancelled()
run: |
cat test-suite.log
cat scripts/*.log
18 changes: 15 additions & 3 deletions .github/workflows/macos-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ on:
pull_request:
branches: [ '*' ]

env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1

jobs:
build:

runs-on: macos-latest
timeout-minutes: 10
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
steps:
- uses: actions/checkout@master
with:
repository: wolfssl/wolfssl
path: wolfssl
- name: brew
run: brew install automake libtool md5sha1sum
run: |
brew install automake libtool md5sha1sum mosquitto
echo "/usr/local/sbin/" >> $GITHUB_PATH
echo "/usr/local/opt/mosquitto/sbin/" >> $GITHUB_PATH
- name: wolfssl autogen
working-directory: ./wolfssl
Expand All @@ -45,6 +49,13 @@ jobs:
- name: make check
run: make check

- name: configure without TLS
run: ./configure --enable-all --disable-tls
- name: make
run: make
- name: make check
run: make check

- name: configure with SN Enabled
run: ./configure --enable-sn
- name: make
Expand All @@ -71,3 +82,4 @@ jobs:
if: failure() || cancelled()
run: |
cat test-suite.log
cat scripts/*.log
10 changes: 10 additions & 0 deletions .github/workflows/ubuntu-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ jobs:
- name: wolfmqtt make check
run: make check

- name: wolfmqtt configure without TLS
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
run: ./configure --enable-all --disable-tls
- name: wolfmqtt make
run: make
- name: wolfmqtt make check
run: make check

- name: wolfmqtt configure with SN Enabled
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
Expand Down Expand Up @@ -104,3 +113,4 @@ jobs:
if: failure() || cancelled()
run: |
cat test-suite.log
cat scripts/*.log
151 changes: 73 additions & 78 deletions examples/firmware/fwclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
/* The signature wrapper for this example was added in wolfSSL after 3.7.1 */
#if defined(LIBWOLFSSL_VERSION_HEX) && LIBWOLFSSL_VERSION_HEX > 0x03007001 \
&& defined(HAVE_ECC) && !defined(NO_SIG_WRAPPER)
#undef ENABLE_FIRMWARE_EXAMPLE
#define ENABLE_FIRMWARE_EXAMPLE
#undef ENABLE_FIRMWARE_SIG
#define ENABLE_FIRMWARE_SIG
#endif
#endif


#if defined(ENABLE_FIRMWARE_EXAMPLE)

#if defined(ENABLE_FIRMWARE_SIG)
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/ecc.h>
#include <wolfssl/wolfcrypt/signature.h>
#include <wolfssl/wolfcrypt/hash.h>
#endif

#include "fwclient.h"
#include "firmware.h"
Expand Down Expand Up @@ -109,10 +109,12 @@ static int fwfile_save(const char* filePath, byte* fileBuf, int fileLen)

static int fw_message_process(MQTTCtx *mqttCtx, byte* buffer, word32 len)
{
int rc;
int rc = 0;
FirmwareHeader* header = (FirmwareHeader*)buffer;
byte *sigBuf, *pubKeyBuf, *fwBuf;
#ifdef ENABLE_FIRMWARE_SIG
ecc_key eccKey;
#endif
word32 check_len = sizeof(FirmwareHeader) + header->sigLen +
header->pubKeyLen + header->fwLen;

Expand All @@ -129,6 +131,7 @@ static int fw_message_process(MQTTCtx *mqttCtx, byte* buffer, word32 len)
fwBuf = (buffer + sizeof(FirmwareHeader) + header->sigLen +
header->pubKeyLen);

#ifdef ENABLE_FIRMWARE_SIG
/* Import the public key */
wc_ecc_init(&eccKey);
rc = wc_ecc_import_x963(pubKeyBuf, header->pubKeyLen, &eccKey);
Expand All @@ -141,17 +144,22 @@ static int fw_message_process(MQTTCtx *mqttCtx, byte* buffer, word32 len)
&eccKey, sizeof(eccKey));
PRINTF("Firmware Signature Verification: %s (%d)",
(rc == 0) ? "Pass" : "Fail", rc);

#else
(void)pubKeyBuf;
(void)sigBuf;
#endif
if (rc == 0) {
/* TODO: Process firmware image */
/* For example, save to disk using topic name */
fwfile_save(mqttCtx->pub_file, fwBuf, header->fwLen);
}
#ifdef ENABLE_FIRMWARE_SIG
}
else {
PRINTF("ECC public key import failed! %d", rc);
}
wc_ecc_free(&eccKey);
#endif

return rc;
}
Expand Down Expand Up @@ -484,89 +492,76 @@ int fwclient_test(MQTTCtx *mqttCtx)

return rc;
}
#endif /* ENABLE_FIRMWARE_EXAMPLE */


/* so overall tests can pull in test function */
#ifdef USE_WINDOWS_API
#include <windows.h> /* for ctrl handler */
#ifdef USE_WINDOWS_API
#include <windows.h> /* for ctrl handler */

static BOOL CtrlHandler(DWORD fdwCtrlType)
{
if (fdwCtrlType == CTRL_C_EVENT) {
#if defined(ENABLE_FIRMWARE_EXAMPLE)
mStopRead = 1;
#endif
PRINTF("Received Ctrl+c");
return TRUE;
}
return FALSE;
static BOOL CtrlHandler(DWORD fdwCtrlType)
{
if (fdwCtrlType == CTRL_C_EVENT) {
#if defined(ENABLE_FIRMWARE_SIG)
mStopRead = 1;
#endif
PRINTF("Received Ctrl+c");
return TRUE;
}
#elif HAVE_SIGNAL
#include <signal.h>
static void sig_handler(int signo)
{
if (signo == SIGINT) {
#if defined(ENABLE_FIRMWARE_EXAMPLE)
mStopRead = 1;
#endif
PRINTF("Received SIGINT");
}
return FALSE;
}
#elif HAVE_SIGNAL
#include <signal.h>
static void sig_handler(int signo)
{
if (signo == SIGINT) {
#if defined(ENABLE_FIRMWARE_SIG)
mStopRead = 1;
#endif
PRINTF("Received SIGINT");
}
#endif
}
#endif

#if defined(NO_MAIN_DRIVER)
int fwclient_main(int argc, char** argv)
int fwclient_main(int argc, char** argv)
#else
int main(int argc, char** argv)
int main(int argc, char** argv)
#endif
{
int rc;
#ifdef ENABLE_FIRMWARE_EXAMPLE
MQTTCtx mqttCtx;

/* init defaults */
mqtt_init_ctx(&mqttCtx);
mqttCtx.app_name = "fwclient";
mqttCtx.client_id = mqtt_append_random(FIRMWARE_CLIIENT_ID,
(word32)XSTRLEN(FIRMWARE_CLIIENT_ID));
mqttCtx.dynamicClientId = 1;
mqttCtx.topic_name = FIRMWARE_TOPIC_NAME;
mqttCtx.qos = FIRMWARE_MQTT_QOS;
mqttCtx.pub_file = FIRMWARE_DEF_SAVE_AS;

/* parse arguments */
rc = mqtt_parse_args(&mqttCtx, argc, argv);
if (rc != 0) {
return rc;
}
#endif

#ifdef USE_WINDOWS_API
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE) == FALSE) {
PRINTF("Error setting Ctrl Handler! Error %d", (int)GetLastError());
}
#elif HAVE_SIGNAL
if (signal(SIGINT, sig_handler) == SIG_ERR) {
PRINTF("Can't catch SIGINT");
}
#endif

#ifdef ENABLE_FIRMWARE_EXAMPLE
do {
rc = fwclient_test(&mqttCtx);
} while (!mStopRead && rc == MQTT_CODE_CONTINUE);
{
int rc;
MQTTCtx mqttCtx;

/* init defaults */
mqtt_init_ctx(&mqttCtx);
mqttCtx.app_name = "fwclient";
mqttCtx.client_id = mqtt_append_random(FIRMWARE_CLIIENT_ID,
(word32)XSTRLEN(FIRMWARE_CLIIENT_ID));
mqttCtx.dynamicClientId = 1;
mqttCtx.topic_name = FIRMWARE_TOPIC_NAME;
mqttCtx.qos = FIRMWARE_MQTT_QOS;
mqttCtx.pub_file = FIRMWARE_DEF_SAVE_AS;

/* parse arguments */
rc = mqtt_parse_args(&mqttCtx, argc, argv);
if (rc != 0) {
return rc;
}

mqtt_free_ctx(&mqttCtx);
#else
(void)argc;
(void)argv;
#ifdef USE_WINDOWS_API
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE) == FALSE) {
PRINTF("Error setting Ctrl Handler! Error %d", (int)GetLastError());
}
#elif HAVE_SIGNAL
if (signal(SIGINT, sig_handler) == SIG_ERR) {
PRINTF("Can't catch SIGINT");
}
#endif

/* This example requires wolfSSL after 3.7.1 for signature wrapper */
PRINTF("Example not compiled in!");
rc = 0; /* return success, so make check passes with TLS disabled */
#endif
do {
rc = fwclient_test(&mqttCtx);
} while (!mStopRead && rc == MQTT_CODE_CONTINUE);

return (rc == 0) ? 0 : EXIT_FAILURE;
}
mqtt_free_ctx(&mqttCtx);

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

0 comments on commit 8ba1cea

Please sign in to comment.