VirtualBox

source: vbox/trunk/src/VBox/Devices/testcase/tstDeviceStructSize.cpp@ 11492

Last change on this file since 11492 was 11270, checked in by vboxsync, 17 years ago

#1865: DevParallel. Also fixed some serious GC/R0 alignment bugs and adding the thing to the testcase.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1/* $Id: tstDeviceStructSize.cpp 11270 2008-08-08 16:56:16Z vboxsync $ */
2/** @file
3 * tstDeviceStructSize - testcase for check structure sizes/alignment
4 * and to verify that HC and GC uses the same
5 * representation of the structures.
6 */
7
8/*
9 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/types.h>
28#include <VBox/x86.h>
29
30#define VBOX_DEVICE_STRUCT_TESTCASE
31#undef LOG_GROUP
32#include "../Bus/DevPCI.cpp"
33#undef LOG_GROUP
34#include "../Graphics/DevVGA.cpp"
35#undef LOG_GROUP
36#include "../Input/DevPS2.cpp"
37#undef LOG_GROUP
38#include "../Network/DevPCNet.cpp"
39#undef LOG_GROUP
40#include "../PC/DevACPI.cpp"
41#undef LOG_GROUP
42#include "../PC/DevPIC.cpp"
43#undef LOG_GROUP
44#include "../PC/DevPit-i8254.cpp"
45#undef LOG_GROUP
46#include "../PC/DevRTC.cpp"
47#undef LOG_GROUP
48#include "../PC/DevAPIC.cpp"
49#undef LOG_GROUP
50#include "../Storage/DevATA.cpp"
51#ifdef VBOX_WITH_USB
52# undef LOG_GROUP
53# include "../USB/DevOHCI.cpp"
54# include "../USB/DevEHCI.cpp"
55#endif
56#undef LOG_GROUP
57#include "../VMMDev/VBoxDev.cpp"
58#undef LOG_GROUP
59#include "../Parallel/DevParallel.cpp"
60#undef LOG_GROUP
61#include "../Serial/DevSerial.cpp"
62#ifdef VBOX_WITH_AHCI
63# undef LOG_GROUP
64# include "../Storage/DevAHCI.cpp"
65#endif
66#ifdef VBOX_WITH_E1000
67# undef LOG_GROUP
68# include "../Network/DevE1000.cpp"
69#endif
70
71#include <stdio.h>
72
73
74/*******************************************************************************
75* Defined Constants And Macros *
76*******************************************************************************/
77/**
78 * Checks the offset of a data member.
79 * @param type Type.
80 * @param off Correct offset.
81 * @param m Member name.
82 */
83#define CHECK_OFF(type, off, m) \
84 do { \
85 if (off != RT_OFFSETOF(type, m)) \
86 { \
87 printf("%#010x %s Off by %d!! (off=%#x)\n", RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), off); \
88 rc++; \
89 } \
90 /*else */ \
91 /*printf("%#08x %s\n", RT_OFFSETOF(type, m), #m);*/ \
92 } while (0)
93
94/**
95 * Checks the size of type.
96 * @param type Type.
97 * @param size Correct size.
98 */
99#define CHECK_SIZE(type, size) \
100 do { \
101 if (size != sizeof(type)) \
102 { \
103 printf("sizeof(%s): %#x (%d) Off by %d!!\n", #type, (int)sizeof(type), (int)sizeof(type), (int)(sizeof(type) - size)); \
104 rc++; \
105 } \
106 else \
107 printf("sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
108 } while (0)
109
110/**
111 * Checks the alignment of a struct member.
112 */
113#define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
114 do \
115 { \
116 if ( RT_OFFSETOF(strct, member) & ((align) - 1) ) \
117 { \
118 printf("%s::%s offset=%d expected alignment %d, meaning %d off\n", #strct, #member, RT_OFFSETOF(strct, member), \
119 align, RT_OFFSETOF(strct, member) & (align - 1)); \
120 rc++; \
121 } \
122 } while (0)
123
124/**
125 * Checks that the size of a type is aligned correctly.
126 */
127#define CHECK_SIZE_ALIGNMENT(type, align) \
128 do { \
129 if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
130 { \
131 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)); \
132 rc++; \
133 } \
134 } while (0)
135
136/**
137 * Checks that a internal struct padding is big enough.
138 */
139#define CHECK_PADDING(strct, member) \
140 do \
141 { \
142 strct *p; \
143 if (sizeof(p->member.s) > sizeof(p->member.padding)) \
144 { \
145 printf("padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
146 (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), 32)); \
147 rc++; \
148 } \
149 } while (0)
150
151/**
152 * Checks that a internal struct padding is big enough.
153 */
154#define CHECK_PADDING2(strct) \
155 do \
156 { \
157 strct *p; \
158 if (sizeof(p->s) > sizeof(p->padding)) \
159 { \
160 printf("padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
161 (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 32)); \
162 rc++; \
163 } \
164 } while (0)
165
166/**
167 * Checks that a internal struct padding is big enough.
168 */
169#define CHECK_PADDING3(strct, member, pad_member) \
170 do \
171 { \
172 strct *p; \
173 if (sizeof(p->member) > sizeof(p->pad_member)) \
174 { \
175 printf("padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
176 (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
177 rc++; \
178 } \
179 } while (0)
180
181/**
182 * Prints the offset of a struct member.
183 */
184#define PRINT_OFFSET(strct, member) \
185 do \
186 { \
187 printf("%s::%s offset %d sizeof %d\n", #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
188 } while (0)
189
190
191int main()
192{
193 int rc = 0;
194 printf("tstDeviceStructSize: TESTING\n");
195
196 /* Assert sanity */
197 CHECK_SIZE(uint128_t, 128/8);
198 CHECK_SIZE(int128_t, 128/8);
199 CHECK_SIZE(uint64_t, 64/8);
200 CHECK_SIZE(int64_t, 64/8);
201 CHECK_SIZE(uint32_t, 32/8);
202 CHECK_SIZE(int32_t, 32/8);
203 CHECK_SIZE(uint16_t, 16/8);
204 CHECK_SIZE(int16_t, 16/8);
205 CHECK_SIZE(uint8_t, 8/8);
206 CHECK_SIZE(int8_t, 8/8);
207
208 /*
209 * Misc alignment checks.
210 */
211 CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 32);
212 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s, 16);
213 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s.aIORegions, 16);
214 CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
215 CHECK_MEMBER_ALIGNMENT(PCIGLOBALS, pci_irq_levels, 16);
216 CHECK_MEMBER_ALIGNMENT(PCNetState, u64LastPoll, 8);
217 CHECK_MEMBER_ALIGNMENT(VGASTATE, Dev, 8);
218 CHECK_MEMBER_ALIGNMENT(VGASTATE, StatGCMemoryRead, 8);
219#ifdef VBOX_WITH_STATISTICS
220// CHECK_MEMBER_ALIGNMENT(PCNetState, StatMMIOReadGC, 8);
221 CHECK_MEMBER_ALIGNMENT(DEVPIC, StatSetIrqGC, 8);
222 CHECK_MEMBER_ALIGNMENT(APICState, StatMMIOReadGC, 8);
223 CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
224 CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
225#endif
226 CHECK_MEMBER_ALIGNMENT(PITState, StatPITIrq, 8);
227 CHECK_MEMBER_ALIGNMENT(ATADevState, cTotalSectors, 8);
228 CHECK_MEMBER_ALIGNMENT(ATADevState, StatATADMA, 8);
229 CHECK_MEMBER_ALIGNMENT(ATADevState, StatReads, 8);
230 CHECK_MEMBER_ALIGNMENT(ATACONTROLLER, StatAsyncOps, 8);
231#ifdef VBOX_WITH_USB
232 CHECK_MEMBER_ALIGNMENT(OHCI, RootHub, 8);
233# ifdef VBOX_WITH_STATISTICS
234 CHECK_MEMBER_ALIGNMENT(OHCI, StatCanceledIsocUrbs, 8);
235# endif
236 CHECK_MEMBER_ALIGNMENT(EHCI, RootHub, 8);
237# ifdef VBOX_WITH_STATISTICS
238 CHECK_MEMBER_ALIGNMENT(EHCI, StatCanceledIsocUrbs, 8);
239# endif
240#endif
241
242
243 /*
244 * Compare HC and GC.
245 */
246 printf("tstDeviceStructSize: Comparing HC and GC...\n");
247#include "tstDeviceStructSizeGC.h"
248
249 /*
250 * Report result.
251 */
252 if (rc)
253 printf("tstDeviceStructSize: FAILURE - %d errors\n", rc);
254 else
255 printf("tstDeviceStructSize: SUCCESS\n");
256 return rc;
257}
258
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