diff mbox

[2/2] acpi unit-test: hook to rebuild expected aml files

Message ID 1388054651-13764-3-git-send-email-marcel.a@redhat.com
State New
Headers show

Commit Message

Marcel Apfelbaum Dec. 26, 2013, 10:44 a.m. UTC
When running the test with ACPI_REBUILD_AML=y environment
variable, the test will rebuild and validate the expected aml
files.

Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
 tests/acpi-test.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

Comments

Michael S. Tsirkin Dec. 26, 2013, 10:56 a.m. UTC | #1
On Thu, Dec 26, 2013 at 12:44:11PM +0200, Marcel Apfelbaum wrote:
> When running the test with ACPI_REBUILD_AML=y environment
> variable, the test will rebuild and validate the expected aml
> files.
> 
> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> ---
>  tests/acpi-test.c | 30 +++++++++++++++++++++++++-----
>  1 file changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/acpi-test.c b/tests/acpi-test.c
> index 954d9b9..2b8545d 100644
> --- a/tests/acpi-test.c
> +++ b/tests/acpi-test.c
> @@ -13,6 +13,7 @@
>  #include <string.h>
>  #include <stdio.h>
>  #include <glib.h>
> +#include <glib/gstdio.h>
>  #include "qemu-common.h"
>  #include "libqtest.h"
>  #include "qemu/compiler.h"
> @@ -21,6 +22,8 @@
>  #define MACHINE_PC "pc"
>  #define MACHINE_Q35 "q35"
>  
> +#define ACPI_REBUILD_EXPECTED_AML "ACPI_REBUILD_AML"
> +

Put TEST somewhere in the name please. Maybe as a prefix:
TEST_ACPI_REBUILD_AML

>  /* DSDT and SSDTs format */
>  typedef struct {
>      AcpiTableHeader header;
> @@ -363,10 +366,11 @@ static void test_acpi_ssdt_tables(test_data *data)
>      }
>  }
>  
> -static void dump_aml_files(test_data *data)
> +static void dump_aml_files(test_data *data, bool rebuild)
>  {
>      AcpiSdtTable *sdt;
>      GError *error = NULL;
> +    gchar *aml_file = NULL;
>      gint fd;
>      int i;
>  
> @@ -374,12 +378,24 @@ static void dump_aml_files(test_data *data)
>          sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
>          g_assert(sdt->aml);
>  
> -        fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
> -        g_assert_no_error(error);
> +        if (rebuild) {
> +            aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine,
> +                                       (gchar *)&sdt->header.signature);

Hmm will this work if there are many SSDTs?
They all have same signature,

> +            fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
> +                        S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
> +        } else {
> +            fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
> +            g_assert_no_error(error);
> +        }
> +        g_assert(fd >= 0);
>  
>          write(fd, sdt, sizeof(AcpiTableHeader));
>          write(fd, sdt->aml, sdt->aml_len);
>          close(fd);
> +
> +        if (aml_file) {
> +            g_free(aml_file);
> +        }
>      }
>  }
>  
> @@ -487,7 +503,7 @@ static void test_acpi_asl(test_data *data)
>  
>      memset(&exp_data, 0, sizeof(exp_data));
>      exp_data.ssdt_tables = load_expected_aml(data);
> -    dump_aml_files(data);
> +    dump_aml_files(data, false);
>      for (i = 0; i < data->ssdt_tables->len; ++i) {
>          GString *asl, *exp_asl;
>  
> @@ -553,7 +569,11 @@ static void test_acpi_one(const char *params, test_data *data)
>      test_acpi_ssdt_tables(data);
>  
>      if (iasl) {
> -        test_acpi_asl(data);
> +        if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
> +            dump_aml_files(data, true);
> +        } else {
> +            test_acpi_asl(data);
> +        }
>      }
>  
>      qtest_quit(global_qtest);
> -- 
> 1.8.3.1
Marcel Apfelbaum Dec. 26, 2013, 11:03 a.m. UTC | #2
On Thu, 2013-12-26 at 12:56 +0200, Michael S. Tsirkin wrote:
> On Thu, Dec 26, 2013 at 12:44:11PM +0200, Marcel Apfelbaum wrote:
> > When running the test with ACPI_REBUILD_AML=y environment
> > variable, the test will rebuild and validate the expected aml
> > files.
> > 
> > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> > ---
> >  tests/acpi-test.c | 30 +++++++++++++++++++++++++-----
> >  1 file changed, 25 insertions(+), 5 deletions(-)
> > 
> > diff --git a/tests/acpi-test.c b/tests/acpi-test.c
> > index 954d9b9..2b8545d 100644
> > --- a/tests/acpi-test.c
> > +++ b/tests/acpi-test.c
> > @@ -13,6 +13,7 @@
> >  #include <string.h>
> >  #include <stdio.h>
> >  #include <glib.h>
> > +#include <glib/gstdio.h>
> >  #include "qemu-common.h"
> >  #include "libqtest.h"
> >  #include "qemu/compiler.h"
> > @@ -21,6 +22,8 @@
> >  #define MACHINE_PC "pc"
> >  #define MACHINE_Q35 "q35"
> >  
> > +#define ACPI_REBUILD_EXPECTED_AML "ACPI_REBUILD_AML"
> > +
> 
> Put TEST somewhere in the name please. Maybe as a prefix:
> TEST_ACPI_REBUILD_AML
Sure

> 
> >  /* DSDT and SSDTs format */
> >  typedef struct {
> >      AcpiTableHeader header;
> > @@ -363,10 +366,11 @@ static void test_acpi_ssdt_tables(test_data *data)
> >      }
> >  }
> >  
> > -static void dump_aml_files(test_data *data)
> > +static void dump_aml_files(test_data *data, bool rebuild)
> >  {
> >      AcpiSdtTable *sdt;
> >      GError *error = NULL;
> > +    gchar *aml_file = NULL;
> >      gint fd;
> >      int i;
> >  
> > @@ -374,12 +378,24 @@ static void dump_aml_files(test_data *data)
> >          sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
> >          g_assert(sdt->aml);
> >  
> > -        fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
> > -        g_assert_no_error(error);
> > +        if (rebuild) {
> > +            aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine,
> > +                                       (gchar *)&sdt->header.signature);
> 
> Hmm will this work if there are many SSDTs?
> They all have same signature,
From what I understand there is only one ssdt table named SSDT,
all others are named differently: "APIC" "HPET".
I think multiple SSDTS have different signatures, even in my laptop
they are called: SSDT1, SSDT2, SSDT3,...

So, even if the SPEC allows it, for qemu we can use different signatures
for ssdt tables. (it will complicate the code unnecessary)

Thanks,
Marcel

> 
> > +            fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
> > +                        S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
> > +        } else {
> > +            fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
> > +            g_assert_no_error(error);
> > +        }
> > +        g_assert(fd >= 0);
> >  
> >          write(fd, sdt, sizeof(AcpiTableHeader));
> >          write(fd, sdt->aml, sdt->aml_len);
> >          close(fd);
> > +
> > +        if (aml_file) {
> > +            g_free(aml_file);
> > +        }
> >      }
> >  }
> >  
> > @@ -487,7 +503,7 @@ static void test_acpi_asl(test_data *data)
> >  
> >      memset(&exp_data, 0, sizeof(exp_data));
> >      exp_data.ssdt_tables = load_expected_aml(data);
> > -    dump_aml_files(data);
> > +    dump_aml_files(data, false);
> >      for (i = 0; i < data->ssdt_tables->len; ++i) {
> >          GString *asl, *exp_asl;
> >  
> > @@ -553,7 +569,11 @@ static void test_acpi_one(const char *params, test_data *data)
> >      test_acpi_ssdt_tables(data);
> >  
> >      if (iasl) {
> > -        test_acpi_asl(data);
> > +        if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
> > +            dump_aml_files(data, true);
> > +        } else {
> > +            test_acpi_asl(data);
> > +        }
> >      }
> >  
> >      qtest_quit(global_qtest);
> > -- 
> > 1.8.3.1
diff mbox

Patch

diff --git a/tests/acpi-test.c b/tests/acpi-test.c
index 954d9b9..2b8545d 100644
--- a/tests/acpi-test.c
+++ b/tests/acpi-test.c
@@ -13,6 +13,7 @@ 
 #include <string.h>
 #include <stdio.h>
 #include <glib.h>
+#include <glib/gstdio.h>
 #include "qemu-common.h"
 #include "libqtest.h"
 #include "qemu/compiler.h"
@@ -21,6 +22,8 @@ 
 #define MACHINE_PC "pc"
 #define MACHINE_Q35 "q35"
 
+#define ACPI_REBUILD_EXPECTED_AML "ACPI_REBUILD_AML"
+
 /* DSDT and SSDTs format */
 typedef struct {
     AcpiTableHeader header;
@@ -363,10 +366,11 @@  static void test_acpi_ssdt_tables(test_data *data)
     }
 }
 
-static void dump_aml_files(test_data *data)
+static void dump_aml_files(test_data *data, bool rebuild)
 {
     AcpiSdtTable *sdt;
     GError *error = NULL;
+    gchar *aml_file = NULL;
     gint fd;
     int i;
 
@@ -374,12 +378,24 @@  static void dump_aml_files(test_data *data)
         sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
         g_assert(sdt->aml);
 
-        fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
-        g_assert_no_error(error);
+        if (rebuild) {
+            aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine,
+                                       (gchar *)&sdt->header.signature);
+            fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
+                        S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
+        } else {
+            fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
+            g_assert_no_error(error);
+        }
+        g_assert(fd >= 0);
 
         write(fd, sdt, sizeof(AcpiTableHeader));
         write(fd, sdt->aml, sdt->aml_len);
         close(fd);
+
+        if (aml_file) {
+            g_free(aml_file);
+        }
     }
 }
 
@@ -487,7 +503,7 @@  static void test_acpi_asl(test_data *data)
 
     memset(&exp_data, 0, sizeof(exp_data));
     exp_data.ssdt_tables = load_expected_aml(data);
-    dump_aml_files(data);
+    dump_aml_files(data, false);
     for (i = 0; i < data->ssdt_tables->len; ++i) {
         GString *asl, *exp_asl;
 
@@ -553,7 +569,11 @@  static void test_acpi_one(const char *params, test_data *data)
     test_acpi_ssdt_tables(data);
 
     if (iasl) {
-        test_acpi_asl(data);
+        if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
+            dump_aml_files(data, true);
+        } else {
+            test_acpi_asl(data);
+        }
     }
 
     qtest_quit(global_qtest);