blob: 97550f8c4b8ccc854a2ab4a795e84f9547dd4ef8 [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 Venture563a3562018-10-30 09:31:26 -070025 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070026 &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 Venture563a3562018-10-30 09:31:26 -070041 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042 &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 Venture563a3562018-10-30 09:31:26 -070057 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070058 &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 Venture563a3562018-10-30 09:31:26 -070064 // This test just verifies inputProc behaves as expected.
Patrick Venture3349ef22018-06-12 14:09:29 -070065
66 ZoneMock z;
67
68 std::vector<std::string> inputs = {"fleeting0"};
69 float setpoint = 10.0;
70 ec::pidinfo initial;
71
Patrick Venture563a3562018-10-30 09:31:26 -070072 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070073 &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
Patrick Venture563a3562018-10-30 09:31:26 -070078 EXPECT_EQ(5.0, p->inputProc());
Patrick Venture3349ef22018-06-12 14:09:29 -070079}
80
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070081TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected)
82{
Patrick Venture563a3562018-10-30 09:31:26 -070083 // This test just verifies inputProc behaves as expected.
Patrick Venture3349ef22018-06-12 14:09:29 -070084
85 ZoneMock z;
86
87 std::vector<std::string> inputs = {"fleeting0"};
88 float setpoint = 10.0;
89 ec::pidinfo initial;
90
Patrick Venture563a3562018-10-30 09:31:26 -070091 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070092 &z, "therm1", inputs, setpoint, initial);
Patrick Venture3349ef22018-06-12 14:09:29 -070093 EXPECT_FALSE(p == nullptr);
94
Patrick Venture563a3562018-10-30 09:31:26 -070095 EXPECT_EQ(setpoint, p->setptProc());
Patrick Venture3349ef22018-06-12 14:09:29 -070096}
97
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070098TEST(ThermalControllerTest, OutputProc_BehavesAsExpected)
99{
Patrick Venture563a3562018-10-30 09:31:26 -0700100 // This test just verifies inputProc behaves as expected.
Patrick Venture3349ef22018-06-12 14:09:29 -0700101
102 ZoneMock z;
103
104 std::vector<std::string> inputs = {"fleeting0"};
105 float setpoint = 10.0;
106 ec::pidinfo initial;
107
Patrick Venture563a3562018-10-30 09:31:26 -0700108 std::unique_ptr<PIDController> p = ThermalController::createThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700109 &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
Patrick Venture563a3562018-10-30 09:31:26 -0700115 p->outputProc(value);
Patrick Venture3349ef22018-06-12 14:09:29 -0700116}