1 | /* $Id: tstHelp.h 19286 2009-05-01 12:41:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM testcase - Helper stuff.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___tstHelp_h
|
---|
23 | #define ___tstHelp_h
|
---|
24 |
|
---|
25 | #include <VBox/cdefs.h>
|
---|
26 | #include <VBox/cpum.h>
|
---|
27 |
|
---|
28 | __BEGIN_DECLS
|
---|
29 | void tstDumpCtx(PCPUMCTX pCtx, const char *pszComment);
|
---|
30 | __END_DECLS
|
---|
31 |
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Checks the offset of a data member.
|
---|
35 | * @param type Type.
|
---|
36 | * @param off Correct offset.
|
---|
37 | * @param m Member name.
|
---|
38 | */
|
---|
39 | #define CHECK_OFF(type, off, m) \
|
---|
40 | do { \
|
---|
41 | if (off != RT_OFFSETOF(type, m)) \
|
---|
42 | { \
|
---|
43 | printf("%#010x %s Off by %d!! (off=%#x)\n", RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), 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("sizeof(%s): %#x (%d) Off by %d!!\n", #type, (int)sizeof(type), (int)sizeof(type), (int)(sizeof(type) - size)); \
|
---|
60 | rc++; \
|
---|
61 | } \
|
---|
62 | else \
|
---|
63 | printf("sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
|
---|
64 | } while (0)
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Checks the alignment of a struct member.
|
---|
68 | */
|
---|
69 | #define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
|
---|
70 | do \
|
---|
71 | { \
|
---|
72 | if ( RT_OFFSETOF(strct, member) & ((align) - 1) ) \
|
---|
73 | { \
|
---|
74 | printf("%s::%s offset=%#x expected alignment %x, meaning %#x off\n", #strct, #member, (unsigned)RT_OFFSETOF(strct, member), \
|
---|
75 | (unsigned)(align), (unsigned)(RT_OFFSETOF(strct, member) & ((align) - 1))); \
|
---|
76 | rc++; \
|
---|
77 | } \
|
---|
78 | } while (0)
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Checks that the size of a type is aligned correctly.
|
---|
82 | */
|
---|
83 | #define CHECK_SIZE_ALIGNMENT(type, align) \
|
---|
84 | do { \
|
---|
85 | if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
|
---|
86 | { \
|
---|
87 | printf("%s size=%#x, align=%#x %#x bytes off\n", #type, (int)sizeof(type), \
|
---|
88 | (align), (int)RT_ALIGN_Z(sizeof(type), align) - (int)sizeof(type)); \
|
---|
89 | rc++; \
|
---|
90 | } \
|
---|
91 | } while (0)
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Checks that a internal struct padding is big enough.
|
---|
95 | */
|
---|
96 | #define CHECK_PADDING(strct, member) \
|
---|
97 | do \
|
---|
98 | { \
|
---|
99 | strct *p; \
|
---|
100 | if (sizeof(p->member.s) > sizeof(p->member.padding)) \
|
---|
101 | { \
|
---|
102 | printf("padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
|
---|
103 | (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), 64)); \
|
---|
104 | rc++; \
|
---|
105 | } \
|
---|
106 | } while (0)
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Checks that a internal struct padding is big enough.
|
---|
110 | */
|
---|
111 | #define CHECK_PADDING2(strct) \
|
---|
112 | do \
|
---|
113 | { \
|
---|
114 | strct *p; \
|
---|
115 | if (sizeof(p->s) > sizeof(p->padding)) \
|
---|
116 | { \
|
---|
117 | printf("padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
|
---|
118 | (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 64)); \
|
---|
119 | rc++; \
|
---|
120 | } \
|
---|
121 | } while (0)
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Checks that a internal struct padding is big enough.
|
---|
125 | */
|
---|
126 | #define CHECK_PADDING3(strct, member, pad_member) \
|
---|
127 | do \
|
---|
128 | { \
|
---|
129 | strct *p; \
|
---|
130 | if (sizeof(p->member) > sizeof(p->pad_member)) \
|
---|
131 | { \
|
---|
132 | printf("padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
|
---|
133 | (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
|
---|
134 | rc++; \
|
---|
135 | } \
|
---|
136 | } while (0)
|
---|
137 |
|
---|
138 |
|
---|
139 | #endif
|
---|