Skip to content

Commit 48ec297

Browse files
committed
Move test_ignition_schedule_RUNNING_to_RUNNINGWITHNEXT_Disallow() to test_ignition_schedule.cpp
1 parent 260d84f commit 48ec297

File tree

4 files changed

+61
-106
lines changed

4 files changed

+61
-106
lines changed

test/test_schedules/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ void runAllScheduleTests(void)
1111
extern void test_status_running_to_off(void);
1212
extern void test_accuracy_timeout(void);
1313
extern void test_accuracy_duration(void);
14-
extern void test_setSchedule(void);
1514
extern void testScheduleStateMachine(void);
1615
extern void test_schedule(void);
1716
extern void test_fuel_schedule(void);
17+
extern void test_ignition_schedule(void);
1818
extern void test_ignition_controller();
1919
extern void test_fuel_controller(void);
2020

@@ -27,10 +27,10 @@ void runAllScheduleTests(void)
2727
test_status_running_to_off();
2828
test_accuracy_timeout();
2929
test_accuracy_duration();
30-
test_setSchedule();
3130
testScheduleStateMachine();
3231
test_schedule();
3332
test_fuel_schedule();
33+
test_ignition_schedule();
3434
test_ignition_controller();
3535
test_fuel_controller();
3636
}

test/test_schedules/test_fuel_schedule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void test_fuel_schedule_RUNNING_to_RUNNINGWITHNEXT_Disallow(void) {
1616
static constexpr uint32_t DURATION_OFFSET = 33;
1717
static constexpr uint32_t TIMEOUT_OFFSET = 77;
1818

19-
raw_counter_t counter = {3333U};
19+
raw_counter_t counter = {INITIAL_COUNTER};
2020
raw_compare_t compare = {0};
2121
FuelSchedule schedule(counter, compare);
2222

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_ignition_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 = {INITIAL_COUNTER};
20+
raw_compare_t compare = {0};
21+
IgnitionSchedule schedule(counter, compare);
22+
23+
setIgnitionSchedule(schedule, TIMEOUT, DURATION);
24+
25+
schedule.Status = RUNNING;
26+
CRANK_ANGLE_MAX_IGN = 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_IGN);
31+
setAngleConverterRevolutionTime(revTime);
32+
TEST_ASSERT_GREATER_THAN_UINT32(MAX_TIMER_PERIOD, angleToTimeMicroSecPerDegree((uint16_t)CRANK_ANGLE_MAX_IGN));
33+
34+
setIgnitionSchedule(schedule, TIMEOUT, DURATION);
35+
// Should not have changed
36+
TEST_ASSERT_EQUAL(INITIAL_COUNTER + uS_TO_TIMER_COMPARE(TIMEOUT), schedule._compare);
37+
TEST_ASSERT_EQUAL(RUNNING, schedule.Status);
38+
TEST_ASSERT_EQUAL(uS_TO_TIMER_COMPARE(DURATION), schedule.duration);
39+
TEST_ASSERT_EQUAL(0, schedule.nextStartCompare);
40+
41+
// Positive test
42+
setAngleConverterRevolutionTime(revTime/2U);
43+
TEST_ASSERT_LESS_THAN(MAX_TIMER_PERIOD, angleToTimeMicroSecPerDegree((uint32_t)CRANK_ANGLE_MAX_INJ));
44+
setIgnitionSchedule(schedule, TIMEOUT+TIMEOUT_OFFSET, DURATION+DURATION_OFFSET);
45+
// Should not have changed
46+
TEST_ASSERT_EQUAL(INITIAL_COUNTER + uS_TO_TIMER_COMPARE(TIMEOUT), schedule._compare);
47+
// These should have changed
48+
TEST_ASSERT_EQUAL(RUNNING_WITHNEXT, schedule.Status);
49+
TEST_ASSERT_EQUAL(uS_TO_TIMER_COMPARE(DURATION+DURATION_OFFSET), schedule.duration);
50+
TEST_ASSERT_EQUAL(INITIAL_COUNTER + uS_TO_TIMER_COMPARE(TIMEOUT+TIMEOUT_OFFSET), schedule.nextStartCompare);
51+
}
52+
53+
void test_ignition_schedule(void)
54+
{
55+
SET_UNITY_FILENAME() {
56+
RUN_TEST_P(test_ignition_schedule_RUNNING_to_RUNNINGWITHNEXT_Disallow);
57+
}
58+
}

test/test_schedules/test_setSchedule.cpp

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)