diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index abebb147..5ae84579 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,20 +3,25 @@ on: [push, pull_request] jobs: linux: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + cc: [gcc, clang] + target: [test, test++, valgrind] + ssl: [MBEDTLS, OPENSSL] + name: linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} + env: + IPV6: 0 + CC: ${{ matrix.cc }} + SSL: ${{ matrix.ssl }} steps: - uses: actions/checkout@v3 - name: Install packages run: sudo apt-get update ; sudo apt-get install libmbedtls-dev valgrind - - name: gcc - run: make test test++ IPV6=0 CC=gcc - - name: clang - run: make test test++ IPV6=0 CC=clang - - name: openssl - run: make test SSL=OPENSSL IPV6=0 + - name: test + run: make ${{ matrix.target }} - name: unamalgamated run: make unamalgamated - - name: valgrind - run: make valgrind IPV6=0 examples: runs-on: ubuntu-latest steps: @@ -55,165 +60,66 @@ jobs: - uses: actions/checkout@v3 - name: arm run: make arm - esp32: + matrix_examples: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + example: + - name: esp32 + path: esp32 + - name: esp8266 + path: esp8266 + - name: stm32-freertos-tcp + path: stm32/stm32-freertos-tcp + - name: stm32-nucleo-f746z + path: stm32/stm32-nucleo-f746z + - name: stm32-nucleo-f429z + path: stm32/stm32-nucleo-f429z + - name: stm32-nucleo-h743z + path: stm32/stm32-nucleo-h743z + - name: nxp-mimxrt1020-azurertos + path: nxp/nxp-mimxrt1020-azurertos + - name: nxp-frdmk66f-freertos + path: nxp/nxp-frdmk66f-freertos + - name: nxp-lpcxpresso54s018m-freertos + path: nxp/nxp-lpcxpresso54s018m-freertos + - name: nxp-mimxrt1020-freertos + path: nxp/nxp-mimxrt1020-freertos + - name: nxp-evkbimxrt1050-lwip-freertos + path: nxp/nxp-evkbimxrt1050-lwip-freertos + - name: nxp-evkmimxrt1020-lwip-freertos + path: nxp/nxp-evkmimxrt1020-lwip-freertos + - name: nxp-evkmimxrt1024-lwip-freertos + path: nxp/nxp-evkmimxrt1024-lwip-freertos + - name: nxp-evkmimxrt1060-lwip-freertos + path: nxp/nxp-evkmimxrt1060-lwip-freertos + - name: nxp-evkmimxrt1064-lwip-freertos + path: nxp/nxp-evkmimxrt1064-lwip-freertos + - name: nxp-evkmimxrt1160-cm7-lwip-freertos + path: nxp/nxp-evkmimxrt1160-cm7-lwip-freertos + - name: nxp-evkmimxrt1170-cm7-lwip-freertos + path: nxp/nxp-evkmimxrt1170-cm7-lwip-freertos + - name: nxp-frdmk64f-lwip-freertos + path: nxp/nxp-frdmk64f-lwip-freertos + - name: nxp-frdmk66f-lwip-freertos + path: nxp/nxp-frdmk66f-lwip-freertos + - name: nxp-lpcxpresso54018-lwip-freertos + path: nxp/nxp-lpcxpresso54018-lwip-freertos + - name: nxp-lpcxpresso54608-lwip-freertos + path: nxp/nxp-lpcxpresso54608-lwip-freertos + - name: nxp-lpcxpresso54618-lwip-freertos + path: nxp/nxp-lpcxpresso54618-lwip-freertos + - name: nxp-lpcxpresso54628-lwip-freertos + path: nxp/nxp-lpcxpresso54628-lwip-freertos + - name: nxp-twrk65f180m-lwip-freertos + path: nxp/nxp-twrk65f180m-lwip-freertos + - name: nxp-twrkv58f220m-lwip-freertos + path: nxp/nxp-twrkv58f220m-lwip-freertos + - name: infineon-xmc4700_4800-lwip-rtx-rtos + path: infineon/infineon-xmc4700_4800-lwip-rtx-rtos + name: ${{ matrix.example.name }} steps: - - uses: actions/checkout@v3 - - name: esp32 - run: make -C examples/esp32 build - esp8266: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: esp8266 - run: make -C examples/esp8266 build - stm32-freertos-tcp: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: stm32-freertos-tcp - run: make -C examples/stm32/stm32-freertos-tcp build - stm32-nucleo-f746z: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: stm32-nucleo-f746z - run: make -C examples/stm32/stm32-nucleo-f746z build - stm32-nucleo-f429z: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: stm32-nucleo-f429z - run: make -C examples/stm32/stm32-nucleo-f429z build - stm32-nucleo-h743z: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: stm32-nucleo-h743z - run: make -C examples/stm32/stm32-nucleo-h743z build - nxp-mimxrt1020-azurertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-mimxrt1020-azurertos - run: make -C examples/nxp/nxp-mimxrt1020-azurertos build - nxp-frdmk66f-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-frdmk66f-freertos - run: make -C examples/nxp/nxp-frdmk66f-freertos build - nxp-lpcxpresso54s018m-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-lpcxpresso54s018m-freertos - run: make -C examples/nxp/nxp-lpcxpresso54s018m-freertos build - nxp-mimxrt1020-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-mimxrt1020-freertos - run: make -C examples/nxp/nxp-mimxrt1020-freertos build - nxp-evkbimxrt1050-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkbimxrt1050-lwip-freertos - run: make -C examples/nxp/nxp-evkbimxrt1050-lwip-freertos build - nxp-evkmimxrt1020-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkmimxrt1020-lwip-freertos - run: make -C examples/nxp/nxp-evkmimxrt1020-lwip-freertos build - nxp-evkmimxrt1024-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkmimxrt1024-lwip-freertos - run: make -C examples/nxp/nxp-evkmimxrt1024-lwip-freertos build - nxp-evkmimxrt1060-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkmimxrt1060-lwip-freertos - run: make -C examples/nxp/nxp-evkmimxrt1060-lwip-freertos build - nxp-evkmimxrt1064-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkmimxrt1064-lwip-freertos - run: make -C examples/nxp/nxp-evkmimxrt1064-lwip-freertos build - nxp-evkmimxrt1160-cm7-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkmimxrt1160-cm7-lwip-freertos - run: make -C examples/nxp/nxp-evkmimxrt1160-cm7-lwip-freertos build - nxp-evkmimxrt1170-cm4-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkmimxrt1170-cm4-lwip-freertos - run: make -C examples/nxp/nxp-evkmimxrt1170-cm4-lwip-freertos build - nxp-evkmimxrt1170-cm7-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-evkmimxrt1170-cm7-lwip-freertos - run: make -C examples/nxp/nxp-evkmimxrt1170-cm7-lwip-freertos build - nxp-frdmk64f-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-frdmk64f-lwip-freertos - run: make -C examples/nxp/nxp-frdmk64f-lwip-freertos build - nxp-frdmk66f-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-frdmk66f-lwip-freertos - run: make -C examples/nxp/nxp-frdmk66f-lwip-freertos build - nxp-lpcxpresso54018-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-lpcxpresso54018-lwip-freertos - run: make -C examples/nxp/nxp-lpcxpresso54018-lwip-freertos build - nxp-lpcxpresso54608-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-lpcxpresso54608-lwip-freertos - run: make -C examples/nxp/nxp-lpcxpresso54608-lwip-freertos build - nxp-lpcxpresso54618-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-lpcxpresso54618-lwip-freertos - run: make -C examples/nxp/nxp-lpcxpresso54618-lwip-freertos build - nxp-lpcxpresso54628-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-lpcxpresso54628-lwip-freertos - run: make -C examples/nxp/nxp-lpcxpresso54628-lwip-freertos build - nxp-twrk65f180m-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-twrk65f180m-lwip-freertos - run: make -C examples/nxp/nxp-twrk65f180m-lwip-freertos build - nxp-twrkv58f220m-lwip-freertos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: nxp-twrkv58f220m-lwip-freertos - run: make -C examples/nxp/nxp-twrkv58f220m-lwip-freertos build - infineon-xmc4700_4800-lwip-rtx-rtos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: infineon-xmc4700_4800-lwip-rtx-rtos - run: make -C examples/infineon/infineon-xmc4700_4800-lwip-rtx-rtos build \ No newline at end of file + - uses: actions/checkout@v3 + - name: ${{ matrix.example.name }} + run: make -C examples/${{ matrix.example.path }} build diff --git a/Makefile b/Makefile index bc5782c4..0f4c34c3 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,26 @@ SRCS = mongoose.c test/unit_test.c test/packed_fs.c HDRS = $(wildcard src/*.h) DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -WARN ?= -W -Wall -Werror -Wshadow -Wdouble-promotion -Wmissing-prototypes -Wstrict-prototypes -fno-common -Wconversion -Wundef +C_WARN ?= -Wmissing-prototypes -Wstrict-prototypes +WARN ?= -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef $(C_WARN) OPTS ?= -O3 -g3 +VALGRIND_OPTS ?= -O0 -g3 INCS ?= -Isrc -I. SSL ?= MBEDTLS CWD ?= $(realpath $(CURDIR)) DOCKER ?= docker run --rm -e Tmp=. -e WINEDEBUG=-all -v $(CWD):$(CWD) -w $(CWD) VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS) IPV6 ?= 1 -ASAN ?= -fsanitize=address,undefined -fno-sanitize-recover +ASAN ?= -fsanitize=address,undefined -fno-sanitize-recover=all ASAN_OPTIONS ?= detect_leaks=1 EXAMPLES := $(wildcard examples/*) PREFIX ?= /usr/local VERSION ?= $(shell cut -d'"' -f2 src/version.h) -CFLAGS ?= $(OPTS) $(WARN) $(INCS) $(DEFS) $(ASAN) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS) $(EXTRA) -.PHONY: examples test +COMMON_CFLAGS ?= $(WARN) $(INCS) $(DEFS) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS) $(EXTRA) +CFLAGS ?= $(OPTS) $(ASAN) $(COMMON_CFLAGS) +VALGRIND_CFLAGS ?= $(VALGRIND_OPTS) $(COMMON_CFLAGS) +VALGRIND_RUN ?= valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --show-leak-kinds=all --leak-resolution=high --track-origins=yes --error-exitcode=1 --exit-on-first-error=yes +.PHONY: examples test valgrind ifeq "$(SSL)" "MBEDTLS" MBEDTLS ?= /usr/local @@ -51,6 +56,7 @@ mg_prefix: mongoose.c mongoose.h # C++ build test++: CC = g++ +test++: C_WARN = test++: WARN += -Wno-shadow -Wno-missing-field-initializers -Wno-deprecated test++: test @@ -67,9 +73,11 @@ fuzzer: mongoose.c mongoose.h Makefile test/fuzz.c fuzz: fuzzer $(RUN) ./fuzzer -# make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1 -test: mongoose.h Makefile $(SRCS) +unit_test: Makefile mongoose.h $(SRCS) $(CC) $(SRCS) $(CFLAGS) -coverage $(LDFLAGS) -g -o unit_test + +# make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1 +test: unit_test ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test coverage: test @@ -79,9 +87,11 @@ coverage: test upload-coverage: coverage curl -s https://codecov.io/bash | /bin/bash -valgrind: ASAN = -valgrind: RUN = valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --show-leak-kinds=all --leak-resolution=high --track-origins=yes --error-exitcode=1 --exit-on-first-error=yes -valgrind: test +valgrind_unit_test: Makefile mongoose.h $(SRCS) + $(CC) $(SRCS) $(VALGRIND_CFLAGS) -coverage $(LDFLAGS) -g -o valgrind_unit_test + +valgrind: valgrind_unit_test + $(VALGRIND_RUN) ./valgrind_unit_test infer: infer run -- cc test/unit_test.c -c -W -Wall -Werror -Isrc -I. -O2 -DMG_ENABLE_MBEDTLS=1 -DMG_ENABLE_LINES -I/usr/local/Cellar/mbedtls/2.23.0/include -DMG_ENABLE_IPV6=1 -g -o /dev/null @@ -139,5 +149,5 @@ mongoose.h: $(HDRS) Makefile (cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/config.h src/str.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@ clean: - rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* test/packed_fs.c pack + rm -rf $(PROG) *.o *.dSYM unit_test* valgrind_unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* test/packed_fs.c pack @for X in $(EXAMPLES); do test -f $$X/Makefile && $(MAKE) -C $$X clean; done