1*3dcfd546SHarvey Wu #include "buildjson/buildjson.hpp"
25426c349SPatrick Venture #include "errors/exception.hpp"
35426c349SPatrick Venture
45426c349SPatrick Venture #include <gmock/gmock.h>
55426c349SPatrick Venture #include <gtest/gtest.h>
65426c349SPatrick Venture
7a076487aSPatrick Venture namespace pid_control
8a076487aSPatrick Venture {
9a076487aSPatrick Venture namespace
10a076487aSPatrick Venture {
11a076487aSPatrick Venture
TEST(ConfigurationVerificationTest,VerifyHappy)125426c349SPatrick Venture TEST(ConfigurationVerificationTest, VerifyHappy)
135426c349SPatrick Venture {
145426c349SPatrick Venture /* Verify a happy configuration throws no exceptions. */
155426c349SPatrick Venture auto j2 = R"(
165426c349SPatrick Venture {
175426c349SPatrick Venture "sensors": [{
185426c349SPatrick Venture "name": "fan1",
195426c349SPatrick Venture "type": "fan",
205426c349SPatrick Venture "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
215426c349SPatrick Venture }],
225426c349SPatrick Venture "zones": [{
235426c349SPatrick Venture "id": 1,
243484bedaSJames Feist "minThermalOutput": 3000.0,
255426c349SPatrick Venture "failsafePercent": 75.0,
265426c349SPatrick Venture "pids": [{
275426c349SPatrick Venture "name": "fan1-5",
285426c349SPatrick Venture "type": "fan",
295426c349SPatrick Venture "inputs": ["fan1", "fan5"],
305426c349SPatrick Venture "setpoint": 90.0,
315426c349SPatrick Venture "pid": {
325426c349SPatrick Venture "samplePeriod": 0.1,
335426c349SPatrick Venture "proportionalCoeff": 0.0,
345426c349SPatrick Venture "integralCoeff": 0.0,
35903b0427SPatrick Venture "feedFwdOffsetCoeff": 0.0,
365426c349SPatrick Venture "feedFwdGainCoeff": 0.010,
375426c349SPatrick Venture "integralLimit_min": 0.0,
385426c349SPatrick Venture "integralLimit_max": 0.0,
395426c349SPatrick Venture "outLim_min": 30.0,
405426c349SPatrick Venture "outLim_max": 100.0,
415426c349SPatrick Venture "slewNeg": 0.0,
425426c349SPatrick Venture "slewPos": 0.0
435426c349SPatrick Venture }
445426c349SPatrick Venture }]
455426c349SPatrick Venture }]
465426c349SPatrick Venture }
475426c349SPatrick Venture )"_json;
485426c349SPatrick Venture
495426c349SPatrick Venture validateJson(j2);
505426c349SPatrick Venture }
515426c349SPatrick Venture
TEST(ConfigurationVerificationTest,VerifyNoSensorKey)525426c349SPatrick Venture TEST(ConfigurationVerificationTest, VerifyNoSensorKey)
535426c349SPatrick Venture {
545426c349SPatrick Venture /* Verify the sensors key must be present. */
555426c349SPatrick Venture auto j2 = R"(
565426c349SPatrick Venture {
575426c349SPatrick Venture "zones": [{
585426c349SPatrick Venture "id": 1,
593484bedaSJames Feist "minThermalOutput": 3000.0,
605426c349SPatrick Venture "failsafePercent": 75.0,
615426c349SPatrick Venture "pids": [{
625426c349SPatrick Venture "name": "fan1-5",
635426c349SPatrick Venture "type": "fan",
645426c349SPatrick Venture "inputs": ["fan1", "fan5"],
655426c349SPatrick Venture "setpoint": 90.0,
665426c349SPatrick Venture "pid": {
675426c349SPatrick Venture "samplePeriod": 0.1,
685426c349SPatrick Venture "proportionalCoeff": 0.0,
695426c349SPatrick Venture "integralCoeff": 0.0,
70903b0427SPatrick Venture "feedFwdOffsetCoeff": 0.0,
715426c349SPatrick Venture "feedFwdGainCoeff": 0.010,
725426c349SPatrick Venture "integralLimit_min": 0.0,
735426c349SPatrick Venture "integralLimit_max": 0.0,
745426c349SPatrick Venture "outLim_min": 30.0,
755426c349SPatrick Venture "outLim_max": 100.0,
765426c349SPatrick Venture "slewNeg": 0.0,
775426c349SPatrick Venture "slewPos": 0.0
785426c349SPatrick Venture }
795426c349SPatrick Venture }]
805426c349SPatrick Venture }]
815426c349SPatrick Venture }
825426c349SPatrick Venture )"_json;
835426c349SPatrick Venture
845426c349SPatrick Venture EXPECT_THROW(validateJson(j2), ConfigurationException);
855426c349SPatrick Venture }
865426c349SPatrick Venture
TEST(ConfigurationVerificationTest,VerifyNoZoneKey)875426c349SPatrick Venture TEST(ConfigurationVerificationTest, VerifyNoZoneKey)
885426c349SPatrick Venture {
895426c349SPatrick Venture /* Verify the zones key must be present. */
905426c349SPatrick Venture auto j2 = R"(
915426c349SPatrick Venture {
925426c349SPatrick Venture "sensors": [{
935426c349SPatrick Venture "name": "fan1",
945426c349SPatrick Venture "type": "fan",
955426c349SPatrick Venture "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
965426c349SPatrick Venture }]
975426c349SPatrick Venture }
985426c349SPatrick Venture )"_json;
995426c349SPatrick Venture
1005426c349SPatrick Venture EXPECT_THROW(validateJson(j2), ConfigurationException);
1015426c349SPatrick Venture }
1025426c349SPatrick Venture
TEST(ConfigurationVerificationTest,VerifyNoSensor)1035426c349SPatrick Venture TEST(ConfigurationVerificationTest, VerifyNoSensor)
1045426c349SPatrick Venture {
1055426c349SPatrick Venture /* Verify that there needs to be at least one sensor in the sensors key. */
1065426c349SPatrick Venture auto j2 = R"(
1075426c349SPatrick Venture {
1085426c349SPatrick Venture "sensors": [],
1095426c349SPatrick Venture "zones": [{
1105426c349SPatrick Venture "id": 1,
1113484bedaSJames Feist "minThermalOutput": 3000.0,
1125426c349SPatrick Venture "failsafePercent": 75.0,
1135426c349SPatrick Venture "pids": [{
1145426c349SPatrick Venture "name": "fan1-5",
1155426c349SPatrick Venture "type": "fan",
1165426c349SPatrick Venture "inputs": ["fan1", "fan5"],
1175426c349SPatrick Venture "setpoint": 90.0,
1185426c349SPatrick Venture "pid": {
1195426c349SPatrick Venture "samplePeriod": 0.1,
1205426c349SPatrick Venture "proportionalCoeff": 0.0,
1215426c349SPatrick Venture "integralCoeff": 0.0,
122903b0427SPatrick Venture "feedFwdOffsetCoeff": 0.0,
1235426c349SPatrick Venture "feedFwdGainCoeff": 0.010,
1245426c349SPatrick Venture "integralLimit_min": 0.0,
1255426c349SPatrick Venture "integralLimit_max": 0.0,
1265426c349SPatrick Venture "outLim_min": 30.0,
1275426c349SPatrick Venture "outLim_max": 100.0,
1285426c349SPatrick Venture "slewNeg": 0.0,
1295426c349SPatrick Venture "slewPos": 0.0
1305426c349SPatrick Venture }
1315426c349SPatrick Venture }]
1325426c349SPatrick Venture }]
1335426c349SPatrick Venture }
1345426c349SPatrick Venture )"_json;
1355426c349SPatrick Venture
1365426c349SPatrick Venture EXPECT_THROW(validateJson(j2), ConfigurationException);
1375426c349SPatrick Venture }
1385426c349SPatrick Venture
TEST(ConfigurationVerificationTest,VerifyNoPidInZone)1395426c349SPatrick Venture TEST(ConfigurationVerificationTest, VerifyNoPidInZone)
1405426c349SPatrick Venture {
1415426c349SPatrick Venture /* Verify that there needs to be at least one PID in the zone. */
1425426c349SPatrick Venture auto j2 = R"(
1435426c349SPatrick Venture {
1445426c349SPatrick Venture "sensors": [{
1455426c349SPatrick Venture "name": "fan1",
1465426c349SPatrick Venture "type": "fan",
1475426c349SPatrick Venture "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1"
1485426c349SPatrick Venture }],
1495426c349SPatrick Venture "zones": [{
1505426c349SPatrick Venture "id": 1,
1513484bedaSJames Feist "minThermalOutput": 3000.0,
1525426c349SPatrick Venture "failsafePercent": 75.0,
1535426c349SPatrick Venture "pids": []
1545426c349SPatrick Venture }]
1555426c349SPatrick Venture }
1565426c349SPatrick Venture )"_json;
1575426c349SPatrick Venture
1585426c349SPatrick Venture EXPECT_THROW(validateJson(j2), ConfigurationException);
1595426c349SPatrick Venture }
160a076487aSPatrick Venture
161a076487aSPatrick Venture } // namespace
162a076487aSPatrick Venture } // namespace pid_control
163