| 403 | Reference<DocumentLayer> g_docLayer; |
| 404 | |
| 405 | ACTOR static void runUnitTests(StringRef testPattern) { |
| 406 | state int testRunLimit = -1; //< Parameter? |
| 407 | state std::vector<UnitTest*> tests; |
| 408 | state int testsAvailable = 0; |
| 409 | state int testsFailed = 0; |
| 410 | state int testsExecuted = 0; |
| 411 | |
| 412 | for (auto t = g_unittests.tests; t != nullptr; t = t->next) { |
| 413 | printf("Test: '%s' pattern: '%s'\n", t->name, testPattern.toString().c_str()); |
| 414 | if (StringRef(t->name).startsWith(testPattern)) { |
| 415 | ++testsAvailable; |
| 416 | tests.push_back(t); |
| 417 | } |
| 418 | } |
| 419 | g_random->randomShuffle(tests); |
| 420 | if (testRunLimit > 0 && tests.size() > testRunLimit) |
| 421 | tests.resize(testRunLimit); |
| 422 | |
| 423 | state std::vector<UnitTest*>::iterator t; |
| 424 | for (t = tests.begin(); t != tests.end(); ++t) { |
| 425 | auto test = *t; |
| 426 | printf("Testing %s\n", test->name); |
| 427 | |
| 428 | state Error result = success(); |
| 429 | state double start_now = now(); |
| 430 | state double start_timer = timer(); |
| 431 | |
| 432 | try { |
| 433 | wait(test->func()); |
| 434 | } catch (Error& e) { |
| 435 | ++testsFailed; |
| 436 | result = e; |
| 437 | printf(" FAILED: %s\n", e.what()); |
| 438 | } |
| 439 | ++testsExecuted; |
| 440 | double wallTime = timer() - start_timer; |
| 441 | double simTime = now() - start_now; |
| 442 | |
| 443 | // self->totalWallTime += wallTime; |
| 444 | // self->totalSimTime += simTime; |
| 445 | |
| 446 | auto unitTest = *t; |
| 447 | TraceEvent(result.code() != error_code_success ? SevError : SevInfo, "UnitTest") |
| 448 | .detail("Name", unitTest->name) |
| 449 | .detail("File", unitTest->file) |
| 450 | .detail("Line", unitTest->line) |
| 451 | .error(result, true) |
| 452 | .detail("WallTime", wallTime) |
| 453 | .detail("FlowTime", simTime); |
| 454 | } |
| 455 | |
| 456 | printf("Tests available: %d\n", testsAvailable); |
| 457 | printf("Tests executed: %d\n", testsExecuted); |
| 458 | printf("Tests failed: %d\n", testsFailed); |
| 459 | |
| 460 | _exit((testsFailed || !testsExecuted) ? 1 : 0); |
| 461 | } |
| 462 | |