本文整理汇总了C++中RTTESTI_CHECK函数的典型用法代码示例。如果您正苦于以下问题:C++ RTTESTI_CHECK函数的具体用法?C++ RTTESTI_CHECK怎么用?C++ RTTESTI_CHECK使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTTESTI_CHECK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tstRTPipe2
static void tstRTPipe2(void)
{
RTTestISub("Negative");
RTPIPE hPipeR = (RTPIPE)1;
RTPIPE hPipeW = (RTPIPE)1;
RTTESTI_CHECK_RC(RTPipeCreate(&hPipeR, &hPipeW, ~0), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTPipeCreate(NULL, &hPipeW, 0), VERR_INVALID_POINTER);
RTTESTI_CHECK_RC(RTPipeCreate(&hPipeR, NULL, 0), VERR_INVALID_POINTER);
RTTESTI_CHECK(hPipeR == (RTPIPE)1);
RTTESTI_CHECK(hPipeW == (RTPIPE)1);
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, 0), VINF_SUCCESS);
char abBuf[_4K];
size_t cbRead = ~(size_t)3;
RTTESTI_CHECK_RC(RTPipeRead(hPipeW, abBuf, 0, &cbRead), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeRead(hPipeW, abBuf, 1, &cbRead), VERR_ACCESS_DENIED);
RTTESTI_CHECK(cbRead == ~(size_t)3);
RTTESTI_CHECK_RC(RTPipeReadBlocking(hPipeW, abBuf, 0, NULL), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeReadBlocking(hPipeW, abBuf, 1, NULL), VERR_ACCESS_DENIED);
size_t cbWrite = ~(size_t)5;
RTTESTI_CHECK_RC(RTPipeWrite(hPipeR, "asdf", 0, &cbWrite), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeWrite(hPipeR, "asdf", 4, &cbWrite), VERR_ACCESS_DENIED);
RTTESTI_CHECK(cbWrite == ~(size_t)5);
RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeR, "asdf", 0, NULL), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeR, "asdf", 4, NULL), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeFlush(hPipeR), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
}
示例2: dotest
static void dotest(void)
{
RTDBGKRNLINFO hKrnlInfo;
RTTESTI_CHECK_RC_RETV(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0), VINF_SUCCESS);
static const char * const s_apszSyms[] =
{
"ast_pending",
"cpu_interrupt",
"dtrace_register",
"dtrace_suspend",
"kext_alloc",
"kext_free",
"vm_map_protect"
};
for (unsigned i = 0; i < RT_ELEMENTS(s_apszSyms); i++)
{
void *pvValue = NULL;
int rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], &pvValue);
RTTestIPrintf(RTTESTLVL_ALWAYS, "%Rrc %p %s\n", rc, pvValue, s_apszSyms[i]);
RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
if (RT_SUCCESS(rc))
RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], NULL), VINF_SUCCESS);
}
RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "no_such_symbol_name_really", NULL), VERR_SYMBOL_NOT_FOUND);
RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(hKrnlInfo) == 0);
RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(NIL_RTDBGKRNLINFO) == 0);
}
示例3: doMemRealloc
static void doMemRealloc(RTTEST hTest)
{
RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "%u reallocation, grow by 1 bytes\n", PAGE_SIZE * 2);
size_t cbAlloc = RTRandS32Ex(1, _16K);
void *pvBuf = NULL;
RTTESTI_CHECK_RC_OK_RETV(RTMemSaferAllocZEx(&pvBuf, cbAlloc, 0));
for (uint32_t i = 0; i <= PAGE_SIZE * 2; i++)
{
cbAlloc += 1;
RTTESTI_CHECK_RC_OK_RETV(RTMemSaferReallocZEx(cbAlloc - 1, pvBuf, cbAlloc, &pvBuf, 0));
memset(pvBuf, i & 0x7f, cbAlloc);
}
RTMemSaferFree(pvBuf, cbAlloc);
RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "100 random reallocations\n");
uint8_t chFiller = 0x42;
cbAlloc = 0;
pvBuf = NULL;
for (uint32_t i = 1; i <= 100; i++)
{
uint32_t cbNew = RTRandS32Ex(1, _16K + (i / 4) * _16K);
RTTESTI_CHECK_RC_OK_RETV(RTMemSaferReallocZEx(cbAlloc, pvBuf, cbNew, &pvBuf, 0));
RTTESTI_CHECK(ASMMemIsAll8(pvBuf, RT_MIN(cbAlloc, cbNew), chFiller) == NULL);
chFiller += 0x31;
memset(pvBuf, chFiller, cbNew);
cbAlloc = cbNew;
}
RTTESTI_CHECK_RC_OK_RETV(RTMemSaferReallocZEx(cbAlloc, pvBuf, 0, &pvBuf, 0));
RTTESTI_CHECK(pvBuf == NULL);
}
示例4: tst1
/**
* Basic API checks.
*/
static void tst1(void)
{
RTTestISub("Manifest creation");
size_t cbSize = 0;
size_t iFailed = 0;
/*
* test1.txt = "This is a test text."
* test2.txt = "Another test text."
*/
static RTMANIFESTTEST /*const*/ s_aFiles[] = /** @todo API misdesign, this should be const. */
{
{ "test1.txt", "794a8cc644b318ae6461aeea62915e399e441e8" },
{ "test2.txt", "f17393902ee94c1e8bbd4bf417cdc70051feca00" }
};
static const char s_szTestPattern[] =
"SHA1 (test1.txt)= 794a8cc644b318ae6461aeea62915e399e441e8\n"
"SHA1 (test2.txt)= f17393902ee94c1e8bbd4bf417cdc70051feca00\n"
;
void *pvBuf = NULL;
RTTESTI_CHECK_RC_RETV(RTManifestWriteFilesBuf(&pvBuf, &cbSize, RTDIGESTTYPE_SHA1, s_aFiles, 2), VINF_SUCCESS);
/* Check returned memory size */
RTTESTI_CHECK_RETV(cbSize == strlen(s_szTestPattern));
/* Check for correct manifest file content */
RTTESTI_CHECK(memcmp(pvBuf, s_szTestPattern, cbSize) == 0);
RTTestISub("Manifest verify");
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VINF_SUCCESS);
/* To little files to check */
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 1, 0), VERR_MANIFEST_FILE_MISMATCH);
/* Make the digest type invalid */
((char*)pvBuf)[0] = 'L';
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VERR_MANIFEST_UNSUPPORTED_DIGEST_TYPE);
((char*)pvBuf)[0] = 'S'; /* Restore */
/* Make the file name invalid */
((char*)pvBuf)[8] = 'z';
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VERR_MANIFEST_FILE_MISMATCH);
((char*)pvBuf)[8] = 's'; /* Restore */
/* Make the second digest invalid */
((char*)pvBuf)[99] = '0';
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, &iFailed), VERR_MANIFEST_DIGEST_MISMATCH);
RTTESTI_CHECK(iFailed == 1);
/* Cleanup */
RTMemFree(pvBuf);
}
示例5: testCopyEx1
static void testCopyEx1(RTTEST hTest)
{
RTTestISub("RTStrCopyEx");
char *pszBuf4H = (char *)RTTestGuardedAllocHead(hTest, 4);
char *pszBuf4T = (char *)RTTestGuardedAllocTail(hTest, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abc", RTSTR_MAX), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abc", RTSTR_MAX), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
RT_BZERO(pszBuf4H, 4); RT_BZERO(pszBuf4T, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abcd", RTSTR_MAX), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abcd", RTSTR_MAX), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
RT_BZERO(pszBuf4H, 4); RT_BZERO(pszBuf4T, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abcd", 3), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abcd", 3), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
RT_BZERO(pszBuf4H, 4); RT_BZERO(pszBuf4T, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abcd", 2), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "ab") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abcd", 2), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "ab") == 0);
}
示例6: tstShowStats
static void tstShowStats(RTSTRCACHE hStrCache)
{
size_t cbStrings;
size_t cbChunks;
size_t cbBigEntries;
uint32_t cHashCollisions;
uint32_t cHashCollisions2;
uint32_t cHashInserts;
uint32_t cRehashes;
uint32_t cStrings = RTStrCacheGetStats(hStrCache, &cbStrings, &cbChunks, &cbBigEntries,
&cHashCollisions, &cHashCollisions2, &cHashInserts, &cRehashes);
if (cbStrings == UINT32_MAX)
{
RTTESTI_CHECK(!RTStrCacheIsRealImpl());
return;
}
RTTestIValue("Strings", cStrings, RTTESTUNIT_OCCURRENCES);
RTTestIValue("Memory overhead", (uint64_t)(cbChunks + cbBigEntries - cbStrings) * 100 / cbStrings, RTTESTUNIT_PCT);
if (cHashInserts > 0)
{
RTTestIValue("Collisions", (uint64_t)cHashCollisions * 100 / cHashInserts, RTTESTUNIT_PCT);
RTTestIValue("Collisions2", (uint64_t)cHashCollisions2 * 100 / cHashInserts, RTTESTUNIT_PCT);
}
RTTestIPrintf(RTTESTLVL_ALWAYS, "cHashInserts=%u cHashCollisions=%u cHashCollisions2=%u cRehashes=%u\n",
cHashInserts, cHashCollisions, cHashCollisions2, cRehashes);
RTTestIPrintf(RTTESTLVL_ALWAYS, "cbChunks=%zu cbBigEntries=%zu cbStrings=%zu\n", cbChunks, cbBigEntries, cbStrings);
}
示例7: test1
static void test1(const char *pszSubTest, const char *pszFilename)
{
int rc;
RTTestISub(pszSubTest);
RTFILE hFile;
rc = RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN);
if (RT_FAILURE(rc))
{
if ( rc == VERR_ACCESS_DENIED
|| rc == VERR_PERMISSION_DENIED
|| rc == VERR_FILE_NOT_FOUND)
{
RTTestIPrintf(RTTESTLVL_ALWAYS, "Cannot access '%s', skipping.", pszFilename);
return;
}
RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN), VINF_SUCCESS);
}
uint64_t cbFile = UINT64_MAX - 42;
RTTESTI_CHECK_RC(rc = RTFileGetSize(hFile, &cbFile), VINF_SUCCESS);
if (RT_SUCCESS(rc))
{
RTTESTI_CHECK(cbFile != UINT64_MAX - 42);
RTTestIValue(pszSubTest, cbFile, RTTESTUNIT_BYTES);
}
RTFileClose(hFile);
RTTestISubDone();
}
示例8: test2
/**
* Does a multi-threading list test. Several list additions, reading, replacing
* and erasing are done simultaneous.
*
*/
static void test2()
{
RTTestISubF("MT test with 6 threads (%u tests per thread).", MTTESTITEMS);
int rc;
MTTESTLISTTYPE<MTTESTTYPE> testList;
RTTHREAD ahThreads[6];
static PFNRTTHREAD apfnThreads[6] =
{
MtTest1ThreadProc, MtTest2ThreadProc, MtTest3ThreadProc, MtTest4ThreadProc, MtTest5ThreadProc, MtTest6ThreadProc
};
for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
{
RTTESTI_CHECK_RC_RETV(RTThreadCreateF(&ahThreads[i], apfnThreads[i], &testList, 0,
RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "mttest%u", i), VINF_SUCCESS);
}
uint64_t tsMsDeadline = RTTimeMilliTS() + 60000;
for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
{
uint64_t tsNow = RTTimeMilliTS();
uint32_t cWait = tsNow > tsMsDeadline ? 5000 : tsMsDeadline - tsNow;
RTTESTI_CHECK_RC(RTThreadWait(ahThreads[i], tsNow, NULL), VINF_SUCCESS);
}
RTTESTI_CHECK_RETV(testList.size() == MTTESTITEMS * 2);
for (size_t i = 0; i < testList.size(); ++i)
{
uint32_t a = testList.at(i);
RTTESTI_CHECK(a == 0x0 || a == 0xFFFFFFFF || a == 0xF0F0F0F0 || a == 0xFF00FF00);
}
}
示例9: tstRTPipe5
static void tstRTPipe5(void)
{
RTTestISub("Inherit non-standard pipe handle, read end");
char szPathSelf[RTPATH_MAX];
RTTESTI_CHECK_RETV(RTProcGetExecutablePath(szPathSelf, sizeof(szPathSelf)) == szPathSelf);
RTPIPE hPipeR;
RTPIPE hPipeW;
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, RTPIPE_C_INHERIT_READ), VINF_SUCCESS);
RTHCINTPTR hNative = RTPipeToNative(hPipeR);
RTTESTI_CHECK_RETV(hNative != -1);
char szNative[64];
RTStrPrintf(szNative, sizeof(szNative), "%RHi", hNative);
const char *papszArgs[4] = { szPathSelf, "--child-5", szNative, NULL };
RTPROCESS hChild;
RTTESTI_CHECK_RC_RETV(RTProcCreate(szPathSelf, papszArgs, RTENV_DEFAULT, 0 /*fFlags*/, &hChild), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTPipeClose(hPipeR), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeW, g_szTest5Message, sizeof(g_szTest5Message) - 1, NULL), VINF_SUCCESS);
int rc;
RTTESTI_CHECK_RC(rc = RTPipeClose(hPipeW), VINF_SUCCESS);
if (RT_FAILURE(rc))
RTTESTI_CHECK_RC(RTProcTerminate(hChild), VINF_SUCCESS);
RTPROCSTATUS ProcStatus;
RTTESTI_CHECK_RC(rc = RTProcWait(hChild, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS);
if (RT_FAILURE(rc))
return;
RTTESTI_CHECK( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
&& ProcStatus.iStatus == 0);
}
示例10: tstVfsIoFromStandardHandle
static void tstVfsIoFromStandardHandle(RTTEST hTest, RTHANDLESTD enmHandle)
{
RTTestSubF(hTest, "RTVfsIoStrmFromStdHandle(%s)", StandardHandleToString(enmHandle));
RTVFSIOSTREAM hVfsIos = NIL_RTVFSIOSTREAM;
int rc = RTVfsIoStrmFromStdHandle(enmHandle, 0, true /*fLeaveOpen*/, &hVfsIos);
if (RT_SUCCESS(rc))
{
if ( enmHandle == RTHANDLESTD_OUTPUT
|| enmHandle == RTHANDLESTD_ERROR)
{
char szTmp[80];
size_t cchTmp = RTStrPrintf(szTmp, sizeof(szTmp), "Test output to %s\n", StandardHandleToString(enmHandle));
size_t cbWritten;
RTTESTI_CHECK_RC(rc = RTVfsIoStrmWrite(hVfsIos, szTmp, cchTmp, true /*fBlocking*/, &cbWritten), VINF_SUCCESS);
if (RT_SUCCESS(rc))
RTTESTI_CHECK(cbWritten == cchTmp);
}
uint32_t cRefs = RTVfsIoStrmRelease(hVfsIos);
RTTESTI_CHECK_MSG(cRefs == 0, ("cRefs=%#x\n", cRefs));
}
else
RTTestFailed(hTest, "Error creating VFS I/O stream for %s: %Rrc\n", StandardHandleToString(enmHandle), rc);
}
示例11: tstRTProcQueryUsername
static void tstRTProcQueryUsername(void)
{
RTTestISub("Basics");
size_t cbUser;
char szUser[1024];
memset(szUser, '-', sizeof(szUser));
/* negative stuff that may assert: */
bool fMayPanic = RTAssertSetMayPanic(false);
bool fQuiet = RTAssertSetQuiet(true);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 8, &cbUser), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, 0, &cbUser), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 0, NULL), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTProcQueryUsernameA(RTProcSelf(), NULL), VERR_INVALID_POINTER);
RTAssertSetMayPanic(fMayPanic);
RTAssertSetQuiet(fQuiet);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 0, &cbUser), VERR_BUFFER_OVERFLOW);
memset(szUser, '-', sizeof(szUser));
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, cbUser - 1, &cbUser), VERR_BUFFER_OVERFLOW);
memset(szUser, '-', sizeof(szUser));
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, sizeof(szUser), &cbUser), VINF_SUCCESS);
RTTestPrintf(NULL, RTTESTLVL_ALWAYS, "Username: %s\n", szUser); /* */
char *pszUser = NULL;
RTTESTI_CHECK_RC(RTProcQueryUsernameA(RTProcSelf(), &pszUser), VINF_SUCCESS);
RTTestPrintf(NULL, RTTESTLVL_ALWAYS, "Username: %s\n", pszUser);
RTTESTI_CHECK(strcmp(pszUser, szUser) == 0);
RTStrFree(pszUser);
}
示例12: doTestsOnDefaultValues
static void doTestsOnDefaultValues(PCFGMNODE pRoot)
{
/* integer */
uint64_t u64;
RTTESTI_CHECK_RC(CFGMR3QueryU64(pRoot, "RamSize", &u64), VINF_SUCCESS);
size_t cb = 0;
RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "RamSize", &cb), VINF_SUCCESS);
RTTESTI_CHECK(cb == sizeof(uint64_t));
/* string */
char *pszName = NULL;
RTTESTI_CHECK_RC(CFGMR3QueryStringAlloc(pRoot, "Name", &pszName), VINF_SUCCESS);
RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "Name", &cb), VINF_SUCCESS);
RTTESTI_CHECK(cb == strlen(pszName) + 1);
MMR3HeapFree(pszName);
}
示例13: tst2
/**
* Check hash and memory performance.
*/
static void tst2(void)
{
RTTestISub("Hash performance");
/*
* Generate test strings using a specific pseudo random generator.
*/
size_t cbStrings = 0;
char *apszTests[8192];
RTRAND hRand;
RTTESTI_CHECK_RC_RETV(RTRandAdvCreateParkMiller(&hRand), VINF_SUCCESS);
for (uint32_t i = 0; i < 8192; i++)
{
char szBuf[8192];
uint32_t cch = RTRandAdvU32Ex(hRand, 3, sizeof(szBuf) - 1);
RTRandAdvBytes(hRand, szBuf, cch);
szBuf[cch] = '\0';
for (uint32_t off = 0; off < cch; off++)
{
uint8_t b = szBuf[off];
b &= 0x7f;
if (!b || b == 0x7f)
b = ' ';
else if (RTLocCIsCntrl(b) && b != '\n' && b != '\r' && b != '\t')
b += 0x30;
szBuf[off] = b;
}
apszTests[i] = (char *)RTMemDup(szBuf, cch + 1);
RTTESTI_CHECK_RETV(apszTests[i] != NULL);
cbStrings += cch + 1;
}
RTRandAdvDestroy(hRand);
RTTestIValue("Average string", cbStrings / RT_ELEMENTS(apszTests), RTTESTUNIT_BYTES);
/*
* Test new insertion first time around.
*/
RTSTRCACHE hStrCache;
RTTESTI_CHECK_RC_RETV(RTStrCacheCreate(&hStrCache, "hash performance"), VINF_SUCCESS);
uint64_t nsTsStart = RTTimeNanoTS();
for (uint32_t i = 0; i < RT_ELEMENTS(apszTests); i++)
RTTESTI_CHECK_RETV(RTStrCacheEnter(hStrCache, apszTests[i]) != NULL);
uint64_t cNsElapsed = RTTimeNanoTS() - nsTsStart;
RTTestIValue("First insert", cNsElapsed / RT_ELEMENTS(apszTests), RTTESTUNIT_NS_PER_CALL);
/*
* Insert existing strings.
*/
nsTsStart = RTTimeNanoTS();
for (uint32_t i = 0; i < 8192; i++)
RTTESTI_CHECK(RTStrCacheEnter(hStrCache, apszTests[i]) != NULL);
cNsElapsed = RTTimeNanoTS() - nsTsStart;
RTTestIValue("Duplicate insert", cNsElapsed / RT_ELEMENTS(apszTests), RTTESTUNIT_NS_PER_CALL);
tstShowStats(hStrCache);
RTTESTI_CHECK_RC(RTStrCacheDestroy(hStrCache), VINF_SUCCESS);
}
示例14: tstRTPipe3
static void tstRTPipe3(void)
{
RTTestISub("Full write buffer");
RTPIPE hPipeR = (RTPIPE)999999;
RTPIPE hPipeW = (RTPIPE)999999;
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, 0), VINF_SUCCESS);
static char s_abBuf[_256K];
int rc = VINF_SUCCESS;
size_t cbTotal = 0;
memset(s_abBuf, 0xff, sizeof(s_abBuf));
for (;;)
{
RTTESTI_CHECK(cbTotal < _1G);
if (cbTotal > _1G)
break;
size_t cbWritten = _1G;
rc = RTPipeWrite(hPipeW, s_abBuf, sizeof(s_abBuf), &cbWritten);
RTTESTI_CHECK_MSG(rc == VINF_SUCCESS || rc == VINF_TRY_AGAIN, ("rc=%Rrc\n", rc));
if (rc != VINF_SUCCESS)
break;
cbTotal += cbWritten;
}
if (rc == VINF_TRY_AGAIN)
{
RTTestIPrintf(RTTESTLVL_ALWAYS, "cbTotal=%zu (%#zx)\n", cbTotal, cbTotal);
RTTESTI_CHECK_RC(RTPipeSelectOne(hPipeW, 0), VERR_TIMEOUT);
RTTESTI_CHECK_RC(RTPipeSelectOne(hPipeW, 1), VERR_TIMEOUT);
size_t cbRead;
RTTESTI_CHECK_RC(RTPipeRead(hPipeR, s_abBuf, RT_MIN(sizeof(s_abBuf), cbTotal) / 2, &cbRead), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeSelectOne(hPipeW, 0), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeSelectOne(hPipeW, 1), VINF_SUCCESS);
size_t cbWritten = _1G;
rc = RTPipeWrite(hPipeW, s_abBuf, sizeof(s_abBuf), &cbWritten);
RTTESTI_CHECK(rc == VINF_SUCCESS);
}
RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
}
示例15: tst1
static void tst1(size_t cTest, size_t cchDigits, char chSep)
{
RTTestISubF("tst #%u (digits: %u; sep: %c)", cTest, cchDigits, chSep ? chSep : ' ');
/* We try to create max possible + one. */
size_t cTimes = 1;
for (size_t i = 0; i < cchDigits; ++i)
cTimes *= 10;
/* Allocate the result array. */
char **papszNames = (char **)RTMemTmpAllocZ(cTimes * sizeof(char *));
RTTESTI_CHECK_RETV(papszNames != NULL);
int rc = VERR_INTERNAL_ERROR;
/* The test loop. */
size_t i;
for (i = 0; i < cTimes; i++)
{
char szName[RTPATH_MAX];
RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS);
if (RT_FAILURE(rc))
break;
RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VINF_SUCCESS);
if (RT_FAILURE(rc))
{
RTTestIFailed("RTDirCreateUniqueNumbered(%s) call #%u -> %Rrc\n", szName, i, rc);
break;
}
RTTESTI_CHECK(papszNames[i] = RTStrDup(szName));
if (!papszNames[i])
break;
RTTestIPrintf(RTTESTLVL_DEBUG, "%s\n", papszNames[i]);
}
/* Try to create one more, which shouldn't be possible. */
if (RT_SUCCESS(rc))
{
char szName[RTPATH_MAX];
RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS);
if (RT_SUCCESS(rc))
RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VERR_ALREADY_EXISTS);
}
/* cleanup */
while (i-- > 0)
{
RTTESTI_CHECK_RC(RTDirRemove(papszNames[i]), VINF_SUCCESS);
RTStrFree(papszNames[i]);
}
RTMemTmpFree(papszNames);
}