Changeset 220744 in webkit
- Timestamp:
- Aug 15, 2017 9:42:41 AM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r220735 r220744 1 2017-08-15 Mark Lam <mark.lam@apple.com> 2 3 Update testmasm to use new CPUState APIs. 4 https://bugs.webkit.org/show_bug.cgi?id=175573 5 6 Reviewed by Keith Miller. 7 8 1. Applied convenience CPUState accessors to minimize casting. 9 2. Converted the CHECK macro to CHECK_EQ to get more friendly failure debugging 10 messages. 11 3. Removed the CHECK_DOUBLE_BITWISE_EQ macro. We can just use CHECK_EQ now since 12 casting is (mostly) no longer an issue. 13 4. Replaced the use of testDoubleWord(id) with bitwise_cast<double>(testWord64(id)) 14 to make it clear that we're comparing against the bit values of testWord64(id). 15 5. Added a "Completed N tests" message at the end of running all tests. 16 This makes it easy to tell at a glance that testmasm completed successfully 17 versus when it crashed midway in a test. The number of tests also serves as 18 a quick checksum to confirm that we ran the number of tests we expected. 19 20 * assembler/testmasm.cpp: 21 (WTF::printInternal): 22 (JSC::testSimple): 23 (JSC::testProbeReadsArgumentRegisters): 24 (JSC::testProbeWritesArgumentRegisters): 25 (JSC::testProbePreservesGPRS): 26 (JSC::testProbeModifiesStackPointer): 27 (JSC::testProbeModifiesProgramCounter): 28 (JSC::run): 29 1 30 2017-08-14 Keith Miller <keith_miller@apple.com> 2 31 -
trunk/Source/JavaScriptCore/assembler/testmasm.cpp
r220579 r220744 51 51 #if ENABLE(JIT) 52 52 53 namespace WTF { 54 55 static void printInternal(PrintStream& out, void* value) 56 { 57 out.printf("%p", value); 58 } 59 60 } // namespace WTF 61 53 62 using namespace JSC; 54 63 … … 72 81 #define testWord(x) testWord32(x) 73 82 #endif 74 #define testDoubleWord(x) static_cast<double>(testWord(x))75 83 76 84 // Nothing fancy for now; we just use the existing WTF assertion machinery. 77 #define CHECK (x) do {\78 if ( !!(x))\85 #define CHECK_EQ(_actual, _expected) do { \ 86 if ((_actual) == (_expected)) \ 79 87 break; \ 80 88 crashLock.lock(); \ 81 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #x); \ 89 dataLog("FAILED while testing " #_actual ": expected: ", _expected, ", actual: ", _actual, "\n"); \ 90 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, "CHECK_EQ("#_actual ", " #_expected ")"); \ 82 91 CRASH(); \ 83 92 } while (false) 84 85 #define CHECK_DOUBLE_BITWISE_EQ(a, b) \86 CHECK(bitwise_cast<uint64_t>(a) == bitwise_cast<uint64_t>(a))87 93 88 94 bool isPC(MacroAssembler::RegisterID id) … … 140 146 void testSimple() 141 147 { 142 CHECK (compileAndRun<int>([] (CCallHelpers& jit) {148 CHECK_EQ(compileAndRun<int>([] (CCallHelpers& jit) { 143 149 jit.emitFunctionPrologue(); 144 150 jit.move(CCallHelpers::TrustedImm32(42), GPRInfo::returnValueGPR); 145 151 jit.emitFunctionEpilogue(); 146 152 jit.ret(); 147 }) ==42);153 }), 42); 148 154 } 149 155 … … 171 177 172 178 jit.probe([&] (ProbeContext* context) { 179 auto& cpu = context->cpu; 173 180 probeWasCalled = true; 174 CHECK (context->gpr(GPRInfo::argumentGPR0) ==testWord(0));175 CHECK (context->gpr(GPRInfo::argumentGPR1) ==testWord(1));176 CHECK (context->gpr(GPRInfo::argumentGPR2) ==testWord(2));177 CHECK (context->gpr(GPRInfo::argumentGPR3) ==testWord(3));178 179 CHECK_ DOUBLE_BITWISE_EQ(context->fpr(FPRInfo::fpRegT0), static_cast<double>(testWord32(0)));180 CHECK_ DOUBLE_BITWISE_EQ(context->fpr(FPRInfo::fpRegT1), static_cast<double>(testWord32(1)));181 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR0), testWord(0)); 182 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR1), testWord(1)); 183 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR2), testWord(2)); 184 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR3), testWord(3)); 185 186 CHECK_EQ(cpu.fpr(FPRInfo::fpRegT0), testWord32(0)); 187 CHECK_EQ(cpu.fpr(FPRInfo::fpRegT1), testWord32(1)); 181 188 }); 182 189 jit.emitFunctionEpilogue(); 183 190 jit.ret(); 184 191 }); 185 CHECK (probeWasCalled);192 CHECK_EQ(probeWasCalled, true); 186 193 } 187 194 … … 212 219 // Write expected values. 213 220 jit.probe([&] (ProbeContext* context) { 214 probeCallCount++; 215 context->gpr(GPRInfo::argumentGPR0) = testWord(0); 216 context->gpr(GPRInfo::argumentGPR1) = testWord(1); 217 context->gpr(GPRInfo::argumentGPR2) = testWord(2); 218 context->gpr(GPRInfo::argumentGPR3) = testWord(3); 221 auto& cpu = context->cpu; 222 probeCallCount++; 223 cpu.gpr(GPRInfo::argumentGPR0) = testWord(0); 224 cpu.gpr(GPRInfo::argumentGPR1) = testWord(1); 225 cpu.gpr(GPRInfo::argumentGPR2) = testWord(2); 226 cpu.gpr(GPRInfo::argumentGPR3) = testWord(3); 219 227 220 c ontext->fpr(FPRInfo::fpRegT0) = testWord32(0);221 c ontext->fpr(FPRInfo::fpRegT1) = testWord32(1);228 cpu.fpr(FPRInfo::fpRegT0) = bitwise_cast<double>(testWord64(0)); 229 cpu.fpr(FPRInfo::fpRegT1) = bitwise_cast<double>(testWord64(1)); 222 230 }); 223 231 224 232 // Validate that expected values were written. 225 233 jit.probe([&] (ProbeContext* context) { 226 probeCallCount++; 227 CHECK(context->gpr(GPRInfo::argumentGPR0) == testWord(0)); 228 CHECK(context->gpr(GPRInfo::argumentGPR1) == testWord(1)); 229 CHECK(context->gpr(GPRInfo::argumentGPR2) == testWord(2)); 230 CHECK(context->gpr(GPRInfo::argumentGPR3) == testWord(3)); 231 232 CHECK_DOUBLE_BITWISE_EQ(context->fpr(FPRInfo::fpRegT0), static_cast<double>(testWord32(0))); 233 CHECK_DOUBLE_BITWISE_EQ(context->fpr(FPRInfo::fpRegT1), static_cast<double>(testWord32(1))); 234 auto& cpu = context->cpu; 235 probeCallCount++; 236 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR0), testWord(0)); 237 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR1), testWord(1)); 238 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR2), testWord(2)); 239 CHECK_EQ(cpu.gpr(GPRInfo::argumentGPR3), testWord(3)); 240 241 CHECK_EQ(cpu.fpr<uint64_t>(FPRInfo::fpRegT0), testWord64(0)); 242 CHECK_EQ(cpu.fpr<uint64_t>(FPRInfo::fpRegT1), testWord64(1)); 234 243 }); 235 244 … … 237 246 jit.ret(); 238 247 }); 239 CHECK (probeCallCount ==2);248 CHECK_EQ(probeCallCount, 2); 240 249 } 241 250 … … 266 275 // Write expected values into the registers (except for sp, fp, and pc). 267 276 jit.probe([&] (ProbeContext* context) { 268 probeCallCount++; 269 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 270 originalState.gpr(id) = context->gpr(id); 271 if (isSpecialGPR(id)) 272 continue; 273 context->gpr(id) = testWord(static_cast<int>(id)); 277 auto& cpu = context->cpu; 278 probeCallCount++; 279 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 280 originalState.gpr(id) = cpu.gpr(id); 281 if (isSpecialGPR(id)) 282 continue; 283 cpu.gpr(id) = testWord(static_cast<int>(id)); 274 284 } 275 285 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) { 276 originalState.fpr(id) = c ontext->fpr(id);277 c ontext->fpr(id) = testDoubleWord(id);286 originalState.fpr(id) = cpu.fpr(id); 287 cpu.fpr(id) = bitwise_cast<double>(testWord64(id)); 278 288 } 279 289 }); … … 282 292 jit.probe([&] (ProbeContext*) { 283 293 probeCallCount++; 284 CHECK (testFunctionToTrashGPRs(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) ==10);285 CHECK (testFunctionToTrashFPRs(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) ==10);294 CHECK_EQ(testFunctionToTrashGPRs(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), 10); 295 CHECK_EQ(testFunctionToTrashFPRs(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), 10); 286 296 }); 287 297 288 298 // Validate that the registers have the expected values. 289 299 jit.probe([&] (ProbeContext* context) { 300 auto& cpu = context->cpu; 290 301 probeCallCount++; 291 302 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 292 303 if (isSP(id) || isFP(id)) { 293 CHECK (context->gpr(id) ==originalState.gpr(id));304 CHECK_EQ(cpu.gpr(id), originalState.gpr(id)); 294 305 continue; 295 306 } 296 307 if (isSpecialGPR(id)) 297 308 continue; 298 CHECK (context->gpr(id) ==testWord(id));309 CHECK_EQ(cpu.gpr(id), testWord(id)); 299 310 } 300 311 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) 301 CHECK_ DOUBLE_BITWISE_EQ(context->fpr(id), testDoubleWord(id));312 CHECK_EQ(cpu.fpr<uint64_t>(id), testWord64(id)); 302 313 }); 303 314 304 315 // Restore the original state. 305 316 jit.probe([&] (ProbeContext* context) { 306 probeCallCount++; 307 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 308 if (isSpecialGPR(id)) 309 continue; 310 context->gpr(id) = originalState.gpr(id); 317 auto& cpu = context->cpu; 318 probeCallCount++; 319 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 320 if (isSpecialGPR(id)) 321 continue; 322 cpu.gpr(id) = originalState.gpr(id); 311 323 } 312 324 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) 313 c ontext->fpr(id) = originalState.fpr(id);325 cpu.fpr(id) = originalState.fpr(id); 314 326 }); 315 327 316 328 // Validate that the original state was restored. 317 329 jit.probe([&] (ProbeContext* context) { 318 probeCallCount++; 319 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 320 if (isSpecialGPR(id)) 321 continue; 322 CHECK(context->gpr(id) == originalState.gpr(id)); 330 auto& cpu = context->cpu; 331 probeCallCount++; 332 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 333 if (isSpecialGPR(id)) 334 continue; 335 CHECK_EQ(cpu.gpr(id), originalState.gpr(id)); 323 336 } 324 337 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) 325 CHECK_ DOUBLE_BITWISE_EQ(context->fpr(id), originalState.fpr(id));338 CHECK_EQ(cpu.fpr<uint64_t>(id), originalState.fpr<uint64_t>(id)); 326 339 }); 327 340 … … 329 342 jit.ret(); 330 343 }); 331 CHECK (probeCallCount ==5);344 CHECK_EQ(probeCallCount, 5); 332 345 } 333 346 … … 336 349 unsigned probeCallCount = 0; 337 350 MacroAssembler::CPUState originalState; 338 uint8_t* originalSP { nullptr };351 void* originalSP { nullptr }; 339 352 void* modifiedSP { nullptr }; 340 353 uintptr_t modifiedFlags { 0 }; … … 357 370 // write expected values into other registers (except for fp, and pc). 358 371 jit.probe([&] (ProbeContext* context) { 359 probeCallCount++; 360 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 361 originalState.gpr(id) = context->gpr(id); 362 if (isSpecialGPR(id)) 363 continue; 364 context->gpr(id) = testWord(static_cast<int>(id)); 372 auto& cpu = context->cpu; 373 probeCallCount++; 374 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 375 originalState.gpr(id) = cpu.gpr(id); 376 if (isSpecialGPR(id)) 377 continue; 378 cpu.gpr(id) = testWord(static_cast<int>(id)); 365 379 } 366 380 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) { 367 originalState.fpr(id) = c ontext->fpr(id);368 c ontext->fpr(id) = testWord(id);369 } 370 371 originalState.spr(flagsSPR) = c ontext->spr(flagsSPR);381 originalState.fpr(id) = cpu.fpr(id); 382 cpu.fpr(id) = bitwise_cast<double>(testWord64(id)); 383 } 384 385 originalState.spr(flagsSPR) = cpu.spr(flagsSPR); 372 386 modifiedFlags = originalState.spr(flagsSPR) ^ flagsMask; 373 c ontext->spr(flagsSPR) = modifiedFlags;374 375 originalSP = reinterpret_cast<uint8_t*>(context->sp());387 cpu.spr(flagsSPR) = modifiedFlags; 388 389 originalSP = cpu.sp(); 376 390 modifiedSP = computeModifiedStack(context); 377 c ontext->sp() = modifiedSP;391 cpu.sp() = modifiedSP; 378 392 }); 379 393 380 394 // Validate that the registers have the expected values. 381 395 jit.probe([&] (ProbeContext* context) { 396 auto& cpu = context->cpu; 382 397 probeCallCount++; 383 398 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 384 399 if (isFP(id)) { 385 CHECK (context->gpr(id) ==originalState.gpr(id));400 CHECK_EQ(cpu.gpr(id), originalState.gpr(id)); 386 401 continue; 387 402 } 388 403 if (isSpecialGPR(id)) 389 404 continue; 390 CHECK (context->gpr(id) ==testWord(id));405 CHECK_EQ(cpu.gpr(id), testWord(id)); 391 406 } 392 407 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) 393 CHECK_ DOUBLE_BITWISE_EQ(context->fpr(id), testDoubleWord(id));394 CHECK (context->spr(flagsSPR) ==modifiedFlags);395 CHECK (context->sp() ==modifiedSP);408 CHECK_EQ(cpu.fpr<uint64_t>(id), testWord64(id)); 409 CHECK_EQ(cpu.spr(flagsSPR), modifiedFlags); 410 CHECK_EQ(cpu.sp(), modifiedSP); 396 411 }); 397 412 398 413 // Restore the original state. 399 414 jit.probe([&] (ProbeContext* context) { 400 probeCallCount++; 401 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 402 if (isSpecialGPR(id)) 403 continue; 404 context->gpr(id) = originalState.gpr(id); 415 auto& cpu = context->cpu; 416 probeCallCount++; 417 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 418 if (isSpecialGPR(id)) 419 continue; 420 cpu.gpr(id) = originalState.gpr(id); 405 421 } 406 422 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) 407 c ontext->fpr(id) = originalState.fpr(id);408 c ontext->spr(flagsSPR) = originalState.spr(flagsSPR);409 c ontext->sp() = originalSP;423 cpu.fpr(id) = originalState.fpr(id); 424 cpu.spr(flagsSPR) = originalState.spr(flagsSPR); 425 cpu.sp() = originalSP; 410 426 }); 411 427 412 428 // Validate that the original state was restored. 413 429 jit.probe([&] (ProbeContext* context) { 414 probeCallCount++; 415 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 416 if (isSpecialGPR(id)) 417 continue; 418 CHECK(context->gpr(id) == originalState.gpr(id)); 430 auto& cpu = context->cpu; 431 probeCallCount++; 432 for (auto id = CCallHelpers::firstRegister(); id <= CCallHelpers::lastRegister(); id = nextID(id)) { 433 if (isSpecialGPR(id)) 434 continue; 435 CHECK_EQ(cpu.gpr(id), originalState.gpr(id)); 419 436 } 420 437 for (auto id = CCallHelpers::firstFPRegister(); id <= CCallHelpers::lastFPRegister(); id = nextID(id)) 421 CHECK_ DOUBLE_BITWISE_EQ(context->fpr(id), originalState.fpr(id));422 CHECK (context->spr(flagsSPR) ==originalState.spr(flagsSPR));423 CHECK (context->sp() ==originalSP);438 CHECK_EQ(cpu.fpr<uint64_t>(id), originalState.fpr<uint64_t>(id)); 439 CHECK_EQ(cpu.spr(flagsSPR), originalState.spr(flagsSPR)); 440 CHECK_EQ(cpu.sp(), originalSP); 424 441 }); 425 442 … … 427 444 jit.ret(); 428 445 }); 429 CHECK (probeCallCount ==4);446 CHECK_EQ(probeCallCount, 4); 430 447 } 431 448 … … 488 505 jit.breakpoint(); // We should never get here. 489 506 }); 490 CHECK (probeCallCount ==2);491 CHECK (continuationWasReached);507 CHECK_EQ(probeCallCount, 2); 508 CHECK_EQ(continuationWasReached, true); 492 509 } 493 510 … … 495 512 if (!shouldRun(#test)) \ 496 513 break; \ 514 numberOfTests++; \ 497 515 tasks.append( \ 498 516 createSharedTask<void()>( \ … … 507 525 { 508 526 JSC::initializeThreading(); 527 unsigned numberOfTests = 0; 509 528 510 529 Deque<RefPtr<SharedTask<void()>>> tasks; … … 551 570 thread->waitForCompletion(); 552 571 crashLock.lock(); 572 dataLog("Completed ", numberOfTests, " tests\n"); 553 573 } 554 574
Note: See TracChangeset
for help on using the changeset viewer.