timer mocking
This commit is contained in:
@@ -126,8 +126,9 @@ Test:
|
||||
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 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
|
||||
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
|
||||
cleanTest:
|
||||
cd test && $(MAKE) clean
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "../libopeninv/include/params.h"
|
||||
#ifdef TEST_COMMON_H
|
||||
#include "../test/digio_mock.h"
|
||||
#include "../test/timer_mock.h"
|
||||
#else
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/rtc.h>
|
||||
#endif
|
||||
|
||||
static bool IsEvseInput();
|
||||
@@ -43,3 +47,14 @@ static void CalcTotals()
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
VALUE_ENTRY(c3iac, "A", 2034 ) \
|
||||
VALUE_ENTRY(c3udc, "V", 2035 ) \
|
||||
VALUE_ENTRY(c3idc, "A", 2036 ) \
|
||||
VALUE_ENTRY(test_time, "s", 2037 ) \
|
||||
|
||||
|
||||
/***** Enum String definitions *****/
|
||||
|
||||
Binary file not shown.
+4
-11
@@ -18,8 +18,12 @@
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#ifdef TEST_COMMON_H
|
||||
#include "../test/timer_mock.h"
|
||||
#else
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/rtc.h>
|
||||
#endif
|
||||
#include <libopencm3/stm32/can.h>
|
||||
#include <libopencm3/stm32/iwdg.h>
|
||||
#include <libopencm3/stm32/crc.h>
|
||||
@@ -42,7 +46,6 @@
|
||||
static Stm32Scheduler* scheduler;
|
||||
static Can* can;
|
||||
static PiController dcCurController;
|
||||
static uint32_t startTime;
|
||||
|
||||
static void EvseRead()
|
||||
{
|
||||
@@ -189,16 +192,6 @@ static bool CheckChargerFaults()
|
||||
(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()
|
||||
{
|
||||
uint32_t now = rtc_get_counter_val();
|
||||
|
||||
@@ -20,6 +20,7 @@ int main() {
|
||||
(TestCase){"test_check_unplugged", test_check_unplugged},
|
||||
(TestCase){"test_disable_all", test_disable_all},
|
||||
(TestCase){"test_calc_totals", test_calc_totals},
|
||||
(TestCase){"test_check_timeout", test_check_timeout},
|
||||
// Example:
|
||||
//(TestCase){"Your tests name", function_name_without_brackets}
|
||||
//...
|
||||
|
||||
Binary file not shown.
+2
-3
@@ -1,7 +1,6 @@
|
||||
|
||||
#ifndef TEST_COMMON_H
|
||||
#define TEST_COMMON_H
|
||||
#include "charger.h"
|
||||
#include "timer_mock.h"
|
||||
#include "digio_mock.h"
|
||||
|
||||
#include "charger.h"
|
||||
#endif
|
||||
|
||||
@@ -27,3 +27,23 @@ void test_calc_totals()
|
||||
s32fp udcmax = Param::Get(Param::udc);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "timer_mock.h"
|
||||
|
||||
uint32_t rtc_get_counter_val(){
|
||||
return Param::Get(Param::test_time) >> 5;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#include <stdint.h>
|
||||
#include "../libopeninv/include/params.h"
|
||||
uint32_t rtc_get_counter_val();
|
||||
Reference in New Issue
Block a user