All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: lvivier@redhat.com, Paolo Bonzini <pbonzini@redhat.com>,
	thuth@redhat.com, philmd@redhat.com, mst@redhat.com
Subject: Re: [RFC v2 1/3] tests: qtest: add qtest_has_kvm() to check if tested binary supports KVM
Date: Thu, 17 Jun 2021 18:28:31 +0200	[thread overview]
Message-ID: <20210617182831.2a867e5e@redhat.com> (raw)
In-Reply-To: <20210617100031.1380288-1-imammedo@redhat.com>

On Thu, 17 Jun 2021 06:00:31 -0400
Igor Mammedov <imammedo@redhat.com> wrote:

Paolo,
Is it acceptable to (ab)use meson like in this patch?

> Currently it not possible to create tests that have KVM as a hard
> requirement on a host that doesn't support KVM for tested target
> binary (modulo going through the trouble of compiling out
> the offending test case).
> 
> Following scenario makes test fail when it's run on non x86 host:
>   qemu-system-x86_64 -enable-kvm -M q35,kernel-irqchip=on -smp 1,maxcpus=288
> 
> This patch introduces qtest_has_kvm() to let users check if KVM is
> available in advance and skip registering non run-able test-cases.
> 
> PS:
> It's simplistic and not as versatile/precise as earlier proposed
> 'query-accels' series, but it get job done for simple cases.
> 
> on upside it's much cheaper to execute than the 'query-accels' as
> it doesn't need to run QEMU for probing.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v2:
>   - fix access() check.
>      s/access()/!access()/
>   - format C array items at meson.build time, and drop
>     splitting targets string at runtime
> 
>  tests/qtest/libqos/libqtest.h |  7 +++++++
>  meson.build                   |  2 ++
>  tests/qtest/libqtest.c        | 18 ++++++++++++++++++
>  3 files changed, 27 insertions(+)
> 
> diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h
> index a68dcd79d4..bab0047117 100644
> --- a/tests/qtest/libqos/libqtest.h
> +++ b/tests/qtest/libqos/libqtest.h
> @@ -588,6 +588,13 @@ bool qtest_big_endian(QTestState *s);
>   */
>  const char *qtest_get_arch(void);
>  
> +/**
> + * qtest_has_kvm:
> + *
> + * Returns: True if the QEMU executable under test supports KVM
> + */
> +bool qtest_has_kvm(void);
> +
>  /**
>   * qtest_add_func:
>   * @str: Test case path.
> diff --git a/meson.build b/meson.build
> index d2a9ce91f5..7fec4e8289 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -75,6 +75,8 @@ elif cpu in ['mips', 'mips64']
>  else
>    kvm_targets = []
>  endif
> +kvm_targets_c = '"' + '" ,"'.join(kvm_targets) + '"'
> +config_host_data.set('CONFIG_KVM_TARGETS', kvm_targets_c)
>  
>  accelerator_targets = { 'CONFIG_KVM': kvm_targets }
>  if cpu in ['x86', 'x86_64', 'arm', 'aarch64']
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 825b13a44c..daa6d54059 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -920,6 +920,24 @@ const char *qtest_get_arch(void)
>      return end + 1;
>  }
>  
> +bool qtest_has_kvm(void)
> +{
> +    int i;
> +    bool ret = false;
> +    const char *arch = qtest_get_arch();
> +    const char *targets[] = { CONFIG_KVM_TARGETS };
> +
> +    for (i = 0; i < ARRAY_SIZE(targets); i++) {
> +        if (!strncmp(targets[i], arch, strlen(arch))) {
> +            if (!access("/dev/kvm", R_OK | W_OK)) {
> +                ret = true;
> +                break;
> +            }
> +        }
> +    }
> +    return ret;
> +}
> +
>  bool qtest_get_irq(QTestState *s, int num)
>  {
>      /* dummy operation in order to make sure irq is up to date */



  reply	other threads:[~2021-06-17 16:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 15:24 [RFC 0/3] qtest: pick tests that require KVM at runtime Igor Mammedov
2021-06-16 15:24 ` [RFC 1/3] tests: qtest: add qtest_has_kvm() to check if tested binary supports KVM Igor Mammedov
2021-06-17 10:00   ` [RFC v2 " Igor Mammedov
2021-06-17 16:28     ` Igor Mammedov [this message]
2021-06-16 15:24 ` [RFC 2/3] tests: acpi: q35: test for x2APIC entries in SRAT Igor Mammedov
2021-06-16 15:24 ` [RFC 3/3] tests: acpi: update expected tables blobs Igor Mammedov
2021-06-16 15:30 ` [RFC 0/3] qtest: pick tests that require KVM at runtime no-reply
2021-06-17 16:49 ` Claudio Fontana
2021-06-18 11:26   ` Igor Mammedov
2021-06-18 12:43     ` Claudio Fontana
2021-06-18 13:29       ` Igor Mammedov
2021-06-22  8:07         ` Alex Bennée
2021-06-22  8:22           ` Philippe Mathieu-Daudé
2021-06-22 10:36             ` Igor Mammedov
2021-06-22 11:27               ` Philippe Mathieu-Daudé
2021-06-18 15:58     ` Igor Mammedov
2021-06-22  6:58       ` Claudio Fontana
2021-06-22  7:20 ` Thomas Huth
2021-06-22  7:26   ` Philippe Mathieu-Daudé
2021-06-22  7:59     ` Thomas Huth
2021-06-22 10:54       ` Igor Mammedov

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=20210617182831.2a867e5e@redhat.com \
    --to=imammedo@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.