Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /* | |||
2 | * @file test_nissan_vq_vvt.cpp | |||
3 | * | |||
4 | * Created on: Jul 2, 2021 | |||
5 | * @author Andrey Belomutskiy, (c) 2012-2021 | |||
6 | */ | |||
7 | ||||
8 | #include "pch.h" | |||
9 | #include "trigger_nissan.h" | |||
10 | #include "nissan_vq.h" | |||
11 | ||||
12 | class TriggerCallback { | |||
13 | public: | |||
14 | Engine *engine; | |||
15 | int toothIndex; | |||
16 | TriggerWaveform *form; | |||
17 | bool isVvt; | |||
18 | int vvtBankIndex; | |||
19 | scheduling_s sched; | |||
20 | }; | |||
21 | ||||
22 | 1152 | static void func(TriggerCallback *callback) { | ||
23 | 1152 | int formIndex = callback->toothIndex % callback->form->getSize(); | ||
24 | ||||
25 | 1152 | TriggerValue value = callback->form->wave.getChannelState(0, formIndex); | ||
26 | 1152 | efitick_t nowNt = getTimeNowNt(); | ||
27 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 960 times.
|
2/2✓ Decision 'true' taken 192 times.
✓ Decision 'false' taken 960 times.
|
1152 | if (callback->isVvt) { |
28 | 192 | hwHandleVvtCamSignal(value, nowNt, callback->vvtBankIndex * CAMS_PER_BANK); | ||
29 | } else { | |||
30 | 960 | handleShaftSignal(0, value == TriggerValue::RISE, nowNt); | ||
31 | } | |||
32 | 1152 | } | ||
33 | ||||
34 | 3 | static void scheduleTriggerEvents(TriggerWaveform *shape, | ||
35 | float timeScale, | |||
36 | int count, | |||
37 | bool isVvt, | |||
38 | int vvtBankIndex, | |||
39 | int vvtOffset, | |||
40 | std::vector<std::shared_ptr<TriggerCallback>>& ptrs) { | |||
41 | 3 | int totalIndex = 0; | ||
42 | ||||
43 | /** | |||
44 | * yet another approach to trigger testing: let's schedule a huge list of events from heap | |||
45 | * and then execute those one | |||
46 | */ | |||
47 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 3 times.
|
2/2✓ Decision 'true' taken 64 times.
✓ Decision 'false' taken 3 times.
|
67 | for (int r = 0; r < count; r++) { |
48 |
2/2✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 64 times.
|
2/2✓ Decision 'true' taken 1152 times.
✓ Decision 'false' taken 64 times.
|
1216 | for (size_t i = 0; i < shape->getSize(); i++) { |
49 |
1/1✓ Branch 1 taken 1152 times.
|
1152 | float angle = vvtOffset + shape->getAngle(totalIndex); | |
50 | ||||
51 |
1/1✓ Branch 2 taken 1152 times.
|
1152 | std::shared_ptr<TriggerCallback> param = std::make_shared<TriggerCallback>(); | |
52 |
1/1✓ Branch 1 taken 1152 times.
|
1152 | ptrs.push_back(param); | |
53 | ||||
54 | 1152 | param->engine = engine; | ||
55 | 1152 | param->toothIndex = totalIndex; | ||
56 | 1152 | param->form = shape; | ||
57 | 1152 | param->isVvt = isVvt; | ||
58 | 1152 | param->vvtBankIndex = vvtBankIndex; | ||
59 | ||||
60 | 1152 | efitick_t timeNt = efitick_t{US2NT(timeScale * 1000 * angle)}; | ||
61 | ||||
62 |
1/1✓ Branch 5 taken 1152 times.
|
1152 | engine->scheduler.schedule("test", ¶m->sched, timeNt, action_s::make<func>(param.get())); | |
63 | 1152 | totalIndex++; | ||
64 | 1152 | } | ||
65 | } | |||
66 | 3 | } | ||
67 | ||||
68 | 4 | TEST(nissan, vq_vvt) { | ||
69 | extern bool unitTestTaskPrecisionHack; | |||
70 | 1 | unitTestTaskPrecisionHack = true; | ||
71 | // hold a reference to the heap allocated scheduling events until the test is done | |||
72 | 1 | std::vector<std::shared_ptr<TriggerCallback>> ptrs; | ||
73 | ||||
74 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth (engine_type_e::HELLEN_121_NISSAN_6_CYL); | |
75 | 1 | engineConfiguration->isFasterEngineSpinUpEnabled = false; | ||
76 | 1 | engineConfiguration->isIgnitionEnabled = false; | ||
77 | 1 | engineConfiguration->isInjectionEnabled = false; | ||
78 | ||||
79 | 1 | int cyclesCount = 48; | ||
80 | ||||
81 | { | |||
82 |
3/7✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
1 | static TriggerWaveform crank; | |
83 |
1/1✓ Branch 1 taken 1 time.
|
1 | initializeNissanVQ35crank(&crank); | |
84 | ||||
85 |
1/1✓ Branch 1 taken 1 time.
|
1 | scheduleTriggerEvents(&crank, | |
86 | /* timeScale */ 1, | |||
87 | cyclesCount, false, -1, 0, ptrs); | |||
88 | } | |||
89 | 1 | float vvtTimeScale = 1; | ||
90 | ||||
91 | 1 | angle_t testVvtOffset = 13; | ||
92 | ||||
93 | { | |||
94 |
3/7✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
1 | static TriggerWaveform vvt; | |
95 |
1/1✓ Branch 1 taken 1 time.
|
1 | initializeNissanVQvvt(&vvt); | |
96 | ||||
97 |
1/1✓ Branch 1 taken 1 time.
|
1 | scheduleTriggerEvents(&vvt, | |
98 | /* timeScale */ vvtTimeScale, | |||
99 | cyclesCount / 6, true, | |||
100 | /* vvtBankIndex */ 0, | |||
101 | /* vvtOffset */ testVvtOffset, | |||
102 | ptrs); | |||
103 | } | |||
104 | ||||
105 | { | |||
106 |
3/7✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
1 | static TriggerWaveform vvt; | |
107 |
1/1✓ Branch 1 taken 1 time.
|
1 | initializeNissanVQvvt(&vvt); | |
108 | ||||
109 | 1 | scheduleTriggerEvents(&vvt, | ||
110 | /* timeScale */ vvtTimeScale, | |||
111 | cyclesCount / 6, true, | |||
112 | /* vvtBankIndex */1, | |||
113 |
1/1✓ Branch 1 taken 1 time.
|
1 | /* vvtOffset, making it positive */ 720 + testVvtOffset + NISSAN_VQ_CAM_OFFSET, | |
114 | ptrs); | |||
115 | } | |||
116 | ||||
117 |
1/1✓ Branch 1 taken 1 time.
|
1 | eth.setTimeAndInvokeEventsUs(1473000); | |
118 |
4/9✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 31 taken 1 time.
✗ Branch 32 not taken.
|
1 | ASSERT_EQ(167, round(Sensor::getOrZero(SensorType::Rpm))); | |
119 | ||||
120 |
1/1✓ Branch 1 taken 1 time.
|
1 | eth.setTimeAndInvokeEventsUs(1475000); | |
121 |
4/9✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 31 taken 1 time.
✗ Branch 32 not taken.
|
1 | ASSERT_EQ(167, round(Sensor::getOrZero(SensorType::Rpm))); | |
122 | 1 | TriggerCentral *tc = &engine->triggerCentral; | ||
123 | ||||
124 |
1/1✓ Branch 1 taken 1 time.
|
1 | eth.setTimeAndInvokeEventsUs(3593000); | |
125 |
3/9✓ Branch 3 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 33 taken 1 time.
✗ Branch 34 not taken.
|
1 | ASSERT_TRUE(tc->vvtState[0][0].getShaftSynchronized()); | |
126 | ||||
127 | scheduling_s *head; | |||
128 | ||||
129 | 1 | int queueIndex = 0; | ||
130 |
3/3✓ Branch 1 taken 433 times.
✓ Branch 3 taken 432 times.
✓ Branch 4 taken 1 time.
|
0/1? Decision couldn't be analyzed.
|
433 | while ((head = engine->scheduler.getHead()) != nullptr) { |
131 | // todo: what shall we change here once we migrate unit_tests to NT? | |||
132 |
1/1✓ Branch 2 taken 432 times.
|
432 | eth.setTimeAndInvokeEventsUs(head->getMomentUs()); | |
133 | ||||
134 |
3/9✓ Branch 3 taken 432 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 432 times.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 33 taken 432 times.
✗ Branch 34 not taken.
|
432 | ASSERT_TRUE(tc->vvtState[0][0].getShaftSynchronized()); | |
135 | // let's celebrate that vvtPosition stays the same | |||
136 |
3/10✓ Branch 2 taken 432 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 432 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✓ Branch 30 taken 432 times.
✗ Branch 31 not taken.
|
432 | ASSERT_NEAR(34, tc->vvtPosition[0][0], EPS2D) << "queueIndex=" << queueIndex; | |
137 | 432 | queueIndex++; | ||
138 | } | |||
139 |
3/10✓ Branch 3 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
✓ Branch 32 taken 1 time.
✗ Branch 33 not taken.
|
1 | ASSERT_EQ(queueIndex, 432) << "Total queueIndex=" << queueIndex; | |
140 | ||||
141 |
3/9✓ Branch 3 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✗ Branch 12 not taken.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✓ Branch 33 taken 1 time.
✗ Branch 34 not taken.
|
1 | ASSERT_TRUE(tc->vvtState[1][0].getShaftSynchronized()); | |
142 | ||||
143 |
3/8✓ Branch 2 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 24 taken 1 time.
✗ Branch 25 not taken.
|
1 | ASSERT_NEAR(34, tc->vvtPosition[0][0], EPS2D); | |
144 |
3/8✓ Branch 2 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 24 taken 1 time.
✗ Branch 25 not taken.
|
1 | ASSERT_NEAR(34, tc->vvtPosition[1][0], EPS2D); | |
145 | ||||
146 |
3/7✓ Branch 3 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 time.
✗ Branch 17 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
1 | EXPECT_EQ(0u, eth.recentWarnings()->getCount()); | |
147 | 1 | } | ||
148 |