blob: 7d3d44930aac8c609787ec8eb3c107a951c463d9 [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,
19 "minThermalRpm": 3000.0,
20 "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,
30 "feedFwdOffOffsetCoeff": 0.0,
31 "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,
54 "minThermalRpm": 3000.0,
55 "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,
65 "feedFwdOffOffsetCoeff": 0.0,
66 "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,
106 "minThermalRpm": 3000.0,
107 "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,
117 "feedFwdOffOffsetCoeff": 0.0,
118 "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,
146 "minThermalRpm": 3000.0,
147 "failsafePercent": 75.0,
148 "pids": []
149 }]
150 }
151 )"_json;
152
153 EXPECT_THROW(validateJson(j2), ConfigurationException);
154}