VirtualBox

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

Last change on this file since 38636 was 36931, checked in by vboxsync, 14 years ago

PGMPAGE: A tiny bit more.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/* $Id: tstHelp.h 36931 2011-05-03 13:34:43Z vboxsync $ */
2/** @file
3 * VMM testcase - Helper stuff.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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 ___tstHelp_h
19#define ___tstHelp_h
20
21#include <VBox/cdefs.h>
22#include <VBox/vmm/cpum.h>
23
24RT_C_DECLS_BEGIN
25void tstDumpCtx(PCPUMCTX pCtx, const char *pszComment);
26RT_C_DECLS_END
27
28
29/**
30 * Checks the offset of a data member.
31 * @param type Type.
32 * @param off Correct offset.
33 * @param m Member name.
34 */
35#define CHECK_OFF(type, off, m) \
36 do { \
37 if (off != RT_OFFSETOF(type, m)) \
38 { \
39 printf("error! %#010x %s Off by %d!! (off=%#x)\n", RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), off); \
40 rc++; \
41 } \
42 /*else */ \
43 /*printf("%#08x %s\n", RT_OFFSETOF(type, m), #m);*/ \
44 } while (0)
45
46/**
47 * Checks the size of type.
48 * @param type Type.
49 * @param size Correct size.
50 */
51#define CHECK_SIZE(type, size) \
52 do { \
53 if (size != sizeof(type)) \
54 { \
55 printf("error! sizeof(%s): %#x (%d) Off by %d!!\n", #type, (int)sizeof(type), (int)sizeof(type), (int)(sizeof(type) - size)); \
56 rc++; \
57 } \
58 else \
59 printf("info: sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
60 } while (0)
61
62/**
63 * Checks the alignment of a struct member.
64 */
65#define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
66 do \
67 { \
68 if (RT_OFFSETOF(strct, member) & ((align) - 1) ) \
69 { \
70 printf("error! %s::%s offset=%#x (%u) expected alignment %x, meaning %#x (%u) off\n", \
71 #strct, #member, \
72 (unsigned)RT_OFFSETOF(strct, member), \
73 (unsigned)RT_OFFSETOF(strct, member), \
74 (unsigned)(align), \
75 (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)), \
76 (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)) ); \
77 rc++; \
78 } \
79 } while (0)
80
81/**
82 * Checks that the size of a type is aligned correctly.
83 */
84#define CHECK_SIZE_ALIGNMENT(type, align) \
85 do { \
86 if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
87 { \
88 printf("error! %s size=%#x (%u), align=%#x %#x (%u) bytes off\n", \
89 #type, \
90 (unsigned)sizeof(type), \
91 (unsigned)sizeof(type), \
92 (align), \
93 (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type), \
94 (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type)); \
95 rc++; \
96 } \
97 } while (0)
98
99/**
100 * Checks that a internal struct padding is big enough.
101 */
102#define CHECK_PADDING(strct, member, align) \
103 do \
104 { \
105 strct *p = NULL; NOREF(p); \
106 if (sizeof(p->member.s) > sizeof(p->member.padding)) \
107 { \
108 printf("error! padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
109 (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
110 rc++; \
111 } \
112 else if (RT_ALIGN_Z(sizeof(p->member.padding), (align)) != sizeof(p->member.padding)) \
113 { \
114 printf("error! padding of %s::%s is misaligned, padding=%d correct=%d\n", #strct, #member, \
115 (int)sizeof(p->member.padding), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
116 rc++; \
117 } \
118 } while (0)
119
120/**
121 * Checks that a internal struct padding is big enough.
122 */
123#define CHECK_PADDING2(strct) \
124 do \
125 { \
126 strct *p = NULL; NOREF(p); \
127 if (sizeof(p->s) > sizeof(p->padding)) \
128 { \
129 printf("error! padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
130 (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 64)); \
131 rc++; \
132 } \
133 } while (0)
134
135/**
136 * Checks that a internal struct padding is big enough.
137 */
138#define CHECK_PADDING3(strct, member, pad_member) \
139 do \
140 { \
141 strct *p = NULL; NOREF(p); \
142 if (sizeof(p->member) > sizeof(p->pad_member)) \
143 { \
144 printf("error! padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
145 (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
146 rc++; \
147 } \
148 } while (0)
149
150/**
151 * Checks that an expression is true.
152 */
153#define CHECK_EXPR(expr) \
154 do \
155 { \
156 if (!(expr)) \
157 { \
158 printf("error! '%s' failed! (line %d)\n", #expr, __LINE__); \
159 rc++; \
160 } \
161 } while (0)
162
163
164#endif
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