1 | /* $Id: tstHelp.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM testcase - Helper stuff.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef VMM_INCLUDED_SRC_testcase_tstHelp_h
|
---|
19 | #define VMM_INCLUDED_SRC_testcase_tstHelp_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/vmm/cpum.h>
|
---|
26 |
|
---|
27 | RT_C_DECLS_BEGIN
|
---|
28 | void tstDumpCtx(PCPUMCTX pCtx, const char *pszComment);
|
---|
29 | RT_C_DECLS_END
|
---|
30 |
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Checks the offset of a data member.
|
---|
34 | * @param type Type.
|
---|
35 | * @param off Correct offset.
|
---|
36 | * @param m Member name.
|
---|
37 | */
|
---|
38 | #define CHECK_OFF(type, off, m) \
|
---|
39 | do { \
|
---|
40 | if (off != RT_OFFSETOF(type, m)) \
|
---|
41 | { \
|
---|
42 | printf("error! %#010x %s Off by %d!! (expected off=%#x)\n", \
|
---|
43 | RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), (int)off); \
|
---|
44 | rc++; \
|
---|
45 | } \
|
---|
46 | /*else */ \
|
---|
47 | /*printf("%#08x %s\n", RT_OFFSETOF(type, m), #m);*/ \
|
---|
48 | } while (0)
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Checks the size of type.
|
---|
52 | * @param type Type.
|
---|
53 | * @param size Correct size.
|
---|
54 | */
|
---|
55 | #define CHECK_SIZE(type, size) \
|
---|
56 | do { \
|
---|
57 | if (size != sizeof(type)) \
|
---|
58 | { \
|
---|
59 | printf("error! sizeof(%s): %#x (%d) Off by %d!! (expected %#x)\n", \
|
---|
60 | #type, (int)sizeof(type), (int)sizeof(type), (int)sizeof(type) - (int)size, (int)size); \
|
---|
61 | rc++; \
|
---|
62 | } \
|
---|
63 | else \
|
---|
64 | printf("info: sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
|
---|
65 | } while (0)
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Checks the alignment of a struct member.
|
---|
69 | */
|
---|
70 | #define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
|
---|
71 | do \
|
---|
72 | { \
|
---|
73 | if (RT_UOFFSETOF(strct, member) & ((align) - 1) ) \
|
---|
74 | { \
|
---|
75 | printf("error! %s::%s offset=%#x (%u) expected alignment %#x, meaning %#x (%u) off\n", \
|
---|
76 | #strct, #member, \
|
---|
77 | (unsigned)RT_OFFSETOF(strct, member), \
|
---|
78 | (unsigned)RT_OFFSETOF(strct, member), \
|
---|
79 | (unsigned)(align), \
|
---|
80 | (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)), \
|
---|
81 | (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)) ); \
|
---|
82 | rc++; \
|
---|
83 | } \
|
---|
84 | } while (0)
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Checks that the size of a type is aligned correctly.
|
---|
88 | */
|
---|
89 | #define CHECK_SIZE_ALIGNMENT(type, align) \
|
---|
90 | do { \
|
---|
91 | if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
|
---|
92 | { \
|
---|
93 | printf("error! %s size=%#x (%u), align=%#x %#x (%u) bytes off\n", \
|
---|
94 | #type, \
|
---|
95 | (unsigned)sizeof(type), \
|
---|
96 | (unsigned)sizeof(type), \
|
---|
97 | (align), \
|
---|
98 | (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type), \
|
---|
99 | (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type)); \
|
---|
100 | rc++; \
|
---|
101 | } \
|
---|
102 | } while (0)
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Checks that a internal struct padding is big enough.
|
---|
106 | */
|
---|
107 | #define CHECK_PADDING(strct, member, align) \
|
---|
108 | do \
|
---|
109 | { \
|
---|
110 | strct *p = NULL; NOREF(p); \
|
---|
111 | if (sizeof(p->member.s) > sizeof(p->member.padding)) \
|
---|
112 | { \
|
---|
113 | printf("error! padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
|
---|
114 | (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
|
---|
115 | rc++; \
|
---|
116 | } \
|
---|
117 | else if (RT_ALIGN_Z(sizeof(p->member.padding), (align)) != sizeof(p->member.padding)) \
|
---|
118 | { \
|
---|
119 | printf("error! padding of %s::%s is misaligned, padding=%d correct=%d\n", #strct, #member, \
|
---|
120 | (int)sizeof(p->member.padding), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
|
---|
121 | rc++; \
|
---|
122 | } \
|
---|
123 | } while (0)
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Checks that a internal struct padding is big enough.
|
---|
127 | */
|
---|
128 | #define CHECK_PADDING2(strct) \
|
---|
129 | do \
|
---|
130 | { \
|
---|
131 | strct *p = NULL; NOREF(p); \
|
---|
132 | if (sizeof(p->s) > sizeof(p->padding)) \
|
---|
133 | { \
|
---|
134 | printf("error! padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
|
---|
135 | (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 64)); \
|
---|
136 | rc++; \
|
---|
137 | } \
|
---|
138 | } while (0)
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Checks that a internal struct padding is big enough.
|
---|
142 | */
|
---|
143 | #define CHECK_PADDING3(strct, member, pad_member) \
|
---|
144 | do \
|
---|
145 | { \
|
---|
146 | strct *p = NULL; NOREF(p); \
|
---|
147 | if (sizeof(p->member) > sizeof(p->pad_member)) \
|
---|
148 | { \
|
---|
149 | printf("error! padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
|
---|
150 | (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
|
---|
151 | rc++; \
|
---|
152 | } \
|
---|
153 | } while (0)
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Checks that an expression is true.
|
---|
157 | */
|
---|
158 | #define CHECK_EXPR(expr) \
|
---|
159 | do \
|
---|
160 | { \
|
---|
161 | if (!(expr)) \
|
---|
162 | { \
|
---|
163 | printf("error! '%s' failed! (line %d)\n", #expr, __LINE__); \
|
---|
164 | rc++; \
|
---|
165 | } \
|
---|
166 | } while (0)
|
---|
167 |
|
---|
168 |
|
---|
169 | #endif /* !VMM_INCLUDED_SRC_testcase_tstHelp_h */
|
---|