blob: 49134615cd1d8e02c5b43f7a1fe9ca4e33f394eb [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
7TEST(ConfigurationVerificationTest, VerifyHappy)
8{
9 /* Verify a happy configuration throws no exceptions. */
10 auto j2 = R"(
11 {
12 "sensors": [{
13 "name": "fan1",
14 "type": "fan",
15 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
16 }],
17 "zones": [{
18 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -080019 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -080020 "failsafePercent": 75.0,
21 "pids": [{
22 "name": "fan1-5",
23 "type": "fan",
24 "inputs": ["fan1", "fan5"],
25 "setpoint": 90.0,
26 "pid": {
27 "samplePeriod": 0.1,
28 "proportionalCoeff": 0.0,
29 "integralCoeff": 0.0,
Patrick Venture903b0422019-02-20 07:35:48 -080030 "feedFwdOffsetCoeff": 0.0,
Patrick Venture5426c342019-02-11 12:03:30 -080031 "feedFwdGainCoeff": 0.010,
32 "integralLimit_min": 0.0,
33 "integralLimit_max": 0.0,
34 "outLim_min": 30.0,
35 "outLim_max": 100.0,
36 "slewNeg": 0.0,
37 "slewPos": 0.0
38 }
39 }]
40 }]
41 }
42 )"_json;
43
44 validateJson(j2);
45}
46
47TEST(ConfigurationVerificationTest, VerifyNoSensorKey)
48{
49 /* Verify the sensors key must be present. */
50 auto j2 = R"(
51 {
52 "zones": [{
53 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -080054 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -080055 "failsafePercent": 75.0,
56 "pids": [{
57 "name": "fan1-5",
58 "type": "fan",
59 "inputs": ["fan1", "fan5"],
60 "setpoint": 90.0,
61 "pid": {
62 "samplePeriod": 0.1,
63 "proportionalCoeff": 0.0,
64 "integralCoeff": 0.0,
Patrick Venture903b0422019-02-20 07:35:48 -080065 "feedFwdOffsetCoeff": 0.0,
Patrick Venture5426c342019-02-11 12:03:30 -080066 "feedFwdGainCoeff": 0.010,
67 "integralLimit_min": 0.0,
68 "integralLimit_max": 0.0,
69 "outLim_min": 30.0,
70 "outLim_max": 100.0,
71 "slewNeg": 0.0,
72 "slewPos": 0.0
73 }
74 }]
75 }]
76 }
77 )"_json;
78
79 EXPECT_THROW(validateJson(j2), ConfigurationException);
80}
81
82TEST(ConfigurationVerificationTest, VerifyNoZoneKey)
83{
84 /* Verify the zones key must be present. */
85 auto j2 = R"(
86 {
87 "sensors": [{
88 "name": "fan1",
89 "type": "fan",
90 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
91 }]
92 }
93 )"_json;
94
95 EXPECT_THROW(validateJson(j2), ConfigurationException);
96}
97
98TEST(ConfigurationVerificationTest, VerifyNoSensor)
99{
100 /* Verify that there needs to be at least one sensor in the sensors key. */
101 auto j2 = R"(
102 {
103 "sensors": [],
104 "zones": [{
105 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -0800106 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -0800107 "failsafePercent": 75.0,
108 "pids": [{
109 "name": "fan1-5",
110 "type": "fan",
111 "inputs": ["fan1", "fan5"],
112 "setpoint": 90.0,
113 "pid": {
114 "samplePeriod": 0.1,
115 "proportionalCoeff": 0.0,
116 "integralCoeff": 0.0,
Patrick Venture903b0422019-02-20 07:35:48 -0800117 "feedFwdOffsetCoeff": 0.0,
Patrick Venture5426c342019-02-11 12:03:30 -0800118 "feedFwdGainCoeff": 0.010,
119 "integralLimit_min": 0.0,
120 "integralLimit_max": 0.0,
121 "outLim_min": 30.0,
122 "outLim_max": 100.0,
123 "slewNeg": 0.0,
124 "slewPos": 0.0
125 }
126 }]
127 }]
128 }
129 )"_json;
130
131 EXPECT_THROW(validateJson(j2), ConfigurationException);
132}
133
134TEST(ConfigurationVerificationTest, VerifyNoPidInZone)
135{
136 /* Verify that there needs to be at least one PID in the zone. */
137 auto j2 = R"(
138 {
139 "sensors": [{
140 "name": "fan1",
141 "type": "fan",
142 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
143 }],
144 "zones": [{
145 "id": 1,
James Feist3484bed2019-02-25 13:28:18 -0800146 "minThermalOutput": 3000.0,
Patrick Venture5426c342019-02-11 12:03:30 -0800147 "failsafePercent": 75.0,
148 "pids": []
149 }]
150 }
151 )"_json;
152
153 EXPECT_THROW(validateJson(j2), ConfigurationException);
154}