forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
186 lines (168 loc) · 6.18 KB
/
Copy pathmain.cpp
File metadata and controls
186 lines (168 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* @file main.cpp
* @file Unit tests (and some integration tests to be fair) of rusEFI
*
* @author Andrey Belomutskiy, (c) 2012-2021
*/
#include "pch.h"
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "can_msg_tx.h"
#include "unit_test_logger.h"
#include <chrono>
#include <string>
#include <unordered_set>
bool hasInitGtest = false;
#if EFI_SIMULATOR || EFI_UNIT_TEST
// Clears the shared txCanBuffer before every test so that frames left over
// from a previous test cannot pollute subsequent tests. See discussion in
// LuaHooks.CanTx* vs CanObd2.handleGetDataRequest_SUPPORTED_PIDS_01_20.
class TxCanBufferCleaner : public ::testing::EmptyTestEventListener {
void OnTestStart(const ::testing::TestInfo& /*test_info*/) override {
txCanBuffer.clear();
}
};
// Tests known to produce log artifacts larger than LOG_FILE_SIZE_LIMIT (16 MB)
// when unit-test logging is enabled. For these we skip log creation so the
// LogsTooLargeException doesn't fail them. Keep in sync with the failure list
// observed under setUnitTestCreateLogs(true).
static const std::unordered_set<std::string>& getLogDisabledTests() {
static const std::unordered_set<std::string> s = {
"Toyota3ToothCam.RealEngineRunning",
"arctic.realStartFromFile",
"realBQS.realHarleyCranking",
"realBQS.readAsPrimarySensor",
"realBQS.readAsCam",
"realChryslerPhaser.phaser_cam_1",
"realChryslerPhaser.phaser_cam_2",
"cranking.realCrankingFromFile",
"cranking.naCrankFromFile",
"realCrankingVQ40.normalCrankingSyncCam1",
"realCrankingVQ40.normalCrankingSyncCam2",
"realCas24Plus1.spinningOnBench",
"real4b11.running",
"real4b11.runningDoubledEdge",
"real4g93.cranking",
"real4g93.crankingOn11",
"real4g93.crankingCamOnly",
"real6g72.sync_3000gt_cranking_rusefi",
"real6g72.sync_3000gt_cranking_rusefi_2",
"real6g72.sync_3000gt_crank_cam_cranking",
"real6g72.sync_3000gt_crank_cam_cranking_2",
"real6g72.sync_3000gt_crank_cam_cranking_idle",
"real6g75.withoutSparkPlugs",
"real6g75.realWithSparkPlugs",
"fordCoyote.intakeCam",
"fordCoyote.exhaustCam",
"fordCoyote.exhaustCamInverted",
"crankingVW.vwRealCrankingFromFile",
"crankingVW.crankingTwiceWithGap",
"realCrankingNB2.normalCranking",
"realCrankingNB2.crankingMissingInjector",
"realNeon.srt4_looks_like_cam",
"realNeon.srt4_crank",
"crankingGm24x_5.gmRealCrankingFromFile",
"nissan.realFromFile",
"nissan.realNoSparkPlugsFromFile",
"nissan.realFromFile4seconds",
"nissan.realFromFileVVTIN",
"realk24.crankingNoPlugs1",
"realk24.crankingNoPlugs2",
"realk20.cranking",
"realJeepEva.cranking",
"real.SubaruEj20gcranking_only_cam7",
"real.SubaruEj20gDefaultCranking",
"real.SubaruEj20gCrankingWot",
"real.SubaruEj20gDefaultCranking_only_crank",
"real.SubaruEj20gDefaultCrankingSeparateTrigger",
"real.SubaruEj20gDefaultRev",
"RealNoisyTrigger.AvoidOverdwell1NoInstant",
"RealNoisyTrigger.AvoidOverdwell1WithInstant",
"RealNoisyTrigger.AvoidOverdwell2NoInstant",
"RealNoisyTrigger.AvoidOverdwell2WithInstant",
"RealNoisyTrigger.AvoidOverdwell3NoInstant",
"RealNoisyTrigger.AvoidOverdwell3WithInstant",
"harley.hdCrankingWithCam1",
"harley.hdCrankingWithCam3",
"harley.hdCrankingWithCam4",
"harley.hdCrankingWithCamAnother",
"harley.hdCrankingWithCamAnother2",
"harley.hdCrankingWithCamAnother3",
};
return s;
}
// Toggles setUnitTestCreateLogs(false) around tests known to overflow the
// 16 MB per-file log cap (LogsTooLargeException), restoring the prior value
// after each such test finishes.
class LogDisablerForHeavyTests : public ::testing::EmptyTestEventListener {
std::unique_ptr<ScopedUnitTestCreateLogs> disabler;
void OnTestStart(const ::testing::TestInfo& test_info) override {
std::string fullName = std::string(test_info.test_suite_name()) + "." + test_info.name();
if (getLogDisabledTests().count(fullName) > 0) {
disabler = std::make_unique<ScopedUnitTestCreateLogs>(false);
}
}
void OnTestEnd(const ::testing::TestInfo& /*test_info*/) override {
disabler.reset();
}
};
#endif
GTEST_API_ int main(int argc, char **argv) {
if (argc == 2 && strcmp(argv[1], "ltft_sandbox") == 0) {
void runLtftSandbox();
// feed real log sensor data into our logic
runLtftSandbox();
return 0;
}
if (argc == 2 && strcmp(argv[1], "replay_log") == 0) {
void runLogReplay();
// feed real log sensor data into our logic
runLogReplay();
return 0;
}
if (argc == 3 && strcmp(argv[1], "csv2logicdata") == 0) {
void runCsv2LogicData(const char* csvFileName);
runCsv2LogicData(argv[2]);
return 0;
}
if (argc == 3 && strcmp(argv[1], "logicdata2csv") == 0) {
void runLogicData2Csv(const char* logicDataFileName);
runLogicData2Csv(argv[2]);
return 0;
}
if (argc == 3 && strcmp(argv[1], "msl2csv") == 0) {
void runMsl2Csv(const char* mslFileName);
runMsl2Csv(argv[2]);
return 0;
}
setUnitTestCreateLogs(true);
hasInitGtest = true;
// cleanTestResultsFolder();
testing::InitGoogleTest(&argc, argv);
#if EFI_SIMULATOR || EFI_UNIT_TEST
// Auto-clear shared txCanBuffer before every test to prevent inter-test pollution
::testing::UnitTest::GetInstance()->listeners().Append(new TxCanBufferCleaner());
::testing::UnitTest::GetInstance()->listeners().Append(new LogDisablerForHeavyTests());
#endif
// uncomment if you only want to run selected tests
/**
* See TEST_FROM_TRIGGER_ID to limit test just for last trigger
*/
// todo: can we check argc or argv and setVerboseTrigger(true) dynamically if invoked with AllTriggersFixture?
// command line AllTriggersFixture #7946
// setVerboseTrigger(true);
// --gtest_filter=*TEST_NAME*
//::testing::GTEST_FLAG(filter) = "*AllTriggersFixture*";
auto testsStart = std::chrono::steady_clock::now();
int result = RUN_ALL_TESTS();
auto testsEnd = std::chrono::steady_clock::now();
double totalSeconds = std::chrono::duration<double>(testsEnd - testsStart).count();
printf("Total tests execution time: %.3f s\n", totalSeconds);
// windows ERRORLEVEL in Jenkins batch file seems to want negative value to detect failure
// TODO: Jenkins is long gone! Can we remove this returnCode hack?
int returnCode = result == 0 ? 0 : -1;
printf("DONE returning %d\n", returnCode);
sayByeBye();
return returnCode;
}