blob: 386c779b9aea382a0d5d40da157fc91e08abe888 [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"};
22 float setpoint = 10.0;
23 ec::pidinfo initial;
24
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid(
26 &z, "therm1", inputs, setpoint, initial);
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 = {};
38 float setpoint = 10.0;
39 ec::pidinfo initial;
40
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070041 std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid(
42 &z, "therm1", inputs, setpoint, initial);
Patrick Venture3349ef22018-06-12 14:09:29 -070043 EXPECT_TRUE(p == nullptr);
44}
45
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046TEST(ThermalControllerTest, VerifyFactoryFailsForMoreThanOneInput)
47{
Patrick Venture3349ef22018-06-12 14:09:29 -070048 // ThermalControllers currently only support one input, so don't let
49 // someone accidentally specify more.
50
51 ZoneMock z;
52
53 std::vector<std::string> inputs = {"fleeting0", "asdf"};
54 float setpoint = 10.0;
55 ec::pidinfo initial;
56
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070057 std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid(
58 &z, "therm1", inputs, setpoint, initial);
Patrick Venture3349ef22018-06-12 14:09:29 -070059 EXPECT_TRUE(p == nullptr);
60}
61
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070062TEST(ThermalControllerTest, InputProc_BehavesAsExpected)
63{
Patrick Venture3349ef22018-06-12 14:09:29 -070064 // This test just verifies input_proc behaves as expected.
65
66 ZoneMock z;
67
68 std::vector<std::string> inputs = {"fleeting0"};
69 float setpoint = 10.0;
70 ec::pidinfo initial;
71
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070072 std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid(
73 &z, "therm1", inputs, setpoint, initial);
Patrick Venture3349ef22018-06-12 14:09:29 -070074 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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070081TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected)
82{
Patrick Venture3349ef22018-06-12 14:09:29 -070083 // This test just verifies input_proc behaves as expected.
84
85 ZoneMock z;
86
87 std::vector<std::string> inputs = {"fleeting0"};
88 float setpoint = 10.0;
89 ec::pidinfo initial;
90
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070091 std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid(
92 &z, "therm1", inputs, setpoint, initial);
Patrick Venture3349ef22018-06-12 14:09:29 -070093 EXPECT_FALSE(p == nullptr);
94
95 EXPECT_EQ(setpoint, p->setpt_proc());
96}
97
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070098TEST(ThermalControllerTest, OutputProc_BehavesAsExpected)
99{
Patrick Venture3349ef22018-06-12 14:09:29 -0700100 // This test just verifies input_proc behaves as expected.
101
102 ZoneMock z;
103
104 std::vector<std::string> inputs = {"fleeting0"};
105 float setpoint = 10.0;
106 ec::pidinfo initial;
107
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700108 std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid(
109 &z, "therm1", inputs, setpoint, initial);
Patrick Venture3349ef22018-06-12 14:09:29 -0700110 EXPECT_FALSE(p == nullptr);
111
112 float value = 90.0;
113 EXPECT_CALL(z, addRPMSetPoint(value));
114
115 p->output_proc(value);
116}