timer mocking

This commit is contained in:
Janosch
2022-10-10 22:34:56 +01:00
parent 5c8f5694f0
commit d7673cd292
11 changed files with 53 additions and 15 deletions
+2 -1
View File
@@ -126,8 +126,9 @@ Test:
g++ -c -Ilibopeninv/include/ -Iinclude -o errormessage.o libopeninv/src/errormessage.cpp g++ -c -Ilibopeninv/include/ -Iinclude -o errormessage.o libopeninv/src/errormessage.cpp
g++ -c -Ilibopeninv/include/ -Iinclude -o printf.o libopeninv/src/printf.cpp g++ -c -Ilibopeninv/include/ -Iinclude -o printf.o libopeninv/src/printf.cpp
g++ -c -Ilibopeninv/include/ -Iinclude -o digio_mock.o test/digio_mock.cpp g++ -c -Ilibopeninv/include/ -Iinclude -o digio_mock.o test/digio_mock.cpp
g++ -c -Ilibopeninv/include/ -Iinclude -o timer_mock.o test/timer_mock.cpp
ar rcs libopeninv/libopeninv.a *.o ar rcs libopeninv/libopeninv.a *.o
rm -f my_fp.o my_string.o params.o errormessage.o printf.o digio_mock.o chademo.o terminal.o rm -f my_fp.o my_string.o params.o errormessage.o printf.o digio_mock.o timer_mock.o chademo.o terminal.o
g++ -gdwarf-2 -g test/test.c -Llibopeninv -Iinclude -lopeninv -o test/test.out && gdb -ex='set confirm on' -ex=run -ex=quit --args ./test/test.out g++ -gdwarf-2 -g test/test.c -Llibopeninv -Iinclude -lopeninv -o test/test.out && gdb -ex='set confirm on' -ex=run -ex=quit --args ./test/test.out
cleanTest: cleanTest:
cd test && $(MAKE) clean cd test && $(MAKE) clean
+15
View File
@@ -1,6 +1,10 @@
#include "../libopeninv/include/params.h" #include "../libopeninv/include/params.h"
#ifdef TEST_COMMON_H #ifdef TEST_COMMON_H
#include "../test/digio_mock.h" #include "../test/digio_mock.h"
#include "../test/timer_mock.h"
#else
#include <libopencm3/stm32/timer.h>
#include <libopencm3/stm32/rtc.h>
#endif #endif
static bool IsEvseInput(); static bool IsEvseInput();
@@ -43,3 +47,14 @@ static void CalcTotals()
Param::SetFixed(Param::udc, udcmax); Param::SetFixed(Param::udc, udcmax);
} }
static uint32_t startTime;
static bool CheckTimeout()
{
uint32_t now = rtc_get_counter_val();
uint32_t timeout = Param::GetInt(Param::timelim);
timeout *= 60;
return timeout > 0 && (now - startTime) > timeout;
}
+1
View File
@@ -107,6 +107,7 @@
VALUE_ENTRY(c3iac, "A", 2034 ) \ VALUE_ENTRY(c3iac, "A", 2034 ) \
VALUE_ENTRY(c3udc, "V", 2035 ) \ VALUE_ENTRY(c3udc, "V", 2035 ) \
VALUE_ENTRY(c3idc, "A", 2036 ) \ VALUE_ENTRY(c3idc, "A", 2036 ) \
VALUE_ENTRY(test_time, "s", 2037 ) \
/***** Enum String definitions *****/ /***** Enum String definitions *****/
Binary file not shown.
+4 -11
View File
@@ -18,8 +18,12 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include <libopencm3/stm32/usart.h> #include <libopencm3/stm32/usart.h>
#ifdef TEST_COMMON_H
#include "../test/timer_mock.h"
#else
#include <libopencm3/stm32/timer.h> #include <libopencm3/stm32/timer.h>
#include <libopencm3/stm32/rtc.h> #include <libopencm3/stm32/rtc.h>
#endif
#include <libopencm3/stm32/can.h> #include <libopencm3/stm32/can.h>
#include <libopencm3/stm32/iwdg.h> #include <libopencm3/stm32/iwdg.h>
#include <libopencm3/stm32/crc.h> #include <libopencm3/stm32/crc.h>
@@ -42,7 +46,6 @@
static Stm32Scheduler* scheduler; static Stm32Scheduler* scheduler;
static Can* can; static Can* can;
static PiController dcCurController; static PiController dcCurController;
static uint32_t startTime;
static void EvseRead() static void EvseRead()
{ {
@@ -189,16 +192,6 @@ static bool CheckChargerFaults()
(active3 && ((Param::GetInt(Param::c3flag) & FLAG_FAULT) || timeouts[2])); (active3 && ((Param::GetInt(Param::c3flag) & FLAG_FAULT) || timeouts[2]));
} }
static bool CheckTimeout()
{
uint32_t now = rtc_get_counter_val();
uint32_t timeout = Param::GetInt(Param::timelim);
timeout *= 60;
return timeout > 0 && (now - startTime) > timeout;
}
static bool CheckDelay() static bool CheckDelay()
{ {
uint32_t now = rtc_get_counter_val(); uint32_t now = rtc_get_counter_val();
+1
View File
@@ -20,6 +20,7 @@ int main() {
(TestCase){"test_check_unplugged", test_check_unplugged}, (TestCase){"test_check_unplugged", test_check_unplugged},
(TestCase){"test_disable_all", test_disable_all}, (TestCase){"test_disable_all", test_disable_all},
(TestCase){"test_calc_totals", test_calc_totals}, (TestCase){"test_calc_totals", test_calc_totals},
(TestCase){"test_check_timeout", test_check_timeout},
// Example: // Example:
//(TestCase){"Your tests name", function_name_without_brackets} //(TestCase){"Your tests name", function_name_without_brackets}
//... //...
BIN
View File
Binary file not shown.
+2 -3
View File
@@ -1,7 +1,6 @@
#ifndef TEST_COMMON_H #ifndef TEST_COMMON_H
#define TEST_COMMON_H #define TEST_COMMON_H
#include "charger.h" #include "timer_mock.h"
#include "digio_mock.h" #include "digio_mock.h"
#include "charger.h"
#endif #endif
+20
View File
@@ -27,3 +27,23 @@ void test_calc_totals()
s32fp udcmax = Param::Get(Param::udc); s32fp udcmax = Param::Get(Param::udc);
assert(366 == FP_TOINT(udcmax)); assert(366 == FP_TOINT(udcmax));
} }
// TIMER NEEDED
void test_check_timeout()
{
bool res;
startTime = 11;
Param::SetInt(Param::test_time, 14 * 60);
Param::SetInt(Param::timelim, 13);
res = CheckTimeout();
assert(res);
Param::SetInt(Param::test_time, 12 * 60);
res = CheckTimeout();
assert(!res);
startTime = 1100;
res = CheckTimeout();
assert(res);
}
+5
View File
@@ -0,0 +1,5 @@
#include "timer_mock.h"
uint32_t rtc_get_counter_val(){
return Param::Get(Param::test_time) >> 5;
}
+3
View File
@@ -0,0 +1,3 @@
#include <stdint.h>
#include "../libopeninv/include/params.h"
uint32_t rtc_get_counter_val();