VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstHelp.h@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette