VirtualBox

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

Last change on this file since 62182 was 62182, checked in by vboxsync, 8 years ago

Devices/testcase: fixes for VBOX_WITH_AUDIO_50

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