regulators: Add test cases for object 'sensor_monitoring'.
*Valid: test sensor_monitoring with only property rule id.
*Valid: test sensor_monitoring with only property actions.
*Invalid: test sensor_monitoring with both property rule_id and actions.
*Invalid: test sensor_monitoring with no rule_id and actions.
*Invalid: test sensor_monitoring with property comments wrong type.
*Invalid: test sensor_monitoring with property rule_id wrong type.
*Invalid: test sensor_monitoring with property actions wrong type.
*Invalid: test sensor_monitoring with property rule_id wrong format.
*Invalid: test sensor_monitoring with property comments empty array.
*Invalid: test sensor_monitoring with property actions empty array.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I8892dbdfe3546dd983b2c7d7478c287f79e98cc9
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index bf4880d..aeb5614 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -1796,6 +1796,104 @@
"u'set_voltage_rule%' does not match u'^[A-Za-z0-9_]+$'");
}
}
+TEST(ValidateRegulatorsConfigTest, SensorMonitoring)
+{
+ // Valid: test rails sensor_monitoring with only property rule id.
+ {
+ json configFile = validConfigFile;
+ EXPECT_JSON_VALID(configFile);
+ }
+ // Valid: test rails sensor_monitoring with only property actions.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ .erase("rule_id");
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["actions"][0]["compare_presence"]["fru"] =
+ "/system/chassis/motherboard/cpu3";
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["actions"][0]["compare_presence"]["value"] = true;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["comments"][0] = "comments";
+ EXPECT_JSON_VALID(configFile);
+ }
+ // Invalid: test rails sensor_monitoring with both property rule_id and
+ // actions.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["actions"][0]["compare_presence"]["fru"] =
+ "/system/chassis/motherboard/cpu3";
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["actions"][0]["compare_presence"]["value"] = true;
+ EXPECT_JSON_INVALID(
+ configFile, "Validation failed.",
+ "{u'rule_id': u'read_sensors_rule', u'actions': "
+ "[{u'compare_presence': {u'value': True, u'fru': "
+ "u'/system/chassis/motherboard/cpu3'}}]} is valid under each of "
+ "{u'required': [u'actions']}, {u'required': [u'rule_id']}");
+ }
+ // Invalid: test rails sensor_monitoring with no rule_id and actions.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ .erase("rule_id");
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "u'rule_id' is a required property");
+ }
+ // Invalid: test rails sensor_monitoring with property comments wrong type.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["comments"] = true;
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "True is not of type u'array'");
+ }
+ // Invalid: test rails sensor_monitoring with property rule_id wrong type.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["rule_id"] = true;
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "True is not of type u'string'");
+ }
+ // Invalid: test rails sensor_monitoring with property actions wrong type.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ .erase("rule_id");
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["actions"] = true;
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "True is not of type u'array'");
+ }
+ // Invalid: test rails sensor_monitoring with property rule_id wrong format.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["rule_id"] = "id@";
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "u'id@' does not match u'^[A-Za-z0-9_]+$'");
+ }
+ // Invalid: test rails sensor_monitoring with property comments empty array.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["comments"] = json::array();
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "[] is too short");
+ }
+ // Invalid: test rails sensor_monitoring with property actions empty array.
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ .erase("rule_id");
+ configFile["chassis"][0]["devices"][0]["rails"][0]["sensor_monitoring"]
+ ["actions"] = json::array();
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "[] is too short");
+ }
+}
TEST(ValidateRegulatorsConfigTest, SetDevice)
{
json setDeviceFile = validConfigFile;