- Timestamp:
- Jun 24, 2009 7:32:12 PM (16 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support/testcase
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/testcase/Makefile.kmk
r19892 r20903 46 46 tstGIP-2 \ 47 47 tstGetPagingMode \ 48 tstSupSem 48 tstSupSem \ 49 tstSupSem-Zombie 49 50 endif # VBOX_WITH_TESTCASES 50 51 … … 89 90 tstSupSem_SOURCES = tstSupSem.cpp 90 91 92 tstSupSem-Zombie_TEMPLATE = VBOXR3TSTEXE 93 tstSupSem-Zombie_SOURCES = tstSupSem-Zombie.cpp 94 91 95 include $(KBUILD_PATH)/subfooter.kmk 92 96 -
trunk/src/VBox/HostDrivers/Support/testcase/tstSupSem-Zombie.cpp
r20902 r20903 1 1 /* $Id$ */ 2 2 /** @file 3 * Support Library Testcase - Ring-3 Semaphore interface .3 * Support Library Testcase - Ring-3 Semaphore interface - Zombie bugs. 4 4 */ 5 5 … … 36 36 37 37 #include <VBox/param.h> 38 #include <iprt/env.h> 38 39 #include <iprt/err.h> 39 40 #include <iprt/initterm.h> 41 #include <iprt/process.h> 40 42 #include <iprt/stream.h> 41 43 #include <iprt/test.h> 44 #include <iprt/time.h> 42 45 #include <iprt/thread.h> 43 46 … … 48 51 static PSUPDRVSESSION g_pSession; 49 52 static RTTEST g_hTest; 50 static uint32_t g_cMillies; /* Used by the interruptible tests. */ 51 52 53 54 static DECLCALLBACK(int) tstSupSemInterruptibleSRE(RTTHREAD hSelf, void *pvUser) 53 54 55 56 static DECLCALLBACK(int) tstSupSemSRETimed(RTTHREAD hSelf, void *pvUser) 55 57 { 56 58 SUPSEMEVENT hEvent = (SUPSEMEVENT)pvUser; 57 59 RTThreadUserSignal(hSelf); 58 return SUPSemEventWaitNoResume(g_pSession, hEvent, g_cMillies);59 } 60 61 62 static DECLCALLBACK(int) tstSupSem InterruptibleMRE(RTTHREAD hSelf, void *pvUser)60 return SUPSemEventWaitNoResume(g_pSession, hEvent, 120*1000); 61 } 62 63 64 static DECLCALLBACK(int) tstSupSemMRETimed(RTTHREAD hSelf, void *pvUser) 63 65 { 64 66 SUPSEMEVENTMULTI hEventMulti = (SUPSEMEVENTMULTI)pvUser; 65 67 RTThreadUserSignal(hSelf); 66 return SUPSemEventMultiWaitNoResume(g_pSession, hEventMulti, g_cMillies); 67 } 68 69 70 int main(int argc, char **argv) 68 return SUPSemEventMultiWaitNoResume(g_pSession, hEventMulti, 120*1000); 69 } 70 71 72 static DECLCALLBACK(int) tstSupSemSREInf(RTTHREAD hSelf, void *pvUser) 73 { 74 SUPSEMEVENT hEvent = (SUPSEMEVENT)pvUser; 75 RTThreadUserSignal(hSelf); 76 return SUPSemEventWaitNoResume(g_pSession, hEvent, RT_INDEFINITE_WAIT); 77 } 78 79 80 static DECLCALLBACK(int) tstSupSemMREInf(RTTHREAD hSelf, void *pvUser) 81 { 82 SUPSEMEVENTMULTI hEventMulti = (SUPSEMEVENTMULTI)pvUser; 83 RTThreadUserSignal(hSelf); 84 return SUPSemEventMultiWaitNoResume(g_pSession, hEventMulti, RT_INDEFINITE_WAIT); 85 } 86 87 static int mainChild(void) 71 88 { 72 89 /* … … 76 93 if (RT_FAILURE(rc)) 77 94 { 78 RTPrintf("tstSupSem : fatal error: RTR3InitAndSUPLib failed with rc=%Rrc\n", rc);95 RTPrintf("tstSupSem-Zombie-Child: fatal error: RTR3InitAndSUPLib failed with rc=%Rrc\n", rc); 79 96 return 1; 80 97 } 81 98 82 99 RTTEST hTest; 83 rc = RTTestCreate("tstSupSem ", &hTest);100 rc = RTTestCreate("tstSupSem-Zombie-Child", &hTest); 84 101 if (RT_FAILURE(rc)) 85 102 { 86 RTPrintf("tstSupSem : fatal error: RTTestCreate failed with rc=%Rrc\n", rc);103 RTPrintf("tstSupSem-Zombie-Child: fatal error: RTTestCreate failed with rc=%Rrc\n", rc); 87 104 return 1; 88 105 } … … 98 115 g_pSession = pSession; 99 116 117 /* 118 * A semaphore of each kind and throw a bunch of threads on them. 119 */ 120 SUPSEMEVENT hEvent = NIL_SUPSEMEVENT; 121 RTTESTI_CHECK_RC(rc = SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS); 122 if (RT_SUCCESS(rc)) 123 { 124 SUPSEMEVENTMULTI hEventMulti = NIL_SUPSEMEVENT; 125 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS); 126 if (RT_SUCCESS(rc)) 127 { 128 for (uint32_t cThreads = 0; cThreads < 5; cThreads++) 129 { 130 RTTHREAD hThread; 131 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemSRETimed, (void *)hEvent, 0, RTTHREADTYPE_TIMER, 0 /*fFlags*/, "IntSRE"), VINF_SUCCESS); 132 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemMRETimed, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, 0 /*fFlags*/, "IntMRE"), VINF_SUCCESS); 133 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemSREInf, (void *)hEvent, 0, RTTHREADTYPE_TIMER, 0 /*fFlags*/, "IntSRE"), VINF_SUCCESS); 134 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemMREInf, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, 0 /*fFlags*/, "IntMRE"), VINF_SUCCESS); 135 RTThreadSleep(2); 136 } 137 RTThreadSleep(50); 138 139 /* 140 * This is where the test really starts... 141 */ 142 return 0; 143 } 144 } 145 146 return RTTestSummaryAndDestroy(hTest); 147 } 148 149 150 /** 151 * The parent main routine. 152 * @param argv0 The executable name (or whatever). 153 */ 154 static int mainParent(const char *argv0) 155 { 100 156 /* 101 * Basic API checks. 102 */ 103 RTTestSub(hTest, "Single Release Event (SRE) API"); 104 SUPSEMEVENT hEvent = NIL_SUPSEMEVENT; 105 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS); 106 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT); 107 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT); 108 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS); 109 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS); 110 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS); 111 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VINF_SUCCESS); 112 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS); 113 RTTESTI_CHECK_RC(SUPSemEventSignal(pSession, hEvent), VINF_SUCCESS); 114 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VINF_SUCCESS); 115 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent, 0), VERR_TIMEOUT); 116 RTTESTI_CHECK_RC(SUPSemEventWaitNoResume(pSession, hEvent,20), VERR_TIMEOUT); 117 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED); 118 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VERR_INVALID_HANDLE); 119 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, NIL_SUPSEMEVENT), VINF_SUCCESS); 120 121 RTTestSub(hTest, "Multiple Release Event (MRE) API"); 122 SUPSEMEVENTMULTI hEventMulti = NIL_SUPSEMEVENT; 123 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS); 124 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT); 125 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT); 126 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS); 127 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS); 128 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS); 129 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS); 130 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS); 131 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS); 132 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS); 133 RTTESTI_CHECK_RC(SUPSemEventMultiReset(pSession, hEventMulti), VINF_SUCCESS); 134 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VERR_TIMEOUT); 135 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti,20), VERR_TIMEOUT); 136 RTTESTI_CHECK_RC(SUPSemEventMultiSignal(pSession, hEventMulti), VINF_SUCCESS); 137 RTTESTI_CHECK_RC(SUPSemEventMultiWaitNoResume(pSession, hEventMulti, 0), VINF_SUCCESS); 138 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED); 139 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VERR_INVALID_HANDLE); 140 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, NIL_SUPSEMEVENTMULTI), VINF_SUCCESS); 141 142 #if !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS) 143 RTTestSub(hTest, "SRE Interruptibility"); 144 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS); 145 g_cMillies = RT_INDEFINITE_WAIT; 146 RTTHREAD hThread = NIL_RTTHREAD; 147 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS); 148 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS); 149 RTThreadSleep(120); 150 RTThreadPoke(hThread); 151 int rcThread = VINF_SUCCESS; 152 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS); 153 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED); 154 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED); 155 156 RTTESTI_CHECK_RC(SUPSemEventCreate(pSession, &hEvent), VINF_SUCCESS); 157 g_cMillies = 120*1000; 158 hThread = NIL_RTTHREAD; 159 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleSRE, (void *)hEvent, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntSRE"), VINF_SUCCESS); 160 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS); 161 RTThreadSleep(120); 162 RTThreadPoke(hThread); 163 rcThread = VINF_SUCCESS; 164 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS); 165 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED); 166 RTTESTI_CHECK_RC(SUPSemEventClose(pSession, hEvent), VINF_OBJECT_DESTROYED); 167 168 169 RTTestSub(hTest, "MRE Interruptibility"); 170 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS); 171 g_cMillies = RT_INDEFINITE_WAIT; 172 hThread = NIL_RTTHREAD; 173 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntMRE"), VINF_SUCCESS); 174 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS); 175 RTThreadSleep(120); 176 RTThreadPoke(hThread); 177 rcThread = VINF_SUCCESS; 178 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS); 179 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED); 180 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED); 181 182 RTTESTI_CHECK_RC(SUPSemEventMultiCreate(pSession, &hEventMulti), VINF_SUCCESS); 183 g_cMillies = 120*1000; 184 hThread = NIL_RTTHREAD; 185 RTTESTI_CHECK_RC(RTThreadCreate(&hThread, tstSupSemInterruptibleMRE, (void *)hEventMulti, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "IntMRE"), VINF_SUCCESS); 186 RTTESTI_CHECK_RC(RTThreadUserWait(hThread, 60*1000), VINF_SUCCESS); 187 RTThreadSleep(120); 188 RTThreadPoke(hThread); 189 rcThread = VINF_SUCCESS; 190 RTTESTI_CHECK_RC(RTThreadWait(hThread, 60*1000, &rcThread), VINF_SUCCESS); 191 RTTESTI_CHECK_RC(rcThread, VERR_INTERRUPTED); 192 RTTESTI_CHECK_RC(SUPSemEventMultiClose(pSession, hEventMulti), VINF_OBJECT_DESTROYED); 193 #endif /* !OS2 && !WINDOWS */ 157 * Init. 158 */ 159 RTTEST hTest; 160 int rc = RTTestInitAndCreate("tstSupSem-Zombie", &hTest); 161 if (rc) 162 return rc; 163 RTTestBanner(hTest); 194 164 195 165 /* 196 * Done. 197 */ 166 * Spin of the child process which may or may not turn into a zombie 167 */ 168 for (uint32_t iPass = 0; iPass < 32; iPass++) 169 { 170 RTTestSubF(hTest, "Pass %u", iPass); 171 172 RTPROCESS hProcess; 173 const char *apszArgs[3] = { argv0, "--child", NULL }; 174 RTTESTI_CHECK_RC_OK(rc = RTProcCreate(argv0, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, &hProcess)); 175 if (RT_SUCCESS(rc)) 176 { 177 /* 178 * Wait for 60 seconds then give up. 179 */ 180 RTPROCSTATUS Status; 181 uint64_t StartTS = RTTimeMilliTS(); 182 for (;;) 183 { 184 rc = RTProcWait(hProcess, RTPROCWAIT_FLAGS_NOBLOCK, &Status); 185 if (RT_SUCCESS(rc)) 186 break; 187 uint64_t cElapsed = RTTimeMilliTS() - StartTS; 188 if (cElapsed > 60*1000) 189 break; 190 RTThreadSleep(cElapsed < 60 ? 30 : cElapsed < 200 ? 10 : 100); 191 } 192 RTTESTI_CHECK_RC_OK(rc); 193 if ( RT_SUCCESS(rc) 194 && ( Status.enmReason != RTPROCEXITREASON_NORMAL 195 || Status.iStatus != 0)) 196 { 197 RTTestIFailed("child %u (%d) reason %d\n", Status.iStatus, Status.iStatus, Status.enmReason); 198 rc = VERR_PERMISSION_DENIED; 199 } 200 } 201 /* one zombie process is enough. */ 202 if (RT_FAILURE(rc)) 203 break; 204 } 205 198 206 return RTTestSummaryAndDestroy(hTest); 199 207 } 200 208 209 210 int main(int argc, char **argv) 211 { 212 if ( argc == 2 213 && !strcmp(argv[1], "--child")) 214 return mainChild(); 215 return mainParent(argv[0]); 216 } 217 -
trunk/src/VBox/HostDrivers/Support/testcase/tstSupSem.cpp
r19923 r20903 97 97 } 98 98 g_pSession = pSession; 99 RTTestBanner(hTest); 99 100 100 101 /*
Note:
See TracChangeset
for help on using the changeset viewer.