diff options
Diffstat (limited to 'src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp')
-rw-r--r-- | src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp | 112 |
1 files changed, 107 insertions, 5 deletions
diff --git a/src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp b/src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp index 92126939..98263305 100644 --- a/src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp +++ b/src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -29,18 +29,50 @@ *******************************************************************************/ #include <iprt/initterm.h> +#include <iprt/asm.h> +#include <iprt/cpuset.h> #include <iprt/err.h> #include <iprt/path.h> #include <iprt/param.h> #include <iprt/stream.h> #include <iprt/string.h> #include <iprt/test.h> +#include <iprt/time.h> #include <iprt/thread.h> #ifdef VBOX # include <VBox/sup.h> # include "tstR0ThreadPreemption.h" #endif +/******************************************************************************* +* Global Variables * +*******************************************************************************/ +static bool volatile g_fTerminate = false; + + +/** + * Try make sure all online CPUs will be engaged. + */ +static DECLCALLBACK(int) MyThreadProc(RTTHREAD hSelf, void *pvCpuIdx) +{ + RTCPUSET Affinity; + RTCpuSetEmpty(&Affinity); + RTCpuSetAddByIndex(&Affinity, (intptr_t)pvCpuIdx); + RTThreadSetAffinity(&Affinity); /* ignore return code as it's not supported on all hosts. */ + + while (!g_fTerminate) + { + uint64_t tsStart = RTTimeMilliTS(); + do + { + ASMNopPause(); + } while (RTTimeMilliTS() - tsStart < 8); + RTThreadSleep(4); + } + + return VINF_SUCCESS; +} + int main(int argc, char **argv) { @@ -114,8 +146,8 @@ int main(int argc, char **argv) TSTR0THREADPREMEPTION_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS); if (RT_FAILURE(rc)) return RTTestSummaryAndDestroy(hTest); - RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1), ("%s", Req.szMsg)); - if (strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1)) + RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42")), ("%s", Req.szMsg)); + if (strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42"))) return RTTestSummaryAndDestroy(hTest); /* @@ -138,10 +170,39 @@ int main(int argc, char **argv) RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); /* + * Is it trusty. + */ + RTTestSub(hTest, "RTThreadPreemptIsPendingTrusty"); + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1, + TSTR0THREADPREMEPTION_IS_TRUSTY, 0, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + if (Req.szMsg[0] == '!') + RTTestIFailed("%s", &Req.szMsg[1]); + else if (Req.szMsg[0]) + RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); + + /* * Stay in ring-0 until preemption is pending. */ -RTThreadSleep(250); /** @todo fix GIP initialization? */ + RTTHREAD ahThreads[RTCPUSET_MAX_CPUS]; + uint32_t cThreads = RTMpGetCount(); + RTCPUSET OnlineSet; + RTMpGetOnlineSet(&OnlineSet); + for (uint32_t i = 0; i < RT_ELEMENTS(ahThreads); i++) + { + ahThreads[i] = NIL_RTTHREAD; + if (RTCpuSetIsMemberByIndex(&OnlineSet, i)) + RTThreadCreateF(&ahThreads[i], MyThreadProc, (void *)(uintptr_t)i, 0, RTTHREADTYPE_DEFAULT, + RTTHREADFLAGS_WAITABLE, "cpu=%u", i); + } + + RTTestSub(hTest, "Pending Preemption"); + RTThreadSleep(250); /** @todo fix GIP initialization? */ for (int i = 0; ; i++) { Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; @@ -149,7 +210,7 @@ RTThreadSleep(250); /** @todo fix GIP initialization? */ Req.szMsg[0] = '\0'; RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1, TSTR0THREADPREMEPTION_IS_PENDING, 0, &Req.Hdr), VINF_SUCCESS); - if ( strcmp(Req.szMsg, "cLoops=1\n") + if ( strcmp(Req.szMsg, "!cLoops=1\n") || i >= 64) { if (Req.szMsg[0] == '!') @@ -160,8 +221,15 @@ RTThreadSleep(250); /** @todo fix GIP initialization? */ } if ((i % 3) == 0) RTThreadYield(); + else if ((i % 16) == 0) + RTThreadSleep(8); } + ASMAtomicWriteBool(&g_fTerminate, true); + for (uint32_t i = 0; i < RT_ELEMENTS(ahThreads); i++) + if (ahThreads[i] != NIL_RTTHREAD) + RTThreadWait(ahThreads[i], 5000, NULL); + /* * Test nested RTThreadPreemptDisable calls. */ @@ -176,6 +244,40 @@ RTThreadSleep(250); /** @todo fix GIP initialization? */ else if (Req.szMsg[0]) RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); + + /* + * Test thread-context hooks. + */ + RTTestSub(hTest, "RTThreadCtxHooks"); + uint64_t u64StartTS = RTTimeMilliTS(); + uint64_t cMsMax = 60000; /* ca. 1 minute timeout. */ + uint64_t cMsElapsed; + for (unsigned i = 0; i < 50; i++) + { + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1, + TSTR0THREADPREEMPTION_CTXHOOKS, 0, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + if (Req.szMsg[0] == '!') + RTTestIFailed("%s", &Req.szMsg[1]); + else if (Req.szMsg[0]) + RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); + if (!(i % 10)) + RTTestIPrintf(RTTESTLVL_ALWAYS, "RTThreadCtxHooks passed %u iteration(s)\n", i); + + /* Check timeout and bail. */ + cMsElapsed = RTTimeMilliTS() - u64StartTS; + if (cMsElapsed > cMsMax) + { + RTTestIPrintf(RTTESTLVL_INFO, "RTThreadCtxHooks Stopping iterations. %RU64 ms. for %u iterations.\n", + cMsElapsed, i); + break; + } + } + /* * Done. */ |