Skip to content

Commit

Permalink
Merge pull request wolfSSL#387 from philljj/add_stress_test
Browse files Browse the repository at this point in the history
Add stress test.
  • Loading branch information
embhorn authored Jan 3, 2024
2 parents 91b01f4 + 9685820 commit d2bd509
Show file tree
Hide file tree
Showing 16 changed files with 421 additions and 202 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ubuntu-check-curl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ jobs:
- name: wolfmqtt make check
run: make check

- name: wolfmqtt configure with libCurl and Stress
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
run: ./configure --enable-curl --enable-stress
- name: wolfmqtt make
run: make
- name: wolfmqtt make check
run: make check

# capture logs on failure
- name: Show logs on failure
if: failure() || cancelled()
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/ubuntu-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ jobs:
- name: make check
run: make check

- name: wolfmqtt configure with Stress
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
run: ./configure --enable-stress
- name: wolfmqtt make
run: make
- name: wolfmqtt make check
run: make check

# capture logs on failure
- name: Show logs on failure
if: failure() || cancelled()
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ if (WOLFMQTT_CURL)
list(APPEND WOLFMQTT_DEFINITIONS "-DENABLE_MQTT_CURL")
endif()

# Note: not adding stress option to cmake build as of yet. stress is for
# testing only and requires the scripts/ dir to be useful.


# generate options file
message("Generating user options header...")
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ The Sensor Network client implements the MQTT-SN protocol for low-bandwidth netw
More about MQTT-SN examples in [examples/sn-client/README.md](examples/sn-client/README.md)

### Multithread Example
This example exercises the multithreading capabilities of the client library. The client implements two tasks: one that publishes to the broker; and another that waits for messages from the broker. The publish thread is created `NUM_PUB_TASKS` times (10 by default) and sends unique messages to the broker. This feature is enabled using the `--enable-mt` configuration option. The example is located in `/examples/multithread/`.
This example exercises the multithreading capabilities of the client library. The client implements two tasks: one that publishes to the broker; and another that waits for messages from the broker. The publish thread is created `NUM_PUB_TASKS` times (5 by default) and sends unique messages to the broker. This feature is enabled using the `--enable-mt` configuration option. The example is located in `/examples/multithread/`.

The multi-threading feature can also be used with the non-blocking socket (--enable-nonblock).

Expand Down Expand Up @@ -380,3 +380,18 @@ The `--enable-curl` option works with these combinations:
However `--enable-curl` is incompatible and not supported with these options:
- `--enable-all`
- `--enable-sn`

## Stress Build Option

To simplify testing a stress build option has been added, `--enable-stress=[args]`.
The Stress option enables multithreading and nonblocking, and adds defines for
`TEST_NONBLOCK`, `NUM_PUB_TASKS`, and `NUM_PUB_PER_TASK`.

Examples of useage:
- `--enable-stress`: stress with default options.
- `--enable-stress=t7,p8`: stress with 7 threads, and 8 publishes per thread.
- `--enable-stress=t7,p8 --enable-curl`: same as above, but with curl backend.

Note: When stress is enabled, the Multithread Example becomes localhost only
and will not connect to remote servers. Additionally the test `scripts/stress.test`
is added to `make check`, and all other tests are disabled.
54 changes: 53 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ if test "x$ENABLED_CURL" = "xyes"; then
AC_CHECK_LIB([curl],[curl_easy_init],,[AC_MSG_ERROR([libcurl is required and wasn't found on the system. It can be obtained from https://curl.se/download.html.])])
fi


# MQTT v5.0
AC_ARG_ENABLE([v5],
[AS_HELP_STRING([--enable-v5],[Enable MQTT v5.0 support (default: disabled)])],
Expand Down Expand Up @@ -329,10 +328,62 @@ then
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_MULTITHREAD"
fi

# Stress test convenience build option.
AC_ARG_ENABLE([stress],
[AS_HELP_STRING([--enable-stress],[Enable stress test (default: disabled)])],
[ ENABLED_STRESS=$enableval ],
[ ENABLED_STRESS=no ]
)

# Set defaults of t5,p4 if unset (5 tasks, 4 pubs per task).
NUM_TASKS=5
NUM_PUBS=4

for v in `echo $ENABLED_STRESS | tr "," " "`; do
case $v in
yes)
ENABLED_STRESS="yes"
;;
no)
ENABLED_STRESS="no"
;;
t*)
NUM_TASKS=`echo $v | cut -c 2-`
;;
p*)
NUM_PUBS=`echo $v | cut -c 2-`
;;
*)
AC_MSG_ERROR([enable-stress: arg $v not supported])
;;
esac
done

if test "x$ENABLED_STRESS" != "xno"; then
if test "x$ENABLED_ALL" = "xyes"; then
AC_MSG_ERROR([--enable-all and --enable-stress are incompatible])
fi

if test "x$ENABLED_SN" = "xyes"; then
AC_MSG_ERROR([--enable-sn and --enable-stress are incompatible])
fi

ENABLED_TIMEOUT=yes
ENABLED_NONBLOCK=yes
ENABLED_MULTITHREAD=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_STRESS"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_NONBLOCK"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_TEST_NONBLOCK"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_TEST_NONBLOCK_TIMES=2"
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_MULTITHREAD"
AM_CFLAGS="$AM_CFLAGS -DNUM_PUB_TASKS=$NUM_TASKS"
AM_CFLAGS="$AM_CFLAGS -DNUM_PUB_PER_TASK=$NUM_PUBS"
fi


AM_CONDITIONAL([HAVE_LIBWOLFSSL], [test "x$ENABLED_TLS" = "xyes"])
AM_CONDITIONAL([HAVE_LIBCURL], [test "x$ENABLED_CURL" = "xyes"])
AM_CONDITIONAL([BUILD_STRESS], [test "x$ENABLED_STRESS" != "xno"])
AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$ENABLED_EXAMPLES" = "xyes"])
AM_CONDITIONAL([BUILD_STDINCAP], [test "x$ENABLED_STDINCAP" = "xyes"])
AM_CONDITIONAL([BUILD_SN], [test "x$ENABLED_SN" = "xyes"])
Expand Down Expand Up @@ -465,3 +516,4 @@ echo " * STDIN Capture: $ENABLED_STDINCAP"
echo " * TLS: $ENABLED_TLS"
echo " * CURL: $ENABLED_CURL"
echo " * Multi-thread: $ENABLED_MULTITHREAD"
echo " * Stress: $ENABLED_STRESS"
6 changes: 6 additions & 0 deletions examples/mqttexample.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ int mqtt_check_timeout(int rc, word32* start_sec, word32 timeout_sec)
return rc;
}

/* Default to 2s timeout. This function sometimes incorrectly
* triggers if 1s is used because of rounding. */
if (timeout_sec == 0) {
timeout_sec = DEFAULT_CHK_TIMEOUT_S;
}

elapsed_sec = mqtt_get_timer_seconds();
if (*start_sec < elapsed_sec) {
elapsed_sec -= *start_sec;
Expand Down
1 change: 1 addition & 0 deletions examples/mqttexample.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

#define DEFAULT_CMD_TIMEOUT_MS 30000
#define DEFAULT_CON_TIMEOUT_MS 5000
#define DEFAULT_CHK_TIMEOUT_S 2
#define DEFAULT_MQTT_QOS MQTT_QOS_0
#define DEFAULT_KEEP_ALIVE_SEC 60
#define DEFAULT_CLIENT_ID "WolfMQTTClient"
Expand Down
Loading

0 comments on commit d2bd509

Please sign in to comment.