Skip to content

Commit

Permalink
device tests: some of them can be run on host (#6912)
Browse files Browse the repository at this point in the history
* device tests: mock scripts + rename some tests to enable mock-testing them

* move symbol
  • Loading branch information
d-a-v committed Dec 16, 2019
1 parent d1237fd commit d40dbb4
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 6 deletions.
32 changes: 27 additions & 5 deletions tests/device/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = @
Expand All @@ -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

Expand All @@ -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 $@)
Expand Down Expand Up @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
//
// Same tests with axTLS
//
#if !CORE_MOCK
{
// small request
#pragma GCC diagnostic push
Expand Down Expand Up @@ -242,6 +243,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
}
}
}
#endif
}

void loop()
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/host/common/ArduinoMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions tests/host/common/MockUART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 2 additions & 0 deletions tests/host/common/mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d40dbb4

Please sign in to comment.