tstRTCircBuf.cpp revision 292dc462b10ba7ef37b871434e332aecf8ad97df
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * IPRT Testcase - Lock free circular buffers.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Copyright (C) 2010 Oracle Corporation
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * available from http://www.virtualbox.org. This file is free software;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * you can redistribute it and/or modify it under the terms of the GNU
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * General Public License (GPL) as published by the Free Software
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * The contents of this file may alternatively be used under the terms
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * of the Common Development and Distribution License Version 1.0
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * VirtualBox OSE distribution, in which case the provisions of the
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * CDDL are applicable instead of those of the GPL.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * You may elect to license modified versions of this file under the
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * terms and conditions of either the GPL or the CDDL or both.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/*******************************************************************************
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync* Header Files *
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync*******************************************************************************/
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Basic API checks.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncstatic void tst1(void)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync char pcTestPattern1[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9 };
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync char pcTestPattern2[] = { 0x8, 0x9, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9 };
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync char pcTestPattern3[] = { 0x5, 0x6, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 };
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Create */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync RTTESTI_CHECK_RC(RTCircBufCreate(&pBuf, 10), VINF_SUCCESS);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Full write */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync RTCircBufAcquireWriteBlock(pBuf, 10, &pvBuf, &cbSize);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync// RTTESTI_CHECK(memcmp(pBuf->pvBuf, pcTestPattern1, 10) == 0); /* Check the internal state */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Half read */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync RTCircBufAcquireReadBlock(pBuf, 5, &pvBuf, &cbSize);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync RTTESTI_CHECK(memcmp(pvBuf, pcTestPattern1, 5) == 0);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Sub write */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync RTCircBufAcquireWriteBlock(pBuf, 2, &pvBuf, &cbSize);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync// RTTESTI_CHECK(memcmp(pBuf->pvBuf, pcTestPattern2, 10) == 0); /* Check the internal state */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Split tests */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /* Split read */
106ee6c5692ad0546845ce72b29e0fddbed2a455vboxsync RTCircBufAcquireReadBlock(pBuf, 7, &pvBuf, &cbSize);
106ee6c5692ad0546845ce72b29e0fddbed2a455vboxsync RTTESTI_CHECK(memcmp(pvBuf, &pcTestPattern1[5], 5) == 0);
106ee6c5692ad0546845ce72b29e0fddbed2a455vboxsync RTCircBufAcquireReadBlock(pBuf, 2, &pvBuf, &cbSize);
106ee6c5692ad0546845ce72b29e0fddbed2a455vboxsync RTTESTI_CHECK(memcmp(pvBuf, &pcTestPattern1[8], 2) == 0);
106ee6c5692ad0546845ce72b29e0fddbed2a455vboxsync /* Split write */
106ee6c5692ad0546845ce72b29e0fddbed2a455vboxsync RTCircBufAcquireWriteBlock(pBuf, 10, &pvBuf, &cbSize);
int main()
if (rc)
return rc;
tst1();