VirtualBox

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

Last change on this file since 54153 was 53831, checked in by vboxsync, 10 years ago

PDM/Audio: Build fix; forgot some files.

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