VirtualBox

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

Last change on this file since 56640 was 56292, checked in by vboxsync, 10 years ago

Devices: Updated (C) year.

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