VirtualBox

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

Last change on this file since 26624 was 25891, checked in by vboxsync, 15 years ago

PDMDrv,*: multi context drivers, part 1.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1/* $Id: tstHelp.h 25891 2010-01-18 13:07:21Z 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
28RT_C_DECLS_BEGIN
29void tstDumpCtx(PCPUMCTX pCtx, const char *pszComment);
30RT_C_DECLS_END
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("error! %#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("error! 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("info: 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("error! %s::%s offset=%#x (%u) expected alignment %x, meaning %#x (%u) off\n", \
75 #strct, #member, \
76 (unsigned)RT_OFFSETOF(strct, member), \
77 (unsigned)RT_OFFSETOF(strct, member), \
78 (unsigned)(align), \
79 (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)), \
80 (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)) ); \
81 rc++; \
82 } \
83 } while (0)
84
85/**
86 * Checks that the size of a type is aligned correctly.
87 */
88#define CHECK_SIZE_ALIGNMENT(type, align) \
89 do { \
90 if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
91 { \
92 printf("error! %s size=%#x (%u), align=%#x %#x (%u) bytes off\n", \
93 #type, \
94 (unsigned)sizeof(type), \
95 (unsigned)sizeof(type), \
96 (align), \
97 (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type), \
98 (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type)); \
99 rc++; \
100 } \
101 } while (0)
102
103/**
104 * Checks that a internal struct padding is big enough.
105 */
106#define CHECK_PADDING(strct, member, align) \
107 do \
108 { \
109 strct *p; \
110 if (sizeof(p->member.s) > sizeof(p->member.padding)) \
111 { \
112 printf("error! padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
113 (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
114 rc++; \
115 } \
116 else if (RT_ALIGN_Z(sizeof(p->member.padding), (align)) != sizeof(p->member.padding)) \
117 { \
118 printf("error! padding of %s::%s is misaligned, padding=%d correct=%d\n", #strct, #member, \
119 (int)sizeof(p->member.padding), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
120 rc++; \
121 } \
122 } while (0)
123
124/**
125 * Checks that a internal struct padding is big enough.
126 */
127#define CHECK_PADDING2(strct) \
128 do \
129 { \
130 strct *p; \
131 if (sizeof(p->s) > sizeof(p->padding)) \
132 { \
133 printf("error! padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
134 (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 64)); \
135 rc++; \
136 } \
137 } while (0)
138
139/**
140 * Checks that a internal struct padding is big enough.
141 */
142#define CHECK_PADDING3(strct, member, pad_member) \
143 do \
144 { \
145 strct *p; \
146 if (sizeof(p->member) > sizeof(p->pad_member)) \
147 { \
148 printf("error! padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
149 (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
150 rc++; \
151 } \
152 } while (0)
153
154
155#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