VirtualBox

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

Last change on this file since 53392 was 52817, checked in by vboxsync, 10 years ago

xHCI: Ripped up and reconstituted with separate USB2/USB3 hubs.

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