Skip to content

Commit ab7af89

Browse files
committed
Device side test library and test runner
1 parent 33723a9 commit ab7af89

26 files changed

+1118
-206
lines changed

tests/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
hardware
22
tmp
3-
.env

tests/FSWrapper/FSWrapper.ino

Lines changed: 0 additions & 155 deletions
This file was deleted.

tests/Time/Time.ino

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/device/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.build
2+
.hardware

tests/device/Makefile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
SHELL := /bin/bash
2+
V ?= 0
3+
TEST_LIST ?= $(wildcard test_*/*.ino)
4+
ESP8266_CORE_PATH ?= ../..
5+
BUILD_DIR ?= $(PWD)/.build
6+
HARDWARE_DIR ?= $(PWD)/.hardware
7+
ESPTOOL ?= $(ESP8266_CORE_PATH)/tools/esptool/esptool
8+
UPLOAD_PORT ?= $(shell ls /dev/tty* | grep -m 1 -i USB)
9+
UPLOAD_BAUD ?= 921600
10+
UPLOAD_BOARD ?= nodemcu
11+
BS_DIR ?= libraries/BSTest
12+
DEBUG_LEVEL ?= DebugLevel=None____
13+
FQBN ?= esp8266com:esp8266:generic:CpuFrequency=80,FlashFreq=40,FlashMode=DIO,UploadSpeed=115200,FlashSize=4M1M,ResetMethod=none,Debug=Serial$(DEBUG_LEVEL)
14+
BUILD_TOOL = $(ARDUINO_IDE_PATH)/arduino-builder
15+
TEST_CONFIG = libraries/test_config/test_config.h
16+
17+
ifeq ("$(UPLOAD_PORT)","")
18+
$(error "Failed to detect upload port, please export UPLOAD_PORT manually")
19+
endif
20+
21+
ifeq ("$(ARDUINO_IDE_PATH)","")
22+
$(error "Please export ARDUINO_IDE_PATH")
23+
endif
24+
25+
ifneq ("$(V)","1")
26+
SILENT = @
27+
else
28+
BUILDER_DEBUG_FLAG = -verbose
29+
RUNNER_DEBUG_FLAG = -d
30+
UPLOAD_VERBOSE_FLAG = -v
31+
endif
32+
33+
34+
all: count tests
35+
36+
count:
37+
@echo Running $(words $(TEST_LIST)) tests
38+
39+
tests: $(BUILD_DIR) $(HARDWARE_DIR) virtualenv $(TEST_CONFIG) $(TEST_LIST)
40+
41+
$(TEST_LIST): LOCAL_BUILD_DIR=$(BUILD_DIR)/$(notdir $@)
42+
43+
$(TEST_LIST):
44+
$(SILENT)mkdir -p $(LOCAL_BUILD_DIR)
45+
ifneq ("$(NO_BUILD)","1")
46+
@echo Compiling $(notdir $@)
47+
$(SILENT)$(BUILD_TOOL) -compile -logger=human \
48+
-libraries "$(PWD)/libraries" \
49+
-core-api-version="10608" \
50+
-warnings=none \
51+
$(BUILDER_DEBUG_FLAG) \
52+
-build-path $(LOCAL_BUILD_DIR) \
53+
-tools $(ARDUINO_IDE_PATH)/tools-builder \
54+
-hardware $(HARDWARE_DIR)\
55+
-hardware $(ARDUINO_IDE_PATH)/hardware \
56+
-fqbn=$(FQBN) \
57+
$@
58+
endif
59+
ifneq ("$(NO_UPLOAD)","1")
60+
$(SILENT)$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) \
61+
-cp $(UPLOAD_PORT) \
62+
-cb $(UPLOAD_BAUD) \
63+
-cd $(UPLOAD_BOARD) \
64+
-cf $(LOCAL_BUILD_DIR)/$(notdir $@).bin
65+
endif
66+
ifneq ("$(NO_RUN)","1")
67+
@echo Running tests
68+
$(SILENT)$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) -cp $(UPLOAD_PORT) -cd $(UPLOAD_BOARD) -cr
69+
@source $(BS_DIR)/virtualenv/bin/activate && \
70+
python $(BS_DIR)/runner.py \
71+
$(RUNNER_DEBUG_FLAG) \
72+
-p $(UPLOAD_PORT) \
73+
-n $(basename $(notdir $@)) \
74+
-o $(LOCAL_BUILD_DIR)/test_result.xml
75+
endif
76+
77+
$(BUILD_DIR):
78+
mkdir -p $(BUILD_DIR)
79+
80+
$(HARDWARE_DIR):
81+
mkdir -p $(HARDWARE_DIR)/esp8266com
82+
cd $(HARDWARE_DIR)/esp8266com && ln -s $(realpath $(ESP8266_CORE_PATH)) esp8266
83+
84+
virtualenv:
85+
make -C $(BS_DIR) virtualenv
86+
87+
clean:
88+
rm -rf $(BUILD_DIR)
89+
rm -rf $(HARDWARE_DIR)
90+
91+
$(TEST_CONFIG):
92+
@echo "****** "
93+
@echo "****** libraries/test_config/test_config.h does not exist"
94+
@echo "****** Create one from libraries/test_config/test_config.h.template"
95+
@echo "****** "
96+
false
97+
98+
.PHONY: tests all count venv $(BUILD_DIR) $(TEST_LIST)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test/test
2+
virtualenv
3+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PYTHON_ENV_DIR=virtualenv
2+
TEST_EXECUTABLE=test/test
3+
4+
all: test
5+
6+
install: $(PYTHON_ENV_DIR)
7+
8+
clean:
9+
rm -rf $(PYTHON_ENV_DIR)
10+
rm -rf $(TEST_EXECUTABLE)
11+
12+
$(PYTHON_ENV_DIR):
13+
virtualenv --no-site-packages $(PYTHON_ENV_DIR)
14+
source $(PYTHON_ENV_DIR)/bin/activate && pip install -r requirements.txt
15+
16+
test: $(TEST_EXECUTABLE) $(PYTHON_ENV_DIR)
17+
source $(PYTHON_ENV_DIR)/bin/activate && python runner.py -e $(TEST_EXECUTABLE)
18+
19+
$(TEST_EXECUTABLE): test/test.cpp
20+
g++ -std=c++11 -Isrc -o $@ test/test.cpp
21+
22+
.PHONY: test clean install all
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=BSTest
2+
version=0.1
3+
author=Ivan Grokhotkov <[email protected]>
4+
maintainer=Ivan Grokhotkov <[email protected]>
5+
sentence=BS Test library
6+
paragraph=
7+
category=Uncategorized
8+
url=
9+
architectures=esp8266
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
junit-xml==1.6
2+
pexpect==4.0.1
3+
ptyprocess==0.5.1
4+
pyserial==3.0.1
5+
six==1.10.0
6+
wheel==0.24.0

0 commit comments

Comments
 (0)