Skip to content

Commit

Permalink
unit testing time API
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Apr 27, 2024
1 parent fef5317 commit a61291f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mock/lib-time-mocks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <rusefi/rusefi_time_math.h>

int timeNowUs = 0;
static int timeNowUs = 0;

efitimeus_t getTimeNowUs() {
return timeNowUs;
Expand All @@ -13,3 +13,11 @@ efitimesec_t getTimeNowS() {
efitick_t getTimeNowNt() {
return getTimeNowUs() * US_TO_NT_MULTIPLIER;
}

void setTimeNowUs(int us) {
timeNowUs = us;
}

void advanceTimeUs(int us) {
timeNowUs += us;
}
6 changes: 6 additions & 0 deletions util/include/rusefi/rusefi_time_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
#define NT2USF(x) (((float)(x)) / US_TO_NT_MULTIPLIER)

#define NT_PER_SECOND (US2NT(US_PER_SECOND_LL))

#if EFI_UNIT_TEST
// In unit tests, we can time travel...
void setTimeNowUs(int us);
void advanceTimeUs(int us);
#endif

0 comments on commit a61291f

Please sign in to comment.