things are happy without gtest (#3999)

* things are happy without gtest

* this is not a static lib
This commit is contained in:
Matthew Kennedy 2022-03-14 12:00:02 -07:00 committed by GitHub
parent 3076027887
commit 5811f691d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 22 deletions

View File

@ -30,13 +30,7 @@ extern bool printTriggerTrace;
extern bool printFuelDebug;
extern int minCrankingRpm;
bool isTestingInitialized = false;
EngineTestHelperBase::EngineTestHelperBase(Engine * eng, engine_configuration_s * econfig, persistent_config_s * pers) {
if (!isTestingInitialized) {
testing::InitGoogleTest();
isTestingInitialized = true;
}
// todo: make this not a global variable, we need currentTimeProvider interface on engine
timeNowUs = 0;
minCrankingRpm = 0;
@ -124,9 +118,14 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb
//todo: reuse initPeriodicEvents() method
engine.periodicSlowCallback();
// Setup running in mock airmass mode
engineConfiguration->fuelAlgorithm = LM_MOCK;
engine.mockAirmassModel = &mockAirmass;
extern bool hasInitGtest;
if (hasInitGtest) {
// Setup running in mock airmass mode if running actual tests
engineConfiguration->fuelAlgorithm = LM_MOCK;
mockAirmass = std::make_unique<::testing::NiceMock<MockAirmass>>();
engine.mockAirmassModel = mockAirmass.get();
}
memset(mockPinStates, 0, sizeof(mockPinStates));

View File

@ -100,7 +100,7 @@ public:
Engine engine;
persistent_config_s persistentConfig;
::testing::NiceMock<MockAirmass> mockAirmass;
std::unique_ptr<::testing::NiceMock<MockAirmass>> mockAirmass;
private:
void writeEvents(const char *fileName);

View File

@ -9,7 +9,11 @@
#include "pch.h"
#include <stdlib.h>
bool hasInitGtest = false;
GTEST_API_ int main(int argc, char **argv) {
hasInitGtest = true;
testing::InitGoogleTest(&argc, argv);
// uncomment if you only want to run selected tests
/**
@ -21,4 +25,3 @@ GTEST_API_ int main(int argc, char **argv) {
// windows ERRORLEVEL in Jenkins batch file seems to want negative value to detect failure
return result == 0 ? 0 : -1;
}

View File

@ -32,7 +32,7 @@ TEST(fuelControl, transitionIssue1592) {
engine->tdcMarkEnabled = false;
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth, IM_SEQUENTIAL);
EXPECT_CALL(eth.mockAirmass, getAirmass(500))
EXPECT_CALL(*eth.mockAirmass, getAirmass(500))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
// This is easiest to trip on a wheel that requires sync

View File

@ -13,7 +13,7 @@ using ::testing::_;
TEST(fuelCut, coasting) {
EngineTestHelper eth(TEST_ENGINE);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
// configure coastingFuelCut

View File

@ -138,7 +138,7 @@ TEST(FuelMath, testDifferentInjectionModes) {
EngineTestHelper eth(TEST_ENGINE);
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{1.3440001f, 50.0f}));
setInjectionMode((int)IM_BATCH);
@ -164,7 +164,7 @@ TEST(FuelMath, deadtime) {
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{1.3440001f, 50.0f}));
// First test with no deadtime
@ -182,7 +182,7 @@ TEST(FuelMath, deadtime) {
TEST(FuelMath, CylinderFuelTrim) {
EngineTestHelper eth(TEST_ENGINE);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{1, 50.0f}));
setTable(config->fuelTrims[0].table, -4);

View File

@ -46,7 +46,7 @@ TEST(ignition, trailingSpark) {
*/
engine->enableOverdwellProtection = false;
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);

View File

@ -264,7 +264,7 @@ TEST(misc, testRpmCalculator) {
// These tests were written when the default target AFR was 14.0, so replicate that
engineConfiguration->stoichRatioPrimary = 14;
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
IgnitionEventList *ilist = &engine->ignitionEvents;
@ -520,7 +520,7 @@ static void assertInjectionEventBatch(const char *msg, InjectionEvent *ev, int i
static void setTestBug299(EngineTestHelper *eth) {
setupSimpleTestEngineWithMafAndTT_ONE_trigger(eth);
EXPECT_CALL(eth->mockAirmass, getAirmass(_))
EXPECT_CALL(*eth->mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008001f, 50.0f}));
Engine *engine = &eth->engine;
@ -892,7 +892,7 @@ TEST(big, testFuelSchedulerBug299smallAndMedium) {
TEST(big, testTwoWireBatch) {
EngineTestHelper eth(TEST_ENGINE);
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
engineConfiguration->injectionMode = IM_BATCH;
@ -919,7 +919,7 @@ TEST(big, testTwoWireBatch) {
TEST(big, testSequential) {
EngineTestHelper eth(TEST_ENGINE);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
EXPECT_CALL(*eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);

View File

@ -15,7 +15,7 @@ PCHSUB = unit_tests
include $(PROJECT_DIR)/rusefi_rules.mk
ifneq ($(OS),Windows_NT)
# at the moment lib asan breaks JNI static library
# at the moment lib asan breaks JNI library
SANITIZE = no
else
SANITIZE = no