Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Unit Tests

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
native-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache pip packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}

- name: Cache PlatformIO packages
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio-${{ hashFiles('**/platformio.ini') }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio

- name: Install GUI dependencies
run: |
cd gui-v2
npm install
npm run build

- name: Install project dependencies
run: pio lib install

- name: Run native unit tests
run: pio test -e native_test

- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: native-test-results
path: .pio/test/

esp32-build-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache pip packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}

- name: Cache PlatformIO packages
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio-${{ hashFiles('**/platformio.ini') }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio

- name: Install GUI dependencies
run: |
cd gui-v2
npm install
npm run build

- name: Install project dependencies
run: pio lib install

- name: Build test firmware for ESP32
run: pio run -e test_esp32dev

- name: Build test firmware for OpenEVSE WiFi v1
run: pio run -e test_openevse_wifi_v1

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: esp32-test-firmware
path: .pio/build/*/firmware.bin

python-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Python dependencies
run: |
cd divert_sim
pip install -r requirements.txt

- name: Run Python divert simulation tests
run: |
cd divert_sim
pytest -v

- name: Upload Python test results
uses: actions/upload-artifact@v3
if: always()
with:
name: python-test-results
path: divert_sim/
80 changes: 75 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[platformio]
data_dir = src/data
default_envs = openevse_wifi_v1
test_dir = test_embedded

[common]
lib_deps =
Expand Down Expand Up @@ -77,9 +78,7 @@ debug_flags =
src_build_flags =
# -D ARDUINOJSON_USE_LONG_LONG
# -D ENABLE_ASYNC_WIFI_SCAN
build_flags =
-D ESP32
-D CS_PLATFORM=CS_P_ESP32
feature_flags =
-D MG_ENABLE_SSL=1
-D MG_ENABLE_HTTP_STREAMING_MULTIPART=1
-D MG_ENABLE_EXTRA_ERRORS_DESC=1
Expand All @@ -94,7 +93,6 @@ build_flags =
#-D MBEDTLS_DEBUG_C
-D MG_ENABLE_SNTP=1
#-D ENABLE_DEBUG_MICROTASKS
-D CS_PLATFORM=CS_P_ESP32
-D MO_CUSTOM_WS ; MicroOcpp: don't use built-in WS library
-D MO_CUSTOM_CONSOLE ; MicroOcpp: use custom debug out
-D MO_DBG_LEVEL=MO_DL_INFO
Expand All @@ -104,10 +102,16 @@ build_flags =
#-D ENABLE_DEBUG_MONGOOSE_HTTP_CLIENT
-D RAPI_MAX_COMMANDS=20
-D BUILD_ENV_NAME="$PIOENV"
-D MG_MAX_HTTP_REQUEST_SIZE=8196

build_flags =
-D ESP32
-D CS_PLATFORM=CS_P_ESP32
-D ARDUINO_ARCH_ESP32
-D USE_ESP32
-D USE_ESP32_FRAMEWORK_ARDUINO
-D MG_MAX_HTTP_REQUEST_SIZE=8196
${common.feature_flags}

build_flags_openevse_tft =
${common.build_flags}
${common.src_build_flags}
Expand Down Expand Up @@ -518,3 +522,69 @@ build_flags =
#upload_protocol = custom
#upload_command = curl -F firmware=@$SOURCE http://$UPLOAD_PORT/update
build_type = debug

[env:native]
platform = native
framework =
lib_deps =
${common.lib_deps}
https://github.com/jeremypoulter/EpoxyDuino
EpoxyFS
EpoxyEepromEsp
EpoxyMockWiFi
lib_extra_dirs = .pio/libdeps/native_test/EpoxyDuino/libraries
build_flags =
-std=c++14
${common.feature_flags}
#${common.src_build_flags}
-D UNIT_TEST
-D ARDUINO=100
-D EPOXY_DUINO
-D CS_PLATFORM=CS_P_UNIX
-D RAPI_PORT=SerialStdio
-D DEBUG_PORT=SerialStdio

; ==============================================
; Test Environments
; ==============================================

[env:native_test]
platform = native
framework =
lib_deps =
${common.lib_deps}
https://github.com/jeremypoulter/EpoxyDuino
EpoxyFS
EpoxyEepromEsp
EpoxyMockWiFi
lib_extra_dirs = .pio/libdeps/native_test/EpoxyDuino/libraries
build_flags =
-std=c++14
-D UNIT_TEST
-D ARDUINO=100
-D EPOXY_DUINO
#-D EPOXY_CORE_ESP32
#-D ESP32
-D EPOXY_CORE_ESP8266
-D ESP8266
-D CS_PLATFORM=CS_P_UNIX
test_framework = unity

[env:esp32_test]
platform = [email protected]
framework = arduino
board = esp32dev
lib_deps =
${common.lib_deps}
build_flags =
${common.build_flags}
-D UNIT_TEST
-D ESP32_TEST
-D ENABLE_DEBUG
-Wl,--wrap=millis
test_framework = unity
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_src_filter =
+<src/app_config.cpp>
+<test_embedded/test_utils.cpp>
10 changes: 8 additions & 2 deletions src/debug.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef UNIT_TEST

#include <StreamSpy.h>

#ifndef DEBUG_PORT
Expand Down Expand Up @@ -27,11 +29,15 @@
StreamSpy SerialDebug(DEBUG_PORT);
StreamSpy SerialEvse(RAPI_PORT);

#endif // UNIT_TEST

void debug_setup()
{
DEBUG_PORT.begin(115200);
SerialDebug.begin(2048);

RAPI_PORT.begin(115200);

#ifndef UNIT_TEST
SerialDebug.begin(2048);
SerialEvse.begin(2048);
#endif // UNIT_TEST
}
15 changes: 10 additions & 5 deletions src/debug.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#ifndef __DEBUG_H
#define __DEBUG_H

#undef DEBUG_PORT
#define DEBUG_PORT SerialDebug
#include "MicroDebug.h"

#undef RAPI_PORT
#define RAPI_PORT SerialEvse
#ifndef UNIT_TEST

#include "MicroDebug.h"
#include "StreamSpy.h"

extern StreamSpy SerialDebug;
extern StreamSpy SerialEvse;

#undef DEBUG_PORT
#define DEBUG_PORT SerialDebug

#undef RAPI_PORT
#define RAPI_PORT SerialEvse

extern void debug_setup();

#endif // UNIT_TEST

#endif // __DEBUG_H
Loading
Loading