VirtualBox

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

Last change on this file since 1233 was 161, checked in by vboxsync, 18 years ago

64-bit: structure alignment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1/* $Id: tstHelp.h 161 2007-01-18 18:25:45Z vboxsync $ */
2/** @file
3 * VMM testcase - Helper stuff.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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
29void 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=%d expected alignment %d, meaning %d off\n", #strct, #member, RT_OFFSETOF(strct, member), \
75 align, 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), (align), (int)RT_ALIGN_Z(sizeof(type), align) - (int)sizeof(type)); \
88 rc++; \
89 } \
90 } while (0)
91
92/**
93 * Checks that a internal struct padding is big enough.
94 */
95#define CHECK_PADDING(strct, member) \
96 do \
97 { \
98 strct *p; \
99 if (sizeof(p->member.s) > sizeof(p->member.padding)) \
100 { \
101 printf("padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
102 (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), 32)); \
103 rc++; \
104 } \
105 } while (0)
106
107/**
108 * Checks that a internal struct padding is big enough.
109 */
110#define CHECK_PADDING2(strct) \
111 do \
112 { \
113 strct *p; \
114 if (sizeof(p->s) > sizeof(p->padding)) \
115 { \
116 printf("padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
117 (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 32)); \
118 rc++; \
119 } \
120 } while (0)
121
122/**
123 * Checks that a internal struct padding is big enough.
124 */
125#define CHECK_PADDING3(strct, member, pad_member) \
126 do \
127 { \
128 strct *p; \
129 if (sizeof(p->member) > sizeof(p->pad_member)) \
130 { \
131 printf("padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
132 (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
133 rc++; \
134 } \
135 } while (0)
136
137
138#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