From b87d223dff16d56ed724951a34e400a50947a4da Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Thu, 21 Nov 2019 08:34:35 +0100 Subject: [PATCH] Conformance testing script check.sh added --- README.md | 19 +++++++++++++++++-- check.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 check.sh diff --git a/README.md b/README.md index 2960f3d..73acd90 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ ![build badge](https://travis-ci.com/LibreSolar/charge-controller-firmware.svg?branch=master) -Firmware based on ARM mbed framework for the Libre Solar MPPT/PWM solar charge controllers +Firmware based on ARM mbed framework for the Libre Solar MPPT/PWM solar charge controllers. + +Coding style is described [here](https://libre.solar/docs/coding_style/). ## Supported devices @@ -72,12 +74,25 @@ The custom linker script file STM32L073XZ.ld.link_script.ld needs to be updated The documentation auto-generated by Doxygen can be found [here](https://libre.solar/charge-controller-firmware/). -## Unit tests +## Conformance testing + +We are using Travis CI to perform several checks for each commit or pull-request. In order to run +the same tests locally (recommended before each pull-request) use the script `check.sh`: + + bash check.sh + +### Unit-tests In order to run the unit tests, you need a PlatformIO Plus account. Run tests with the following command: platformio test -e unit-test-native +### Static code analysis + +PlatformIO integrates cppcheck and clangtidy. The following command is an example to run the checks for MPPT 1210 HUS charge controller code: + + platformio check -e mppt-1210-hus-v0.7 + ## Additional firmware documentation (docs folder) - [MPPT charger firmware details](docs/firmware.md) diff --git a/check.sh b/check.sh new file mode 100755 index 0000000..da26d3f --- /dev/null +++ b/check.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# This file performs the same checks as TravisCI and should be run after each commit and before +# pushing the commits +# + +echo "---------- Trailing whitespace check -------------" +git diff --check `git rev-list HEAD | tail -n 1`..$TRAVIS_BRANCH +if [ $? != 0 ]; then + exit 1; +fi + +echo "---------- Preparation of config -------------" +if [ -f "src/config.h" ]; then + echo "Making backup of existing config" + mv src/config.h src/config.h_backup_checksh +fi +cp src/config.h_template src/config.h + +echo "---------- Running compile check -------------" +platformio run -e mppt-2420-lc-v0.10 -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 +if [ $? != 0 ]; then + mv src/config.h_backup_checksh src/config.h + exit 1; +fi + +echo "---------- Running unit-tests -------------" +platformio test -e unit-test-native +if [ $? != 0 ]; then + mv src/config.h_backup_checksh src/config.h + exit 1; +fi + +echo "---------- Running static code checks -------------" +platformio check -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 +if [ $? != 0 ]; then + mv src/config.h_backup_checksh src/config.h + exit 1; +fi + +mv src/config.h_backup_checksh src/config.h + +echo "---------- All tests passed -------------"