Skip to content

Commit 260d84f

Browse files
committed
Move test_fuel_schedule_RUNNING_to_RUNNINGWITHNEXT_Disallow() to test_fuel_schedule.cpp
1 parent 6001c95 commit 260d84f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

test/test_schedules/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void runAllScheduleTests(void)
1414
extern void test_setSchedule(void);
1515
extern void testScheduleStateMachine(void);
1616
extern void test_schedule(void);
17+
extern void test_fuel_schedule(void);
1718
extern void test_ignition_controller();
1819
extern void test_fuel_controller(void);
1920

@@ -29,6 +30,7 @@ void runAllScheduleTests(void)
2930
test_setSchedule();
3031
testScheduleStateMachine();
3132
test_schedule();
33+
test_fuel_schedule();
3234
test_ignition_controller();
3335
test_fuel_controller();
3436
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
#include <Arduino.h>
3+
#include <unity.h>
4+
#include "../test_utils.h"
5+
#include "scheduler.h"
6+
#include "type_traits.h"
7+
8+
using raw_counter_t = type_traits::remove_reference<IgnitionSchedule::counter_t>::type;
9+
using raw_compare_t = type_traits::remove_reference<IgnitionSchedule::compare_t>::type;
10+
11+
static constexpr uint32_t TIMEOUT = 5000U;
12+
static constexpr uint32_t DURATION = 2000U;
13+
static constexpr COMPARE_TYPE INITIAL_COUNTER = 3333U;
14+
15+
static void test_fuel_schedule_RUNNING_to_RUNNINGWITHNEXT_Disallow(void) {
16+
static constexpr uint32_t DURATION_OFFSET = 33;
17+
static constexpr uint32_t TIMEOUT_OFFSET = 77;
18+
19+
raw_counter_t counter = {3333U};
20+
raw_compare_t compare = {0};
21+
FuelSchedule schedule(counter, compare);
22+
23+
setFuelSchedule(schedule, TIMEOUT, DURATION);
24+
25+
schedule.Status = RUNNING;
26+
CRANK_ANGLE_MAX_INJ = 360;
27+
28+
// Negative test
29+
// Calculate a revolution time that will result in 360° taking longer than MAX_TIMER_PERIOD
30+
auto revTime = MAX_TIMER_PERIOD+(MAX_TIMER_PERIOD/CRANK_ANGLE_MAX_INJ);
31+
setAngleConverterRevolutionTime(revTime);
32+
TEST_ASSERT_GREATER_THAN(MAX_TIMER_PERIOD, angleToTimeMicroSecPerDegree((uint16_t)CRANK_ANGLE_MAX_INJ));
33+
setFuelSchedule(schedule, TIMEOUT, DURATION);
34+
// Should not have changed
35+
TEST_ASSERT_EQUAL(INITIAL_COUNTER + uS_TO_TIMER_COMPARE(TIMEOUT), schedule._compare);
36+
TEST_ASSERT_EQUAL(RUNNING, schedule.Status);
37+
TEST_ASSERT_EQUAL(uS_TO_TIMER_COMPARE(DURATION), schedule.duration);
38+
TEST_ASSERT_EQUAL(0, schedule.nextStartCompare);
39+
40+
// Positive test
41+
setAngleConverterRevolutionTime(revTime/2U);
42+
TEST_ASSERT_LESS_THAN(MAX_TIMER_PERIOD, angleToTimeMicroSecPerDegree((uint32_t)CRANK_ANGLE_MAX_INJ));
43+
setFuelSchedule(schedule, TIMEOUT+TIMEOUT_OFFSET, DURATION+DURATION_OFFSET);
44+
// Should not have changed
45+
TEST_ASSERT_EQUAL(INITIAL_COUNTER + uS_TO_TIMER_COMPARE(TIMEOUT), schedule._compare);
46+
// These should have changed
47+
TEST_ASSERT_EQUAL(RUNNING_WITHNEXT, schedule.Status);
48+
TEST_ASSERT_EQUAL(uS_TO_TIMER_COMPARE(DURATION+DURATION_OFFSET), schedule.duration);
49+
TEST_ASSERT_EQUAL(INITIAL_COUNTER + uS_TO_TIMER_COMPARE(TIMEOUT+TIMEOUT_OFFSET), schedule.nextStartCompare);
50+
}
51+
52+
53+
void test_fuel_schedule(void)
54+
{
55+
SET_UNITY_FILENAME() {
56+
RUN_TEST_P(test_fuel_schedule_RUNNING_to_RUNNINGWITHNEXT_Disallow);
57+
}
58+
}

0 commit comments

Comments
 (0)