Re: [PATCH v2 2/5] bios-tables-test: teach test to use smbios 3.0 tables

2022-08-25 Thread Igor Mammedov
On Sun, 31 Jul 2022 18:21:38 +0200
Julia Suvorova  wrote:

> Introduce the 64-bit entry point. Since we no longer have a total
> number of structures, stop checking for the new ones at the EOF
> structure (type 127).

needs fixing checkpatch warnings

other than that

Reviewed-by: Igor Mammedov 

> Signed-off-by: Julia Suvorova 
> ---
>  tests/qtest/bios-tables-test.c | 95 +-
>  1 file changed, 71 insertions(+), 24 deletions(-)
> 
> diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
> index 359916c228..e352d5249f 100644
> --- a/tests/qtest/bios-tables-test.c
> +++ b/tests/qtest/bios-tables-test.c
> @@ -88,8 +88,8 @@ typedef struct {
>  uint64_t rsdp_addr;
>  uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
>  GArray *tables;
> -uint32_t smbios_ep_addr;
> -struct smbios_21_entry_point smbios_ep_table;
> +uint64_t smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE__MAX];
> +SmbiosEntryPoint smbios_ep_table;
>  uint16_t smbios_cpu_max_speed;
>  uint16_t smbios_cpu_curr_speed;
>  uint8_t *required_struct_types;
> @@ -533,10 +533,9 @@ static void test_acpi_asl(test_data *data)
>  free_test_data(_data);
>  }
>  
> -static bool smbios_ep_table_ok(test_data *data)
> +static bool smbios_ep2_table_ok(test_data *data, uint32_t addr)
>  {
> -struct smbios_21_entry_point *ep_table = >smbios_ep_table;
> -uint32_t addr = data->smbios_ep_addr;
> +struct smbios_21_entry_point *ep_table = >smbios_ep_table.ep21;
>  
>  qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
>  if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
> @@ -559,13 +558,29 @@ static bool smbios_ep_table_ok(test_data *data)
>  return true;
>  }
>  
> -static void test_smbios_entry_point(test_data *data)
> +static bool smbios_ep3_table_ok(test_data *data, uint64_t addr)
> +{
> +struct smbios_30_entry_point *ep_table = >smbios_ep_table.ep30;
> +
> +qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
> +if (memcmp(ep_table->anchor_string, "_SM3_", 5)) {
> +return false;
> +}
> +
> +if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table)) {
> +return false;
> +}
> +
> +return true;
> +}
> +
> +static SmbiosEntryPointType test_smbios_entry_point(test_data *data)
>  {
>  uint32_t off;
>  
>  /* find smbios entry point structure */
>  for (off = 0xf; off < 0x10; off += 0x10) {
> -uint8_t sig[] = "_SM_";
> +uint8_t sig[] = "_SM_", sig3[] = "_SM3_";
>  int i;
>  
>  for (i = 0; i < sizeof sig - 1; ++i) {
> @@ -574,14 +589,30 @@ static void test_smbios_entry_point(test_data *data)
>  
>  if (!memcmp(sig, "_SM_", sizeof sig)) {
>  /* signature match, but is this a valid entry point? */
> -data->smbios_ep_addr = off;
> -if (smbios_ep_table_ok(data)) {
> +if (smbios_ep2_table_ok(data, off)) {
> +data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] = off;
> +}
> +}
> +
> +for (i = 0; i < sizeof sig3 - 1; ++i) {
> +sig3[i] = qtest_readb(data->qts, off + i);
> +}
> +
> +if (!memcmp(sig3, "_SM3_", sizeof sig3)) {
> +if (smbios_ep3_table_ok(data, off)) {
> +data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] = off;
> +/* found 64-bit entry point, no need to look for 32-bit one 
> */
>  break;
>  }
>  }
>  }
>  
> -g_assert_cmphex(off, <, 0x10);
> +/* found at least one entry point */
> +g_assert_true(data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] ||
> +  data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64]);
> +
> +return data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] ?
> +   SMBIOS_ENTRY_POINT_TYPE_64 : SMBIOS_ENTRY_POINT_TYPE_32;
>  }
>  
>  static inline bool smbios_single_instance(uint8_t type)
> @@ -625,16 +656,23 @@ static bool smbios_cpu_test(test_data *data, uint32_t 
> addr)
>  return true;
>  }
>  
> -static void test_smbios_structs(test_data *data)
> +static void test_smbios_structs(test_data *data, SmbiosEntryPointType 
> ep_type)
>  {
>  DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
> -struct smbios_21_entry_point *ep_table = >smbios_ep_table;
> -uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
> -int i, len, max_len = 0;
> +
> +SmbiosEntryPoint *ep_table = >smbios_ep_table;
> +int i = 0, len, max_len = 0;
>  uint8_t type, prv, crt;
> +uint64_t addr;
> +
> +if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32) {
> +addr = le32_to_cpu(ep_table->ep21.structure_table_address);
> +} else {
> +addr = le64_to_cpu(ep_table->ep30.structure_table_address);
> +}
>  
>  /* walk the smbios tables */
> -for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
> +do {
>  
>  /* grab type 

[PATCH v2 2/5] bios-tables-test: teach test to use smbios 3.0 tables

2022-07-31 Thread Julia Suvorova
Introduce the 64-bit entry point. Since we no longer have a total
number of structures, stop checking for the new ones at the EOF
structure (type 127).

Signed-off-by: Julia Suvorova 
---
 tests/qtest/bios-tables-test.c | 95 +-
 1 file changed, 71 insertions(+), 24 deletions(-)

diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
index 359916c228..e352d5249f 100644
--- a/tests/qtest/bios-tables-test.c
+++ b/tests/qtest/bios-tables-test.c
@@ -88,8 +88,8 @@ typedef struct {
 uint64_t rsdp_addr;
 uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
 GArray *tables;
-uint32_t smbios_ep_addr;
-struct smbios_21_entry_point smbios_ep_table;
+uint64_t smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE__MAX];
+SmbiosEntryPoint smbios_ep_table;
 uint16_t smbios_cpu_max_speed;
 uint16_t smbios_cpu_curr_speed;
 uint8_t *required_struct_types;
@@ -533,10 +533,9 @@ static void test_acpi_asl(test_data *data)
 free_test_data(_data);
 }
 
-static bool smbios_ep_table_ok(test_data *data)
+static bool smbios_ep2_table_ok(test_data *data, uint32_t addr)
 {
-struct smbios_21_entry_point *ep_table = >smbios_ep_table;
-uint32_t addr = data->smbios_ep_addr;
+struct smbios_21_entry_point *ep_table = >smbios_ep_table.ep21;
 
 qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
 if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
@@ -559,13 +558,29 @@ static bool smbios_ep_table_ok(test_data *data)
 return true;
 }
 
-static void test_smbios_entry_point(test_data *data)
+static bool smbios_ep3_table_ok(test_data *data, uint64_t addr)
+{
+struct smbios_30_entry_point *ep_table = >smbios_ep_table.ep30;
+
+qtest_memread(data->qts, addr, ep_table, sizeof(*ep_table));
+if (memcmp(ep_table->anchor_string, "_SM3_", 5)) {
+return false;
+}
+
+if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table)) {
+return false;
+}
+
+return true;
+}
+
+static SmbiosEntryPointType test_smbios_entry_point(test_data *data)
 {
 uint32_t off;
 
 /* find smbios entry point structure */
 for (off = 0xf; off < 0x10; off += 0x10) {
-uint8_t sig[] = "_SM_";
+uint8_t sig[] = "_SM_", sig3[] = "_SM3_";
 int i;
 
 for (i = 0; i < sizeof sig - 1; ++i) {
@@ -574,14 +589,30 @@ static void test_smbios_entry_point(test_data *data)
 
 if (!memcmp(sig, "_SM_", sizeof sig)) {
 /* signature match, but is this a valid entry point? */
-data->smbios_ep_addr = off;
-if (smbios_ep_table_ok(data)) {
+if (smbios_ep2_table_ok(data, off)) {
+data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] = off;
+}
+}
+
+for (i = 0; i < sizeof sig3 - 1; ++i) {
+sig3[i] = qtest_readb(data->qts, off + i);
+}
+
+if (!memcmp(sig3, "_SM3_", sizeof sig3)) {
+if (smbios_ep3_table_ok(data, off)) {
+data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] = off;
+/* found 64-bit entry point, no need to look for 32-bit one */
 break;
 }
 }
 }
 
-g_assert_cmphex(off, <, 0x10);
+/* found at least one entry point */
+g_assert_true(data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_32] ||
+  data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64]);
+
+return data->smbios_ep_addr[SMBIOS_ENTRY_POINT_TYPE_64] ?
+   SMBIOS_ENTRY_POINT_TYPE_64 : SMBIOS_ENTRY_POINT_TYPE_32;
 }
 
 static inline bool smbios_single_instance(uint8_t type)
@@ -625,16 +656,23 @@ static bool smbios_cpu_test(test_data *data, uint32_t 
addr)
 return true;
 }
 
-static void test_smbios_structs(test_data *data)
+static void test_smbios_structs(test_data *data, SmbiosEntryPointType ep_type)
 {
 DECLARE_BITMAP(struct_bitmap, SMBIOS_MAX_TYPE+1) = { 0 };
-struct smbios_21_entry_point *ep_table = >smbios_ep_table;
-uint32_t addr = le32_to_cpu(ep_table->structure_table_address);
-int i, len, max_len = 0;
+
+SmbiosEntryPoint *ep_table = >smbios_ep_table;
+int i = 0, len, max_len = 0;
 uint8_t type, prv, crt;
+uint64_t addr;
+
+if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32) {
+addr = le32_to_cpu(ep_table->ep21.structure_table_address);
+} else {
+addr = le64_to_cpu(ep_table->ep30.structure_table_address);
+}
 
 /* walk the smbios tables */
-for (i = 0; i < le16_to_cpu(ep_table->number_of_structures); i++) {
+do {
 
 /* grab type and formatted area length from struct header */
 type = qtest_readb(data->qts, addr);
@@ -660,19 +698,28 @@ static void test_smbios_structs(test_data *data)
 }
 
 /* keep track of max. struct size */
-if (max_len < len) {
+if (ep_type == SMBIOS_ENTRY_POINT_TYPE_32 && max_len < len) {
 max_len = len;
-g_assert_cmpuint(max_len, <=,