Changeset 92778 in vbox for trunk/src/VBox
- Timestamp:
- Dec 7, 2021 1:26:15 AM (3 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTSemEvent.cpp
r92728 r92778 47 47 /** The test handle. */ 48 48 static RTTEST g_hTest; 49 50 51 static DECLCALLBACK(int) test1Thread1(RTTHREAD ThreadSelf, void *pvUser) 52 { 53 RTSEMEVENTMULTI hSem = *(PRTSEMEVENTMULTI)pvUser; 54 RT_NOREF_PV(ThreadSelf); 55 56 uint64_t u64 = RTTimeSystemMilliTS(); 57 RTTEST_CHECK_RC(g_hTest, RTSemEventMultiWait(hSem, 1000), VERR_TIMEOUT); 58 u64 = RTTimeSystemMilliTS() - u64; 59 RTTEST_CHECK_MSG(g_hTest, u64 < 1500 && u64 > 950, (g_hTest, "u64=%llu\n", u64)); 60 61 RTTEST_CHECK_RC(g_hTest, RTSemEventMultiWait(hSem, 2000), VINF_SUCCESS); 49 /** Use to stop test loops. */ 50 static volatile bool g_fStop = false; 51 52 53 54 /********************************************************************************************************************************* 55 * Benchmark #1: Two thread pinging each other on two event sempahores. * 56 *********************************************************************************************************************************/ 57 /** Pair of event semphores for the first benchmark test. */ 58 static RTSEMEVENT g_ahEvtBench1[2]; 59 static uint64_t g_cBench1Iterations; 60 static uint64_t g_uTimeoutBench1; 61 static uint64_t g_fWaitBench1; 62 63 64 static DECLCALLBACK(int) bench1Thread(RTTHREAD hThreadSelf, void *pvUser) 65 { 66 uintptr_t const idxThread = (uintptr_t)pvUser; 67 RT_NOREF(hThreadSelf); 68 69 uint64_t cIterations = 0; 70 for (;; cIterations++) 71 { 72 int rc = RTSemEventWaitEx(g_ahEvtBench1[idxThread], g_fWaitBench1, g_uTimeoutBench1); 73 if (RT_SUCCESS(rc)) 74 RTTEST_CHECK_RC(g_hTest, RTSemEventSignal(g_ahEvtBench1[(idxThread + 1) & 1]), VINF_SUCCESS); 75 else if ( rc == VERR_TIMEOUT 76 && g_uTimeoutBench1 == 0 77 && (g_fWaitBench1 & RTSEMWAIT_FLAGS_RELATIVE) ) 78 { /* likely */ } 79 else 80 RTTestFailed(g_hTest, "rc=%Rrc g_fWaitBench1=%#x g_uTimeoutBench1=%#RX64 (now=%#RX64)", 81 rc, g_fWaitBench1, g_uTimeoutBench1, RTTimeSystemNanoTS()); 82 if (g_fStop) 83 { 84 RTTEST_CHECK_RC(g_hTest, RTSemEventSignal(g_ahEvtBench1[(idxThread + 1) & 1]), VINF_SUCCESS); 85 break; 86 } 87 } 88 89 if (idxThread == 0) 90 g_cBench1Iterations = cIterations; 62 91 return VINF_SUCCESS; 63 92 } 64 93 65 94 66 static DECLCALLBACK(int) test1Thread2(RTTHREAD ThreadSelf, void *pvUser) 67 { 68 RTSEMEVENTMULTI hSem = *(PRTSEMEVENTMULTI)pvUser; 69 RT_NOREF_PV(ThreadSelf); 70 71 RTTEST_CHECK_RC(g_hTest, RTSemEventMultiWait(hSem, RT_INDEFINITE_WAIT), VINF_SUCCESS); 95 static void bench1(const char *pszTest, uint32_t fFlags, uint64_t uTimeout) 96 { 97 RTTestISub(pszTest); 98 99 /* 100 * Create the two threads and make the wait on one another's sempahore. 101 */ 102 g_fStop = false; 103 g_uTimeoutBench1 = uTimeout; 104 g_fWaitBench1 = fFlags; 105 106 RTTESTI_CHECK_RC_RETV(RTSemEventCreate(&g_ahEvtBench1[0]), VINF_SUCCESS); 107 RTTESTI_CHECK_RC_RETV(RTSemEventCreate(&g_ahEvtBench1[1]), VINF_SUCCESS); 108 109 RTTHREAD hThread1; 110 RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread1, bench1Thread, (void *)0, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "bench1t1"), VINF_SUCCESS); 111 RTTHREAD hThread2; 112 RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread2, bench1Thread, (void *)1, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "bench1t2"), VINF_SUCCESS); 113 RTThreadSleep(256); 114 115 /* 116 * Kick off the first thread and wait for 5 seconds before stopping them 117 * and seeing how many iterations they managed to perform. 118 */ 119 uint64_t const nsStart = RTTimeNanoTS(); 120 RTTESTI_CHECK_RC(RTSemEventSignal(g_ahEvtBench1[0]), VINF_SUCCESS); 121 RTThreadSleep(RT_MS_5SEC); 122 123 ASMAtomicWriteBool(&g_fStop, true); 124 uint64_t const cNsElapsed = RTTimeNanoTS() - nsStart; 125 126 RTTESTI_CHECK_RC(RTSemEventSignal(g_ahEvtBench1[0]), VINF_SUCCESS); /* paranoia */ 127 RTTESTI_CHECK_RC(RTThreadWait(hThread1, RT_MS_5SEC, NULL), VINF_SUCCESS); 128 RTTESTI_CHECK_RC(RTSemEventSignal(g_ahEvtBench1[1]), VINF_SUCCESS); 129 RTTESTI_CHECK_RC(RTThreadWait(hThread2, RT_MS_5SEC, NULL), VINF_SUCCESS); 130 131 RTTESTI_CHECK_RC(RTSemEventDestroy(g_ahEvtBench1[0]), VINF_SUCCESS); 132 RTTESTI_CHECK_RC(RTSemEventDestroy(g_ahEvtBench1[1]), VINF_SUCCESS); 133 134 /* 135 * Report the result. 136 */ 137 RTTestValue(g_hTest, "Throughput", g_cBench1Iterations * RT_NS_1SEC / cNsElapsed, RTTESTUNIT_OCCURRENCES_PER_SEC); 138 RTTestValue(g_hTest, "Roundtrip", cNsElapsed / g_cBench1Iterations, RTTESTUNIT_NS_PER_OCCURRENCE); 139 140 } 141 142 143 /********************************************************************************************************************************* 144 * Test #1: Simple setup checking wakup order of two waiting thread. * 145 *********************************************************************************************************************************/ 146 147 static DECLCALLBACK(int) test1Thread(RTTHREAD hThreadSelf, void *pvUser) 148 { 149 RTSEMEVENT hSem = *(PRTSEMEVENT)pvUser; 150 RTTEST_CHECK_RC(g_hTest, RTThreadUserSignal(hThreadSelf), VINF_SUCCESS); 151 RTTEST_CHECK_RC(g_hTest, RTSemEventWait(hSem, RT_INDEFINITE_WAIT), VINF_SUCCESS); 72 152 return VINF_SUCCESS; 73 153 } … … 79 159 80 160 /* 81 * Create the threads and let them block on the event multi semaphore. 161 * Create the threads and let them block on the event semaphore one 162 * after the other. 82 163 */ 83 RTSEMEVENTMULTI hSem; 84 RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&hSem), VINF_SUCCESS); 164 RTSEMEVENT hSem; 165 RTTESTI_CHECK_RC_RETV(RTSemEventCreate(&hSem), VINF_SUCCESS); 166 167 RTTHREAD hThread1; 168 RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread1, test1Thread, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1t1"), VINF_SUCCESS); 169 RTTESTI_CHECK_RC_RETV(RTThreadUserWait(hThread1, RT_MS_30SEC), VINF_SUCCESS); 170 RTThreadSleep(256); 85 171 86 172 RTTHREAD hThread2; 87 RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread2, test1Thread2, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test2"), VINF_SUCCESS); 88 RTThreadSleep(100); 89 90 RTTHREAD hThread1; 91 RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread1, test1Thread1, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1"), VINF_SUCCESS); 92 93 /* Force first thread (which has a timeout of 1 second) to timeout in the 94 * first wait, and the second wait will succeed. */ 95 RTTESTI_CHECK_RC(RTThreadSleep(1500), VINF_SUCCESS); 96 RTTESTI_CHECK_RC(RTSemEventMultiSignal(hSem), VINF_SUCCESS); 173 RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread2, test1Thread, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1t2"), VINF_SUCCESS); 174 RTTESTI_CHECK_RC_RETV(RTThreadUserWait(hThread2, RT_MS_30SEC), VINF_SUCCESS); 175 RTThreadSleep(256); 176 177 /* Signal once, hopefully waking up thread1: */ 178 RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS); 97 179 RTTESTI_CHECK_RC(RTThreadWait(hThread1, 5000, NULL), VINF_SUCCESS); 180 181 /* Signal once more, hopefully waking up thread2: */ 182 RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS); 98 183 RTTESTI_CHECK_RC(RTThreadWait(hThread2, 5000, NULL), VINF_SUCCESS); 99 RTTESTI_CHECK_RC(RTSemEventMultiDestroy(hSem), VINF_SUCCESS); 100 } 101 102 103 static void testBasicsWaitTimeout(RTSEMEVENTMULTI hSem, unsigned i) 104 { 105 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWait(hSem, 0), VERR_TIMEOUT); 184 185 RTTESTI_CHECK_RC(RTSemEventDestroy(hSem), VINF_SUCCESS); 186 } 187 188 189 /********************************************************************************************************************************* 190 * Basic tests * 191 *********************************************************************************************************************************/ 192 193 194 static void testBasicsWaitTimeout(RTSEMEVENT hSem, unsigned i) 195 { 196 RTTESTI_CHECK_RC_RETV(RTSemEventWait(hSem, 0), VERR_TIMEOUT); 106 197 #if 0 107 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiWaitNoResume(hSem, 0), VERR_TIMEOUT);198 RTTESTI_CHECK_RC_RETV(RTSemEventWaitNoResume(hSem, 0), VERR_TIMEOUT); 108 199 #else 109 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 110 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE, 111 0), 112 VERR_TIMEOUT); 113 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 114 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 115 RTTimeSystemNanoTS() + 1000*i), 116 VERR_TIMEOUT); 117 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 118 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 119 RTTimeNanoTS() + 1000*i), 120 VERR_TIMEOUT); 121 122 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 123 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_RELATIVE, 124 0), 125 VERR_TIMEOUT); 200 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE, 201 0), VERR_TIMEOUT); 202 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 203 RTTimeSystemNanoTS() + 1000*i), VERR_TIMEOUT); 204 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 205 RTTimeNanoTS() + 1000*i), VERR_TIMEOUT); 206 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_RELATIVE, 207 0), VERR_TIMEOUT); 126 208 #endif 127 209 } 128 210 129 211 130 static void testBasicsWaitSuccess(RTSEMEVENTMULTI hSem, unsigned i) 131 { 132 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWait(hSem, 0), VINF_SUCCESS); 133 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWait(hSem, RT_INDEFINITE_WAIT), VINF_SUCCESS); 134 #if 0 135 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitNoResume(hSem, 0), VINF_SUCCESS); 136 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitNoResume(hSem, RT_INDEFINITE_WAIT), VINF_SUCCESS); 137 #else 138 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 139 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE, 212 static void testBasics(void) 213 { 214 RTTestISub("Basics"); 215 216 RTSEMEVENT hSem; 217 RTTESTI_CHECK_RC_RETV(RTSemEventCreate(&hSem), VINF_SUCCESS); 218 219 /* The semaphore is created in a non-signalled state. */ 220 testBasicsWaitTimeout(hSem, 0); 221 testBasicsWaitTimeout(hSem, 1); 222 if (RTTestIErrorCount()) 223 return; 224 225 /* When signalling the semaphore, only the next waiter call shall 226 success, all subsequent ones should timeout as above. */ 227 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 228 RTTESTI_CHECK_RC_RETV(RTSemEventWait(hSem, 0), VINF_SUCCESS); 229 testBasicsWaitTimeout(hSem, 0); 230 if (RTTestIErrorCount()) 231 return; 232 233 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 234 RTTESTI_CHECK_RC_RETV(RTSemEventWait(hSem, 2), VINF_SUCCESS); 235 testBasicsWaitTimeout(hSem, 2); 236 237 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 238 RTTESTI_CHECK_RC_RETV(RTSemEventWait(hSem, RT_INDEFINITE_WAIT), VINF_SUCCESS); 239 testBasicsWaitTimeout(hSem, 1); 240 241 if (RTTestIErrorCount()) 242 return; 243 244 /* Now do all the event wait ex variations: */ 245 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 246 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE, 140 247 0), 141 248 VINF_SUCCESS); 142 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_INDEFINITE, 0), VINF_SUCCESS); 143 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_INDEFINITE, 0), VINF_SUCCESS); 144 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 145 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 146 RTTimeSystemNanoTS() + 1000*i), 147 VINF_SUCCESS); 148 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 149 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 150 RTTimeNanoTS() + 1000*i), 151 VINF_SUCCESS); 152 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 153 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 154 0), 155 VINF_SUCCESS); 156 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 157 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 158 _1G), 159 VINF_SUCCESS); 160 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 161 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 162 UINT64_MAX), 163 VINF_SUCCESS); 164 165 166 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 167 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 168 RTTimeSystemMilliTS() + 1000*i), 169 VINF_SUCCESS); 170 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 171 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 172 RTTimeMilliTS() + 1000*i), 173 VINF_SUCCESS); 174 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 175 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 176 0), 177 VINF_SUCCESS); 178 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 179 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 180 _1M), 181 VINF_SUCCESS); 182 RTTESTI_CHECK_RC_RETV(RTSemEventMultiWaitEx(hSem, 183 RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 184 UINT64_MAX), 185 VINF_SUCCESS); 186 #endif 187 } 188 189 190 static void testBasics(void) 191 { 192 RTTestISub("Basics"); 193 194 RTSEMEVENTMULTI hSem; 195 RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&hSem), VINF_SUCCESS); 196 197 /* The semaphore is created in a reset state, calling reset explicitly 198 shouldn't make any difference. */ 199 testBasicsWaitTimeout(hSem, 0); 200 RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS); 201 testBasicsWaitTimeout(hSem, 1); 202 if (RTTestIErrorCount()) 203 return; 204 205 /* When signalling the semaphore all successive wait calls shall 206 succeed, signalling it again should make no difference. */ 207 RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS); 208 testBasicsWaitSuccess(hSem, 2); 209 if (RTTestIErrorCount()) 210 return; 211 212 /* After resetting it we should time out again. */ 213 RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS); 214 testBasicsWaitTimeout(hSem, 3); 215 if (RTTestIErrorCount()) 216 return; 217 218 /* The number of resets or signal calls shouldn't matter. */ 219 RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS); 220 RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS); 221 RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS); 222 testBasicsWaitTimeout(hSem, 4); 223 224 RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS); 225 RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS); 226 RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS); 227 RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS); 228 RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS); 229 testBasicsWaitSuccess(hSem, 5); 230 231 RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS); 232 testBasicsWaitTimeout(hSem, 6); 249 testBasicsWaitTimeout(hSem, 1); 250 251 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 252 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_INDEFINITE, 0), VINF_SUCCESS); 253 testBasicsWaitTimeout(hSem, 1); 254 255 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 256 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_INDEFINITE, 0), VINF_SUCCESS); 257 testBasicsWaitTimeout(hSem, 1); 258 259 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 260 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 261 RTTimeSystemNanoTS() + RT_NS_1US), VINF_SUCCESS); 262 testBasicsWaitTimeout(hSem, 1); 263 264 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 265 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 266 RTTimeNanoTS() + RT_NS_1US), VINF_SUCCESS); 267 testBasicsWaitTimeout(hSem, 0); 268 269 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 270 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 271 RTTimeNanoTS() + RT_NS_1HOUR), VINF_SUCCESS); 272 testBasicsWaitTimeout(hSem, 0); 273 274 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 275 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 276 0), VINF_SUCCESS); 277 testBasicsWaitTimeout(hSem, 1); 278 279 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 280 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 281 _1G), VINF_SUCCESS); 282 testBasicsWaitTimeout(hSem, 1); 283 284 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 285 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 286 UINT64_MAX), VINF_SUCCESS); 287 288 testBasicsWaitTimeout(hSem, 10); 289 290 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 291 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 292 RTTimeSystemMilliTS() + RT_MS_1SEC), VINF_SUCCESS); 293 testBasicsWaitTimeout(hSem, 1); 294 295 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 296 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 297 RTTimeMilliTS() + RT_MS_1SEC), VINF_SUCCESS); 298 testBasicsWaitTimeout(hSem, 1); 299 300 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 301 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 302 0), VINF_SUCCESS); 303 testBasicsWaitTimeout(hSem, 0); 304 305 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 306 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 307 _1M), VINF_SUCCESS); 308 testBasicsWaitTimeout(hSem, 1); 309 310 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 311 RTTESTI_CHECK_RC_RETV(RTSemEventWaitEx(hSem, RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_ABSOLUTE, 312 UINT64_MAX), VINF_SUCCESS); 313 testBasicsWaitTimeout(hSem, 1); 233 314 234 315 /* Destroy it. */ 235 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiDestroy(hSem), VINF_SUCCESS);236 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiDestroy(NIL_RTSEMEVENTMULTI), VINF_SUCCESS);237 238 /* Whether it is reset (above),signalled or not used shouldn't matter. */239 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiCreate(&hSem), VINF_SUCCESS);240 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiSignal(hSem), VINF_SUCCESS);241 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiDestroy(hSem), VINF_SUCCESS);242 243 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiCreate(&hSem), VINF_SUCCESS);244 RTTESTI_CHECK_RC_RETV(RTSemEvent MultiDestroy(hSem), VINF_SUCCESS);316 RTTESTI_CHECK_RC_RETV(RTSemEventDestroy(hSem), VINF_SUCCESS); 317 RTTESTI_CHECK_RC_RETV(RTSemEventDestroy(NIL_RTSEMEVENT), VINF_SUCCESS); 318 319 /* Whether it is signalled or not used shouldn't matter. */ 320 RTTESTI_CHECK_RC_RETV(RTSemEventCreate(&hSem), VINF_SUCCESS); 321 RTTESTI_CHECK_RC_RETV(RTSemEventSignal(hSem), VINF_SUCCESS); 322 RTTESTI_CHECK_RC_RETV(RTSemEventDestroy(hSem), VINF_SUCCESS); 323 324 RTTESTI_CHECK_RC_RETV(RTSemEventCreate(&hSem), VINF_SUCCESS); 325 RTTESTI_CHECK_RC_RETV(RTSemEventDestroy(hSem), VINF_SUCCESS); 245 326 246 327 RTTestISubDone(); … … 252 333 RT_NOREF_PV(argc); RT_NOREF_PV(argv); 253 334 254 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTSemEvent Multi", &g_hTest);335 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTSemEvent", &g_hTest); 255 336 if (rcExit != RTEXITCODE_SUCCESS) 256 337 return rcExit; … … 261 342 test1(); 262 343 } 344 if (!RTTestErrorCount(g_hTest)) 345 { 346 bench1("Benchmark: Ping Pong, spin", RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_MILLISECS | RTSEMWAIT_FLAGS_RELATIVE, 347 0); 348 bench1("Benchmark: Ping Pong, indefinite", RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_INDEFINITE, 349 0); 350 bench1("Benchmark: Ping Pong, absolute", RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE, 351 RTTimeSystemNanoTS() + RT_NS_1HOUR); 352 bench1("Benchmark: Ping Pong, relative", RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE, 353 RT_NS_1HOUR); 354 bench1("Benchmark: Ping Pong, relative, resume", RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_RELATIVE, 355 RT_NS_1HOUR); 356 } 263 357 264 358 return RTTestSummaryAndDestroy(g_hTest);
Note:
See TracChangeset
for help on using the changeset viewer.