LCOV - code coverage report
Current view: top level - unit_tests/tests - test_lambda_monitor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 37 97.3 %
Date: 2024-04-22 23:59:02 Functions: 7 8 87.5 %

          Line data    Source code
       1             : #include "pch.h"
       2             : 
       3             : struct MockLambdaMonitor : public LambdaMonitorBase {
       4             :         bool isGood = true;
       5           6 :         bool isCurrentlyGood(float /*rpm*/, float /*load*/) const override {
       6           6 :                 return isGood;
       7             :         }
       8             : 
       9             :         bool isRestore = false;
      10           3 :         bool restoreConditionsMet(float /*rpm*/, float /*load*/) const override {
      11           3 :                 return isRestore;
      12             :         }
      13             : 
      14           6 :         float getTimeout() const override {
      15             :                 // Timeout of 1 second
      16           6 :                 return 1;
      17             :         }
      18             : 
      19           0 :         MOCK_METHOD(float, getMaxAllowedLambda, (float rpm, float load), (const, override));
      20             : };
      21             : 
      22           4 : TEST(LambdaMonitor, Response) {
      23           1 :         MockLambdaMonitor mlm;
      24             : 
      25             :         extern int timeNowUs;
      26           1 :         int startTime = 1e6;
      27           1 :         timeNowUs = startTime;
      28             : 
      29           1 :         mlm.isGood = true;
      30           1 :         mlm.isRestore = false;
      31           1 :         mlm.update(2000, 50);
      32           1 :         EXPECT_TRUE(mlm.lambdaCurrentlyGood);
      33           1 :         EXPECT_FALSE(mlm.isCut());
      34             : 
      35             :         // now lambda will be bad, but we don't cut yet
      36           1 :         mlm.isGood = false;
      37           1 :         mlm.update(2000, 50);
      38           1 :         EXPECT_FALSE(mlm.lambdaCurrentlyGood);
      39           1 :         EXPECT_FALSE(mlm.isCut());
      40             : 
      41             :         // 0.9 second later, still not cut
      42           1 :         timeNowUs = startTime + 0.9e6;
      43           1 :         mlm.update(2000, 50);
      44           1 :         EXPECT_FALSE(mlm.lambdaCurrentlyGood);
      45           1 :         EXPECT_FALSE(mlm.isCut());
      46             : 
      47             :         // 1.1 second later, cut!
      48           1 :         timeNowUs = startTime + 1.1e6;
      49           1 :         mlm.update(2000, 50);
      50           1 :         EXPECT_FALSE(mlm.lambdaCurrentlyGood);
      51           1 :         EXPECT_TRUE(mlm.isCut());
      52             : 
      53             :         // Lambda goes back to normal, but restore conditions not met so we should stay cut
      54           1 :         mlm.isGood = true;
      55           1 :         mlm.update(2000, 50);
      56           1 :         EXPECT_TRUE(mlm.lambdaCurrentlyGood);
      57           1 :         EXPECT_TRUE(mlm.isCut());
      58             : 
      59           1 :         mlm.isRestore = true;
      60           1 :         mlm.update(2000, 50);
      61           1 :         EXPECT_TRUE(mlm.lambdaCurrentlyGood);
      62           1 :         EXPECT_FALSE(mlm.isCut());
      63           2 : }

Generated by: LCOV version 1.14