Changeset 21286 in vbox
- Timestamp:
- Jul 7, 2009 12:53:55 AM (15 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 1 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r21082 r21286 75 75 tstMemAutoPtr \ 76 76 tstRTMemPool \ 77 tstRTR0MemUserKernelDriver \ 77 78 tstMove \ 78 79 tstMp-1 \ … … 126 127 tstLdrObj \ 127 128 tstLdrObjR0 \ 129 tstRTR0MemUserKernel \ 128 130 tstR0ThreadPreemption 129 131 if1of ($(VBOX_LDR_FMT)), lx pe) … … 290 292 tstRTMemPool_TEMPLATE = VBOXR3TSTEXE 291 293 tstRTMemPool_SOURCES = tstRTMemPool.cpp 294 295 tstRTR0MemUserKernel_TEMPLATE = VBOXR0 296 tstRTR0MemUserKernel_INST = $(INST_TESTCASE) 297 tstRTR0MemUserKernel_DEFS = IN_RT_R0 298 tstRTR0MemUserKernel_SYSSUFF = .r0 299 tstRTR0MemUserKernel_SOURCES = tstRTR0MemUserKernel.cpp 300 tstRTR0MemUserKernel_LIBS = $(PATH_LIB)/RuntimeR0$(VBOX_SUFF_LIB) 301 if1of ($(VBOX_LDR_FMT), pe lx) 302 tstRTR0MemUserKernel_LIBS += $(PATH_LIB)/SUPR0$(VBOX_SUFF_LIB) 303 endif 304 305 tstRTR0MemUserKernelDriver_SOURCES = tstRTR0MemUserKernelDriver.cpp 292 306 293 307 tstMove_SOURCES = tstMove.cpp -
trunk/src/VBox/Runtime/testcase/tstRTR0MemUserKernel.cpp
r21283 r21286 32 32 * Header Files * 33 33 *******************************************************************************/ 34 #include <iprt/ thread.h>34 #include <iprt/mem.h> 35 35 36 36 #include <iprt/err.h> 37 #include <iprt/param.h> 37 38 #include <iprt/time.h> 38 39 #include <iprt/string.h> 39 40 #include <VBox/sup.h> 40 #include <VBox/x86.h> 41 #include "tstR0ThreadPreemption.h" 41 #include "tstRTR0MemUserKernel.h" 42 42 43 43 … … 51 51 * @param pReqHdr The request header. Input / Output. Optional. 52 52 */ 53 DECLEXPORT(int) TSTR 0ThreadPreemptionSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,54 53 DECLEXPORT(int) TSTRTR0MemUserKernelSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation, 54 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr) 55 55 { 56 if (u64Arg)57 return VERR_INVALID_PARAMETER;58 56 if (!VALID_PTR(pReqHdr)) 59 57 return VERR_INVALID_PARAMETER; … … 65 63 66 64 /* 65 * R3Ptr is valid and good for up to a page. The page before 66 * and after are both invalid. 67 */ 68 RTR3PTR R3Ptr = (RTR3PTR)u64Arg; 69 if (R3Ptr != u64Arg) 70 return VERR_INVALID_PARAMETER; 71 72 /* 73 * Allocate a kernel buffer. 74 */ 75 uint8_t *pbKrnlBuf = (uint8_t *)RTMemAlloc(PAGE_SIZE * 2); 76 if (!pbKrnlBuf) 77 { 78 RTStrPrintf(pszErr, cchErr, "!no memory for kernel buffers"); 79 return VINF_SUCCESS; 80 } 81 82 /* 67 83 * The big switch. 68 84 */ 69 85 switch (uOperation) 70 86 { 71 case TSTR 0THREADPREMEPTION_SANITY_OK:87 case TSTRTR0MEMUSERKERNEL_SANITY_OK: 72 88 break; 73 89 74 case TSTR 0THREADPREMEPTION_SANITY_FAILURE:90 case TSTRTR0MEMUSERKERNEL_SANITY_FAILURE: 75 91 RTStrPrintf(pszErr, cchErr, "!42failure42%1024s", ""); 76 92 break; 77 93 78 case TSTR 0THREADPREMEPTION_BASIC:94 case TSTRTR0MEMUSERKERNEL_BASIC: 79 95 { 80 RTTHREADPREEMPTSTATE State = RTTHREADPREEMPTSTATE_INITIALIZER; 81 if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 82 RTStrPrintf(pszErr, cchErr, "RTThreadPreemptIsEnabled returns false by default"); 83 RTThreadPreemptDisable(&State); 84 if (RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 85 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns true after RTThreadPreemptDisable"); 86 else if (!(ASMGetFlags() & X86_EFL_IF)) 87 RTStrPrintf(pszErr, cchErr, "!Interrupts disabled"); 88 RTThreadPreemptRestore(&State); 96 int rc = RTR0MemUserCopyFrom(pbKrnlBuf, R3Ptr, PAGE_SIZE); 97 if (rc == VINF_SUCCESS) 98 { 99 rc = RTR0MemUserCopyTo(R3Ptr, pbKrnlBuf, PAGE_SIZE); 100 if (rc == VINF_SUCCESS) 101 { 102 if (RTR0MemUserIsValidAddr(R3Ptr)) 103 { 104 if (RTR0MemKernelIsValidAddr(pbKrnlBuf)) 105 { 106 if (RTR0MemAreKrnlAndUsrDifferent()) 107 { 108 RTStrPrintf(pszErr, cchErr, "RTR0MemAreKrnlAndUsrDifferent returns true"); 109 if (!RTR0MemUserIsValidAddr((uintptr_t)pbKrnlBuf)) 110 { 111 if (!RTR0MemKernelIsValidAddr((void *)R3Ptr)) 112 { 113 /* done */ 114 } 115 else 116 RTStrPrintf(pszErr, cchErr, "! #5 - RTR0MemKernelIsValidAddr -> true, expected false"); 117 } 118 else 119 RTStrPrintf(pszErr, cchErr, "! #5 - RTR0MemUserIsValidAddr -> true, expected false"); 120 } 121 else 122 RTStrPrintf(pszErr, cchErr, "RTR0MemAreKrnlAndUsrDifferent returns false"); 123 } 124 else 125 RTStrPrintf(pszErr, cchErr, "! #4 - RTR0MemKernelIsValidAddr -> false, expected true"); 126 } 127 else 128 RTStrPrintf(pszErr, cchErr, "! #3 - RTR0MemUserIsValidAddr -> false, expected true"); 129 } 130 else 131 RTStrPrintf(pszErr, cchErr, "! #2 - RTR0MemUserCopyTo -> %Rrc expected %Rrc", rc, VINF_SUCCESS); 132 } 133 else 134 RTStrPrintf(pszErr, cchErr, "! #1 - RTR0MemUserCopyFrom -> %Rrc expected %Rrc", rc, VINF_SUCCESS); 89 135 break; 90 136 } 91 137 92 case TSTR0THREADPREMEPTION_IS_PENDING: 138 #define TEST_OFF_SIZE(off, size, rcExpect) \ 139 if (1) \ 140 { \ 141 int rc = RTR0MemUserCopyFrom(pbKrnlBuf, R3Ptr + (off), (size)); \ 142 if (rc != (rcExpect)) \ 143 { \ 144 RTStrPrintf(pszErr, cchErr, "!RTR0MemUserCopyFrom(, +%#x, %#x) -> %Rrc, expected %Rrc", \ 145 (off), (size), rc, (rcExpect)); \ 146 break; \ 147 } \ 148 rc = RTR0MemUserCopyTo(R3Ptr + (off), pbKrnlBuf, (size)); \ 149 if (rc != (rcExpect)) \ 150 { \ 151 RTStrPrintf(pszErr, cchErr, "!RTR0MemUserCopyTo(+%#x,, %#x) -> %Rrc, expected %Rrc", \ 152 (off), (size), rc, (rcExpect)); \ 153 break; \ 154 } \ 155 } else do {} while (0) 156 157 case TSTRTR0MEMUSERKERNEL_GOOD: 93 158 { 94 RTTHREADPREEMPTSTATE State = RTTHREADPREEMPTSTATE_INITIALIZER; 95 RTThreadPreemptDisable(&State); 96 if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 97 { 98 if (ASMGetFlags() & X86_EFL_IF) 99 { 100 uint64_t u64StartSysTS = RTTimeSystemNanoTS(); 101 uint64_t u64StartTS = RTTimeNanoTS(); 102 uint64_t cLoops = 0; 103 uint64_t cNanosSysElapsed; 104 uint64_t cNanosElapsed; 105 bool fPending; 106 do 107 { 108 fPending = RTThreadPreemptIsPending(NIL_RTTHREAD); 109 cNanosElapsed = RTTimeNanoTS() - u64StartTS; 110 cNanosSysElapsed = RTTimeSystemNanoTS() - u64StartSysTS; 111 cLoops++; 112 } while ( !fPending 113 && cNanosElapsed < UINT64_C(2)*1000U*1000U*1000U 114 && cNanosSysElapsed < UINT64_C(2)*1000U*1000U*1000U 115 && cLoops < 100U*_1M); 116 if (!fPending) 117 RTStrPrintf(pszErr, cchErr, "!Preempt not pending after %'llu loops / %'llu ns / %'llu ns (sys)", 118 cLoops, cNanosElapsed, cNanosSysElapsed); 119 else if (cLoops == 1) 120 RTStrPrintf(pszErr, cchErr, "!cLoops=1\n"); 121 else 122 RTStrPrintf(pszErr, cchErr, "RTThreadPreemptIsPending returned true after %'llu loops / %'llu ns / %'llu ns (sys)", 123 cLoops, cNanosElapsed, cNanosSysElapsed); 124 } 125 else 126 RTStrPrintf(pszErr, cchErr, "!Interrupts disabled"); 127 } 128 else 129 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns true after RTThreadPreemptDisable"); 130 RTThreadPreemptRestore(&State); 159 for (unsigned off = 0; off < 16 && !*pszErr; off++) 160 for (unsigned cb = 0; cb < PAGE_SIZE - 16; cb++) 161 TEST_OFF_SIZE(off, cb, VINF_SUCCESS); 131 162 break; 132 163 } 133 164 134 case TSTR 0THREADPREMEPTION_NESTED:165 case TSTRTR0MEMUSERKERNEL_BAD: 135 166 { 136 bool const fDefault = RTThreadPreemptIsEnabled(NIL_RTTHREAD); 137 RTTHREADPREEMPTSTATE State1 = RTTHREADPREEMPTSTATE_INITIALIZER; 138 RTThreadPreemptDisable(&State1); 139 if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 140 { 141 RTTHREADPREEMPTSTATE State2 = RTTHREADPREEMPTSTATE_INITIALIZER; 142 RTThreadPreemptDisable(&State2); 143 if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 144 { 145 RTTHREADPREEMPTSTATE State3 = RTTHREADPREEMPTSTATE_INITIALIZER; 146 RTThreadPreemptDisable(&State3); 147 if (RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 148 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns true after 3rd RTThreadPreemptDisable"); 149 150 RTThreadPreemptRestore(&State3); 151 if (RTThreadPreemptIsEnabled(NIL_RTTHREAD) && !*pszErr) 152 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns true after 1st RTThreadPreemptRestore"); 153 } 154 else 155 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns true after 2nd RTThreadPreemptDisable"); 156 157 RTThreadPreemptRestore(&State2); 158 if (RTThreadPreemptIsEnabled(NIL_RTTHREAD) && !*pszErr) 159 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns true after 2nd RTThreadPreemptRestore"); 160 } 161 else 162 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns true after 1st RTThreadPreemptDisable"); 163 RTThreadPreemptRestore(&State1); 164 if (RTThreadPreemptIsEnabled(NIL_RTTHREAD) != fDefault && !*pszErr) 165 RTStrPrintf(pszErr, cchErr, "!RTThreadPreemptIsEnabled returns false after 3rd RTThreadPreemptRestore"); 167 for (unsigned off = 0; off < 16 && !*pszErr; off++) 168 for (unsigned cb = 0; cb < PAGE_SIZE - 16; cb++) 169 TEST_OFF_SIZE(off, cb, cb > 0 ? VERR_ACCESS_DENIED : VINF_SUCCESS); 166 170 break; 167 171 } … … 173 177 174 178 /* The error indicator is the '!' in the message buffer. */ 179 RTMemFree(pbKrnlBuf); 175 180 return VINF_SUCCESS; 176 181 } -
trunk/src/VBox/Runtime/testcase/tstRTR0MemUserKernel.h
r21283 r21286 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT R0 Testcase - Thread Preemption, common header.3 * IPRT R0 Testcase - User & Kernel Memory, common header. 4 4 */ 5 5 … … 31 31 #ifdef IN_RING0 32 32 RT_C_DECLS_BEGIN 33 DECLEXPORT(int) TSTR 0ThreadPreemptionSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,34 33 DECLEXPORT(int) TSTRTR0MemUserKernelSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation, 34 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr); 35 35 RT_C_DECLS_END 36 36 #endif 37 37 38 typedef enum TSTR 0THREADPREMEPTION38 typedef enum TSTRTR0MEMUSERKERNEL 39 39 { 40 TSTR 0THREADPREMEPTION_SANITY_OK = 1,41 TSTR 0THREADPREMEPTION_SANITY_FAILURE,42 TSTR 0THREADPREMEPTION_BASIC,43 TSTR 0THREADPREMEPTION_IS_PENDING,44 TSTR 0THREADPREMEPTION_NESTED45 } TSTR 0THREADPREMEPTION;40 TSTRTR0MEMUSERKERNEL_SANITY_OK = 1, 41 TSTRTR0MEMUSERKERNEL_SANITY_FAILURE, 42 TSTRTR0MEMUSERKERNEL_BASIC, 43 TSTRTR0MEMUSERKERNEL_GOOD, 44 TSTRTR0MEMUSERKERNEL_BAD 45 } TSTRTR0MEMUSERKERNEL; 46 46 -
trunk/src/VBox/Runtime/testcase/tstRTR0MemUserKernelDriver.cpp
r21283 r21286 43 43 #ifdef VBOX 44 44 # include <VBox/sup.h> 45 # include "tstR 0ThreadPreemption.h"45 # include "tstRTR0MemUserKernel.h" 46 46 #endif 47 47 … … 57 57 */ 58 58 RTTEST hTest; 59 int rc = RTTestInitAndCreate("tstR 0ThreadPreemption", &hTest);59 int rc = RTTestInitAndCreate("tstRTR0MemUserKernel", &hTest); 60 60 if (rc) 61 61 return rc; 62 62 RTTestBanner(hTest); 63 64 uint8_t *pbPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE); 65 if (!pbPage) 66 { 67 RTTestFailed(hTest, "RTTestGuardedAllocTail failed with rc=%Rrc\n", rc); 68 return RTTestSummaryAndDestroy(hTest); 69 } 63 70 64 71 PSUPDRVSESSION pSession; … … 73 80 rc = RTPathExecDir(szPath, sizeof(szPath)); 74 81 if (RT_SUCCESS(rc)) 75 rc = RTPathAppend(szPath, sizeof(szPath), "tstR 0ThreadPreemption.r0");82 rc = RTPathAppend(szPath, sizeof(szPath), "tstRTR0MemUserKernel.r0"); 76 83 if (RT_FAILURE(rc)) 77 84 { … … 81 88 82 89 void *pvImageBase; 83 rc = SUPR3LoadServiceModule(szPath, "tstR 0ThreadPreemption",84 "TSTR 0ThreadPreemptionSrvReqHandler",90 rc = SUPR3LoadServiceModule(szPath, "tstRTR0MemUserKernel", 91 "TSTRTR0MemUserKernelSrvReqHandler", 85 92 &pvImageBase); 86 93 if (RT_FAILURE(rc)) … … 104 111 Req.Hdr.cbReq = sizeof(Req); 105 112 Req.szMsg[0] = '\0'; 106 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR 0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,107 TSTR 0THREADPREMEPTION_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);113 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, 114 TSTRTR0MEMUSERKERNEL_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS); 108 115 if (RT_FAILURE(rc)) 109 116 return RTTestSummaryAndDestroy(hTest); … … 115 122 Req.Hdr.cbReq = sizeof(Req); 116 123 Req.szMsg[0] = '\0'; 117 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR 0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,118 TSTR 0THREADPREMEPTION_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);124 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, 125 TSTRTR0MEMUSERKERNEL_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS); 119 126 if (RT_FAILURE(rc)) 120 127 return RTTestSummaryAndDestroy(hTest); … … 130 137 Req.Hdr.cbReq = sizeof(Req); 131 138 Req.szMsg[0] = '\0'; 132 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR 0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,133 TSTR 0THREADPREMEPTION_BASIC, 0, &Req.Hdr), VINF_SUCCESS);139 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, 140 TSTRTR0MEMUSERKERNEL_BASIC, (uintptr_t)pbPage, &Req.Hdr), VINF_SUCCESS); 134 141 if (RT_FAILURE(rc)) 135 142 return RTTestSummaryAndDestroy(hTest); … … 143 150 144 151 /* 145 * Stay in ring-0 until preemption is pending.152 * Good buffer, bail out on failure. 146 153 */ 147 RTTestSub(hTest, "Pending Preemption"); 148 for (int i = 0; ; i++) 149 { 150 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; 151 Req.Hdr.cbReq = sizeof(Req); 152 Req.szMsg[0] = '\0'; 153 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1, 154 TSTR0THREADPREMEPTION_IS_PENDING, 0, &Req.Hdr), VINF_SUCCESS); 155 if ( strcmp(Req.szMsg, "cLoops=1\n") 156 || i >= 64) 157 { 158 if (Req.szMsg[0] == '!') 159 RTTestIFailed("%s", &Req.szMsg[1]); 160 else if (Req.szMsg[0]) 161 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); 162 break; 163 } 164 if ((i % 3) == 0) 165 RTThreadYield(); 166 } 167 168 /* 169 * Test nested RTThreadPreemptDisable calls. 170 */ 171 RTTestSub(hTest, "Nested"); 154 RTTestSub(hTest, "Good buffer"); 172 155 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; 173 156 Req.Hdr.cbReq = sizeof(Req); 174 157 Req.szMsg[0] = '\0'; 175 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1, 176 TSTR0THREADPREMEPTION_NESTED, 0, &Req.Hdr), VINF_SUCCESS); 158 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, 159 TSTRTR0MEMUSERKERNEL_GOOD, (uintptr_t)pbPage, &Req.Hdr), VINF_SUCCESS); 160 if (RT_FAILURE(rc)) 161 return RTTestSummaryAndDestroy(hTest); 177 162 if (Req.szMsg[0] == '!') 163 { 178 164 RTTestIFailed("%s", &Req.szMsg[1]); 179 else if (Req.szMsg[0]) 165 return RTTestSummaryAndDestroy(hTest); 166 } 167 if (Req.szMsg[0]) 168 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); 169 170 /* 171 * Bad buffer, bail out on failure. 172 */ 173 RTTestSub(hTest, "Bad buffer"); 174 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; 175 Req.Hdr.cbReq = sizeof(Req); 176 Req.szMsg[0] = '\0'; 177 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, 178 TSTRTR0MEMUSERKERNEL_BAD, (uintptr_t)pbPage + PAGE_SIZE, &Req.Hdr), VINF_SUCCESS); 179 if (RT_FAILURE(rc)) 180 return RTTestSummaryAndDestroy(hTest); 181 if (Req.szMsg[0] == '!') 182 { 183 RTTestIFailed("%s", &Req.szMsg[1]); 184 return RTTestSummaryAndDestroy(hTest); 185 } 186 if (Req.szMsg[0]) 180 187 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); 181 188
Note:
See TracChangeset
for help on using the changeset viewer.