tstDeviceStructSize.cpp revision 3f72ab7ee9d1539bfa4ed19972430194627b9273
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * tstDeviceStructSize - testcase for check structure sizes/alignment
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * and to verify that HC and GC uses the same
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * representation of the structures.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Copyright (C) 2006-2007 Sun Microsystems, Inc.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * This file is part of VirtualBox Open Source Edition (OSE), as
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * available from http://www.virtualbox.org. This file is free software;
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * you can redistribute it and/or modify it under the terms of the GNU
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * General Public License (GPL) as published by the Free Software
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Foundation, in version 2 as it comes in the "COPYING" file of the
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Clara, CA 95054 USA or visit http://www.sun.com if you need
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * additional information or have any questions.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar/*******************************************************************************
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar* Header Files *
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar*******************************************************************************/
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar/*******************************************************************************
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar* Defined Constants And Macros *
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar*******************************************************************************/
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Checks the offset of a data member.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * @param type Type.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * @param off Correct offset.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * @param m Member name.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("%#010x %s Off by %d!! (off=%#x)\n", RT_OFFSETOF(type, m), #type "." #m, off - RT_OFFSETOF(type, m), off); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar /*printf("%#08x %s\n", RT_OFFSETOF(type, m), #m);*/ \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Checks the size of type.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * @param type Type.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * @param size Correct size.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("sizeof(%s): %#x (%d) Off by %d!!\n", #type, (int)sizeof(type), (int)sizeof(type), (int)(sizeof(type) - size)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("sizeof(%s): %#x (%d)\n", #type, (int)sizeof(type), (int)sizeof(type)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Checks the alignment of a struct member.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar#define CHECK_MEMBER_ALIGNMENT(strct, member, align) \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar if ( RT_OFFSETOF(strct, member) & ((align) - 1) ) \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("%s::%s offset=%d expected alignment %d, meaning %d off\n", #strct, #member, RT_OFFSETOF(strct, member), \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar align, RT_OFFSETOF(strct, member) & (align - 1)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Checks that the size of a type is aligned correctly.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar if (RT_ALIGN_Z(sizeof(type), (align)) != sizeof(type)) \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar 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)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Checks that a internal struct padding is big enough.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar if (sizeof(p->member.s) > sizeof(p->member.padding)) \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("padding of %s::%s is too small, padding=%d struct=%d correct=%d\n", #strct, #member, \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar (int)sizeof(p->member.padding), (int)sizeof(p->member.s), (int)RT_ALIGN_Z(sizeof(p->member.s), 32)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Checks that a internal struct padding is big enough.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar if (sizeof(p->s) > sizeof(p->padding)) \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("padding of %s is too small, padding=%d struct=%d correct=%d\n", #strct, \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar (int)sizeof(p->padding), (int)sizeof(p->s), (int)RT_ALIGN_Z(sizeof(p->s), 32)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Checks that a internal struct padding is big enough.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar#define CHECK_PADDING3(strct, member, pad_member) \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar if (sizeof(p->member) > sizeof(p->pad_member)) \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("padding of %s::%s is too small, padding=%d struct=%d\n", #strct, #member, \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar (int)sizeof(p->pad_member), (int)sizeof(p->member)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Prints the offset of a struct member.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("%s::%s offset %d sizeof %d\n", #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar /* Assert sanity */
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Misc alignment checks.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 32);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s, 16);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(PCIDEVICE, Int.s.aIORegions, 16);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(PCIGLOBALS, pci_irq_levels, 16);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(PCNetState, u64LastPoll, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(VGASTATE, StatGCMemoryRead, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar// CHECK_MEMBER_ALIGNMENT(PCNetState, StatMMIOReadGC, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(DEVPIC, StatSetIrqGC, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(APICState, StatMMIOReadGC, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(IOAPICState, StatMMIOReadGC, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(PITState, StatPITIrq, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(ATADevState, cTotalSectors, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(ATADevState, StatATADMA, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(ATADevState, StatReads, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(ATACONTROLLER, StatAsyncOps, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(OHCI, StatCanceledIsocUrbs, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CHECK_MEMBER_ALIGNMENT(EHCI, StatCanceledIsocUrbs, 8);
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Compare HC and GC.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("tstDeviceStructSize: Comparing HC and GC...\n");
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar * Report result.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar printf("tstDeviceStructSize: FAILURE - %d errors\n", rc);