regulators: Add test cases for object 'configuration'.
*Valid: test configuration with property rule_id and with no actions.
*Valid: test configuration with property actions and with no rule_id.
*Valid: comments not specified (optional property).
*Valid: volts not specified (optional property).
*Valid: configuration is property of a rail (vs. a device).
*Invalid: comments property has wrong data type (not an array).
*Invalid: test configuration with both property actions rule_id.
*Invalid: test configuration with no rule_id and actions.
*Invalid: test configuration with property volts wrong type.
*Invalid: test configuration with property rule_id wrong type.
*Invalid: test configuration with property actions wrong type.
*Invalid: test configuration with property comments empty array.
*Invalid: test configuration with property rule_id wrong format.
*Invalid: test configuration with property actions empty array.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I9b1617c8eb1ac49c28089b4d0d85ae2bd55db80d
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index 33e762b..8a8ee9f 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -538,6 +538,139 @@
"1 is not of type u'string'");
}
}
+TEST(ValidateRegulatorsConfigTest, Configuration)
+{
+ json configurationFile = validConfigFile;
+ configurationFile["chassis"][0]["devices"][0]["configuration"]["comments"]
+ [0] = "Set rail to 1.25V using standard rule";
+ configurationFile["chassis"][0]["devices"][0]["configuration"]["volts"] =
+ 1.25;
+ configurationFile["chassis"][0]["devices"][0]["configuration"]["rule_id"] =
+ "set_voltage_rule";
+ // Valid: test configuration with property rule_id and with no actions.
+ {
+ json configFile = configurationFile;
+ EXPECT_JSON_VALID(configFile);
+ }
+ // Valid: test configuration with property actions and with no rule_id.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"].erase(
+ "rule_id");
+ configFile["chassis"][0]["devices"][0]["configuration"]["actions"][0]
+ ["compare_presence"]["fru"] =
+ "/system/chassis/motherboard/cpu3";
+ configFile["chassis"][0]["devices"][0]["configuration"]["actions"][0]
+ ["compare_presence"]["value"] = true;
+ EXPECT_JSON_VALID(configFile);
+ }
+ // Valid: comments not specified (optional property).
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"].erase(
+ "comments");
+ EXPECT_JSON_VALID(configFile);
+ }
+ // Valid: volts not specified (optional property).
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"].erase("volts");
+ EXPECT_JSON_VALID(configFile);
+ }
+ // Valid: configuration is property of a rail (vs. a device).
+ {
+ json configFile = validConfigFile;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["configuration"]
+ ["comments"][0] = "Set rail to 1.25V using standard rule";
+ configFile["chassis"][0]["devices"][0]["rails"][0]["configuration"]
+ ["volts"] = 1.25;
+ configFile["chassis"][0]["devices"][0]["rails"][0]["configuration"]
+ ["rule_id"] = "set_voltage_rule";
+ EXPECT_JSON_VALID(configFile);
+ }
+ // Invalid: comments property has wrong data type (not an array).
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"]["comments"] = 1;
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "1 is not of type u'array'");
+ }
+ // Invalid: test configuration with both actions and rule_id properties.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"]["actions"][0]
+ ["compare_presence"]["fru"] =
+ "/system/chassis/motherboard/cpu3";
+ configFile["chassis"][0]["devices"][0]["configuration"]["actions"][0]
+ ["compare_presence"]["value"] = true;
+ EXPECT_JSON_INVALID(
+ configFile, "Validation failed.",
+ "{u'volts': 1.25, u'comments': [u'Set rail to 1.25V using standard "
+ "rule'], u'actions': [{u'compare_presence': {u'value': True, "
+ "u'fru': u'/system/chassis/motherboard/cpu3'}}], u'rule_id': "
+ "u'set_voltage_rule'} is valid under each of {u'required': "
+ "[u'actions']}, {u'required': [u'rule_id']}");
+ }
+ // Invalid: test configuration with no rule_id and actions.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"].erase(
+ "rule_id");
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "u'rule_id' is a required property");
+ }
+ // Invalid: test configuration with property volts wrong type.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"]["volts"] = true;
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "True is not of type u'number'");
+ }
+ // Invalid: test configuration with property rule_id wrong type.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"]["rule_id"] =
+ true;
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "True is not of type u'string'");
+ }
+ // Invalid: test configuration with property actions wrong type.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"].erase(
+ "rule_id");
+ configFile["chassis"][0]["devices"][0]["configuration"]["actions"] =
+ true;
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "True is not of type u'array'");
+ }
+ // Invalid: test configuration with property comments empty array.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"]["comments"] =
+ json::array();
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "[] is too short");
+ }
+ // Invalid: test configuration with property rule_id wrong format.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"]["rule_id"] =
+ "id!";
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "u'id!' does not match u'^[A-Za-z0-9_]+$'");
+ }
+ // Invalid: test configuration with property actions empty array.
+ {
+ json configFile = configurationFile;
+ configFile["chassis"][0]["devices"][0]["configuration"].erase(
+ "rule_id");
+ configFile["chassis"][0]["devices"][0]["configuration"]["actions"] =
+ json::array();
+ EXPECT_JSON_INVALID(configFile, "Validation failed.",
+ "[] is too short");
+ }
+}
TEST(ValidateRegulatorsConfigTest, Device)
{