Skip to content

Commit d40dbb4

Browse files
authored
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
1 parent d1237fd commit d40dbb4

File tree

16 files changed

+41
-6
lines changed

16 files changed

+41
-6
lines changed

tests/device/Makefile

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
SHELL := /bin/bash
22
V ?= 0
3-
TEST_LIST ?= $(wildcard test_*/*.ino)
43
ESP8266_CORE_PATH ?= $(realpath ../..)
54
BUILD_DIR ?= $(PWD)/.build
65
HARDWARE_DIR ?= $(PWD)/.hardware
@@ -18,6 +17,12 @@ TEST_CONFIG := test_env.cfg
1817
TEST_REPORT_XML := test_report.xml
1918
TEST_REPORT_HTML := test_report.html
2019

20+
ifeq ("$(MOCK)", "1")
21+
# To enable a test for mock testing, just rename dir+files to '*_sw_*'
22+
TEST_LIST ?= $(wildcard test_sw_*/*.ino)
23+
else
24+
TEST_LIST ?= $(wildcard test_*/*.ino)
25+
endif
2126

2227
ifneq ("$(V)","1")
2328
SILENT = @
@@ -29,10 +34,14 @@ else
2934
endif
3035

3136
help:
32-
@echo 'make list - show list of tests'
33-
@echo 'make [V=1] sometest/sometest.ino - run one test'
34-
@echo 'make [V=1] all - run all tests'
35-
@echo 'variables needed: $$ARDUINO_IDE_PATH'
37+
@echo
38+
@echo 'make list - show list of tests'
39+
@echo 'make sometest/sometest.ino - run one test'
40+
@echo 'make all - run all tests'
41+
@echo 'make MOCK=1 all - run all emulation-on-host compatible tests'
42+
@echo 'variables needed: $$ARDUINO_IDE_PATH $$ESP8266_CORE_PATH'
43+
@echo 'make options: V=1 NO_BUILD=1 NO_UPLOAD=1 NO_RUN=1 MOCK=1'
44+
@echo
3645

3746
list: showtestlist
3847

@@ -53,6 +62,18 @@ $(TEST_LIST):
5362
@echo "--------------------------------"
5463
@echo "Running test '$@' of $(words $(TEST_LIST)) tests"
5564
$(SILENT)mkdir -p $(LOCAL_BUILD_DIR)
65+
ifeq ("$(MOCK)", "1")
66+
@echo Compiling $(notdir $@)
67+
(cd ../host; make ULIBDIRS=../device/libraries/BSTest ../device/$(@:%.ino=%))
68+
$(SILENT)source $(BS_DIR)/virtualenv/bin/activate && \
69+
$(PYTHON) $(BS_DIR)/runner.py \
70+
$(RUNNER_DEBUG_FLAG) \
71+
-e "$(ESP8266_CORE_PATH)/tests/host/bin/$(@:%.ino=%)" \
72+
-n $(basename $(notdir $@)) \
73+
-o $(LOCAL_BUILD_DIR)/test_result.xml \
74+
--env-file $(TEST_CONFIG) \
75+
`test -f $(addsuffix .py, $(basename $@)) && echo "-m $(addsuffix .py, $(basename $@))" || echo ""`
76+
else
5677
ifneq ("$(NO_BUILD)","1")
5778
@test -n "$(ARDUINO_IDE_PATH)" || (echo "Please export ARDUINO_IDE_PATH" && exit 1)
5879
@echo Compiling $(notdir $@)
@@ -108,6 +129,7 @@ ifneq ("$(NO_RUN)","1")
108129
--env-file $(TEST_CONFIG) \
109130
`test -f $(addsuffix .py, $(basename $@)) && echo "-m $(addsuffix .py, $(basename $@))" || echo ""`
110131
endif
132+
endif
111133

112134
$(TEST_REPORT_XML): $(HARDWARE_DIR) virtualenv
113135
$(SILENT)$(BS_DIR)/xunitmerge $(shell find $(BUILD_DIR) -name 'test_result.xml' | xargs echo) $(TEST_REPORT_XML)

tests/device/test_http_client/test_http_client.ino renamed to tests/device/test_sw_http_client/test_sw_http_client.ino

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
210210
//
211211
// Same tests with axTLS
212212
//
213+
#if !CORE_MOCK
213214
{
214215
// small request
215216
#pragma GCC diagnostic push
@@ -242,6 +243,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
242243
}
243244
}
244245
}
246+
#endif
245247
}
246248

247249
void loop()

tests/host/common/ArduinoMain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void control_c (int sig)
174174
int main (int argc, char* const argv [])
175175
{
176176
bool fast = false;
177-
bool blocking_uart = false;
177+
blocking_uart = false; // global
178178

179179
signal(SIGINT, control_c);
180180
if (geteuid() == 0)

tests/host/common/MockUART.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
extern "C" {
4141

42+
bool blocking_uart = true; // system default
43+
4244
static int s_uart_debug_nr = UART1;
4345

4446
static uart_t *UART[2] = { NULL, NULL };
@@ -190,6 +192,13 @@ uart_read(uart_t* uart, char* userbuffer, size_t usersize)
190192
if(uart == NULL || !uart->rx_enabled)
191193
return 0;
192194

195+
if (!blocking_uart)
196+
{
197+
char c;
198+
if (read(0, &c, 1) == 1)
199+
uart_new_data(0, c);
200+
}
201+
193202
size_t ret = 0;
194203
while (ret < usersize && uart_rx_available_unsafe(uart->rx_buffer))
195204
{

tests/host/common/mock.h

+2
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ extern "C" {
104104
#endif
105105
int ets_printf (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
106106
#define os_printf_plus printf
107+
#define ets_vsnprintf vsnprintf
107108

108109
int mockverbose (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
109110

110111
extern const char* host_interface; // cmdline parameter
111112
extern bool serial_timestamp;
112113
extern int mock_port_shifter;
114+
extern bool blocking_uart;
113115

114116
#define NO_GLOBAL_BINDING 0xffffffff
115117
extern uint32_t global_ipv4_netfmt; // selected interface addresse to bind to

0 commit comments

Comments
 (0)