VirtualBox

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

Last change on this file since 48935 was 48214, checked in by vboxsync, 11 years ago

Added new PS/2 mouse implementation (currently disabled).

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