Skip to contentSkip to conversation

tests/bios-tables-test: Fix endianess problems when passing data to iasl

PATCH Superseded Thomas Huth 2 participants 3 messages Nov 16, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/bios-tables-test: Fix endianess problems when passing data to iasl

The bios-tables-test was writing out files that we pass to iasl in with the wrong endianness in the header when running on a big endian host. So instead of storing mixed endian information in our structures, let's keep everything in little endian and byte-swap it only when we need a value in the code.

---
 tests/acpi-utils.h       | 27 +++++----------------------
 tests/bios-tables-test.c | 42 ++++++++++++++++++++++--------------------
 2 files changed, 27 insertions(+), 42 deletions(-)
tests/acpi-utils.h +5 -22
index f8d8723..d5ca5b6 100644
@@ -28,24 +28,9 @@ typedef struct {
     bool tmp_files_retain;   /* do not delete the temp asl/aml */
 } AcpiSdtTable;
 
-#define ACPI_READ_FIELD(field, addr)           \
-    do {                                       \
-        switch (sizeof(field)) {               \
-        case 1:                                \
-            field = readb(addr);               \
-            break;                             \
-        case 2:                                \
-            field = readw(addr);               \
-            break;                             \
-        case 4:                                \
-            field = readl(addr);               \
-            break;                             \
-        case 8:                                \
-            field = readq(addr);               \
-            break;                             \
-        default:                               \
-            g_assert(false);                   \
-        }                                      \
+#define ACPI_READ_FIELD(field, addr)            \
+    do {                                        \
+        memread(addr, &field, sizeof(field));   \
         addr += sizeof(field);                  \
     } while (0);
 
@@ -74,16 +59,14 @@ typedef struct {
     } while (0);
 
 #define ACPI_ASSERT_CMP(actual, expected) do { \
-    uint32_t ACPI_ASSERT_CMP_le = cpu_to_le32(actual); \
     char ACPI_ASSERT_CMP_str[5] = {}; \
-    memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \
+    memcpy(ACPI_ASSERT_CMP_str, &actual, 4); \
     g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
 } while (0)
 
 #define ACPI_ASSERT_CMP64(actual, expected) do { \
-    uint64_t ACPI_ASSERT_CMP_le = cpu_to_le64(actual); \
     char ACPI_ASSERT_CMP_str[9] = {}; \
-    memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \
+    memcpy(ACPI_ASSERT_CMP_str, &actual, 8); \
     g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \
 } while (0)
 
tests/bios-tables-test.c +22 -20

137 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Thomas Huth

The bios-tables-test was writing out files that we pass to iasl in with the wrong endianness in the header when running on a big endian host. So instead of storing mixed endian information in our structures, let's keep everything in little endian and byte-swap it only when we need a value in the code.

Quoted 8 lines
---
 tests/acpi-utils.h       | 27 +++++----------------------
 tests/bios-tables-test.c | 42 ++++++++++++++++++++++--------------------
 2 files changed, 27 insertions(+), 42 deletions(-)

This fixes bios-tables-test, but has broken vmgenid-tgst

TEST: tests/vmgenid-test... (pid=8197)
/i386/vmgenid/vmgenid/set-guid: **
ERROR:/builddir/build/BUILD/qemu-2.10.0/tests/vmgenid-test.c:62:acpi_find_vgia: assertion failed (ACPI_ASSERT_CMP_str == "RSDT"): ("" == "RSDT") FAIL
GTester: last random seed: R02S1ab59ff8ca3a4e0f7ff4b8bbddb007f1
(pid=8204)
/i386/vmgenid/vmgenid/set-guid-auto: **
ERROR:/builddir/build/BUILD/qemu-2.10.0/tests/vmgenid-test.c:62:acpi_find_vgia: assertion failed (ACPI_ASSERT_CMP_str == "RSDT"): ("" == "RSDT") FAIL
GTester: last random seed: R02S1c3bcc9f459161566b19571adc5cb5d1
(pid=8216)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 16 lines · Daniel P. Berrange
Quoted 6 lines · Thomas Huth

The bios-tables-test was writing out files that we pass to iasl in with the wrong endianness in the header when running on a big endian host. So instead of storing mixed endian information in our structures, let's keep everything in little endian and byte-swap it only when we need a value in the code.

Quoted 8 lines
---
 tests/acpi-utils.h       | 27 +++++----------------------
 tests/bios-tables-test.c | 42 ++++++++++++++++++++++--------------------
 2 files changed, 27 insertions(+), 42 deletions(-)
Quoted 6 lines

This fixes bios-tables-test, but has broken vmgenid-tgst

TEST: tests/vmgenid-test... (pid=8197)
/i386/vmgenid/vmgenid/set-guid: **
ERROR:/builddir/build/BUILD/qemu-2.10.0/tests/vmgenid-test.c:62:acpi_find_vgia: assertion failed (ACPI_ASSERT_CMP_str == "RSDT"): ("" == "RSDT") FAIL

Bummer. Sorry, I've should have run the whole test suite afterwards, I only checked the bios-tables-test :-/

I'll send a v2 with a fix...

Thomas