From 1dd67013bfcea2e433752d6a15f2354d30a54088 Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Mon, 26 Oct 2020 14:49:21 +0100 Subject: [PATCH 1/2] Add VOC algorithm tests These are pure software tests. But since we can't yet distinguish between pure software tests and tests that need hardware we just run them the same. --- .gitignore | 1 + tests/Makefile | 7 ++++++- tests/sensirion-voc-algorithm-test.cpp | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/sensirion-voc-algorithm-test.cpp diff --git a/.gitignore b/.gitignore index a41989f..1050030 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ tests/sgpc3-test-hw_i2c tests/sgpc3-test-sw_i2c tests/svm30-test-hw_i2c tests/svm30-test-sw_i2c +tests/sensirion-voc-algorithm-test diff --git a/tests/Makefile b/tests/Makefile index d50fa75..cc37ed3 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -8,7 +8,9 @@ include ${sgp_driver_dir}/sgpc3/default_config.inc sgp30_test_binaries := sgp30-test-hw_i2c sgp30-test-sw_i2c sgp40_test_binaries := sgp40-test-hw_i2c sgp40-test-sw_i2c -sgp40_voc_index_test_binaries := sgp40-voc-index-test-hw_i2c sgp40-voc-index-test-sw_i2c +sgp40_voc_index_test_binaries := sgp40-voc-index-test-hw_i2c \ + sgp40-voc-index-test-sw_i2c \ + sensirion-voc-algorithm-test sgpc3_test_binaries := sgpc3-test-hw_i2c sgpc3-test-sw_i2c svm30_test_binaries := svm30-test-hw_i2c svm30-test-sw_i2c sgp_test_binaries := ${sgp30_test_binaries} \ @@ -48,6 +50,9 @@ sgp40-voc-index-test-sw_i2c: CONFIG_I2C_TYPE := sw_i2c sgp40-voc-index-test-sw_i2c: sgp40-voc-index-test.cpp ${sgp40_voc_index_sources} ${sw_i2c_sources} ${sensirion_test_sources} $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) +sensirion-voc-algorithm-test: sensirion-voc-algorithm-test.cpp ${sgp40_voc_index_voc_algorithm_sources} + $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) + sgpc3-test-hw_i2c: CONFIG_I2C_TYPE := hw_i2c sgpc3-test-hw_i2c: sgpc3-test.cpp ${sgpc3_sources} ${hw_i2c_sources} ${sensirion_test_sources} $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) diff --git a/tests/sensirion-voc-algorithm-test.cpp b/tests/sensirion-voc-algorithm-test.cpp new file mode 100644 index 0000000..42e4bc5 --- /dev/null +++ b/tests/sensirion-voc-algorithm-test.cpp @@ -0,0 +1,19 @@ +#include "CppUTest/CommandLineTestRunner.h" +#include "sensirion_voc_algorithm.h" + +TEST_GROUP (Sgp40VocIndexAlgorithmTest) {}; + +TEST (Sgp40VocIndexAlgorithmTest, returns_zero_during_blackout) { + VocAlgorithmParams params; + VocAlgorithm_init(¶ms); + for (int i = 0; i < VocAlgorithm_INITIAL_BLACKOUT; ++i) { + int32_t voc_index; + VocAlgorithm_process(¶ms, 0, &voc_index); + CHECK_EQUAL_TEXT(0, voc_index, + "VOC index should be 0 during initial blackout"); + } +} + +int main(int argc, char** argv) { + return CommandLineTestRunner::RunAllTests(argc, argv); +} From 10dee7c132cf1a187ae88b7e3437003f6bda0c4d Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Mon, 26 Oct 2020 15:45:07 +0100 Subject: [PATCH 2/2] Add VOC algorithm test for value after blackout period Immediatly after the warmup / blackout, the value should be the typical / offset value. --- tests/sensirion-voc-algorithm-test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/sensirion-voc-algorithm-test.cpp b/tests/sensirion-voc-algorithm-test.cpp index 42e4bc5..c95843a 100644 --- a/tests/sensirion-voc-algorithm-test.cpp +++ b/tests/sensirion-voc-algorithm-test.cpp @@ -14,6 +14,19 @@ TEST (Sgp40VocIndexAlgorithmTest, returns_zero_during_blackout) { } } +TEST (Sgp40VocIndexAlgorithmTest, returns_average_after_blackout) { + VocAlgorithmParams params; + VocAlgorithm_init(¶ms); + int32_t voc_index; + for (int i = 0; i < VocAlgorithm_INITIAL_BLACKOUT + 2; ++i) { + VocAlgorithm_process(¶ms, 0, &voc_index); + } + + CHECK_EQUAL_TEXT( + VocAlgorithm_VOC_INDEX_OFFSET_DEFAULT, voc_index, + "VOC index should be the offset default after the the blackout period"); +} + int main(int argc, char** argv) { return CommandLineTestRunner::RunAllTests(argc, argv); }