VirtualBox

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

Last change on this file since 1071 was 736, checked in by vboxsync, 18 years ago

Disabled the wrong check.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1/* $Id: tstDeviceStructSize.cpp 736 2007-02-07 01:15:17Z 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/apic.c"
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
60#include <stdio.h>
61
62
63/*******************************************************************************
64* Defined Constants And Macros *
65*******************************************************************************/
66/**
67 * Checks the offset of a data member.
68 * @param type Type.
69 * @param off Correct offset.
70 * @param m Member name.
71 */
72#define CHECK_OFF(type, off, m) \
73 do { \
74 if (off != RT_OFFSETOF(type, m)) \
75 { \
76 printf("%#010x %s Off by %d!! (off=%#x)\n", RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), off); \
77 rc++; \
78 } \
79 /*else */ \
80 /*printf("%#08x %s\n", RT_OFFSETOF(type, m), #m);*/ \
81 } while (0)
82
83/**
84 * Checks the size of type.
85 * @param type Type.
86 * @param size Correct size.
87 */
88#define CHECK_SIZE(type, size) \
89 do { \
90 if (size != sizeof(type)) \
91 { \
92 printf("sizeof(%s): %#x (%d) Off by %d!!\n", #type, (int)sizeof(type), (int)sizeof(type), (int)(sizeof(type) - size)); \
93 rc++; \
94 } \
95 else \
96 printf("sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
97 } while (0)
98
99/**
100 * Checks the alignment of a struct member.
101 */
102#define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
103 do \
104 { \
105 if ( RT_OFFSETOF(strct, member) & ((align) - 1) ) \
106 { \
107 printf("%s::%s offset=%d expected alignment %d, meaning %d off\n", #strct, #member, RT_OFFSETOF(strct, member), \
108 align, RT_OFFSETOF(strct, member) & (align - 1)); \
109 rc++; \
110 } \
111 } while (0)
112
113/**
114 * Checks that the size of a type is aligned correctly.
115 */
116#define CHECK_SIZE_ALIGNMENT(type, align) \
117 do { \
118 if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
119 { \
120 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)); \
121 rc++; \
122 } \
123 } while (0)
124
125/**
126 * Checks that a internal struct padding is big enough.
127 */
128#define CHECK_PADDING(strct, member) \
129 do \
130 { \
131 strct *p; \
132 if (sizeof(p->member.s) > sizeof(p->member.padding)) \
133 { \
134 printf("padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
135 (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), 32)); \
136 rc++; \
137 } \
138 } while (0)
139
140/**
141 * Checks that a internal struct padding is big enough.
142 */
143#define CHECK_PADDING2(strct) \
144 do \
145 { \
146 strct *p; \
147 if (sizeof(p->s) > sizeof(p->padding)) \
148 { \
149 printf("padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
150 (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 32)); \
151 rc++; \
152 } \
153 } while (0)
154
155/**
156 * Checks that a internal struct padding is big enough.
157 */
158#define CHECK_PADDING3(strct, member, pad_member) \
159 do \
160 { \
161 strct *p; \
162 if (sizeof(p->member) > sizeof(p->pad_member)) \
163 { \
164 printf("padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
165 (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
166 rc++; \
167 } \
168 } while (0)
169
170/**
171 * Prints the offset of a struct member.
172 */
173#define PRINT_OFFSET(strct, member) \
174 do \
175 { \
176 printf("%s::%s offset %d sizeof %d\n", #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
177 } while (0)
178
179
180int main()
181{
182 int rc = 0;
183 printf("tstDeviceStructSize: TESTING\n");
184
185 /* Assert sanity */
186 CHECK_SIZE(uint128_t, 128/8);
187 CHECK_SIZE(int128_t, 128/8);
188 CHECK_SIZE(uint64_t, 64/8);
189 CHECK_SIZE(int64_t, 64/8);
190 CHECK_SIZE(uint32_t, 32/8);
191 CHECK_SIZE(int32_t, 32/8);
192 CHECK_SIZE(uint16_t, 16/8);
193 CHECK_SIZE(int16_t, 16/8);
194 CHECK_SIZE(uint8_t, 8/8);
195 CHECK_SIZE(int8_t, 8/8);
196
197 /*
198 * Misc alignment checks.
199 */
200 CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 32);
201 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s, 16);
202 CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s.aIORegions, 16);
203 CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
204 CHECK_MEMBER_ALIGNMENT(PCIGLOBALS, pci_irq_levels, 16);
205 CHECK_MEMBER_ALIGNMENT(PCNetState, u64LastPoll, 8);
206 CHECK_MEMBER_ALIGNMENT(VGASTATE, Dev, 8);
207 CHECK_MEMBER_ALIGNMENT(VGASTATE, StatGCMemoryRead, 8);
208#ifdef VBOX_WITH_STATISTICS
209// CHECK_MEMBER_ALIGNMENT(PCNetState, StatMMIOReadGC, 8);
210 CHECK_MEMBER_ALIGNMENT(DEVPIC, StatSetIrqGC, 8);
211 CHECK_MEMBER_ALIGNMENT(APICState, StatMMIOReadGC, 8);
212 CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
213 CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
214#endif
215 CHECK_MEMBER_ALIGNMENT(PITState, StatPITIrq, 8);
216 CHECK_MEMBER_ALIGNMENT(ATADevState, cTotalSectors, 8);
217 CHECK_MEMBER_ALIGNMENT(ATADevState, StatReads, 8);
218 CHECK_MEMBER_ALIGNMENT(ATACONTROLLER, StatAsyncOps, 8);
219#ifdef VBOX_WITH_USB
220 CHECK_MEMBER_ALIGNMENT(OHCI, RootHub, 8);
221# ifdef VBOX_WITH_STATISTICS
222 CHECK_MEMBER_ALIGNMENT(OHCI, StatCanceledIsocUrbs, 8);
223# endif
224#endif
225
226
227 /*
228 * Compare HC and GC.
229 */
230 printf("tstDeviceStructSize: Comparing HC and GC...\n");
231#include "tstDeviceStructSizeGC.h"
232
233 /*
234 * Report result.
235 */
236 if (rc)
237 printf("tstDeviceStructSize: FAILURE - %d errors\n", rc);
238 else
239 printf("tstDeviceStructSize: SUCCESS\n");
240 return rc;
241}
242
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