Skip to content

Commit

Permalink
fix JLed::Update() returning wrong result sometimes (#124)
Browse files Browse the repository at this point in the history
* also check the outcome of Update() in tests
because this reveales the root cause of #122, that false is returned
while the effect is acutally running

* upgrade to catch2 v3

* update platformio to 6.1.10

* release 4.13.1

* update coversall action
  • Loading branch information
jandelgado committed Sep 10, 2023
1 parent 0633121 commit 1c79299
Show file tree
Hide file tree
Showing 21 changed files with 24,035 additions and 18,043 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: install python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.11'

- name: linter
run: |
Expand All @@ -28,16 +28,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: install python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.11'

- name: install tools
run: |
pip install platformio==6.1.4
pip install platformio==6.1.10
sudo apt-get update && sudo apt-get install -y lcov
- name: run tests
Expand All @@ -47,10 +47,10 @@ jobs:
make clean coverage OPT=-O0
- name: Upload coverage to coveralls
uses: coverallsapp/github-action@v1.1.2
uses: coverallsapp/github-action@v2.2.3
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: test/coverage.info
file: test/coverage.lcov

- name: build examples
run: make ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test/bin
*.gcov
*.gcno
*.gcda
*.lcov
test/coverage.info
test/report
**/tags
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# JLed changelog (github.com/jandelgado/jled)

## [2023-09-10] 4.13.1

* fix: `Update()` sometimes returning wrong state (https://github.com/jandelgado/jled/issues/122)

## [2023-08-20] 4.13.0

* new: `Stop()` takes optional parameter allowing to turn LED fully off
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ all: phony

lint: phony
cpplint --filter -readability/check \
--extensions=cpp,h,ino $(shell find . -maxdepth 3 \( ! -regex '.*/\..*' \) \
--exclude test/catch2 \
--extensions=cpp,h,ino $(shell find . -maxdepth 3 \( ! -regex '.*/\..*' \) \
-type f -a \( -name "*\.cpp" -o -name "*\.h" -o -name "*\.ino" \) )

ci: phony
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JLed",
"version": "4.13.0",
"version": "4.13.1",
"description": "An embedded library to control LEDs",
"license": "MIT",
"frameworks": ["espidf", "arduino", "mbed"],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=JLed
version=4.13.0
version=4.13.1
author=Jan Delgado <jdelgado[at]gmx.net>
maintainer=Jan Delgado <jdelgado[at]gmx.net>
sentence=An Arduino library to control LEDs
Expand Down
4 changes: 1 addition & 3 deletions src/jled_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,15 @@ class TJLed {
if (t < period) {
state_ = ST_RUNNING;
Write(Eval(t));
return true;
} else {
if (state_ == ST_RUNNING) {
// when in delay after phase, just call Write()
// once at the beginning.
state_ = ST_IN_DELAY_AFTER_PHASE;
Write(Eval(period - 1));
return true;
}
}
return false;
return true;
}

B& SetBrightnessEval(BrightnessEvaluator* be) {
Expand Down
27 changes: 15 additions & 12 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# JLed unit tests Makefile
# run `make coverage` to run all test and calculate coverage
#
.PHONY: phony

CFLAGS=-std=c++14 -c -Wall -Wextra -I. -I../src -I./esp-idf \
Expand All @@ -10,29 +11,31 @@ CFLAGS=-std=c++14 -c -Wall -Wextra -I. -I../src -I./esp-idf \

LDFLAGS=-fprofile-arcs -ftest-coverage

TEST_ARDUINO_MOCK_SRC=Arduino.cpp test_arduino_mock.cpp test_main.cpp
CATCH=catch2/catch_amalgamated.cpp

TEST_ARDUINO_MOCK_SRC=Arduino.cpp test_arduino_mock.cpp test_main.cpp ${CATCH}
TEST_ARDUINO_MOCK_OBJECTS=$(TEST_ARDUINO_MOCK_SRC:.cpp=.o)

TEST_JLED_SRC=Arduino.cpp test_jled.cpp test_main.cpp ../src/jled_base.cpp
TEST_JLED_SRC=Arduino.cpp test_jled.cpp test_main.cpp ../src/jled_base.cpp ${CATCH}
TEST_JLED_OBJECTS=$(TEST_JLED_SRC:.cpp=.o)

TEST_JLED_SEQUENCE_SRC=Arduino.cpp test_jled_sequence.cpp test_main.cpp ../src/jled_base.cpp
TEST_JLED_SEQUENCE_SRC=Arduino.cpp test_jled_sequence.cpp test_main.cpp ../src/jled_base.cpp ${CATCH}
TEST_JLED_SEQUENCE_OBJECTS=$(TEST_JLED_SEQUENCE_SRC:.cpp=.o)

TEST_ESP32_SRC=esp-idf/esp_timer.cpp esp-idf/driver/ledc.cpp \
test_esp32_hal.cpp ../src/esp32_hal.cpp test_main.cpp
test_esp32_hal.cpp ../src/esp32_hal.cpp test_main.cpp ${CATCH}
TEST_ESP32_OBJECTS=$(TEST_ESP32_SRC:.cpp=.o)

TEST_ESP8266_SRC=Arduino.cpp test_esp8266_hal.cpp test_main.cpp
TEST_ESP8266_SRC=Arduino.cpp test_esp8266_hal.cpp test_main.cpp ${CATCH}
TEST_ESP8266_OBJECTS=$(TEST_ESP8266_SRC:.cpp=.o)

TEST_MBED_SRC=mbed.cpp test_mbed_hal.cpp test_main.cpp
TEST_MBED_SRC=mbed.cpp test_mbed_hal.cpp test_main.cpp ${CATCH}
TEST_MBED_OBJECTS=$(TEST_MBED_SRC:.cpp=.o)

TEST_ARDUINO_SRC=Arduino.cpp test_arduino_hal.cpp test_main.cpp
TEST_ARDUINO_SRC=Arduino.cpp test_arduino_hal.cpp test_main.cpp ${CATCH}
TEST_ARDUINO_OBJECTS=$(TEST_ARDUINO_SRC:.cpp=.o)

TEST_MORSE_SRC=test_example_morse.cpp test_main.cpp
TEST_MORSE_SRC=test_example_morse.cpp test_main.cpp ${CATCH}
TEST_MORSE_OBJECTS=$(TEST_MORSE_SRC:.cpp=.o)


Expand Down Expand Up @@ -69,10 +72,10 @@ bin/test_example_morse: $(TEST_MORSE_OBJECTS)
$(CXX) -o $@ $(LDFLAGS) $(TEST_MORSE_OBJECTS)

coverage: test
lcov --config-file=.lcovrc --directory ../src --directory .. --capture --output-file coverage.info --no-external
lcov --config-file=.lcovrc --list coverage.info
lcov --config-file=.lcovrc --directory ../src --directory .. --capture --output-file coverage.lcov --no-external
lcov --config-file=.lcovrc --list coverage.lcov
mkdir -p report
genhtml coverage.info -o report
genhtml coverage.lcov -o report

test: depend all
./bin/test_jled
Expand All @@ -93,7 +96,7 @@ bin:
mkdir -p bin

clean: phony
rm -f {./,esp-idf,esp-idf/driver}/{*.gcov,*.gcda,*.gcno,*.o} .depend
rm -f {./,esp-idf,esp-idf/driver,catch2}/{*.gcov,*.gcda,*.gcno,*.o} .depend

clobber: clean
rm -f bin/*
Expand Down
Loading

0 comments on commit 1c79299

Please sign in to comment.