|
| 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) |
0 commit comments