summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2019-03-26 07:10:59 -0700
committerPatrick Venture <venture@google.com>2019-03-26 07:13:12 -0700
commite3eeef45a722b57d4c3bb379df165e0bd14993bd (patch)
tree5fa2191d8d7ecb7d26aaca3f524be41ffa667b0c /test
parent90e9dbcae6c1df3127dd3de41f9d1e1b5a438828 (diff)
downloadphosphor-pid-control-e3eeef45a722b57d4c3bb379df165e0bd14993bd.tar.gz
phosphor-pid-control-e3eeef45a722b57d4c3bb379df165e0bd14993bd.zip
bugfix: grab hystersis parameter from pid json
The code incorrectly attempts to read the hystersis parameters from the wrong scope of the json object. This fixes it to read from the pid configuration's scope. Tested: Added a new unit-test to hit this case. Change-Id: I808bc907ec33a0b12d68a88fd316c3c9fae41516 Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/pid_json_unittest.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/pid_json_unittest.cpp b/test/pid_json_unittest.cpp
index c8a1f61..9d33789 100644
--- a/test/pid_json_unittest.cpp
+++ b/test/pid_json_unittest.cpp
@@ -66,3 +66,52 @@ TEST(ZoneFromJson, oneZoneOnePid)
EXPECT_EQ(pidConfig[1]["fan1-5"].type, "fan");
EXPECT_DOUBLE_EQ(zoneConfig[1].minThermalOutput, 3000.0);
}
+
+TEST(ZoneFromJson, oneZoneOnePidWithHysteresis)
+{
+ // Parse a valid configuration with one zone and one PID and the PID uses
+ // Hysteresis parameters.
+
+ std::map<int64_t, conf::PIDConf> pidConfig;
+ std::map<int64_t, struct conf::ZoneConfig> zoneConfig;
+
+ auto j2 = R"(
+ {
+ "zones" : [{
+ "id": 1,
+ "minThermalOutput": 3000.0,
+ "failsafePercent": 75.0,
+ "pids": [{
+ "name": "fan1-5",
+ "type": "fan",
+ "inputs": ["fan1", "fan5"],
+ "setpoint": 90.0,
+ "pid": {
+ "samplePeriod": 0.1,
+ "proportionalCoeff": 0.0,
+ "integralCoeff": 0.0,
+ "feedFwdOffsetCoeff": 0.0,
+ "feedFwdGainCoeff": 0.010,
+ "integralLimit_min": 0.0,
+ "integralLimit_max": 0.0,
+ "outLim_min": 30.0,
+ "outLim_max": 100.0,
+ "slewNeg": 0.0,
+ "slewPos": 0.0,
+ "positiveHysteresis": 1000.0,
+ "negativeHysteresis": 9000.0
+ }
+ }]
+ }]
+ }
+ )"_json;
+
+ std::tie(pidConfig, zoneConfig) = buildPIDsFromJson(j2);
+ EXPECT_EQ(pidConfig.size(), 1);
+ EXPECT_EQ(zoneConfig.size(), 1);
+
+ EXPECT_EQ(pidConfig[1]["fan1-5"].type, "fan");
+ EXPECT_DOUBLE_EQ(pidConfig[1]["fan1-5"].pidInfo.positiveHysteresis, 1000.0);
+
+ EXPECT_DOUBLE_EQ(zoneConfig[1].minThermalOutput, 3000.0);
+}
OpenPOWER on IntegriCloud