LCOV - code coverage report
Current view: top level - unit_tests/tests - test_gpio.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 54 54 100.0 %
Date: 2024-04-22 23:59:02 Functions: 24 24 100.0 %

          Line data    Source code
       1             : #include "pch.h"
       2             : 
       3           4 : TEST(gpio, testPinInitNonInverted) {
       4           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
       5             : 
       6           1 :         OutputPin dut;
       7             : 
       8             :         // Set the "hardware" pin to on initially
       9           1 :         setMockState(Gpio::A6, true);
      10           1 :         ASSERT_TRUE(efiReadPin(Gpio::A6));
      11             : 
      12             :         // this should turn it off
      13           1 :         pin_output_mode_e mode = OM_DEFAULT;
      14           1 :         dut.initPin("test", Gpio::A6, mode);
      15             : 
      16           1 :         EXPECT_FALSE(efiReadPin(Gpio::A6));
      17           1 : }
      18             : 
      19           4 : TEST(gpio, testPinInitInverted) {
      20           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      21             : 
      22           1 :         OutputPin dut;
      23             : 
      24             :         // Set the "hardware" pin to off initially
      25           1 :         setMockState(Gpio::A6, false);
      26           1 :         ASSERT_FALSE(efiReadPin(Gpio::A6));
      27             : 
      28             :         // this should turn it off
      29           1 :         pin_output_mode_e mode = OM_INVERTED;
      30           1 :         dut.initPin("test", Gpio::A6, mode);
      31             : 
      32           1 :         EXPECT_TRUE(efiReadPin(Gpio::A6));
      33           1 : }
      34             : 
      35           4 : TEST(gpio, multipleInit) {
      36           1 :         OutputPin dut;
      37             : 
      38             :         // Initial setup should be ok
      39           1 :         EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", Gpio::A6));
      40             : 
      41             :         // Reinit with the same pin should be ok
      42           1 :         EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", Gpio::A6));
      43             : 
      44             :         // Reinit with DIFFERENT pin should fail
      45           1 :         EXPECT_FATAL_ERROR(dut.initPin("testPin", Gpio::B5));
      46           1 : }
      47             : 
      48           4 : TEST(gpio, deInit) {
      49           1 :         OutputPin dut;
      50             : 
      51             :         // Initial setup should be ok
      52           1 :         EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", Gpio::A6));
      53             : 
      54           1 :         dut.deInit();
      55             : 
      56             :         // Reinit with DIFFERENT pin should work after deinit
      57           1 :         EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", Gpio::B5));
      58           1 : }
      59             : 
      60           4 : TEST(gpio, pinSetNotInverted) {
      61           1 :         OutputPin dut;
      62             : 
      63           1 :         pin_output_mode_e mode = OM_DEFAULT;
      64           1 :         dut.initPin("test", Gpio::A6, mode);
      65             : 
      66             :         // Initial state should be logic 0
      67           1 :         EXPECT_FALSE(efiReadPin(Gpio::A6));
      68             : 
      69           1 :         dut.setValue(true);
      70           1 :         EXPECT_TRUE(efiReadPin(Gpio::A6));
      71           1 :         EXPECT_TRUE(dut.getLogicValue());
      72             : 
      73           1 :         dut.setValue(false);
      74           1 :         EXPECT_FALSE(efiReadPin(Gpio::A6));
      75           1 :         EXPECT_FALSE(dut.getLogicValue());
      76           1 : }
      77             : 
      78           4 : TEST(gpio, pinSetInverted) {
      79           1 :         OutputPin dut;
      80             : 
      81           1 :         pin_output_mode_e mode = OM_INVERTED;
      82           1 :         dut.initPin("test", Gpio::A6, mode);
      83             : 
      84             :         // Initial state should be logic 0
      85           1 :         EXPECT_TRUE(efiReadPin(Gpio::A6));
      86             : 
      87           1 :         dut.setValue(true);
      88           1 :         EXPECT_FALSE(efiReadPin(Gpio::A6));
      89           1 :         EXPECT_TRUE(dut.getLogicValue());
      90             : 
      91           1 :         dut.setValue(false);
      92           1 :         EXPECT_TRUE(efiReadPin(Gpio::A6));
      93           1 :         EXPECT_FALSE(dut.getLogicValue());
      94           1 : }

Generated by: LCOV version 1.14