Skip to content

Commit 92002ec

Browse files
authored
Device tests updates (#9246)
Stop pyexpect from closing serial port when running with WSL2 Remove makefile flags & opts making it too silent. At some point it makes a lot of useful info just disappear. There are external means of silencing make, so probably best to leave useful data always available Replace SPIFFS with LittleFS in FS test Re-use certs-from-mozilla.py in FS test Fix libc tests w/o -fno-builtin not actually testing anything, also add the flag via .globals.h in case it breaks Fix libc tests generating warnings when using invalid (but safe) size arguments
1 parent a5f18b5 commit 92002ec

File tree

13 files changed

+407
-321
lines changed

13 files changed

+407
-321
lines changed

libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@
1313
import sys
1414
from shutil import which
1515

16-
from subprocess import Popen, PIPE, call
17-
try:
18-
from urllib.request import urlopen
19-
except Exception:
20-
from urllib2 import urlopen
21-
try:
22-
from StringIO import StringIO
23-
except Exception:
24-
from io import StringIO
16+
from io import StringIO
17+
from subprocess import Popen, PIPE, call, CalledProcessError
18+
from urllib.request import urlopen
2519

2620
# check if ar and openssl are available
2721
if which('ar') is None and not os.path.isfile('./ar') and not os.path.isfile('./ar.exe'):
@@ -62,10 +56,10 @@
6256
thisPem = pems[i].replace("'", "")
6357
print(names[i] + " -> " + certName)
6458
ssl = Popen(['openssl','x509','-inform','PEM','-outform','DER','-out', certName], shell = False, stdin = PIPE)
65-
pipe = ssl.stdin
66-
pipe.write(thisPem.encode('utf-8'))
67-
pipe.close()
68-
ssl.wait()
59+
ssl.communicate(thisPem.encode('utf-8'))
60+
ret = ssl.wait()
61+
if ret != 0:
62+
raise CalledProcessError(ret, certName)
6963
if os.path.exists(certName):
7064
derFiles.append(certName)
7165
idx = idx + 1

tests/device/Makefile

Lines changed: 132 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,65 @@
11
SHELL := /bin/bash
2-
V ?= 0
3-
ESP8266_CORE_PATH ?= $(realpath ../..)
4-
BUILD_DIR ?= $(PWD)/.build
5-
HARDWARE_DIR ?= $(PWD)/.hardware
2+
3+
ESP8266_CORE_PATH ?= $(shell git rev-parse --show-toplevel)
4+
5+
BUILD_DIR ?= $(PWD)/build
6+
BS_DIR ?= $(PWD)/libraries/BSTest
7+
68
PYTHON ?= python3
79
ESPTOOL ?= $(PYTHON) $(ESP8266_CORE_PATH)/tools/esptool/esptool.py
8-
MKSPIFFS ?= $(ESP8266_CORE_PATH)/tools/mkspiffs/mkspiffs
10+
11+
VENV_PYTHON ?= $(BS_DIR)/virtualenv/bin/python
12+
VENV_JUNIT2HTML ?= $(BS_DIR)/virtualenv/bin/junit2html
13+
14+
MKFS ?= $(ESP8266_CORE_PATH)/tools/mklittlefs/mklittlefs
15+
916
UPLOAD_PORT ?= $(shell ls /dev/tty* | grep -m 1 -i USB)
1017
UPLOAD_BAUD ?= 460800
11-
UPLOAD_BOARD ?= nodemcu
12-
BS_DIR ?= libraries/BSTest
13-
DEBUG_LEVEL ?= lvl=None____
14-
FQBN ?= esp8266com:esp8266:generic:xtal=160,FlashFreq=40,FlashMode=dio,baud=115200,eesz=4M1M,ip=lm2f,ResetMethod=nodemcu,dbg=Serial,$(DEBUG_LEVEL)
15-
BUILD_TOOL := $(ARDUINO_IDE_PATH)/arduino-builder
18+
19+
TEST_BAUD ?= 115200
20+
BUILD_TOOL ?= arduino-cli
21+
22+
BUILD_BOARD ?= generic
23+
BUILD_CPU ?= 160
24+
BUILD_SIZE ?= 4M1M
25+
BUILD_LWIP ?= lm2f
26+
BUILD_EXTRA ?= ,dbg=Serial,lvl=CORE
27+
28+
FQBN ?= esp8266com:esp8266:$(BUILD_BOARD):xtal=$(BUILD_CPU),baud=$(TEST_BAUD),eesz=$(BUILD_SIZE),ip=$(BUILD_LWIP)$(BUILD_EXTRA)
29+
1630
TEST_CONFIG := test_env.cfg
31+
TEST_RESULT_XML := test_result.xml
1732
TEST_REPORT_XML := test_report.xml
1833
TEST_REPORT_HTML := test_report.html
1934

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
2435
TEST_LIST ?= $(wildcard test_*/*.ino)
36+
BUILD_FLAGS ?=
37+
BS_FLAGS ?=
38+
39+
# To enable a test for mock testing, just rename dir+files to '*_sw_*'
40+
ifeq ("$(MOCK)", "1")
41+
TEST_LIST := $(filter test_sw_%.ino,$(TEST_LIST))
42+
NO_UPLOAD := 1
43+
NO_RUN := 1
2544
endif
2645

27-
ifneq ("$(V)","1")
28-
SILENT = @
29-
REDIR = >& /dev/null
30-
else
31-
BUILDER_DEBUG_FLAG = -verbose
32-
RUNNER_DEBUG_FLAG = -d
33-
#UPLOAD_VERBOSE_FLAG = -v
46+
# To enable verbose mode, call `make V=1` ...
47+
V ?= 0
48+
ifeq ("$(V)", "1")
49+
BUILD_FLAGS += --verbose
50+
BS_FLAGS += --debug
3451
endif
3552

53+
# ${sketch}.py helper script when building locally
54+
mock_script = \
55+
`test -f $(addsuffix .py, $(basename $(1))) && echo "--mock $(addsuffix .py, $(basename $(1)))" || echo ""`
56+
3657
help:
3758
@echo
3859
@echo 'make list - show list of tests'
3960
@echo 'make sometest/sometest.ino - run one test'
4061
@echo 'make all - run all tests'
4162
@echo 'make MOCK=1 all - run all emulation-on-host compatible tests'
42-
@echo 'variables needed: $$ARDUINO_IDE_PATH $$ESP8266_CORE_PATH'
4363
@echo 'make options: V=1 NO_BUILD=1 NO_UPLOAD=1 NO_RUN=1 MOCK=1'
4464
@echo
4565

@@ -49,110 +69,132 @@ all: count tests test_report
4969

5070
$(TEST_LIST): | virtualenv $(TEST_CONFIG) $(BUILD_DIR) $(HARDWARE_DIR)
5171

72+
.NOTPARALLEL: $(TEST_LIST)
73+
5274
tests: showtestlist $(TEST_LIST)
5375

5476
showtestlist:
5577
@echo "-------------------------------- test list:"
56-
@echo $(TEST_LIST)
78+
@printf '%s\n' $(TEST_LIST)
5779
@echo "--------------------------------"
5880

5981
$(TEST_LIST): LOCAL_BUILD_DIR=$(BUILD_DIR)/$(notdir $@)
60-
61-
$(TEST_LIST):
62-
@echo "--------------------------------"
63-
@echo "Running test '$@' of $(words $(TEST_LIST)) tests"
64-
$(SILENT)mkdir -p $(LOCAL_BUILD_DIR)
65-
ifeq ("$(MOCK)", "1")
66-
@echo Compiling $(notdir $@)
67-
(cd ../host; make D=$(V) ULIBDIRS=../device/libraries/BSTest ../device/$(@:%.ino=%))
68-
$(SILENT)$(BS_DIR)/virtualenv/bin/python \
69-
$(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
77-
ifneq ("$(NO_BUILD)","1")
78-
@test -n "$(ARDUINO_IDE_PATH)" || (echo "Please export ARDUINO_IDE_PATH" && exit 1)
79-
@echo Compiling $(notdir $@)
80-
@rm -f $(LOCAL_BUILD_DIR)/build.options.json
81-
$(SILENT)$(BUILD_TOOL) -compile -logger=human \
82-
-libraries "$(PWD)/libraries" \
83-
-core-api-version="10608" \
84-
-warnings=all \
85-
$(BUILDER_DEBUG_FLAG) \
86-
-build-path $(LOCAL_BUILD_DIR) \
87-
-tools $(ARDUINO_IDE_PATH)/tools-builder \
88-
-hardware $(HARDWARE_DIR)\
89-
-hardware $(ARDUINO_IDE_PATH)/hardware \
90-
-fqbn=$(FQBN) \
82+
$(TEST_LIST): LOCAL_DATA_IMG=data.img
83+
84+
define build-arduino
85+
rm -f $(LOCAL_BUILD_DIR)/build.options.json
86+
$(BUILD_TOOL) compile \
87+
$(BUILD_FLAGS) \
88+
--libraries "$(PWD)/libraries" \
89+
--warnings=all \
90+
--build-path $(LOCAL_BUILD_DIR) \
91+
--fqbn=$(FQBN) \
9192
$@
92-
endif
93-
ifneq ("$(NO_UPLOAD)","1")
94-
@test -n "$(UPLOAD_PORT)" || (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1)
95-
@test -e $(dir $@)/make_spiffs.py && ( \
96-
echo "Generating and uploading SPIFFS" && \
97-
(cd $(dir $@) && $(PYTHON) ./make_spiffs.py $(REDIR) ) && \
98-
$(MKSPIFFS) --create $(dir $@)data/ --size 0xFB000 \
99-
--block 8192 --page 256 $(LOCAL_BUILD_DIR)/spiffs.img $(REDIR) && \
100-
$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) \
93+
endef
94+
95+
define build-mock
96+
(cd $(ESP8266_CORE_PATH)/test/host; \
97+
$(MAKE) D=$(V) ULIBDIRS=$(PWD)/libraries/BSTest $(PWD)/$(@:%.ino=%))
98+
$(VENV_PYTHON) $(BS_DIR)/runner.py \
99+
$(BS_FLAGS) \
100+
--name $(basename $(notdir $@)) \
101+
--output $(LOCAL_BUILD_DIR)/$(TEST_RESULT_XML) \
102+
--env-file $(TEST_CONFIG) \
103+
$(call mock_script,$@) \
104+
executable "$(ESP8266_CORE_PATH)/tests/host/bin/$(@:%.ino=%)" || echo ""`
105+
endef
106+
107+
define upload-data
108+
@test -n "$(UPLOAD_PORT)" \
109+
|| (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1)
110+
@test ! \( -d $(dir $@)/data/ \) -a \( -e $(dir $@)/make_data.py \) && \
111+
(cd $(dir $@) && ./make_data.py ) || echo "Filesystem creation skipped"
112+
@test -d $(dir $@)/data/ && ( \
113+
$(MKFS) \
114+
--create $(dir $@)/data/ \
115+
--size 0xFB000 \
116+
--block 8192 \
117+
--page 256 \
118+
$(LOCAL_BUILD_DIR)/$(LOCAL_DATA_IMG) && \
119+
$(ESPTOOL) \
101120
--chip esp8266 \
102121
--port $(UPLOAD_PORT) \
103122
--baud $(UPLOAD_BAUD) \
104123
--after no_reset \
105-
write_flash 0x300000 $(LOCAL_BUILD_DIR)/spiffs.img $(REDIR) ) \
106-
|| (echo "No SPIFFS to upload")
107-
@echo Uploading binary
108-
$(SILENT)$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) \
124+
write_flash 0x300000 $(LOCAL_BUILD_DIR)/$(LOCAL_DATA_IMG) ) \
125+
&& (echo "Uploaded filesystem") \
126+
|| (echo "Filesystem upload skipped")
127+
endef
128+
129+
define upload-binary
130+
@test -n "$(UPLOAD_PORT)" \
131+
|| (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1)
132+
$(ESPTOOL) \
109133
--chip esp8266 \
110134
--port $(UPLOAD_PORT) \
111135
--baud $(UPLOAD_BAUD) \
112136
--after no_reset \
113-
write_flash 0x0 $(LOCAL_BUILD_DIR)/$(notdir $@).bin $(REDIR) # no reset
114-
endif
115-
ifneq ("$(NO_RUN)","1")
116-
@test -n "$(UPLOAD_PORT)" || (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1)
137+
write_flash 0x0 $(LOCAL_BUILD_DIR)/$(notdir $@).bin
138+
endef
139+
140+
define run-test
141+
@test -n "$(UPLOAD_PORT)" \
142+
|| (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1)
117143
@echo Running tests
118-
$(SILENT)$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) \
144+
$(ESPTOOL) \
119145
--chip esp8266 \
120146
--port $(UPLOAD_PORT) \
121147
--baud $(UPLOAD_BAUD) \
122-
read_flash_status $(REDIR) # reset
123-
$(SILENT)$(BS_DIR)/virtualenv/bin/python \
124-
$(BS_DIR)/runner.py \
125-
$(RUNNER_DEBUG_FLAG) \
126-
-p $(UPLOAD_PORT) \
127-
-n $(basename $(notdir $@)) \
128-
-o $(LOCAL_BUILD_DIR)/test_result.xml \
129-
--env-file $(TEST_CONFIG) \
130-
`test -f $(addsuffix .py, $(basename $@)) && echo "-m $(addsuffix .py, $(basename $@))" || echo ""`
148+
read_flash_status # reset via implicit stub reboot
149+
$(VENV_PYTHON) $(BS_DIR)/runner.py \
150+
$(BS_FLAGS) \
151+
--name $(basename $(notdir $@)) \
152+
--output $(LOCAL_BUILD_DIR)/$(TEST_RESULT_XML) \
153+
--env-file $(TEST_CONFIG) \
154+
$(call mock_script,$@) \
155+
port $(UPLOAD_PORT) \
156+
--baudrate $(TEST_BAUD)
157+
endef
158+
159+
$(TEST_LIST):
160+
@echo "--------------------------------"
161+
@echo "Running test '$@' of $(words $(TEST_LIST)) tests"
162+
mkdir -p $(LOCAL_BUILD_DIR)
163+
ifneq ("$(NO_BUILD)","1")
164+
@echo Building $(notdir $@)
165+
ifeq ("$(MOCK)", "1")
166+
$(build-mock)
167+
else
168+
$(build-arduino)
131169
endif
132170
endif
171+
ifneq ("$(NO_UPLOAD)","1")
172+
$(upload-filesystem)
173+
$(upload-binary)
174+
endif
175+
ifneq ("$(NO_RUN)","1")
176+
$(run-test)
177+
endif
133178

134-
$(TEST_REPORT_XML): $(HARDWARE_DIR) virtualenv
135-
$(SILENT)$(BS_DIR)/xunitmerge $(shell find $(BUILD_DIR) -name 'test_result.xml' | xargs echo) $(TEST_REPORT_XML)
179+
$(TEST_REPORT_XML): virtualenv
180+
$(BS_DIR)/xunitmerge \
181+
$(shell find $(BUILD_DIR) -name '$(TEST_RESULT_XML)' | xargs echo) \
182+
$(TEST_REPORT_XML)
136183

137184
$(TEST_REPORT_HTML): $(TEST_REPORT_XML) | virtualenv
138-
$(SILENT)$(BS_DIR)/virtualenv/bin/junit2html $< $@
185+
$(VENV_JUNIT2HTML) $< $@
139186

140187
test_report: $(TEST_REPORT_HTML)
141188
@echo "Test report generated in $(TEST_REPORT_HTML)"
142189

143190
$(BUILD_DIR):
144-
mkdir -p $(BUILD_DIR)
145-
146-
$(HARDWARE_DIR):
147-
mkdir -p $(HARDWARE_DIR)/esp8266com
148-
cd $(HARDWARE_DIR)/esp8266com && ln -s $(realpath $(ESP8266_CORE_PATH)) esp8266
191+
@mkdir -p $(BUILD_DIR)
149192

150193
virtualenv:
151194
@make -C $(BS_DIR) PYTHON=$(PYTHON) virtualenv
152195

153196
clean:
154197
rm -rf $(BUILD_DIR)
155-
rm -rf $(HARDWARE_DIR)
156198
rm -rf $(BS_DIR)/virtualenv
157199
rm -f $(TEST_REPORT_HTML) $(TEST_REPORT_XML)
158200

0 commit comments

Comments
 (0)