qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com,
	Igor Mammedov <imammedo@redhat.com>,
	armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v6 24/29] bios-tables-test: Drop dependence on global_qtest
Date: Fri, 8 Sep 2017 15:49:06 +0300	[thread overview]
Message-ID: <20170908154901-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20170901180340.30009-25-eblake@redhat.com>

On Fri, Sep 01, 2017 at 01:03:35PM -0500, Eric Blake wrote:
> As a general rule, we prefer avoiding implicit global state
> because it makes code harder to safely copy and paste without
> thinking about the global state.  Although bios-tables-test does
> not maintain parallel qtest connections, it's just as easy to be
> explicit about the state; once all tests have been cleaned up, a
> later patch can then get rid of global_qtest and a layer of
> wrappers in libqtest.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  tests/bios-tables-test.c | 78 +++++++++++++++++++++++++-----------------------
>  1 file changed, 40 insertions(+), 38 deletions(-)
> 
> diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
> index 75b29df493..976792f2c5 100644
> --- a/tests/bios-tables-test.c
> +++ b/tests/bios-tables-test.c
> @@ -38,6 +38,7 @@ typedef struct {
>      struct smbios_21_entry_point smbios_ep_table;
>      uint8_t *required_struct_types;
>      int required_struct_types_len;
> +    QTestState *qts;
>  } test_data;
> 
>  static char disk[] = "tests/acpi-test-disk-XXXXXX";
> @@ -77,7 +78,7 @@ static void free_test_data(test_data *data)
> 
>  static void test_acpi_rsdp_address(test_data *data)
>  {
> -    uint32_t off = acpi_find_rsdp_address(global_qtest);
> +    uint32_t off = acpi_find_rsdp_address(data->qts);
>      g_assert_cmphex(off, <, 0x100000);
>      data->rsdp_addr = off;
>  }
> @@ -87,7 +88,7 @@ static void test_acpi_rsdp_table(test_data *data)
>      AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
>      uint32_t addr = data->rsdp_addr;
> 
> -    acpi_parse_rsdp_table(global_qtest, addr, rsdp_table);
> +    acpi_parse_rsdp_table(data->qts, addr, rsdp_table);
> 
>      /* rsdp checksum is not for the whole table, but for the first 20 bytes */
>      g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
> @@ -102,7 +103,7 @@ static void test_acpi_rsdt_table(test_data *data)
>      uint8_t checksum;
> 
>      /* read the header */
> -    ACPI_READ_TABLE_HEADER(global_qtest, rsdt_table, addr);
> +    ACPI_READ_TABLE_HEADER(data->qts, rsdt_table, addr);
>      ACPI_ASSERT_CMP(rsdt_table->signature, "RSDT");
> 
>      /* compute the table entries in rsdt */
> @@ -112,7 +113,7 @@ static void test_acpi_rsdt_table(test_data *data)
> 
>      /* get the addresses of the tables pointed by rsdt */
>      tables = g_new0(uint32_t, tables_nr);
> -    ACPI_READ_ARRAY_PTR(global_qtest, tables, tables_nr, addr);
> +    ACPI_READ_ARRAY_PTR(data->qts, tables, tables_nr, addr);
> 
>      checksum = acpi_calc_checksum((uint8_t *)rsdt_table, rsdt_table->length) +
>                 acpi_calc_checksum((uint8_t *)tables,
> @@ -128,7 +129,7 @@ static void test_acpi_fadt_table(test_data *data)
>  {
>      AcpiFadtDescriptorRev3 *fadt_table = &data->fadt_table;
>      uint32_t addr;
> -    QTestState *qts = global_qtest;
> +    QTestState *qts = data->qts;
> 
>      /* FADT table comes first */
>      addr = data->rsdt_tables_addr[0];
> @@ -196,26 +197,27 @@ static void test_acpi_facs_table(test_data *data)
>      AcpiFacsDescriptorRev1 *facs_table = &data->facs_table;
>      uint32_t addr = data->fadt_table.firmware_ctrl;
> 
> -    ACPI_READ_FIELD(global_qtest, facs_table->signature, addr);
> -    ACPI_READ_FIELD(global_qtest, facs_table->length, addr);
> -    ACPI_READ_FIELD(global_qtest, facs_table->hardware_signature, addr);
> -    ACPI_READ_FIELD(global_qtest, facs_table->firmware_waking_vector, addr);
> -    ACPI_READ_FIELD(global_qtest, facs_table->global_lock, addr);
> -    ACPI_READ_FIELD(global_qtest, facs_table->flags, addr);
> -    ACPI_READ_ARRAY(global_qtest, facs_table->resverved3, addr);
> +    ACPI_READ_FIELD(data->qts, facs_table->signature, addr);
> +    ACPI_READ_FIELD(data->qts, facs_table->length, addr);
> +    ACPI_READ_FIELD(data->qts, facs_table->hardware_signature, addr);
> +    ACPI_READ_FIELD(data->qts, facs_table->firmware_waking_vector, addr);
> +    ACPI_READ_FIELD(data->qts, facs_table->global_lock, addr);
> +    ACPI_READ_FIELD(data->qts, facs_table->flags, addr);
> +    ACPI_READ_ARRAY(data->qts, facs_table->resverved3, addr);
> 
>      ACPI_ASSERT_CMP(facs_table->signature, "FACS");
>  }
> 
> -static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr)
> +static void test_dst_table(test_data *data, AcpiSdtTable *sdt_table,
> +                           uint32_t addr)
>  {
>      uint8_t checksum;
> 
> -    ACPI_READ_TABLE_HEADER(global_qtest, &sdt_table->header, addr);
> +    ACPI_READ_TABLE_HEADER(data->qts, &sdt_table->header, addr);
> 
>      sdt_table->aml_len = sdt_table->header.length - sizeof(AcpiTableHeader);
>      sdt_table->aml = g_malloc0(sdt_table->aml_len);
> -    ACPI_READ_ARRAY_PTR(global_qtest, sdt_table->aml, sdt_table->aml_len, addr);
> +    ACPI_READ_ARRAY_PTR(data->qts, sdt_table->aml, sdt_table->aml_len, addr);
> 
>      checksum = acpi_calc_checksum((uint8_t *)sdt_table,
>                                    sizeof(AcpiTableHeader)) +
> @@ -232,7 +234,7 @@ static void test_acpi_dsdt_table(test_data *data)
>      memset(&dsdt_table, 0, sizeof(dsdt_table));
>      data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
> 
> -    test_dst_table(&dsdt_table, addr);
> +    test_dst_table(data, &dsdt_table, addr);
>      ACPI_ASSERT_CMP(dsdt_table.header.signature, "DSDT");
> 
>      /* Place DSDT first */
> @@ -249,7 +251,7 @@ static void test_acpi_tables(test_data *data)
> 
>          memset(&ssdt_table, 0, sizeof(ssdt_table));
>          uint32_t addr = data->rsdt_tables_addr[i + 1]; /* fadt is first */
> -        test_dst_table(&ssdt_table, addr);
> +        test_dst_table(data, &ssdt_table, addr);
>          g_array_append_val(data->tables, ssdt_table);
>      }
>  }
> @@ -493,32 +495,32 @@ static bool smbios_ep_table_ok(test_data *data)
>      struct smbios_21_entry_point *ep_table = &data->smbios_ep_table;
>      uint32_t addr = data->smbios_ep_addr;
> 
> -    ACPI_READ_ARRAY(global_qtest, ep_table->anchor_string, addr);
> +    ACPI_READ_ARRAY(data->qts, ep_table->anchor_string, addr);
>      if (memcmp(ep_table->anchor_string, "_SM_", 4)) {
>          return false;
>      }
> -    ACPI_READ_FIELD(global_qtest, ep_table->checksum, addr);
> -    ACPI_READ_FIELD(global_qtest, ep_table->length, addr);
> -    ACPI_READ_FIELD(global_qtest, ep_table->smbios_major_version, addr);
> -    ACPI_READ_FIELD(global_qtest, ep_table->smbios_minor_version, addr);
> -    ACPI_READ_FIELD(global_qtest, ep_table->max_structure_size, addr);
> -    ACPI_READ_FIELD(global_qtest, ep_table->entry_point_revision, addr);
> -    ACPI_READ_ARRAY(global_qtest, ep_table->formatted_area, addr);
> -    ACPI_READ_ARRAY(global_qtest, ep_table->intermediate_anchor_string, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->checksum, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->length, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->smbios_major_version, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->smbios_minor_version, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->max_structure_size, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->entry_point_revision, addr);
> +    ACPI_READ_ARRAY(data->qts, ep_table->formatted_area, addr);
> +    ACPI_READ_ARRAY(data->qts, ep_table->intermediate_anchor_string, addr);
>      if (memcmp(ep_table->intermediate_anchor_string, "_DMI_", 5)) {
>          return false;
>      }
> -    ACPI_READ_FIELD(global_qtest, ep_table->intermediate_checksum, addr);
> -    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_length, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->intermediate_checksum, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->structure_table_length, addr);
>      if (ep_table->structure_table_length == 0) {
>          return false;
>      }
> -    ACPI_READ_FIELD(global_qtest, ep_table->structure_table_address, addr);
> -    ACPI_READ_FIELD(global_qtest, ep_table->number_of_structures, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->structure_table_address, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->number_of_structures, addr);
>      if (ep_table->number_of_structures == 0) {
>          return false;
>      }
> -    ACPI_READ_FIELD(global_qtest, ep_table->smbios_bcd_revision, addr);
> +    ACPI_READ_FIELD(data->qts, ep_table->smbios_bcd_revision, addr);
>      if (acpi_calc_checksum((uint8_t *)ep_table, sizeof *ep_table) ||
>          acpi_calc_checksum((uint8_t *)ep_table + 0x10,
>                             sizeof *ep_table - 0x10)) {
> @@ -537,7 +539,7 @@ static void test_smbios_entry_point(test_data *data)
>          int i;
> 
>          for (i = 0; i < sizeof sig - 1; ++i) {
> -            sig[i] = readb(off + i);
> +            sig[i] = qtest_readb(data->qts, off + i);
>          }
> 
>          if (!memcmp(sig, "_SM_", sizeof sig)) {
> @@ -580,9 +582,9 @@ static void test_smbios_structs(test_data *data)
>      for (i = 0; i < ep_table->number_of_structures; i++) {
> 
>          /* grab type and formatted area length from struct header */
> -        type = readb(addr);
> +        type = qtest_readb(data->qts, addr);
>          g_assert_cmpuint(type, <=, SMBIOS_MAX_TYPE);
> -        len = readb(addr + 1);
> +        len = qtest_readb(data->qts, addr + 1);
> 
>          /* single-instance structs must not have been encountered before */
>          if (smbios_single_instance(type)) {
> @@ -594,7 +596,7 @@ static void test_smbios_structs(test_data *data)
>          prv = crt = 1;
>          while (prv || crt) {
>              prv = crt;
> -            crt = readb(addr + len);
> +            crt = qtest_readb(data->qts, addr + len);
>              len++;
>          }
> 
> @@ -631,9 +633,9 @@ static void test_acpi_one(const char *params, test_data *data)
>                             data->machine, "kvm:tcg",
>                             params ? params : "", disk);
> 
> -    qtest_start(args);
> +    data->qts = qtest_init(args);
> 
> -    boot_sector_test(global_qtest);
> +    boot_sector_test(data->qts);
> 
>      test_acpi_rsdp_address(data);
>      test_acpi_rsdp_table(data);
> @@ -654,7 +656,7 @@ static void test_acpi_one(const char *params, test_data *data)
>      test_smbios_entry_point(data);
>      test_smbios_structs(data);
> 
> -    qtest_quit(global_qtest);
> +    qtest_quit(data->qts);
>      g_free(args);
>  }
> 
> -- 
> 2.13.5
> 

  parent reply	other threads:[~2017-09-08 12:49 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-01 18:03 [Qemu-devel] [PATCH v6 00/29] Preliminary libqtest cleanups Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 01/29] tests: Improve .gitignore for tests/multiboot Eric Blake
2017-09-04 14:03   ` Thomas Huth
2017-09-06 19:33     ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 02/29] tests: Sort .gitignore Eric Blake
2017-09-05  7:20   ` Thomas Huth
2017-09-05  9:53     ` Markus Armbruster
2017-09-05  9:58       ` Thomas Huth
2017-09-05 10:10       ` Daniel P. Berrange
2017-09-05 10:44         ` Thomas Huth
2017-09-05 14:22         ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 03/29] test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code Eric Blake
2017-09-05  7:43   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 04/29] qtest: Don't perform side effects inside assertion Eric Blake
2017-09-04 14:06   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 05/29] numa-test: Use hmp() Eric Blake
2017-09-05  7:44   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 06/29] tests: Clean up wait for event Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 07/29] libqtest: Remove dead qtest_instances variable Eric Blake
2017-09-04 17:02   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 08/29] libqtest: Let socket_send() compute length Eric Blake
2017-09-05  8:12   ` Thomas Huth
2017-09-05  9:54     ` Markus Armbruster
2017-09-05 22:20       ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 09/29] libqtest: Use qemu_strtoul() Eric Blake
2017-09-05  9:11   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 10/29] libqtest: Topologically sort functions Eric Blake
2017-09-05  9:22   ` Thomas Huth
2017-09-05 10:01     ` Markus Armbruster
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 11/29] libqtest: Inline qtest_query_target_endianness() Eric Blake
2017-09-02  0:10   ` Philippe Mathieu-Daudé
2017-09-05  9:25   ` Thomas Huth
2017-09-06 20:12     ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus Eric Blake
2017-09-01 19:20   ` Philippe Mathieu-Daudé
2017-09-06 20:48     ` Eric Blake
2017-09-01 23:06   ` John Snow
2017-09-05  9:36   ` Thomas Huth
2017-09-06 21:00     ` Eric Blake
2017-09-07  5:35       ` Thomas Huth
2017-09-07 13:32         ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 13/29] libqos: Use explicit QTestState for pci operations Eric Blake
2017-09-01 19:22   ` Philippe Mathieu-Daudé
2017-09-05 10:03   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 14/29] libqos: Use explicit QTestState for fw_cfg operations Eric Blake
2017-09-01 19:21   ` [Qemu-devel] [PATCH v6 14.5/29] fixup! " Eric Blake
2017-09-01 19:24   ` [Qemu-devel] [PATCH v6 14/29] " Philippe Mathieu-Daudé
2017-09-01 23:06   ` John Snow
2017-09-05 10:12   ` Thomas Huth
2017-09-05 11:03     ` Thomas Huth
2017-09-06 21:10       ` Eric Blake
2017-09-06 21:25         ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 15/29] libqos: Use explicit QTestState for rtas operations Eric Blake
2017-09-05 10:16   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 16/29] libqos: Use explicit QTestState for virtio operations Eric Blake
2017-09-05 10:26   ` Thomas Huth
2017-09-05 12:43     ` [Qemu-devel] [Qemu-block] " Paolo Bonzini
2017-09-06 21:42       ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 17/29] ahci-test: Drop dependence on global_qtest Eric Blake
2017-09-01 23:11   ` John Snow
2017-09-05 10:32   ` Thomas Huth
2017-09-07 20:19     ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 18/29] ivshmem-test: " Eric Blake
2017-09-05 10:36   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 19/29] postcopy-test: " Eric Blake
2017-09-05 10:41   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 20/29] vhost-user-test: " Eric Blake
2017-09-05 10:49   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 21/29] qmp-test: " Eric Blake
2017-09-05  7:11   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 22/29] tests/boot-sector: " Eric Blake
2017-09-05  7:04   ` Thomas Huth
2017-09-08 12:48   ` Michael S. Tsirkin
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 23/29] tests/acpi-utils: " Eric Blake
2017-09-05 10:57   ` Thomas Huth
2017-09-08 12:48   ` Michael S. Tsirkin
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 24/29] bios-tables-test: " Eric Blake
2017-09-05 10:59   ` Thomas Huth
2017-09-07 21:30     ` Eric Blake
2017-09-08 12:49   ` Michael S. Tsirkin [this message]
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 25/29] wdt_ib700-test: " Eric Blake
2017-09-05 11:01   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 26/29] fw_cfg-test: " Eric Blake
2017-09-02  0:07   ` Philippe Mathieu-Daudé
2017-09-05 11:05   ` Thomas Huth
2017-09-06 21:45     ` Eric Blake
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 27/29] libqtest: Make qtest_init() accept format string Eric Blake
2017-09-05 12:46   ` Thomas Huth
2017-09-07 18:00     ` Eric Blake
2017-09-07 19:07       ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 28/29] libqtest: Remove qtest_start() and qtest_end() shortcuts Eric Blake
2017-09-01 23:16   ` John Snow
2017-09-05 13:06   ` Thomas Huth
2017-09-01 18:03 ` [Qemu-devel] [PATCH v6 29/29] libqtest: Rename qtest_init() to qtest_start() Eric Blake
2017-09-01 23:17   ` John Snow
2017-09-05 13:10   ` Thomas Huth
2017-09-07  2:57     ` Eric Blake
2017-09-01 18:31 ` [Qemu-devel] [PATCH v6 00/29] Preliminary libqtest cleanups no-reply
2017-09-01 18:44   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170908154901-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).