VirtualBox

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

Last change on this file since 46272 was 46272, checked in by vboxsync, 12 years ago

Audio/DevIchHda: Implement support for R0 and RC

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.4 KB
Line 
1/* $Id: tstDeviceStructSize.cpp 46272 2013-05-26 18:02:48Z vboxsync $ */
2/** @file
3 * tstDeviceStructSize - testcase for check structure sizes/alignment
4 * and to verify that HC and RC uses the same
5 * representation of the structures.
6 */
7
8/*
9 * Copyright (C) 2006-2012 Oracle Corporation
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
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <VBox/types.h>
24#include <iprt/x86.h>
25
26
27#define VBOX_WITH_HGCM /* grumble */
28#define VBOX_DEVICE_STRUCT_TESTCASE
29#undef LOG_GROUP
30#include "../Bus/DevPCI.cpp"
31#undef LOG_GROUP
32#include "../Bus/DevPciIch9.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 "../Input/PS2K.cpp"
39#ifdef VBOX_WITH_E1000
40# undef LOG_GROUP
41# include "../Network/DevE1000.cpp"
42#endif
43#undef LOG_GROUP
44#include "../Network/DevPCNet.cpp"
45#ifdef VBOX_WITH_VIRTIO
46# undef LOG_GROUP
47# include "../Network/DevVirtioNet.cpp"
48#endif
49#undef LOG_GROUP
50#include "../PC/DevACPI.cpp"
51#undef LOG_GROUP
52#include "../PC/DevPIC.cpp"
53#undef LOG_GROUP
54#include "../PC/DevPit-i8254.cpp"
55#undef LOG_GROUP
56#include "../PC/DevRTC.cpp"
57#undef LOG_GROUP
58#include "../PC/DevAPIC.cpp"
59#undef LOG_GROUP
60#include "../PC/DevIoApic.cpp"
61#undef LOG_GROUP
62#include "../PC/DevHPET.cpp"
63#undef LOG_GROUP
64#include "../PC/DevLPC.cpp"
65#undef LOG_GROUP
66#include "../PC/DevSMC.cpp"
67#undef LOG_GROUP
68#include "../Storage/DevATA.cpp"
69#ifdef VBOX_WITH_USB
70# undef LOG_GROUP
71# include "../USB/DevOHCI.cpp"
72# ifdef VBOX_WITH_EHCI_IMPL
73# include "../USB/DevEHCI.cpp"
74# endif
75#endif
76#undef LOG_GROUP
77#include "../VMMDev/VMMDev.cpp"
78#undef LOG_GROUP
79#include "../Parallel/DevParallel.cpp"
80#undef LOG_GROUP
81#include "../Serial/DevSerial.cpp"
82#ifdef VBOX_WITH_AHCI
83# undef LOG_GROUP
84# include "../Storage/DevAHCI.cpp"
85#endif
86#ifdef VBOX_WITH_BUSLOGIC
87# undef LOG_GROUP
88# include "../Storage/DevBusLogic.cpp"
89#endif
90#ifdef VBOX_WITH_LSILOGIC
91# undef LOG_GROUP
92# include "../Storage/DevLsiLogicSCSI.cpp"
93#endif
94
95#ifdef VBOX_WITH_PCI_PASSTHROUGH_IMPL
96# undef LOG_GROUP
97# include "../Bus/DevPciRaw.cpp"
98#endif
99
100#undef LOG_GROUP
101#include "../Audio/DevIchHda.cpp"
102
103#include <stdio.h>
104
105
106/*******************************************************************************
107* Defined Constants And Macros *
108*******************************************************************************/
109/**
110 * Checks the offset of a data member.
111 * @param type Type.
112 * @param off Correct offset.
113 * @param m Member name.
114 */
115#define CHECK_OFF(type, off, m) \
116 do { \
117 if (off != RT_OFFSETOF(type, m)) \
118 { \
119 printf("tstDeviceStructSize: error! %#010x %s Off by %d!! (off=%#x)\n", RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), off); \
120 rc++; \
121 } \
122 /*else */ \
123 /*printf("%#08x %s\n", RT_OFFSETOF(type, m), #m);*/ \
124 } while (0)
125
126/**
127 * Checks the size of type.
128 * @param type Type.
129 * @param size Correct size.
130 */
131#define CHECK_SIZE(type, size) \
132 do { \
133 if (size != sizeof(type)) \
134 { \
135 printf("tstDeviceStructSize: error! sizeof(%s): %#x (%d) Off by %d!!\n", #type, (int)sizeof(type), (int)sizeof(type), (int)(sizeof(type) - size)); \
136 rc++; \
137 } \
138 else \
139 printf("tstDeviceStructSize: info: sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
140 } while (0)
141
142/**
143 * Checks the alignment of a struct member.
144 */
145#define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
146 do \
147 { \
148 if (RT_OFFSETOF(strct, member) & ((align) - 1) ) \
149 { \
150 printf("tstDeviceStructSize: error! %s::%s offset=%#x (%u) expected alignment %x, meaning %#x (%u) off\n", \
151 #strct, #member, \
152 (unsigned)RT_OFFSETOF(strct, member), \
153 (unsigned)RT_OFFSETOF(strct, member), \
154 (unsigned)(align), \
155 (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)), \
156 (unsigned)(((align) - RT_OFFSETOF(strct, member)) & ((align) - 1)) ); \
157 rc++; \
158 } \
159 } while (0)
160
161/**
162 * Checks that the size of a type is aligned correctly.
163 */
164#define CHECK_SIZE_ALIGNMENT(type, align) \
165 do { \
166 if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
167 { \
168 printf("tstDeviceStructSize: error! %s size=%#x (%u), align=%#x %#x (%u) bytes off\n", \
169 #type, \
170 (unsigned)sizeof(type), \
171 (unsigned)sizeof(type), \
172 (align), \
173 (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type), \
174 (unsigned)RT_ALIGN_Z(sizeof(type), align) - (unsigned)sizeof(type)); \
175 rc++; \
176 } \
177 } while (0)
178
179/**
180 * Checks that a internal struct padding is big enough.
181 */
182#define CHECK_PADDING(strct, member, align) \
183 do \
184 { \
185 strct *p = NULL; NOREF(p); \
186 if (sizeof(p->member.s) > sizeof(p->member.padding)) \
187 { \
188 printf("tstDeviceStructSize: error! padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
189 (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
190 rc++; \
191 } \
192 else if (RT_ALIGN_Z(sizeof(p->member.padding), (align)) != sizeof(p->member.padding)) \
193 { \
194 printf("tstDeviceStructSize: error! padding of %s::%s is misaligned, padding=%d correct=%d\n", #strct, #member, \
195 (int)sizeof(p->member.padding), (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
196 rc++; \
197 } \
198 } while (0)
199
200/**
201 * Checks that a internal struct padding is big enough.
202 */
203#define CHECK_PADDING2(strct) \
204 do \
205 { \
206 strct *p = NULL; NOREF(p); \
207 if (sizeof(p->s) > sizeof(p->padding)) \
208 { \
209 printf("tstDeviceStructSize: error! padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
210 (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 32)); \
211 rc++; \
212 } \
213 } while (0)
214
215/**
216 * Checks that a internal struct padding is big enough.
217 */
218#define CHECK_PADDING3(strct, member, pad_member) \
219 do \
220 { \
221 strct *p = NULL; NOREF(p); \
222 if (sizeof(p->member) > sizeof(p->pad_member)) \
223 { \
224 printf("tstDeviceStructSize: error! padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
225 (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
226 rc++; \
227 } \
228 } while (0)
229
230/**
231 * Prints the offset of a struct member.
232 */
233#define PRINT_OFFSET(strct, member) \
234 do \
235 { \
236 printf("tstDeviceStructSize: info: %s::%s offset %d sizeof %d\n", #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
237 } while (0)
238
239
240int main()
241{
242 int rc = 0;
243 printf("tstDeviceStructSize: TESTING\n");
244
245 /* Assert sanity */
246 CHECK_SIZE(uint128_t, 128/8);
247 CHECK_SIZE(int128_t, 128/8);
248 CHECK_SIZE(uint64_t, 64/8);
249 CHECK_SIZE(int64_t, 64/8);
250 CHECK_SIZE(uint32_t, 32/8);
251 CHECK_SIZE(int32_t, 32/8);
252 CHECK_SIZE(uint16_t, 16/8);
253 CHECK_SIZE(int16_t, 16/8);
254 CHECK_SIZE(uint8_t, 8/8);
255 CHECK_SIZE(int8_t, 8/8);
256
257 /* Basic alignment checks. */
258 CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 64);
259 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s, 16);
260 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s.aIORegions, 16);
261
262 /*
263 * Misc alignment checks (keep this somewhat alphabetical).
264 */
265 CHECK_MEMBER_ALIGNMENT(AHCI, lock, 8);
266 CHECK_MEMBER_ALIGNMENT(AHCIPort, StatDMA, 8);
267#ifdef VBOX_WITH_STATISTICS
268 CHECK_MEMBER_ALIGNMENT(APICDeviceInfo, StatMMIOReadGC, 8);
269#endif
270 CHECK_MEMBER_ALIGNMENT(ATADevState, cTotalSectors, 8);
271 CHECK_MEMBER_ALIGNMENT(ATADevState, StatATADMA, 8);
272 CHECK_MEMBER_ALIGNMENT(ATADevState, StatReads, 8);
273 CHECK_MEMBER_ALIGNMENT(ATACONTROLLER, lock, 8);
274 CHECK_MEMBER_ALIGNMENT(ATACONTROLLER, StatAsyncOps, 8);
275 CHECK_MEMBER_ALIGNMENT(BUSLOGIC, CritSectIntr, 8);
276#ifdef VBOX_WITH_STATISTICS
277 CHECK_MEMBER_ALIGNMENT(DEVPIC, StatSetIrqGC, 8);
278#endif
279#ifdef VBOX_WITH_E1000
280 CHECK_MEMBER_ALIGNMENT(E1KSTATE, cs, 8);
281 CHECK_MEMBER_ALIGNMENT(E1KSTATE, csRx, 8);
282 CHECK_MEMBER_ALIGNMENT(E1KSTATE, StatReceiveBytes, 8);
283#endif
284#ifdef VBOX_WITH_VIRTIO
285 CHECK_MEMBER_ALIGNMENT(VNETSTATE, StatReceiveBytes, 8);
286#endif
287 //CHECK_MEMBER_ALIGNMENT(E1KSTATE, csTx, 8);
288#ifdef VBOX_WITH_USB
289# ifdef VBOX_WITH_EHCI_IMPL
290 CHECK_MEMBER_ALIGNMENT(EHCI, RootHub, 8);
291# ifdef VBOX_WITH_STATISTICS
292 CHECK_MEMBER_ALIGNMENT(EHCI, StatCanceledIsocUrbs, 8);
293# endif
294# endif
295#endif
296 CHECK_MEMBER_ALIGNMENT(E1KSTATE, StatReceiveBytes, 8);
297#ifdef VBOX_WITH_STATISTICS
298 CHECK_MEMBER_ALIGNMENT(IOAPIC, StatMMIOReadGC, 8);
299 CHECK_MEMBER_ALIGNMENT(IOAPIC, StatMMIOReadGC, 8);
300#endif
301 CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, GCPhysMMIOBase, 8);
302 CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, aMessage, 8);
303 CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, ReplyPostQueueCritSect, 8);
304 CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, ReplyFreeQueueCritSect, 8);
305 CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, uReplyFreeQueueNextEntryFreeWrite, 8);
306 CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, VBoxSCSI, 8);
307#ifdef VBOX_WITH_USB
308 CHECK_MEMBER_ALIGNMENT(OHCI, RootHub, 8);
309# ifdef VBOX_WITH_STATISTICS
310 CHECK_MEMBER_ALIGNMENT(OHCI, StatCanceledIsocUrbs, 8);
311# endif
312#endif
313 CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
314 CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
315 CHECK_MEMBER_ALIGNMENT(PCIGLOBALS, pci_irq_levels, 16);
316 CHECK_MEMBER_ALIGNMENT(PCNETSTATE, u64LastPoll, 8);
317 CHECK_MEMBER_ALIGNMENT(PCNETSTATE, CritSect, 8);
318 CHECK_MEMBER_ALIGNMENT(PCNETSTATE, StatReceiveBytes, 8);
319#ifdef VBOX_WITH_STATISTICS
320 CHECK_MEMBER_ALIGNMENT(PCNETSTATE, StatMMIOReadRZ, 8);
321#endif
322 CHECK_MEMBER_ALIGNMENT(PITSTATE, StatPITIrq, 8);
323 CHECK_MEMBER_ALIGNMENT(SerialState, CritSect, 8);
324 CHECK_MEMBER_ALIGNMENT(VGASTATE, Dev, 8);
325 CHECK_MEMBER_ALIGNMENT(VGASTATE, CritSect, 8);
326 CHECK_MEMBER_ALIGNMENT(VGASTATE, StatRZMemoryRead, 8);
327 CHECK_MEMBER_ALIGNMENT(VMMDevState, CritSect, 8);
328#ifdef VBOX_WITH_VIRTIO
329 CHECK_MEMBER_ALIGNMENT(VPCISTATE, cs, 8);
330 CHECK_MEMBER_ALIGNMENT(VPCISTATE, led, 4);
331 CHECK_MEMBER_ALIGNMENT(VPCISTATE, Queues, 8);
332#endif
333#ifdef VBOX_WITH_PCI_PASSTHROUGH_IMPL
334 CHECK_MEMBER_ALIGNMENT(PCIRAWSENDREQ, u.aGetRegionInfo.u64RegionSize, 8);
335#endif
336
337#ifdef VBOX_WITH_RAW_MODE
338 /*
339 * Compare HC and RC.
340 */
341 printf("tstDeviceStructSize: Comparing HC and RC...\n");
342# include "tstDeviceStructSizeRC.h"
343#endif
344
345 /*
346 * Report result.
347 */
348 if (rc)
349 printf("tstDeviceStructSize: FAILURE - %d errors\n", rc);
350 else
351 printf("tstDeviceStructSize: SUCCESS\n");
352 return rc;
353}
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