[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 6/7] tools/tests/tsx: move guest creation to common area


  • To: Edwin Török <edwin.torok@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 24 Feb 2026 12:49:39 +0100
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 24 Feb 2026 11:49:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 23.02.2026 11:14, Edwin Török wrote:
> --- /dev/null
> +++ b/tools/tests/common/guests.c

Everything in the file uses singular, si I'd suggest to use singular also for
the file name.

> @@ -0,0 +1,87 @@
> +#define _GNU_SOURCE
> +#include "guests.h"
> +#include "tests.h"
> +
> +#include <err.h>
> +#include <errno.h>
> +#include <string.h>
> +
> +xc_interface *xch;
> +xc_physinfo_t physinfo;
> +bool xen_has_pv = true, xen_has_hvm = true;

static for at least some of these?

> +void test_guest_init(void)
> +{
> +    int rc;
> +    xch = xc_interface_open(NULL, NULL, 0);
> +
> +    if ( !xch )
> +        err(1, "xc_interface_open");
> +
> +    rc = xc_physinfo(xch, &physinfo);
> +    if ( rc )
> +        err(1, "Failed to obtain physinfo");
> +
> +    xen_has_hvm = physinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm;
> +    xen_has_pv = physinfo.capabilities & XEN_SYSCTL_PHYSCAP_pv;
> +}
> +
> +void test_guest(struct xen_domctl_createdomain *c)

static?

> +{
> +    uint32_t domid = 0;
> +    int rc;
> +
> +    if (!xch)

Everything else uses Xen style, so this wants to, too.

> +        return fail("test_guest_init() not called");
> +
> +    rc = xc_domain_create(xch, &domid, c);
> +    if ( rc )
> +        return fail("  Domain create failure: %d - %s\n",
> +                    errno, strerror(errno));
> +
> +    printf("  Created d%u\n", domid);
> +
> +    test_guest_domid(domid);

This might better be passed as a function pointer, so harnesses can have
multiple functions dealing with different aspects of the testing.

> +    rc = xc_domain_destroy(xch, domid);
> +    if ( rc )
> +        fail("  Failed to destroy domain: %d - %s\n",
> +             errno, strerror(errno));
> +}
> +
> +void test_guests(void)
> +{
> +    if ( xen_has_pv )
> +    {
> +        struct xen_domctl_createdomain c = {
> +            .max_vcpus = 1,
> +            .max_grant_frames = 1,
> +            .grant_opts = XEN_DOMCTL_GRANT_version(1),
> +        };
> +
> +        printf("Testing PV guest\n");

To easily distinguish things in the output of a harness creating multiple
guests, some disambuating string may want passing in.

> +        test_guest(&c);
> +    }
> +
> +    if ( xen_has_hvm )
> +    {
> +        struct xen_domctl_createdomain c = {
> +            .flags = XEN_DOMCTL_CDF_hvm,
> +            .max_vcpus = 1,
> +            .max_grant_frames = 1,
> +            .grant_opts = XEN_DOMCTL_GRANT_version(1),
> +            .arch = {
> +                .emulation_flags = XEN_X86_EMU_LAPIC,
> +            },
> +        };

For starters this may work, but longer term we may need ways to specify certain
propertied of the to be created guest(s).

> --- /dev/null
> +++ b/tools/tests/common/guests.h
> @@ -0,0 +1,11 @@
> +#include <xenctrl.h>
> +#include <xen/domctl.h>
> +
> +extern void test_guest_domid(domid_t domid);

Nit: If this was to stay, no need for "extern", just like ...

> +extern xc_interface *xch;
> +extern xc_physinfo_t physinfo;
> +extern bool xen_has_pv, xen_has_hvm;
> +
> +void test_guest_init(void);
> +void test_guest(struct xen_domctl_createdomain *c);
> +void test_guests(void);

... you have none here.

> --- a/tools/tests/tsx/Makefile
> +++ b/tools/tests/tsx/Makefile
> @@ -11,4 +11,6 @@ CFLAGS += $(CFLAGS_libxenguest)
>  LDFLAGS += $(LDLIBS_libxenctrl)
>  LDFLAGS += $(LDLIBS_libxenguest)
>  
> +$(TARGET): ../common/guests.o

Does this work properly with parallel builds, once more than one test would
use it?

> --- a/tools/tests/tsx/test-tsx.c
> +++ b/tools/tests/tsx/test-tsx.c
> @@ -31,6 +31,7 @@
>  #include <xen-tools/common-macros.h>
>  
>  #include "tests.h"
> +#include "guests.h"

Isn't this ../common/guests.h ? Plus perhaps common stuff could go straight
in the parent directory anyway?

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.