VirtualBox

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

Last change on this file since 73529 was 73135, checked in by vboxsync, 6 years ago

Serial: Split out the generic UART functionality into a separate module so it can be reused.

Add a PCI Express 16 port UART controller emulation based on the Oxford Semiconductor OXPCIe958
PCI Express to octa UART controller (supports chaining two of those together in a single device
to get up to 16 UARTs). This somewhat revives the incomplete and never enabled PCI UART controller
in the old code. Linux detects the device and apparently configures all 16 UARTs but data transfers
were not tested and the code is pretty incomplete still.

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