tstRTMemEf.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * IPRT - Testcase for the RTMemEf* functions.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2010 Oracle Corporation
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * available from http://www.virtualbox.org. This file is free software;
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * you can redistribute it and/or modify it under the terms of the GNU
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * General Public License (GPL) as published by the Free Software
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * The contents of this file may alternatively be used under the terms
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * of the Common Development and Distribution License Version 1.0
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * VirtualBox OSE distribution, in which case the provisions of the
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * CDDL are applicable instead of those of the GPL.
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * You may elect to license modified versions of this file under the
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * terms and conditions of either the GPL or the CDDL or both.
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync/*******************************************************************************
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync* Header Files *
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync*******************************************************************************/
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync/*******************************************************************************
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync* Global Variables *
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync*******************************************************************************/
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsyncstatic unsigned g_cErrors = 0;
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync /* Trivial alloc fence test - allocate a single word and access both
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * the word after the allocated block and the word before. One of them
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * will crash no matter whether the fence is at the bottom or on top. */
730ec694931a669c87102e047d453d14dd3917e0vboxsync int32_t *p = (int32_t *)RTMemEfAllocNP(sizeof(int32_t));
e5f7384e62bc82ad4610e1dd35fe4ca59016814evboxsync RTPrintf("tstRTMemAllocEfAccess: allocated int32_t at %#p\n", p);
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync RTPrintf("tstRTMemAllocEfAccess: triggering buffer overrun...\n");
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync RTPrintf("tstRTMemAllocEfAccess: triggering buffer underrun...\n");
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync /* Reaching this is a severe error. */
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync do { bool const f = !!(expr); if (!f) { RTPrintf("tstRTMemEf(%d): %s!\n", __LINE__, #expr); g_cErrors++; } } while (0)
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync * Some simple stuff.
93916c9acad52e266a71eac82da1da3c2d23d4dbvboxsync RTPrintf("tstMemAutoPtr: FAILED - %d errors\n", g_cErrors);