blob: 804d84a33bacd62ac86dd778c181a777e10aba94 [file] [log] [blame]
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07001#include "pid/ec/pid.hpp"
Patrick Venture3349ef22018-06-12 14:09:29 -07002#include "pid/thermalcontroller.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07003#include "test/zone_mock.hpp"
Patrick Venture3349ef22018-06-12 14:09:29 -07004
Patrick Venture3349ef22018-06-12 14:09:29 -07005#include <string>
6#include <vector>
7
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07008#include <gmock/gmock.h>
9#include <gtest/gtest.h>
Patrick Venture3349ef22018-06-12 14:09:29 -070010
11using ::testing::Return;
12using ::testing::StrEq;
13
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070014TEST(ThermalControllerTest, BoringFactoryTest)
15{
Patrick Venture3349ef22018-06-12 14:09:29 -070016 // Verifies building a ThermalPIDController with the factory works as
17 // expected in the boring (uninteresting) case.
18
19 ZoneMock z;
20
21 std::vector<std::string> inputs = {"fleeting0"};
Patrick Venture5f59c0f2018-11-11 12:55:14 -080022 double setpoint = 10.0;
Patrick Venture3349ef22018-06-12 14:09:29 -070023 ec::pidinfo initial;
24
Patrick Venture563a3562018-10-30 09:31:26 -070025 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
James Feist734f9532018-11-15 12:13:18 -080026 &z, "therm1", inputs, setpoint, initial, ThermalType::margin);
Patrick Venture3349ef22018-06-12 14:09:29 -070027 // Success
28 EXPECT_FALSE(p == nullptr);
29}
30
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070031TEST(ThermalControllerTest, VerifyFactoryFailsWithZeroInputs)
32{
Patrick Venture3349ef22018-06-12 14:09:29 -070033 // A thermal controller needs at least one input.
34
35 ZoneMock z;
36
37 std::vector<std::string> inputs = {};
Patrick Venture5f59c0f2018-11-11 12:55:14 -080038 double setpoint = 10.0;
Patrick Venture3349ef22018-06-12 14:09:29 -070039 ec::pidinfo initial;
James Feist734f9532018-11-15 12:13:18 -080040 std::unique_ptr<PIDController> p;
41 EXPECT_THROW(
42 {
43 p = ThermalController::createThermalPid(
44 &z, "therm1", inputs, setpoint, initial, ThermalType::margin);
45 },
46 std::exception);
Patrick Venture3349ef22018-06-12 14:09:29 -070047 EXPECT_TRUE(p == nullptr);
48}
49
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050TEST(ThermalControllerTest, InputProc_BehavesAsExpected)
51{
Patrick Venture563a3562018-10-30 09:31:26 -070052 // This test just verifies inputProc behaves as expected.
Patrick Venture3349ef22018-06-12 14:09:29 -070053
54 ZoneMock z;
55
56 std::vector<std::string> inputs = {"fleeting0"};
Patrick Venture5f59c0f2018-11-11 12:55:14 -080057 double setpoint = 10.0;
Patrick Venture3349ef22018-06-12 14:09:29 -070058 ec::pidinfo initial;
59
Patrick Venture563a3562018-10-30 09:31:26 -070060 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
James Feist734f9532018-11-15 12:13:18 -080061 &z, "therm1", inputs, setpoint, initial, ThermalType::margin);
Patrick Venture3349ef22018-06-12 14:09:29 -070062 EXPECT_FALSE(p == nullptr);
63
64 EXPECT_CALL(z, getCachedValue(StrEq("fleeting0"))).WillOnce(Return(5.0));
65
Patrick Venture563a3562018-10-30 09:31:26 -070066 EXPECT_EQ(5.0, p->inputProc());
Patrick Venture3349ef22018-06-12 14:09:29 -070067}
68
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070069TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected)
70{
Patrick Venture563a3562018-10-30 09:31:26 -070071 // This test just verifies inputProc behaves as expected.
Patrick Venture3349ef22018-06-12 14:09:29 -070072
73 ZoneMock z;
74
75 std::vector<std::string> inputs = {"fleeting0"};
Patrick Venture5f59c0f2018-11-11 12:55:14 -080076 double setpoint = 10.0;
Patrick Venture3349ef22018-06-12 14:09:29 -070077 ec::pidinfo initial;
78
Patrick Venture563a3562018-10-30 09:31:26 -070079 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
James Feist734f9532018-11-15 12:13:18 -080080 &z, "therm1", inputs, setpoint, initial, ThermalType::margin);
Patrick Venture3349ef22018-06-12 14:09:29 -070081 EXPECT_FALSE(p == nullptr);
82
Patrick Venture563a3562018-10-30 09:31:26 -070083 EXPECT_EQ(setpoint, p->setptProc());
Patrick Venture3349ef22018-06-12 14:09:29 -070084}
85
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070086TEST(ThermalControllerTest, OutputProc_BehavesAsExpected)
87{
James Feist734f9532018-11-15 12:13:18 -080088 // This test just verifies outputProc behaves as expected.
Patrick Venture3349ef22018-06-12 14:09:29 -070089
90 ZoneMock z;
91
92 std::vector<std::string> inputs = {"fleeting0"};
Patrick Venture5f59c0f2018-11-11 12:55:14 -080093 double setpoint = 10.0;
Patrick Venture3349ef22018-06-12 14:09:29 -070094 ec::pidinfo initial;
95
Patrick Venture563a3562018-10-30 09:31:26 -070096 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
James Feist734f9532018-11-15 12:13:18 -080097 &z, "therm1", inputs, setpoint, initial, ThermalType::margin);
Patrick Venture3349ef22018-06-12 14:09:29 -070098 EXPECT_FALSE(p == nullptr);
99
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800100 double value = 90.0;
Patrick Venture3349ef22018-06-12 14:09:29 -0700101 EXPECT_CALL(z, addRPMSetPoint(value));
102
Patrick Venture563a3562018-10-30 09:31:26 -0700103 p->outputProc(value);
Patrick Venture3349ef22018-06-12 14:09:29 -0700104}
James Feist734f9532018-11-15 12:13:18 -0800105
106TEST(ThermalControllerTest, InputProc_MultipleInputsAbsolute)
107{
108 // This test verifies inputProc behaves as expected with multiple absolute
109 // inputs.
110
111 ZoneMock z;
112
113 std::vector<std::string> inputs = {"fleeting0", "fleeting1"};
114 double setpoint = 10.0;
115 ec::pidinfo initial;
116
117 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
118 &z, "therm1", inputs, setpoint, initial, ThermalType::absolute);
119 EXPECT_FALSE(p == nullptr);
120
121 EXPECT_CALL(z, getCachedValue(StrEq("fleeting0"))).WillOnce(Return(5.0));
122 EXPECT_CALL(z, getCachedValue(StrEq("fleeting1"))).WillOnce(Return(10.0));
123
124 EXPECT_EQ(10.0, p->inputProc());
125}
126
127TEST(ThermalControllerTest, InputProc_MultipleInputsMargin)
128{
129 // This test verifies inputProc behaves as expected with multiple margin
130 // inputs.
131
132 ZoneMock z;
133
134 std::vector<std::string> inputs = {"fleeting0", "fleeting1"};
135 double setpoint = 10.0;
136 ec::pidinfo initial;
137
138 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
139 &z, "therm1", inputs, setpoint, initial, ThermalType::margin);
140 EXPECT_FALSE(p == nullptr);
141
142 EXPECT_CALL(z, getCachedValue(StrEq("fleeting0"))).WillOnce(Return(5.0));
143 EXPECT_CALL(z, getCachedValue(StrEq("fleeting1"))).WillOnce(Return(10.0));
144
145 EXPECT_EQ(5.0, p->inputProc());
146}