Refactor: bios: Construct the attribute value table
when constructing the attribute value table, we need to traverse
the attribute table. But there is a bug in the previous version
when traversing the attribute table.
Now we use the iterator of the last commit implementation to rebuild
attribute value table.
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I9fe2b6eabf2b01e124b780fc0fc8615d492c1fed
diff --git a/test/libpldm_bios_table_test.cpp b/test/libpldm_bios_table_test.cpp
index ea94bfe..bc4ec09 100644
--- a/test/libpldm_bios_table_test.cpp
+++ b/test/libpldm_bios_table_test.cpp
@@ -42,14 +42,36 @@
reinterpret_cast<struct pldm_bios_attr_table_entry*>(enumEntry.data());
uint8_t pvNumber = pldm_bios_table_attr_entry_enum_decode_pv_num(entry);
EXPECT_EQ(pvNumber, 2);
- uint8_t defNumber = pldm_bios_table_attr_entry_enum_decode_def_num(entry);
- EXPECT_EQ(defNumber, 1);
-
pvNumber = 0;
auto rc =
pldm_bios_table_attr_entry_enum_decode_pv_num_check(entry, &pvNumber);
EXPECT_EQ(rc, PLDM_SUCCESS);
EXPECT_EQ(pvNumber, 2);
+
+ std::vector<uint16_t> pvHandles(pvNumber, 0);
+ pvNumber = pldm_bios_table_attr_entry_enum_decode_pv_hdls(
+ entry, pvHandles.data(), pvHandles.size());
+ EXPECT_EQ(pvNumber, 2);
+ EXPECT_EQ(pvHandles[0], 2);
+ EXPECT_EQ(pvHandles[1], 3);
+ pvHandles.resize(1);
+ pvNumber = pldm_bios_table_attr_entry_enum_decode_pv_hdls(
+ entry, pvHandles.data(), pvHandles.size());
+ EXPECT_EQ(pvNumber, 1);
+ EXPECT_EQ(pvHandles[0], 2);
+
+ pvHandles.resize(2);
+ rc = pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
+ entry, pvHandles.data(), pvHandles.size());
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(pvHandles[0], 2);
+ EXPECT_EQ(pvHandles[1], 3);
+ rc = pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
+ entry, pvHandles.data(), 1);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ uint8_t defNumber = pldm_bios_table_attr_entry_enum_decode_def_num(entry);
+ EXPECT_EQ(defNumber, 1);
defNumber = 0;
rc =
pldm_bios_table_attr_entry_enum_decode_def_num_check(entry, &defNumber);
@@ -69,6 +91,9 @@
rc =
pldm_bios_table_attr_entry_enum_decode_def_num_check(entry, &defNumber);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ rc =
+ pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(entry, nullptr, 0);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
}
TEST(AttrTable, StringEntryDecodeTest)
@@ -157,6 +182,95 @@
pldm_bios_table_iter_free(iter);
}
+TEST(AttrValTable, EnumEntryEncodeTest)
+{
+ std::vector<uint8_t> enumEntry{
+ 0, 0, /* attr handle */
+ 0, /* attr type */
+ 2, /* number of current value */
+ 0, /* current value string handle index */
+ 1, /* current value string handle index */
+ };
+
+ auto length = pldm_bios_table_attr_value_entry_encode_enum_length(2);
+ EXPECT_EQ(length, enumEntry.size());
+ std::vector<uint8_t> encodeEntry(length, 0);
+ uint8_t handles[] = {0, 1};
+ pldm_bios_table_attr_value_entry_encode_enum(
+ encodeEntry.data(), encodeEntry.size(), 0, 0, 2, handles);
+ EXPECT_EQ(encodeEntry, enumEntry);
+
+ EXPECT_DEATH(
+ pldm_bios_table_attr_value_entry_encode_enum(
+ encodeEntry.data(), encodeEntry.size() - 1, 0, 0, 2, handles),
+ "length <= entry_length");
+
+ auto rc = pldm_bios_table_attr_value_entry_encode_enum_check(
+ encodeEntry.data(), encodeEntry.size(), 0, PLDM_BIOS_ENUMERATION, 2,
+ handles);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(encodeEntry, enumEntry);
+ auto entry = reinterpret_cast<struct pldm_bios_attr_val_table_entry*>(
+ enumEntry.data());
+ entry->attr_type = PLDM_BIOS_ENUMERATION_READ_ONLY;
+ rc = pldm_bios_table_attr_value_entry_encode_enum_check(
+ encodeEntry.data(), encodeEntry.size(), 0,
+ PLDM_BIOS_ENUMERATION_READ_ONLY, 2, handles);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(encodeEntry, enumEntry);
+ rc = pldm_bios_table_attr_value_entry_encode_enum_check(
+ encodeEntry.data(), encodeEntry.size(), 0, PLDM_BIOS_PASSWORD, 2,
+ handles);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ rc = pldm_bios_table_attr_value_entry_encode_enum_check(
+ encodeEntry.data(), encodeEntry.size() - 1, 0, PLDM_BIOS_ENUMERATION, 2,
+ handles);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(AttrValTable, stringEntryEncodeTest)
+{
+ std::vector<uint8_t> stringEntry{
+ 0, 0, /* attr handle */
+ 1, /* attr type */
+ 3, 0, /* current string length */
+ 'a', 'b', 'c', /* defaut value string handle index */
+ };
+
+ auto length = pldm_bios_table_attr_value_entry_encode_string_length(3);
+ EXPECT_EQ(length, stringEntry.size());
+ std::vector<uint8_t> encodeEntry(length, 0);
+ pldm_bios_table_attr_value_entry_encode_string(
+ encodeEntry.data(), encodeEntry.size(), 0, 1, 3, "abc");
+ EXPECT_EQ(encodeEntry, stringEntry);
+
+ EXPECT_DEATH(
+ pldm_bios_table_attr_value_entry_encode_string(
+ encodeEntry.data(), encodeEntry.size() - 1, 0, 1, 3, "abc"),
+ "length <= entry_length");
+
+ auto rc = pldm_bios_table_attr_value_entry_encode_string_check(
+ encodeEntry.data(), encodeEntry.size(), 0, PLDM_BIOS_STRING, 3, "abc");
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(encodeEntry, stringEntry);
+ auto entry = reinterpret_cast<struct pldm_bios_attr_val_table_entry*>(
+ stringEntry.data());
+ entry->attr_type = PLDM_BIOS_STRING_READ_ONLY;
+ rc = pldm_bios_table_attr_value_entry_encode_string_check(
+ encodeEntry.data(), encodeEntry.size(), 0, PLDM_BIOS_STRING_READ_ONLY,
+ 3, "abc");
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(encodeEntry, stringEntry);
+ rc = pldm_bios_table_attr_value_entry_encode_string_check(
+ encodeEntry.data(), encodeEntry.size(), 0, PLDM_BIOS_PASSWORD, 3,
+ "abc");
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ rc = pldm_bios_table_attr_value_entry_encode_string_check(
+ encodeEntry.data(), encodeEntry.size() - 1, 0, PLDM_BIOS_STRING, 3,
+ "abc");
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
TEST(Itearator, DeathTest)
{