blob: 3345163f42eb187f7c928ed7045d10cc43a4c9bb [file] [log] [blame]
Patrick Venture5426c342019-02-11 12:03:30 -08001#include "build/buildjson.hpp"
2#include "errors/exception.hpp"
3
4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
6
Patrick Venturea0764872020-08-08 07:48:43 -07007namespace pid_control
8{
9namespace
10{
11
Patrick Venture5426c342019-02-11 12:03:30 -080012TEST(ConfigurationVerificationTest, VerifyHappy)
13{
14 /* Verify a happy configuration throws no exceptions. */
15 auto j2 = R"(
16 {
17 "sensors": [{
18 "name": "fan1",
19 "type": "fan",
20 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
21 }],
22 "zones": [{
23 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -080024 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -080025 "failsafePercent": 75.0,
26 "pids": [{
27 "name": "fan1-5",
28 "type": "fan",
29 "inputs": ["fan1", "fan5"],
30 "setpoint": 90.0,
31 "pid": {
32 "samplePeriod": 0.1,
33 "proportionalCoeff": 0.0,
34 "integralCoeff": 0.0,
Patrick Venture903b0422019-02-20 07:35:48 -080035 "feedFwdOffsetCoeff": 0.0,
Patrick Venture5426c342019-02-11 12:03:30 -080036 "feedFwdGainCoeff": 0.010,
37 "integralLimit_min": 0.0,
38 "integralLimit_max": 0.0,
39 "outLim_min": 30.0,
40 "outLim_max": 100.0,
41 "slewNeg": 0.0,
42 "slewPos": 0.0
43 }
44 }]
45 }]
46 }
47 )"_json;
48
49 validateJson(j2);
50}
51
52TEST(ConfigurationVerificationTest, VerifyNoSensorKey)
53{
54 /* Verify the sensors key must be present. */
55 auto j2 = R"(
56 {
57 "zones": [{
58 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -080059 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -080060 "failsafePercent": 75.0,
61 "pids": [{
62 "name": "fan1-5",
63 "type": "fan",
64 "inputs": ["fan1", "fan5"],
65 "setpoint": 90.0,
66 "pid": {
67 "samplePeriod": 0.1,
68 "proportionalCoeff": 0.0,
69 "integralCoeff": 0.0,
Patrick Venture903b0422019-02-20 07:35:48 -080070 "feedFwdOffsetCoeff": 0.0,
Patrick Venture5426c342019-02-11 12:03:30 -080071 "feedFwdGainCoeff": 0.010,
72 "integralLimit_min": 0.0,
73 "integralLimit_max": 0.0,
74 "outLim_min": 30.0,
75 "outLim_max": 100.0,
76 "slewNeg": 0.0,
77 "slewPos": 0.0
78 }
79 }]
80 }]
81 }
82 )"_json;
83
84 EXPECT_THROW(validateJson(j2), ConfigurationException);
85}
86
87TEST(ConfigurationVerificationTest, VerifyNoZoneKey)
88{
89 /* Verify the zones key must be present. */
90 auto j2 = R"(
91 {
92 "sensors": [{
93 "name": "fan1",
94 "type": "fan",
95 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
96 }]
97 }
98 )"_json;
99
100 EXPECT_THROW(validateJson(j2), ConfigurationException);
101}
102
103TEST(ConfigurationVerificationTest, VerifyNoSensor)
104{
105 /* Verify that there needs to be at least one sensor in the sensors key. */
106 auto j2 = R"(
107 {
108 "sensors": [],
109 "zones": [{
110 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -0800111 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -0800112 "failsafePercent": 75.0,
113 "pids": [{
114 "name": "fan1-5",
115 "type": "fan",
116 "inputs": ["fan1", "fan5"],
117 "setpoint": 90.0,
118 "pid": {
119 "samplePeriod": 0.1,
120 "proportionalCoeff": 0.0,
121 "integralCoeff": 0.0,
Patrick Venture903b0422019-02-20 07:35:48 -0800122 "feedFwdOffsetCoeff": 0.0,
Patrick Venture5426c342019-02-11 12:03:30 -0800123 "feedFwdGainCoeff": 0.010,
124 "integralLimit_min": 0.0,
125 "integralLimit_max": 0.0,
126 "outLim_min": 30.0,
127 "outLim_max": 100.0,
128 "slewNeg": 0.0,
129 "slewPos": 0.0
130 }
131 }]
132 }]
133 }
134 )"_json;
135
136 EXPECT_THROW(validateJson(j2), ConfigurationException);
137}
138
139TEST(ConfigurationVerificationTest, VerifyNoPidInZone)
140{
141 /* Verify that there needs to be at least one PID in the zone. */
142 auto j2 = R"(
143 {
144 "sensors": [{
145 "name": "fan1",
146 "type": "fan",
147 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
148 }],
149 "zones": [{
150 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -0800151 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -0800152 "failsafePercent": 75.0,
153 "pids": []
154 }]
155 }
156 )"_json;
157
158 EXPECT_THROW(validateJson(j2), ConfigurationException);
159}
Patrick Venturea0764872020-08-08 07:48:43 -0700160
161} // namespace
162} // namespace pid_control