Changeset 85500 in vbox
- Timestamp:
- Jul 29, 2020 8:54:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstLdr-4.cpp
r85461 r85500 36 36 #include <iprt/param.h> 37 37 #include <iprt/path.h> 38 #include <iprt/initterm.h>39 38 #include <iprt/err.h> 40 39 #include <iprt/string.h> 40 #include <iprt/test.h> 41 41 42 42 #include <VBox/sup.h> … … 46 46 * Global Variables * 47 47 *********************************************************************************************************************************/ 48 static SUPGLOBALINFOPAGE g_MyGip = { SUPGLOBALINFOPAGE_MAGIC, SUPGLOBALINFOPAGE_VERSION, SUPGIPMODE_INVARIANT_TSC, 42 }; 49 static PSUPGLOBALINFOPAGE g_pMyGip = &g_MyGip; 48 static RTTEST g_hTest; 49 static SUPGLOBALINFOPAGE g_MyGip = { SUPGLOBALINFOPAGE_MAGIC, SUPGLOBALINFOPAGE_VERSION, SUPGIPMODE_INVARIANT_TSC, 42 }; 50 static PSUPGLOBALINFOPAGE g_pMyGip = &g_MyGip; 50 51 51 52 extern "C" DECLEXPORT(int) DisasmTest1(void); … … 59 60 , *piSeg, pSeg->RVA, pSeg->cbMapped, pSeg->pszName, 60 61 pSeg->LinkAddress, pSeg->cb, pSeg->Alignment, pSeg->fProt, pSeg->offFile); 62 63 /* 64 * Do some address conversion tests: 65 */ 66 if (pSeg->cbMapped != NIL_RTLDRADDR) 67 { 68 /* RTLdrRvaToSegOffset: */ 69 uint32_t iSegConv = ~(uint32_t)42; 70 RTLDRADDR offSegConv = ~(RTLDRADDR)22; 71 int rc = RTLdrRvaToSegOffset(hLdrMod, pSeg->RVA, &iSegConv, &offSegConv); 72 if (RT_FAILURE(rc)) 73 RTTestIFailed("RTLdrRvaToSegOffset failed on Seg #%u / RVA %#RTptr: %Rrc", *piSeg, pSeg->RVA, rc); 74 else if (iSegConv != *piSeg || offSegConv != 0) 75 RTTestIFailed("RTLdrRvaToSegOffset on Seg #%u / RVA %#RTptr returned: iSegConv=%#x offSegConv=%RTptr, expected %#x and 0", 76 *piSeg, pSeg->RVA, iSegConv, offSegConv, *piSeg); 77 78 /* RTLdrSegOffsetToRva: */ 79 RTLDRADDR uRvaConv = ~(RTLDRADDR)22; 80 rc = RTLdrSegOffsetToRva(hLdrMod, *piSeg, 0, &uRvaConv); 81 if (RT_FAILURE(rc)) 82 RTTestIFailed("RTLdrSegOffsetToRva failed on Seg #%u / off 0: %Rrc", *piSeg, rc); 83 else if (uRvaConv != pSeg->RVA) 84 RTTestIFailed("RTLdrSegOffsetToRva on Seg #%u / off 0 returned: %RTptr, expected %RTptr", *piSeg, uRvaConv, pSeg->RVA); 85 86 /* RTLdrLinkAddressToRva: */ 87 uRvaConv = ~(RTLDRADDR)22; 88 rc = RTLdrLinkAddressToRva(hLdrMod, pSeg->LinkAddress, &uRvaConv); 89 if (RT_FAILURE(rc)) 90 RTTestIFailed("RTLdrLinkAddressToRva failed on Seg #%u / %RTptr: %Rrc", *piSeg, pSeg->LinkAddress, rc); 91 else if (uRvaConv != pSeg->RVA) 92 RTTestIFailed("RTLdrLinkAddressToRva on Seg #%u / %RTptr returned: %RTptr, expected %RTptr", 93 *piSeg, pSeg->LinkAddress, uRvaConv, pSeg->RVA); 94 95 /* RTLdrLinkAddressToSegOffset: */ 96 iSegConv = ~(uint32_t)42; 97 offSegConv = ~(RTLDRADDR)22; 98 rc = RTLdrLinkAddressToSegOffset(hLdrMod, pSeg->LinkAddress, &iSegConv, &offSegConv); 99 if (RT_FAILURE(rc)) 100 RTTestIFailed("RTLdrLinkAddressToSegOffset failed on Seg #%u / %#RTptr: %Rrc", *piSeg, pSeg->LinkAddress, rc); 101 else if (iSegConv != *piSeg || offSegConv != 0) 102 RTTestIFailed("RTLdrLinkAddressToSegOffset on Seg #%u / %#RTptr returned: iSegConv=%#x offSegConv=%RTptr, expected %#x and 0", 103 *piSeg, pSeg->LinkAddress, iSegConv, offSegConv, *piSeg); 104 } 105 61 106 *piSeg += 1; 62 107 RT_NOREF(hLdrMod); … … 126 171 * and then relocated between the two and other locations a few times. 127 172 * 128 * @returns number of errors.129 173 * @param pszFilename The file to load the mess with. 130 174 */ 131 static inttestLdrOne(const char *pszFilename)175 static void testLdrOne(const char *pszFilename) 132 176 { 133 int cErrors = 0; 177 RTTestSub(g_hTest, RTPathFilename(pszFilename)); 178 134 179 size_t cbImage = 0; 135 180 struct Load … … 156 201 if (RT_FAILURE(rc)) 157 202 { 158 RT Printf("tstLdr-4: Failed to open '%s'/%d, rc=%Rrc. aborting test.\n", pszFilename, i, rc);203 RTTestIFailed("tstLdr-4: Failed to open '%s'/%d, rc=%Rrc. aborting test.", pszFilename, i, rc); 159 204 Assert(aLoads[i].hLdrMod == NIL_RTLDRMOD); 160 cErrors++;161 205 break; 162 206 } … … 166 210 if (cbImage && cb != cbImage) 167 211 { 168 RTPrintf("tstLdr-4: Size mismatch '%s'/%d. aborting test.\n", pszFilename, i); 169 cErrors++; 212 RTTestIFailed("tstLdr-4: Size mismatch '%s'/%d. aborting test.", pszFilename, i); 170 213 break; 171 214 } … … 176 219 if (!aLoads[i].pvBits) 177 220 { 178 RTPrintf("tstLdr-4: Out of memory '%s'/%d cbImage=%d. aborting test.\n", pszFilename, i, cbImage); 179 cErrors++; 221 RTTestIFailed("Out of memory '%s'/%d cbImage=%d. aborting test.", pszFilename, i, cbImage); 180 222 break; 181 223 } … … 185 227 if (RT_FAILURE(rc)) 186 228 { 187 RTPrintf("tstLdr-4: Failed to get bits for '%s'/%d, rc=%Rrc. aborting test\n", pszFilename, i, rc); 188 cErrors++; 229 RTTestIFailed("Failed to get bits for '%s'/%d, rc=%Rrc. aborting test", pszFilename, i, rc); 189 230 break; 190 231 } … … 194 235 * Execute the code. 195 236 */ 196 if (! cErrors)237 if (!RTTestSubErrorCount(g_hTest)) 197 238 { 198 239 for (i = 0; i < RT_ELEMENTS(aLoads); i += 1) … … 210 251 if (RT_FAILURE(rc)) 211 252 { 212 RTPrintf("tstLdr-4: Failed to get symbol \"DisasmTest1\" from load #%d: %Rrc\n", i, rc); 213 cErrors++; 253 RTTestIFailed("Failed to get symbol \"DisasmTest1\" from load #%d: %Rrc", i, rc); 214 254 break; 215 255 } … … 223 263 rc = pfnDisasmTest1(); 224 264 if (rc) 225 { 226 RTPrintf("tstLdr-4: load #%d Test1 -> %#x\n", i, rc); 227 cErrors++; 228 } 265 RTTestIFailed("load #%d Test1 -> %#x", i, rc); 229 266 230 267 /* While we're here, check a couple of RTLdrQueryProp calls too */ … … 257 294 rc = RTLdrClose(aLoads[i].hLdrMod); 258 295 if (RT_FAILURE(rc)) 259 { 260 RTPrintf("tstLdr-4: Failed to close '%s' i=%d, rc=%Rrc.\n", pszFilename, i, rc); 261 cErrors++; 262 } 263 } 264 } 265 266 return cErrors; 296 RTTestIFailed("Failed to close '%s' i=%d, rc=%Rrc.", pszFilename, i, rc); 297 } 298 } 299 267 300 } 268 301 269 302 270 303 271 int main( int argc, char **argv)304 int main() 272 305 { 273 int cErrors = 0; 274 RTR3InitExe(argc, &argv, 0); 306 RTEXITCODE rcExit = RTTestInitAndCreate("tstLdr-4", &g_hTest); 307 if (rcExit != RTEXITCODE_SUCCESS) 308 return rcExit; 275 309 276 310 /* … … 278 312 */ 279 313 int rc = DisasmTest1(); 280 if (rc) 281 { 282 RTPrintf("tstLdr-4: FATAL ERROR - DisasmTest1 is buggy: rc=%#x\n", rc); 283 return 1; 284 } 285 286 /* 287 * Execute the test. 288 */ 289 char szPath[RTPATH_MAX]; 290 rc = RTPathExecDir(szPath, sizeof(szPath) - sizeof("/tstLdrObjR0.r0")); 291 if (RT_SUCCESS(rc)) 292 { 293 strcat(szPath, "/tstLdrObjR0.r0"); 294 RTPrintf("tstLdr-4: TESTING '%s'...\n", szPath); 295 cErrors += testLdrOne(szPath); 314 if (rc == 0) 315 { 316 /* 317 * Execute the test. 318 */ 319 char szPath[RTPATH_MAX]; 320 rc = RTPathExecDir(szPath, sizeof(szPath) - sizeof("/tstLdrObjR0.r0")); 321 if (RT_SUCCESS(rc)) 322 { 323 strcat(szPath, "/tstLdrObjR0.r0"); 324 325 testLdrOne(szPath); 326 } 327 else 328 RTTestIFailed("RTPathExecDir -> %Rrc", rc); 296 329 } 297 330 else 298 { 299 RTPrintf("tstLdr-4: RTPathExecDir -> %Rrc\n", rc); 300 cErrors++; 301 } 302 303 /* 304 * Test result summary. 305 */ 306 if (!cErrors) 307 RTPrintf("tstLdr-4: SUCCESS\n"); 308 else 309 RTPrintf("tstLdr-4: FAILURE - %d errors\n", cErrors); 310 return !!cErrors; 331 RTTestIFailed("FATAL ERROR - DisasmTest1 is buggy: rc=%#x", rc); 332 333 return RTTestSummaryAndDestroy(g_hTest); 311 334 }
Note:
See TracChangeset
for help on using the changeset viewer.