regulators: Allow empty expected VPD value
Modify the compare_vpd action to support specifying an empty string or
empty byte vector as the expected keyword value.
The VPD service was modified in a previous commit to return an empty
keyword value if the VPD interface or keyword does not exist on the
specified D-Bus object path. Thus, the actual keyword value may be
empty.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: If48ab6423c40e5b24d6cff72264dc2efe750c85f
diff --git a/phosphor-regulators/test/actions/compare_vpd_action_tests.cpp b/phosphor-regulators/test/actions/compare_vpd_action_tests.cpp
index 26361b9..c90c09e 100644
--- a/phosphor-regulators/test/actions/compare_vpd_action_tests.cpp
+++ b/phosphor-regulators/test/actions/compare_vpd_action_tests.cpp
@@ -36,19 +36,36 @@
TEST(CompareVPDActionTests, Constructor)
{
- std::vector<uint8_t> value{0x32, 0x44, 0x33, 0x35}; // "2D35"
- CompareVPDAction action{
- "/xyz/openbmc_project/inventory/system/chassis/disk_backplane", "CCIN",
- value};
- EXPECT_EQ(action.getFRU(),
- "/xyz/openbmc_project/inventory/system/chassis/disk_backplane");
- EXPECT_EQ(action.getKeyword(), "CCIN");
- EXPECT_EQ(action.getValue(), value);
+ // Value vector is not empty
+ {
+ std::vector<uint8_t> value{0x32, 0x44, 0x33, 0x35}; // "2D35"
+ CompareVPDAction action{
+ "/xyz/openbmc_project/inventory/system/chassis/disk_backplane",
+ "CCIN", value};
+ EXPECT_EQ(
+ action.getFRU(),
+ "/xyz/openbmc_project/inventory/system/chassis/disk_backplane");
+ EXPECT_EQ(action.getKeyword(), "CCIN");
+ EXPECT_EQ(action.getValue(), value);
+ }
+
+ // Value vector is empty
+ {
+ std::vector<uint8_t> value{};
+ CompareVPDAction action{
+ "/xyz/openbmc_project/inventory/system/chassis/disk_backplane",
+ "CCIN", value};
+ EXPECT_EQ(
+ action.getFRU(),
+ "/xyz/openbmc_project/inventory/system/chassis/disk_backplane");
+ EXPECT_EQ(action.getKeyword(), "CCIN");
+ EXPECT_EQ(action.getValue(), value);
+ }
}
TEST(CompareVPDActionTests, Execute)
{
- // Test where works: Actual VPD value is not an empty string
+ // Test where works: Actual VPD value is not empty
{
std::string fru{"/xyz/openbmc_project/inventory/system"};
std::string keyword{"Model"};
@@ -85,13 +102,13 @@
}
}
- // Test where works: Actual VPD value is an empty string
+ // Test where works: Actual VPD value is empty
{
std::string fru{"/xyz/openbmc_project/inventory/system"};
std::string keyword{"Model"};
std::vector<uint8_t> emptyValue{};
- // Create MockServices object. VPD service will return "" as VPD value
+ // Create MockServices object. VPD service will return empty VPD value
// 2 times.
MockServices services{};
MockVPD& vpd = services.getMockVPD();
@@ -194,6 +211,7 @@
TEST(CompareVPDActionTests, ToString)
{
+ // Test where value vector is not empty
{
CompareVPDAction action{
"/xyz/openbmc_project/inventory/system/chassis/disk_backplane",
@@ -204,6 +222,7 @@
"CCIN, value: [ 0x1, 0xA3, 0x0, 0xFF ] }");
}
+ // Test where value vector is empty
{
CompareVPDAction action{
"/xyz/openbmc_project/inventory/system/chassis/disk_backplane",
diff --git a/phosphor-regulators/test/config_file_parser_tests.cpp b/phosphor-regulators/test/config_file_parser_tests.cpp
index 38bee22..f477d41 100644
--- a/phosphor-regulators/test/config_file_parser_tests.cpp
+++ b/phosphor-regulators/test/config_file_parser_tests.cpp
@@ -1138,7 +1138,7 @@
TEST(ConfigFileParserTests, ParseCompareVPD)
{
- // Test where works, using "value"
+ // Test where works: value property: Not empty
{
const json element = R"(
{
@@ -1156,7 +1156,24 @@
(std::vector<uint8_t>{0x32, 0x44, 0x33, 0x35}));
}
- // Test where works, using "byte_values"
+ // Test where works: value property: Empty
+ {
+ const json element = R"(
+ {
+ "fru": "system/chassis/disk_backplane",
+ "keyword": "CCIN",
+ "value": ""
+ }
+ )"_json;
+ std::unique_ptr<CompareVPDAction> action = parseCompareVPD(element);
+ EXPECT_EQ(
+ action->getFRU(),
+ "/xyz/openbmc_project/inventory/system/chassis/disk_backplane");
+ EXPECT_EQ(action->getKeyword(), "CCIN");
+ EXPECT_EQ(action->getValue(), (std::vector<uint8_t>{}));
+ }
+
+ // Test where works: byte_values property: Not empty
{
const json element = R"(
{
@@ -1173,6 +1190,23 @@
EXPECT_EQ(action->getValue(), (std::vector<uint8_t>{0x11, 0x22, 0x33}));
}
+ // Test where works: byte_values property: Empty
+ {
+ const json element = R"(
+ {
+ "fru": "system/chassis/disk_backplane",
+ "keyword": "CCIN",
+ "byte_values": []
+ }
+ )"_json;
+ std::unique_ptr<CompareVPDAction> action = parseCompareVPD(element);
+ EXPECT_EQ(
+ action->getFRU(),
+ "/xyz/openbmc_project/inventory/system/chassis/disk_backplane");
+ EXPECT_EQ(action->getKeyword(), "CCIN");
+ EXPECT_EQ(action->getValue(), (std::vector<uint8_t>{}));
+ }
+
// Test where fails: Element is not an object
try
{
@@ -1256,7 +1290,7 @@
"either value or byte_values");
}
- // Test where fails: both value and byte_value specified
+ // Test where fails: both value and byte_values specified
try
{
const json element = R"(
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index f6033d5..2763cc9 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -702,12 +702,20 @@
compareVpdFile["rules"][0]["actions"][1]["compare_vpd"]["keyword"] = "CCIN";
compareVpdFile["rules"][0]["actions"][1]["compare_vpd"]["value"] = "2D35";
- // Valid.
+ // Valid: value property: not empty.
{
json configFile = compareVpdFile;
EXPECT_JSON_VALID(configFile);
}
- // Valid, using byte_values.
+
+ // Valid: value property: empty.
+ {
+ json configFile = compareVpdFile;
+ configFile["rules"][0]["actions"][1]["compare_vpd"]["value"] = "";
+ EXPECT_JSON_VALID(configFile);
+ }
+
+ // Valid: byte_values property: not empty.
{
json configFile = compareVpdFile;
configFile["rules"][0]["actions"][1]["compare_vpd"].erase("value");
@@ -716,6 +724,15 @@
EXPECT_JSON_VALID(configFile);
}
+ // Valid: byte_values property: empty.
+ {
+ json configFile = compareVpdFile;
+ configFile["rules"][0]["actions"][1]["compare_vpd"].erase("value");
+ configFile["rules"][0]["actions"][1]["compare_vpd"]["byte_values"] =
+ json::array();
+ EXPECT_JSON_VALID(configFile);
+ }
+
// Invalid: no FRU property.
{
json configFile = compareVpdFile;
@@ -785,16 +802,6 @@
"'0x50' is not of type 'array'");
}
- // Invalid: property byte_values is empty
- {
- json configFile = compareVpdFile;
- configFile["rules"][0]["actions"][1]["compare_vpd"].erase("value");
- configFile["rules"][0]["actions"][1]["compare_vpd"]["byte_values"] =
- json::array();
- EXPECT_JSON_INVALID(configFile, "Validation failed.",
- "[] is too short");
- }
-
// Invalid: properties byte_values and value both exist
{
json configFile = compareVpdFile;