1 #include "pid/thermalcontroller.hpp" 2 3 #include <gmock/gmock.h> 4 #include <gtest/gtest.h> 5 #include <string> 6 #include <vector> 7 8 #include "pid/ec/pid.hpp" 9 #include "test/zone_mock.hpp" 10 11 using ::testing::Return; 12 using ::testing::StrEq; 13 14 TEST(ThermalControllerTest, BoringFactoryTest) { 15 // Verifies building a ThermalPIDController with the factory works as 16 // expected in the boring (uninteresting) case. 17 18 ZoneMock z; 19 20 std::vector<std::string> inputs = {"fleeting0"}; 21 float setpoint = 10.0; 22 ec::pidinfo initial; 23 24 std::unique_ptr<PIDController> p = 25 ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, 26 initial); 27 // Success 28 EXPECT_FALSE(p == nullptr); 29 } 30 31 TEST(ThermalControllerTest, VerifyFactoryFailsWithZeroInputs) { 32 // A thermal controller needs at least one input. 33 34 ZoneMock z; 35 36 std::vector<std::string> inputs = {}; 37 float setpoint = 10.0; 38 ec::pidinfo initial; 39 40 std::unique_ptr<PIDController> p = 41 ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, 42 initial); 43 EXPECT_TRUE(p == nullptr); 44 } 45 46 TEST(ThermalControllerTest, VerifyFactoryFailsForMoreThanOneInput) { 47 // ThermalControllers currently only support one input, so don't let 48 // someone accidentally specify more. 49 50 ZoneMock z; 51 52 std::vector<std::string> inputs = {"fleeting0", "asdf"}; 53 float setpoint = 10.0; 54 ec::pidinfo initial; 55 56 std::unique_ptr<PIDController> p = 57 ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, 58 initial); 59 EXPECT_TRUE(p == nullptr); 60 } 61 62 TEST(ThermalControllerTest, InputProc_BehavesAsExpected) { 63 // This test just verifies input_proc behaves as expected. 64 65 ZoneMock z; 66 67 std::vector<std::string> inputs = {"fleeting0"}; 68 float setpoint = 10.0; 69 ec::pidinfo initial; 70 71 std::unique_ptr<PIDController> p = 72 ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, 73 initial); 74 EXPECT_FALSE(p == nullptr); 75 76 EXPECT_CALL(z, getCachedValue(StrEq("fleeting0"))).WillOnce(Return(5.0)); 77 78 EXPECT_EQ(5.0, p->input_proc()); 79 } 80 81 TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected) { 82 // This test just verifies input_proc behaves as expected. 83 84 ZoneMock z; 85 86 std::vector<std::string> inputs = {"fleeting0"}; 87 float setpoint = 10.0; 88 ec::pidinfo initial; 89 90 std::unique_ptr<PIDController> p = 91 ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, 92 initial); 93 EXPECT_FALSE(p == nullptr); 94 95 EXPECT_EQ(setpoint, p->setpt_proc()); 96 } 97 98 TEST(ThermalControllerTest, OutputProc_BehavesAsExpected) { 99 // This test just verifies input_proc behaves as expected. 100 101 ZoneMock z; 102 103 std::vector<std::string> inputs = {"fleeting0"}; 104 float setpoint = 10.0; 105 ec::pidinfo initial; 106 107 std::unique_ptr<PIDController> p = 108 ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, 109 initial); 110 EXPECT_FALSE(p == nullptr); 111 112 float value = 90.0; 113 EXPECT_CALL(z, addRPMSetPoint(value)); 114 115 p->output_proc(value); 116 } 117