From d40dbb458420939bc83e3d9a2cb81a07c4d2d6b8 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Mon, 16 Dec 2019 19:20:07 +0100 Subject: [PATCH] device tests: some of them can be run on host (#6912) * device tests: mock scripts + rename some tests to enable mock-testing them * move symbol --- tests/device/Makefile | 32 ++++++++++++++++--- .../test_FS.ino => test_sw_FS/test_sw_FS.ino} | 0 .../test_sw_Print_printf.ino} | 0 .../test_sw_WiFiServer.ino} | 0 .../test_sw_WiFiServer.py} | 0 .../server.crt | 0 .../server.csr | 0 .../server.key | 0 .../test_sw_http_client.ino} | 2 ++ .../test_sw_http_client.py} | 0 .../test_sw_newlib.ino} | 0 .../test_sw_schedule.ino} | 0 .../test_sw_tests.ino} | 0 tests/host/common/ArduinoMain.cpp | 2 +- tests/host/common/MockUART.cpp | 9 ++++++ tests/host/common/mock.h | 2 ++ 16 files changed, 41 insertions(+), 6 deletions(-) rename tests/device/{test_FS/test_FS.ino => test_sw_FS/test_sw_FS.ino} (100%) rename tests/device/{test_Print_printf/test_Print_printf.ino => test_sw_Print_printf/test_sw_Print_printf.ino} (100%) rename tests/device/{test_WiFiServer/test_WiFiServer.ino => test_sw_WiFiServer/test_sw_WiFiServer.ino} (100%) rename tests/device/{test_WiFiServer/test_WiFiServer.py => test_sw_WiFiServer/test_sw_WiFiServer.py} (100%) rename tests/device/{test_http_client => test_sw_http_client}/server.crt (100%) rename tests/device/{test_http_client => test_sw_http_client}/server.csr (100%) rename tests/device/{test_http_client => test_sw_http_client}/server.key (100%) rename tests/device/{test_http_client/test_http_client.ino => test_sw_http_client/test_sw_http_client.ino} (99%) rename tests/device/{test_http_client/test_http_client.py => test_sw_http_client/test_sw_http_client.py} (100%) rename tests/device/{test_newlib/test_newlib.ino => test_sw_newlib/test_sw_newlib.ino} (100%) rename tests/device/{test_schedule/test_schedule.ino => test_sw_schedule/test_sw_schedule.ino} (100%) rename tests/device/{test_tests/test_tests.ino => test_sw_tests/test_sw_tests.ino} (100%) diff --git a/tests/device/Makefile b/tests/device/Makefile index ab2300284..c60135c81 100644 --- a/tests/device/Makefile +++ b/tests/device/Makefile @@ -1,6 +1,5 @@ SHELL := /bin/bash V ?= 0 -TEST_LIST ?= $(wildcard test_*/*.ino) ESP8266_CORE_PATH ?= $(realpath ../..) BUILD_DIR ?= $(PWD)/.build HARDWARE_DIR ?= $(PWD)/.hardware @@ -18,6 +17,12 @@ TEST_CONFIG := test_env.cfg TEST_REPORT_XML := test_report.xml TEST_REPORT_HTML := test_report.html +ifeq ("$(MOCK)", "1") +# To enable a test for mock testing, just rename dir+files to '*_sw_*' +TEST_LIST ?= $(wildcard test_sw_*/*.ino) +else +TEST_LIST ?= $(wildcard test_*/*.ino) +endif ifneq ("$(V)","1") SILENT = @ @@ -29,10 +34,14 @@ else endif help: - @echo 'make list - show list of tests' - @echo 'make [V=1] sometest/sometest.ino - run one test' - @echo 'make [V=1] all - run all tests' - @echo 'variables needed: $$ARDUINO_IDE_PATH' + @echo + @echo 'make list - show list of tests' + @echo 'make sometest/sometest.ino - run one test' + @echo 'make all - run all tests' + @echo 'make MOCK=1 all - run all emulation-on-host compatible tests' + @echo 'variables needed: $$ARDUINO_IDE_PATH $$ESP8266_CORE_PATH' + @echo 'make options: V=1 NO_BUILD=1 NO_UPLOAD=1 NO_RUN=1 MOCK=1' + @echo list: showtestlist @@ -53,6 +62,18 @@ $(TEST_LIST): @echo "--------------------------------" @echo "Running test '$@' of $(words $(TEST_LIST)) tests" $(SILENT)mkdir -p $(LOCAL_BUILD_DIR) +ifeq ("$(MOCK)", "1") + @echo Compiling $(notdir $@) + (cd ../host; make ULIBDIRS=../device/libraries/BSTest ../device/$(@:%.ino=%)) + $(SILENT)source $(BS_DIR)/virtualenv/bin/activate && \ + $(PYTHON) $(BS_DIR)/runner.py \ + $(RUNNER_DEBUG_FLAG) \ + -e "$(ESP8266_CORE_PATH)/tests/host/bin/$(@:%.ino=%)" \ + -n $(basename $(notdir $@)) \ + -o $(LOCAL_BUILD_DIR)/test_result.xml \ + --env-file $(TEST_CONFIG) \ + `test -f $(addsuffix .py, $(basename $@)) && echo "-m $(addsuffix .py, $(basename $@))" || echo ""` +else ifneq ("$(NO_BUILD)","1") @test -n "$(ARDUINO_IDE_PATH)" || (echo "Please export ARDUINO_IDE_PATH" && exit 1) @echo Compiling $(notdir $@) @@ -108,6 +129,7 @@ ifneq ("$(NO_RUN)","1") --env-file $(TEST_CONFIG) \ `test -f $(addsuffix .py, $(basename $@)) && echo "-m $(addsuffix .py, $(basename $@))" || echo ""` endif +endif $(TEST_REPORT_XML): $(HARDWARE_DIR) virtualenv $(SILENT)$(BS_DIR)/xunitmerge $(shell find $(BUILD_DIR) -name 'test_result.xml' | xargs echo) $(TEST_REPORT_XML) diff --git a/tests/device/test_FS/test_FS.ino b/tests/device/test_sw_FS/test_sw_FS.ino similarity index 100% rename from tests/device/test_FS/test_FS.ino rename to tests/device/test_sw_FS/test_sw_FS.ino diff --git a/tests/device/test_Print_printf/test_Print_printf.ino b/tests/device/test_sw_Print_printf/test_sw_Print_printf.ino similarity index 100% rename from tests/device/test_Print_printf/test_Print_printf.ino rename to tests/device/test_sw_Print_printf/test_sw_Print_printf.ino diff --git a/tests/device/test_WiFiServer/test_WiFiServer.ino b/tests/device/test_sw_WiFiServer/test_sw_WiFiServer.ino similarity index 100% rename from tests/device/test_WiFiServer/test_WiFiServer.ino rename to tests/device/test_sw_WiFiServer/test_sw_WiFiServer.ino diff --git a/tests/device/test_WiFiServer/test_WiFiServer.py b/tests/device/test_sw_WiFiServer/test_sw_WiFiServer.py similarity index 100% rename from tests/device/test_WiFiServer/test_WiFiServer.py rename to tests/device/test_sw_WiFiServer/test_sw_WiFiServer.py diff --git a/tests/device/test_http_client/server.crt b/tests/device/test_sw_http_client/server.crt similarity index 100% rename from tests/device/test_http_client/server.crt rename to tests/device/test_sw_http_client/server.crt diff --git a/tests/device/test_http_client/server.csr b/tests/device/test_sw_http_client/server.csr similarity index 100% rename from tests/device/test_http_client/server.csr rename to tests/device/test_sw_http_client/server.csr diff --git a/tests/device/test_http_client/server.key b/tests/device/test_sw_http_client/server.key similarity index 100% rename from tests/device/test_http_client/server.key rename to tests/device/test_sw_http_client/server.key diff --git a/tests/device/test_http_client/test_http_client.ino b/tests/device/test_sw_http_client/test_sw_http_client.ino similarity index 99% rename from tests/device/test_http_client/test_http_client.ino rename to tests/device/test_sw_http_client/test_sw_http_client.ino index 4757fdb4f..6de2314fa 100644 --- a/tests/device/test_http_client/test_http_client.ino +++ b/tests/device/test_sw_http_client/test_sw_http_client.ino @@ -210,6 +210,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") // // Same tests with axTLS // +#if !CORE_MOCK { // small request #pragma GCC diagnostic push @@ -242,6 +243,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") } } } +#endif } void loop() diff --git a/tests/device/test_http_client/test_http_client.py b/tests/device/test_sw_http_client/test_sw_http_client.py similarity index 100% rename from tests/device/test_http_client/test_http_client.py rename to tests/device/test_sw_http_client/test_sw_http_client.py diff --git a/tests/device/test_newlib/test_newlib.ino b/tests/device/test_sw_newlib/test_sw_newlib.ino similarity index 100% rename from tests/device/test_newlib/test_newlib.ino rename to tests/device/test_sw_newlib/test_sw_newlib.ino diff --git a/tests/device/test_schedule/test_schedule.ino b/tests/device/test_sw_schedule/test_sw_schedule.ino similarity index 100% rename from tests/device/test_schedule/test_schedule.ino rename to tests/device/test_sw_schedule/test_sw_schedule.ino diff --git a/tests/device/test_tests/test_tests.ino b/tests/device/test_sw_tests/test_sw_tests.ino similarity index 100% rename from tests/device/test_tests/test_tests.ino rename to tests/device/test_sw_tests/test_sw_tests.ino diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index 565c7942d..7bfcd9703 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -174,7 +174,7 @@ void control_c (int sig) int main (int argc, char* const argv []) { bool fast = false; - bool blocking_uart = false; + blocking_uart = false; // global signal(SIGINT, control_c); if (geteuid() == 0) diff --git a/tests/host/common/MockUART.cpp b/tests/host/common/MockUART.cpp index d86e0418f..023c775bf 100644 --- a/tests/host/common/MockUART.cpp +++ b/tests/host/common/MockUART.cpp @@ -39,6 +39,8 @@ extern "C" { +bool blocking_uart = true; // system default + static int s_uart_debug_nr = UART1; static uart_t *UART[2] = { NULL, NULL }; @@ -190,6 +192,13 @@ uart_read(uart_t* uart, char* userbuffer, size_t usersize) if(uart == NULL || !uart->rx_enabled) return 0; + if (!blocking_uart) + { + char c; + if (read(0, &c, 1) == 1) + uart_new_data(0, c); + } + size_t ret = 0; while (ret < usersize && uart_rx_available_unsafe(uart->rx_buffer)) { diff --git a/tests/host/common/mock.h b/tests/host/common/mock.h index e3d9ec68f..27a2da4c4 100644 --- a/tests/host/common/mock.h +++ b/tests/host/common/mock.h @@ -104,12 +104,14 @@ extern "C" { #endif int ets_printf (const char* fmt, ...) __attribute__ ((format (printf, 1, 2))); #define os_printf_plus printf +#define ets_vsnprintf vsnprintf int mockverbose (const char* fmt, ...) __attribute__ ((format (printf, 1, 2))); extern const char* host_interface; // cmdline parameter extern bool serial_timestamp; extern int mock_port_shifter; +extern bool blocking_uart; #define NO_GLOBAL_BINDING 0xffffffff extern uint32_t global_ipv4_netfmt; // selected interface addresse to bind to