Xen Test Framework
lib.h
Go to the documentation of this file.
1#ifndef XTF_LIB_H
2#define XTF_LIB_H
3
4#include <xtf/compiler.h>
5#include <xtf/console.h>
6#include <xtf/types.h>
7
8#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
9
10#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
11
12void __noreturn panic(const char *fmt, ...) __printf(1, 2);
13
14#define ASSERT(cond) \
15 do { if ( !(cond) ) \
16 panic("ASSERT(%s) failed at %s:%u\n", \
17 #cond, __FILE__, __LINE__); \
18 } while ( 0 )
19
20#if __has_extension(c_static_assert)
21# define BUILD_BUG_ON(cond) \
22 _Static_assert(!(cond), "!(" #cond ")")
23#else
24# define BUILD_BUG_ON(cond) \
25 ((void)sizeof(struct { char: -!!(cond); }))
26#endif
27
28#define min(a, b) \
29 ({ \
30 const typeof(a) _a = (a); \
31 const typeof(b) _b = (b); \
32 (void)(&_a == &_b); \
33 _a < _b ? _a : _b; \
34 })
35
36#define max(a, b) \
37 ({ \
38 const typeof(a) _a = (a); \
39 const typeof(b) _b = (b); \
40 (void)(&_a == &_b); \
41 _a > _b ? _a : _b; \
42 })
43
44#define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1))
45
46void heapsort(void *base, size_t nmemb, size_t size,
47 int (*compar)(const void *, const void *),
48 void (*swap)(void *, void *));
49
55unsigned long exec_user_param(unsigned long (*fn)(unsigned long),
56 unsigned long p1);
57
58/*
59 * Wrapper around exec_user_param(), calling a function which takes no
60 * parameters. p1 is poisioned to catch misuses.
61 */
62static inline unsigned long exec_user(unsigned long (*fn)(void))
63{
64 return exec_user_param((void *)fn, 0xdead0000);
65}
66
67/*
68 * Wrapper around exec_user() which calls a void function.
69 */
70static inline void exec_user_void(void (*fn)(void))
71{
72 exec_user((void *)fn);
73}
74
80
85int xtf_get_domid(void);
86
87#endif /* XTF_LIB_H */
88
89/*
90 * Local variables:
91 * mode: C
92 * c-file-style: "BSD"
93 * c-basic-offset: 4
94 * tab-width: 4
95 * indent-tabs-mode: nil
96 * End:
97 */
#define __noreturn
Definition: compiler.h:10
#define __printf(f, v)
Definition: compiler.h:12
static unsigned long exec_user(unsigned long(*fn)(void))
Definition: lib.h:62
unsigned long exec_user_param(unsigned long(*fn)(unsigned long), unsigned long p1)
Execute fn(p1) at user privilege, passing its return value back.
void heapsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *), void(*swap)(void *, void *))
Definition: heapsort.c:25
int xtf_get_domid(void)
Obtain the current domid.
Definition: lib.c:47
int xtf_probe_sysctl_interface_version(void)
Probe for the SYSCTL_INTERFACE_VERSION in use by the hypervisor.
Definition: lib.c:32
void panic(const char *fmt,...)
Definition: lib.c:15
static void exec_user_void(void(*fn)(void))
Definition: lib.h:70
Common declarations for all tests.