Changeset 18848 in vbox for trunk/src/VBox/VMM/testcase
- Timestamp:
- Apr 8, 2009 4:28:35 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/testcase/tstVMMR0CallHost-1.cpp
r14831 r18848 27 27 #include <iprt/stream.h> 28 28 #include <iprt/alloca.h> 29 #include <iprt/test.h> 29 30 #include <VBox/err.h> 30 31 … … 34 35 #include "VMMInternal.h" 35 36 37 38 /******************************************************************************* 39 * Defined Constants And Macros * 40 *******************************************************************************/ 41 #ifdef RT_OS_DARWIN 42 # define VMM_R0_SWITCH_STACK 43 #endif 36 44 37 45 … … 43 51 /** The number of jumps we've done. */ 44 52 static unsigned volatile g_cJmps; 45 /** The saved stack. */46 static uint8_t g_Stack[8192];47 53 48 54 … … 63 69 return -1; 64 70 } 71 NOREF(iMinusOne); 65 72 return i; 66 73 } … … 69 76 DECLCALLBACK(int) tst2(intptr_t i, intptr_t i2) 70 77 { 71 if (i < 0 || i > 8192) 72 { 73 RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d is out of range [0..8192]\n", i); 74 return 1; 75 } 76 if (i2 != 0) 77 { 78 RTPrintf("tstVMMR0CallHost-1: FAILURE - i2=%d is out of range [0]\n", i2); 79 return 1; 80 } 78 RTTESTI_CHECK_MSG_RET(i >= 0 && i <= 8192, ("i=%d is out of range [0..8192]\n", i), 1); 79 RTTESTI_CHECK_MSG_RET(i2 == 0, ("i2=%d is out of range [0]\n", i2), 1); 81 80 int iExpect = (i % 7) == 0 ? i + 10000 : i; 82 81 int rc = foo(i, 0, -1); 83 if (rc != iExpect) 84 { 85 RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d rc=%d expected=%d\n", i, rc, iExpect); 86 return 1; 87 } 82 RTTESTI_CHECK_MSG_RET(rc == iExpect, ("i=%d rc=%d expected=%d\n", i, rc, iExpect), 1); 88 83 return 0; 89 84 } 90 85 91 int tst(int iFrom, int iTo, int iInc) 86 87 void tst(int iFrom, int iTo, int iInc) 92 88 { 89 #ifdef VMM_R0_SWITCH_STACK 90 int const cIterations = iFrom > iTo ? iFrom - iTo : iTo - iFrom; 91 void *pvPrev = alloca(1); 92 #endif 93 93 94 g_cJmps = 0; 94 for (int i = iFrom ; i != iTo; i += iInc)95 for (int i = iFrom, iItr = 0; i != iTo; i += iInc, iItr++) 95 96 { 96 97 int rc = vmmR0CallHostSetJmp(&g_Jmp, (PFNVMMR0SETJMP)tst2, (PVM)i, 0); 97 if (rc != 0 && rc != 42) 98 RTTESTI_CHECK_MSG_RETV(rc == 0 || rc == 42, ("i=%d rc=%d setjmp\n", i, rc)); 99 100 #ifdef VMM_R0_SWITCH_STACK 101 /* Make the stack pointer slide for the second half of the calls. */ 102 if (iItr >= cIterations / 2) 98 103 { 99 RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d rc=%d setjmp\n", i, rc); 100 return 1; 104 /* Note! gcc does funny rounding up of alloca(). */ 105 void *pv2 = alloca((i % 63) | 1); 106 size_t cb2 = (uintptr_t)pvPrev - (uintptr_t)pv2; 107 RTTESTI_CHECK_MSG(cb2 >= 16 && cb2 <= 128, ("cb2=%zu pv2=%p pvPrev=%p iAlloca=%d\n", cb2, pv2, pvPrev, iItr)); 108 memset(pv2, 0xff, cb2); 109 memset(pvPrev, 0xee, 1); 110 pvPrev = pv2; 101 111 } 112 #endif 102 113 } 103 if (!g_cJmps) 104 { 105 RTPrintf("tstVMMR0CallHost-1: FAILURE - no jumps!\n"); 106 return 1; 107 } 108 return 0; 114 RTTESTI_CHECK_MSG_RETV(g_cJmps, ("No jumps!")); 109 115 } 110 116 … … 115 121 * Init. 116 122 */ 117 RTR3Init(); 118 g_Jmp.pvSavedStack = (RTR0PTR)&g_Stack[0]; 123 RTTEST hTest; 124 int rc; 125 if ( RT_FAILURE(rc = RTR3Init()) 126 || RT_FAILURE(rc = RTTestCreate("tstVMMR0CallHost-1", &hTest))) 127 { 128 RTStrmPrintf(g_pStdErr, "tstVMMR0CallHost-1: Fatal error during init: %Rrc\n", rc); 129 return 1; 130 } 131 RTTestBanner(hTest); 132 133 g_Jmp.pvSavedStack = (RTR0PTR)RTTestGuardedAllocTail(hTest, 8192); 119 134 120 135 /* 121 * Try about 1000 long jumps with increasing stack size..136 * Run two test with about 1000 long jumps each. 122 137 */ 123 RTPrintf("tstVMMR0CallHost-1: Testing 1\n"); 124 int rc = tst(0, 7000, 1); 125 if (!rc) 126 { 127 RTPrintf("tstVMMR0CallHost-1: Testing 2\n"); 128 rc = tst(7599, 0, -1); 129 } 138 RTTestSub(hTest, "Increasing stack usage"); 139 tst(0, 7000, 1); 140 RTTestSub(hTest, "Decreasing stack usage"); 141 tst(7599, 0, -1); 130 142 131 if (!rc) 132 RTPrintf("tstVMMR0CallHost-1: SUCCESS\n"); 133 else 134 RTPrintf("tstVMMR0CallHost-1: FAILED\n"); 135 return !!rc; 143 return RTTestSummaryAndDestroy(hTest); 136 144 }
Note:
See TracChangeset
for help on using the changeset viewer.