rusefi-1/unit_tests/tests/sensor/test_frequency_sensor.cpp

71 lines
1.6 KiB
C++
Raw Normal View History

2021-08-01 20:21:53 -07:00
#include "pch.h"
#include "frequency_sensor.h"
#include "sensor_type.h"
// Fake converter just passes value straight though
struct IdentityFunction : public SensorConverter {
SensorResult convert(float raw) const {
return raw;
}
};
static IdentityFunction identityFunc;
class FrequencySensorTest : public ::testing::Test {
public:
FrequencySensorTest()
: dut(SensorType::FuelEthanolPercent, MS2NT(50))
{
}
void SetUp() override {
// If somehow prodcode will be unwrapped for test it MAYBE! will fire with error.
// At least we must init FlexSensor somehow
Vehicle speed switching to frequency sensor #3106 (#3148) * Add vehicle_speed_converter.h with realization. * Add test_vehicle_speed_converter.cpp with realization. * Add test_vehicle_speed_converter.cpp to Makefile * Edit "VehicleSpeedSensor" from function pointer sensor to frequency sensor * Fix "VehicleSpeedSensor" init function args * Remove "VehicleSpeedConverter" empty constructor * Edit vehicle_speed_converter.h code style * Fix args and engine injection in "VehicleSpeedSensor" initialization procedure * Remove old "Vehicle Speed" module initialization * Revert "Remove old "Vehicle Speed" module initialization" This reverts commit 100b7caa8c615c20eed3d0c23a49824b4e556148. * Remove old "Vehicle Speed" module initialization pieces * Revert "Revert "Remove old "Vehicle Speed" module initialization"" This reverts commit f559a726f1f7f5a7acacd1b6517e571743e84327. * Debug changes * Revert "Debug changes" This reverts commit f7e2be1a8a46c6f3f93f14f002b2f2db539da8e2. * Another debug changes * More debug changes * And more debug changes. * Revert "Another debug changes" This reverts commit 914fbb1df42c37e4b5ecbb119bb45e7cffdf4064. * Revert "More debug changes" This reverts commit 0b2d96d461c3cd9b0f1ae97ed110b8effe6b0cc6. * Revert "And more debug changes." This reverts commit 06ae8daded0e6e1c025e4e5058b47283f4adfe92. * Add "Vehicle Speed" sensor reconfiguration * Revert "Add "Vehicle Speed" sensor reconfiguration" This reverts commit a089a6d563dd710004ce1a7da1744b0b4b90c3b1. * Revert "Revert "Add "Vehicle Speed" sensor reconfiguration"" This reverts commit 7b2bb8af4b3caa547236ca59e4c4bdb3ac1200cc. * Debug changes * Another debug changes * Fix another debug changes * Another debug changes 2 * Revert "Another debug changes 2" This reverts commit cfad55141eec125b2f1d35fb95d9f46b54f666b6. * Revert "Fix another debug changes" This reverts commit 9bc2c74a3be6fd896827ff48cf4580e7657529c0. * Revert "Another debug changes" This reverts commit 4337ed8cad8dff508d093944eb3f75e9a69e4a77. * Edit class FrequencySensor, make it more RAII * Debug changes * Debug changes 2 * Debug changes 3 * Revert "Debug changes 3" This reverts commit 52a7054c122b5157540fe45a055a84b57478d722. * Revert "Debug changes 2" This reverts commit dec79fb913344ccb4b8614910ad62e6c129a243e. * Revert "Debug changes" This reverts commit eb08d7a529b55ba397a7dd2c154b76eab42f212b. * Revert "Edit class FrequencySensor, make it more RAII" This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Citroen Berlingo" engine config. This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Dodge Neon" engine config Co-authored-by: alxrMironov <330OMcorporative>
2021-08-23 21:55:41 -07:00
dut.init(GPIO_INVALID, "Test");
2021-08-01 20:21:53 -07:00
dut.setFunction(identityFunc);
}
/*
* This method must simulate some amount periods of square-wave
* and fire callback on every falling edge.
* (as Sensor works by falling edge)
*/
void generatePwm(EngineTestHelper &eth, float freqHz) {
constexpr auto periods = 50;
auto period = (1 / freqHz);
std::cout << "PERIOD: " << period << std::endl;
for (auto i = 0; i < periods; i++) {
eth.moveTimeForwardSec(period);
dut.onEdge(getTimeNowNt());
}
}
FrequencySensor dut;
};
/*
* Sensor must take PWM input on "valid" frequency and generate any input.
*/
TEST_F(FrequencySensorTest, testValidWithPwm) {
ASSERT_TRUE(dut.Register());
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// Should be invalid - not set yet
{
auto s = Sensor::get(SensorType::FuelEthanolPercent);
EXPECT_FALSE(s.Valid);
}
generatePwm(eth, 10);
// Should be valid, correct frequency
{
auto s = Sensor::get(SensorType::FuelEthanolPercent);
EXPECT_TRUE(s.Valid);
EXPECT_FLOAT_EQ(s.Value, 10);
}
}