Files
xen/tools/tests/domid/harness.h
T
Denis Mukhin 23e2479ff9 xen/domain: introduce DOMID_ANY
Add a new symbol DOMID_ANY to improve the readability of the code.

Update all relevant domid_alloc() call sites and harden the domid_alloc()
input value check.

Also, fix problem with passing invalid domain IDs in
XEN_DOMCTL_createdomain: turns out libxl__domain_make() (toolstack)
uses 0xffff as domain ID.

Fix failing tools tests too.

Amends: 2d50650607 ("xen/domain: unify domain ID allocation")
Signed-off-by: Denis Mukhin <dmukhin@ford.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2026-05-19 22:29:10 -05:00

56 lines
1.4 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Unit test harness for domain ID allocator.
*
* Copyright 2025 Ford Motor Company
*/
#ifndef _TEST_HARNESS_
#define _TEST_HARNESS_
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <xen-tools/common-macros.h>
#include <xen-tools/bitops.h>
typedef bool spinlock_t;
typedef uint16_t domid_t;
extern domid_t domid_alloc(domid_t domid);
extern void domid_free(domid_t domid);
extern unsigned long find_next_zero_bit(const unsigned long *addr,
unsigned long size,
unsigned long offset);
#define __test_and_set_bit(nr, addr) test_and_set_bit(nr, addr)
#define __test_and_clear_bit(nr, addr) test_and_clear_bit(nr, addr)
#define __set_bit(nr, addr) set_bit(nr, addr)
#define BUG_ON(x) assert(!(x))
#define ASSERT(x) assert(x)
#define DEFINE_SPINLOCK(l) spinlock_t l
#define spin_lock(l) (assert(!*(l)), *(l) = true)
#define spin_unlock(l) (assert(*(l)), *(l) = false)
#define printk printf
#define DOMID_FIRST_RESERVED (100)
#define DOMID_INVALID (101)
#define DOMID_ANY (102)
#endif /* _TEST_HARNESS_ */
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/