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