VirtualBox

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

Last change on this file since 1959 was 1931, checked in by vboxsync, 18 years ago

apic.c => DevAPIC.cpp

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1/* $Id: tstDeviceStructSize.cpp 1931 2007-04-04 14:04:15Z vboxsync $ */
2/** @file
3 * tstDeviceStructSize - testcase for check structure sizes/alignment
4 * and to verify that HC and GC uses the same
5 * representation of the structures.
6 */
7
8/*
9 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
15 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
16 * distribution. VirtualBox OSE is distributed in the hope that it will
17 * be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * If you received this file as part of a commercial VirtualBox
20 * distribution, then only the terms of your commercial VirtualBox
21 * license agreement apply instead of the previous paragraph.
22 */
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/types.h>
28#include <VBox/x86.h>
29
30#define VBOX_DEVICE_STRUCT_TESTCASE
31#undef LOG_GROUP
32#include "Bus/DevPCI.cpp"
33#undef LOG_GROUP
34#include "Graphics/DevVGA.cpp"
35#undef LOG_GROUP
36#include "Input/pckbd.c"
37#undef LOG_GROUP
38#include "Network/DevPCNet.cpp"
39//#undef LOG_GROUP
40//#include "Network/ne2000.c"
41#undef LOG_GROUP
42#include "PC/DevACPI.cpp"
43#undef LOG_GROUP
44#include "PC/DevPIC.cpp"
45#undef LOG_GROUP
46#include "PC/DevPit-i8254.cpp"
47#undef LOG_GROUP
48#include "PC/DevRTC.cpp"
49#undef LOG_GROUP
50#include "PC/DevAPIC.cpp"
51#undef LOG_GROUP
52#include "Storage/DevATA.cpp"
53#ifdef VBOX_WITH_USB
54# undef LOG_GROUP
55# include "USB/DevOHCI.cpp"
56#endif
57#undef LOG_GROUP
58#include "VMMDev/VBoxDev.cpp"
59#undef LOG_GROUP
60#include "Serial/DevSerial.cpp"
61
62#include <stdio.h>
63
64
65/*******************************************************************************
66* Defined Constants And Macros *
67*******************************************************************************/
68/**
69 * Checks the offset of a data member.
70 * @param type Type.
71 * @param off Correct offset.
72 * @param m Member name.
73 */
74#define CHECK_OFF(type, off, m) \
75 do { \
76 if (off != RT_OFFSETOF(type, m)) \
77 { \
78 printf("%#010x %s Off by %d!! (off=%#x)\n", RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), off); \
79 rc++; \
80 } \
81 /*else */ \
82 /*printf("%#08x %s\n", RT_OFFSETOF(type, m), #m);*/ \
83 } while (0)
84
85/**
86 * Checks the size of type.
87 * @param type Type.
88 * @param size Correct size.
89 */
90#define CHECK_SIZE(type, size) \
91 do { \
92 if (size != sizeof(type)) \
93 { \
94 printf("sizeof(%s): %#x (%d) Off by %d!!\n", #type, (int)sizeof(type), (int)sizeof(type), (int)(sizeof(type) - size)); \
95 rc++; \
96 } \
97 else \
98 printf("sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
99 } while (0)
100
101/**
102 * Checks the alignment of a struct member.
103 */
104#define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
105 do \
106 { \
107 if ( RT_OFFSETOF(strct, member) & ((align) - 1) ) \
108 { \
109 printf("%s::%s offset=%d expected alignment %d, meaning %d off\n", #strct, #member, RT_OFFSETOF(strct, member), \
110 align, RT_OFFSETOF(strct, member) & (align - 1)); \
111 rc++; \
112 } \
113 } while (0)
114
115/**
116 * Checks that the size of a type is aligned correctly.
117 */
118#define CHECK_SIZE_ALIGNMENT(type, align) \
119 do { \
120 if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
121 { \
122 printf("%s size=%#x, align=%#x %#x bytes off\n", #type, (int)sizeof(type), (align), (int)RT_ALIGN_Z(sizeof(type), align) - (int)sizeof(type)); \
123 rc++; \
124 } \
125 } while (0)
126
127/**
128 * Checks that a internal struct padding is big enough.
129 */
130#define CHECK_PADDING(strct, member) \
131 do \
132 { \
133 strct *p; \
134 if (sizeof(p->member.s) > sizeof(p->member.padding)) \
135 { \
136 printf("padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
137 (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), 32)); \
138 rc++; \
139 } \
140 } while (0)
141
142/**
143 * Checks that a internal struct padding is big enough.
144 */
145#define CHECK_PADDING2(strct) \
146 do \
147 { \
148 strct *p; \
149 if (sizeof(p->s) > sizeof(p->padding)) \
150 { \
151 printf("padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
152 (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 32)); \
153 rc++; \
154 } \
155 } while (0)
156
157/**
158 * Checks that a internal struct padding is big enough.
159 */
160#define CHECK_PADDING3(strct, member, pad_member) \
161 do \
162 { \
163 strct *p; \
164 if (sizeof(p->member) > sizeof(p->pad_member)) \
165 { \
166 printf("padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
167 (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
168 rc++; \
169 } \
170 } while (0)
171
172/**
173 * Prints the offset of a struct member.
174 */
175#define PRINT_OFFSET(strct, member) \
176 do \
177 { \
178 printf("%s::%s offset %d sizeof %d\n", #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
179 } while (0)
180
181
182int main()
183{
184 int rc = 0;
185 printf("tstDeviceStructSize: TESTING\n");
186
187 /* Assert sanity */
188 CHECK_SIZE(uint128_t, 128/8);
189 CHECK_SIZE(int128_t, 128/8);
190 CHECK_SIZE(uint64_t, 64/8);
191 CHECK_SIZE(int64_t, 64/8);
192 CHECK_SIZE(uint32_t, 32/8);
193 CHECK_SIZE(int32_t, 32/8);
194 CHECK_SIZE(uint16_t, 16/8);
195 CHECK_SIZE(int16_t, 16/8);
196 CHECK_SIZE(uint8_t, 8/8);
197 CHECK_SIZE(int8_t, 8/8);
198
199 /*
200 * Misc alignment checks.
201 */
202 CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 32);
203 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s, 16);
204 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s.aIORegions, 16);
205 CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
206 CHECK_MEMBER_ALIGNMENT(PCIGLOBALS, pci_irq_levels, 16);
207 CHECK_MEMBER_ALIGNMENT(PCNetState, u64LastPoll, 8);
208 CHECK_MEMBER_ALIGNMENT(VGASTATE, Dev, 8);
209 CHECK_MEMBER_ALIGNMENT(VGASTATE, StatGCMemoryRead, 8);
210#ifdef VBOX_WITH_STATISTICS
211// CHECK_MEMBER_ALIGNMENT(PCNetState, StatMMIOReadGC, 8);
212 CHECK_MEMBER_ALIGNMENT(DEVPIC, StatSetIrqGC, 8);
213 CHECK_MEMBER_ALIGNMENT(APICState, StatMMIOReadGC, 8);
214 CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
215 CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
216#endif
217 CHECK_MEMBER_ALIGNMENT(PITState, StatPITIrq, 8);
218 CHECK_MEMBER_ALIGNMENT(ATADevState, cTotalSectors, 8);
219 CHECK_MEMBER_ALIGNMENT(ATADevState, StatReads, 8);
220 CHECK_MEMBER_ALIGNMENT(ATACONTROLLER, StatAsyncOps, 8);
221#ifdef VBOX_WITH_USB
222 CHECK_MEMBER_ALIGNMENT(OHCI, RootHub, 8);
223# ifdef VBOX_WITH_STATISTICS
224 CHECK_MEMBER_ALIGNMENT(OHCI, StatCanceledIsocUrbs, 8);
225# endif
226#endif
227
228
229 /*
230 * Compare HC and GC.
231 */
232 printf("tstDeviceStructSize: Comparing HC and GC...\n");
233#include "tstDeviceStructSizeGC.h"
234
235 /*
236 * Report result.
237 */
238 if (rc)
239 printf("tstDeviceStructSize: FAILURE - %d errors\n", rc);
240 else
241 printf("tstDeviceStructSize: SUCCESS\n");
242 return rc;
243}
244
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