mirror of https://github.com/rusefi/rusefi.git
avoid UB in tests
This commit is contained in:
parent
54572658f1
commit
a50fdf34d4
|
@ -44,8 +44,8 @@ static int CHANNEL_FLAGS[] = { 0x13458b, 0x0000ff, 0x00a0f9, 0x00ffff, 0x00ff00,
|
|||
|
||||
static FILE *ptr;
|
||||
|
||||
static int realDurationInSamples;
|
||||
static int scaledDurationInSamples;
|
||||
static uint32_t realDurationInSamples;
|
||||
static uint32_t scaledDurationInSamples;
|
||||
|
||||
static void writeByte(uint8_t value) {
|
||||
fwrite(&value, 1, sizeof(value), ptr);
|
||||
|
@ -214,7 +214,7 @@ static void writeChannelData(int ch, int64_t *chDeltas, int chLastState,
|
|||
write(1);
|
||||
write(lastRecord);
|
||||
|
||||
int numSamplesLeft = realDurationInSamples - lastRecord;
|
||||
uint32_t numSamplesLeft = realDurationInSamples - lastRecord;
|
||||
write(numSamplesLeft);
|
||||
|
||||
write(chLastState);
|
||||
|
@ -389,12 +389,12 @@ static int getChannelState(int ch, const CompositeEvent* event) {
|
|||
}
|
||||
|
||||
static void writeEvents(const std::vector<CompositeEvent>& events) {
|
||||
int count = events.size();
|
||||
size_t count = events.size();
|
||||
// we need at least 2 records
|
||||
if (count < 2)
|
||||
return;
|
||||
int firstRecordTs = events[1].timestamp;
|
||||
int lastRecordTs = events[count - 1].timestamp;
|
||||
uint32_t firstRecordTs = events[1].timestamp;
|
||||
uint32_t lastRecordTs = events[count - 1].timestamp;
|
||||
// we don't know the total duration, so we create a margin after the last record which equals to the duration of the first event
|
||||
realDurationInSamples = lastRecordTs + firstRecordTs;
|
||||
scaledDurationInSamples = realDurationInSamples / 4;
|
||||
|
@ -406,20 +406,20 @@ static void writeEvents(const std::vector<CompositeEvent>& events) {
|
|||
bool useLongDeltas = false;
|
||||
for (int ch = 0; ch < numChannels; ch++) {
|
||||
int chPrevState = -1;
|
||||
int prevTs = 0;
|
||||
uint32_t prevTs = 0;
|
||||
int deltaCount = 0;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
const CompositeEvent* event = &events[i];
|
||||
|
||||
int chState = getChannelState(ch, event);
|
||||
int ts = event->timestamp;
|
||||
uint32_t ts = event->timestamp;
|
||||
|
||||
if (chPrevState == -1) {
|
||||
chPrevState = chState;
|
||||
}
|
||||
if (chState != chPrevState) {
|
||||
long delta = ts - prevTs;
|
||||
int64_t delta = ts - prevTs;
|
||||
if (delta > 0x7fff) {
|
||||
useLongDeltas = true;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
struct CompositeEvent {
|
||||
int timestamp;
|
||||
uint32_t timestamp;
|
||||
bool primaryTrigger;
|
||||
bool secondaryTrigger;
|
||||
bool isTDC;
|
||||
|
|
|
@ -165,6 +165,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
);
|
||||
|
||||
TEST_P(FlowRateFixture, PressureRatio) {
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
float pressureRatio = GetParam();
|
||||
// Flow ratio should be the sqrt of pressure ratio
|
||||
float expectedFlowRatio = sqrtf(pressureRatio);
|
||||
|
@ -172,8 +174,6 @@ TEST_P(FlowRateFixture, PressureRatio) {
|
|||
StrictMock<TesterGetRailPressure> dut;
|
||||
EXPECT_CALL(dut, getFuelDifferentialPressure()).WillOnce(Return(400 * pressureRatio));
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
// Use injector compensation
|
||||
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
||||
|
||||
|
@ -185,10 +185,10 @@ TEST_P(FlowRateFixture, PressureRatio) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, NegativePressureDelta) {
|
||||
StrictMock<TesterGetRailPressure> dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
StrictMock<TesterGetRailPressure> dut;
|
||||
|
||||
// Use injector compensation
|
||||
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
||||
|
||||
|
@ -202,10 +202,10 @@ TEST(InjectorModel, NegativePressureDelta) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, VariableInjectorFlowModeNone) {
|
||||
StrictMock<TesterGetRailPressure> dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
StrictMock<TesterGetRailPressure> dut;
|
||||
|
||||
engineConfiguration->injectorCompensationMode = ICM_None;
|
||||
|
||||
// This shoudn't call getFuelDifferentialPressure, it should just return 1.0
|
||||
|
@ -213,10 +213,10 @@ TEST(InjectorModel, VariableInjectorFlowModeNone) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, RailPressureFixed) {
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
// Reference pressure is 350kpa
|
||||
engineConfiguration->fuelReferencePressure = 350;
|
||||
engineConfiguration->injectorCompensationMode = ICM_FixedRailPressure;
|
||||
|
@ -232,10 +232,10 @@ TEST(InjectorModel, RailPressureFixed) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, RailPressureSensedAbsolute) {
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
// Reference pressure is 350kpa
|
||||
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
||||
engineConfiguration->fuelPressureSensorMode = FPM_Absolute;
|
||||
|
@ -252,10 +252,10 @@ TEST(InjectorModel, RailPressureSensedAbsolute) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, RailPressureSensedGauge) {
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
// Reference pressure is 350kpa
|
||||
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
||||
engineConfiguration->fuelPressureSensorMode = FPM_Gauge;
|
||||
|
@ -273,10 +273,10 @@ TEST(InjectorModel, RailPressureSensedGauge) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, RailPressureSensedDifferential) {
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
// Reference pressure is 350kpa
|
||||
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
||||
engineConfiguration->fuelPressureSensorMode = FPM_Differential;
|
||||
|
@ -291,10 +291,10 @@ TEST(InjectorModel, RailPressureSensedDifferential) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, FailedPressureSensor) {
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
// Reference pressure is 350kpa
|
||||
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
||||
|
||||
|
@ -309,10 +309,10 @@ TEST(InjectorModel, FailedPressureSensor) {
|
|||
}
|
||||
|
||||
TEST(InjectorModel, MissingPressureSensor) {
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
InjectorModelPrimary dut;
|
||||
|
||||
// Reference pressure is 350kpa
|
||||
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ TEST(SensorInit, TpsValuesTooClose) {
|
|||
Sensor::resetRegistry();
|
||||
|
||||
// Test a random bogus pin index, shouldn't fail
|
||||
engineConfiguration->tps1_1AdcChannel = static_cast<adc_channel_e>(175);
|
||||
engineConfiguration->tps1_1AdcChannel = static_cast<adc_channel_e>(EFI_ADC_ERROR);
|
||||
engineConfiguration->tpsMin = 200; // 1.00 volt
|
||||
engineConfiguration->tpsMax = 200; // 1.00 volt
|
||||
EXPECT_NO_FATAL_ERROR(initTps());
|
||||
|
|
|
@ -329,18 +329,15 @@ TEST(trigger, testTriggerDecoder) {
|
|||
printf("====================================================================================== testTriggerDecoder\r\n");
|
||||
|
||||
{
|
||||
persistent_config_s c;
|
||||
Engine e;
|
||||
EngineTestHelperBase base(&e, &c.engineConfiguration, &c);
|
||||
TriggerWaveform * s = &e.triggerCentral.triggerShape;
|
||||
|
||||
initializeSkippedToothTrigger(s, 2, 0, FOUR_STROKE_CAM_SENSOR, SyncEdge::Rise);
|
||||
assertEqualsM("shape size", s->getSize(), 4);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(0), 0.25);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(1), 0.5);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(2), 0.75);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(3), 1);
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
TriggerWaveform * s = &engine->triggerCentral.triggerShape;
|
||||
|
||||
initializeSkippedToothTrigger(s, 2, 0, FOUR_STROKE_CAM_SENSOR, SyncEdge::Rise);
|
||||
assertEqualsM("shape size", s->getSize(), 4);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(0), 0.25);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(1), 0.5);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(2), 0.75);
|
||||
ASSERT_EQ(s->wave.getSwitchTime(3), 1);
|
||||
}
|
||||
|
||||
printf("====================================================================================== testTriggerDecoder part 2\r\n");
|
||||
|
|
Loading…
Reference in New Issue