| 116 | } |
| 117 | |
| 118 | ACTOR static Future<Void> runUnitTests(UnitTestWorkload* self) { |
| 119 | state std::vector<UnitTest*> tests; |
| 120 | |
| 121 | for (auto test = g_unittests.tests; test != nullptr; test = test->next) { |
| 122 | if (StringRef(test->name).startsWith(self->testPattern)) { |
| 123 | ++self->testsAvailable; |
| 124 | tests.push_back(test); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | std::sort(tests.begin(), tests.end(), [](auto lhs, auto rhs) { |
| 129 | return std::string_view(lhs->name) < std::string_view(rhs->name); |
| 130 | }); |
| 131 | |
| 132 | fprintf(stdout, "Found %zu tests\n", tests.size()); |
| 133 | |
| 134 | if (tests.size() == 0) { |
| 135 | TraceEvent(SevError, "NoMatchingUnitTests").detail("TestPattern", self->testPattern); |
| 136 | ++self->testsFailed; |
| 137 | return Void(); |
| 138 | } |
| 139 | |
| 140 | deterministicRandom()->randomShuffle(tests); |
| 141 | if (self->testRunLimit > 0 && tests.size() > self->testRunLimit) |
| 142 | tests.resize(self->testRunLimit); |
| 143 | |
| 144 | state std::vector<UnitTest*>::iterator t; |
| 145 | for (t = tests.begin(); t != tests.end(); ++t) { |
| 146 | state UnitTest* test = *t; |
| 147 | printf("Testing %s\n", test->name); |
| 148 | |
| 149 | TraceEvent(SevInfo, "RunningUnitTest") |
| 150 | .detail("Name", test->name) |
| 151 | .detail("File", test->file) |
| 152 | .detail("Line", test->line); |
| 153 | |
| 154 | state Error result = success(); |
| 155 | state double start_now = now(); |
| 156 | state double start_timer = timer(); |
| 157 | |
| 158 | platform::createDirectory(self->testParams.getDataDir()); |
| 159 | try { |
| 160 | wait(test->func(self->testParams)); |
| 161 | } catch (Error& e) { |
| 162 | ++self->testsFailed; |
| 163 | result = e; |
| 164 | } |
| 165 | if (self->cleanupAfterTests) { |
| 166 | platform::eraseDirectoryRecursive(self->testParams.getDataDir()); |
| 167 | } |
| 168 | ++self->testsExecuted; |
| 169 | double wallTime = timer() - start_timer; |
| 170 | double simTime = now() - start_now; |
| 171 | |
| 172 | self->totalWallTime += wallTime; |
| 173 | self->totalSimTime += simTime; |
| 174 | TraceEvent(result.code() != error_code_success ? SevError : SevInfo, "UnitTest") |
| 175 | .errorUnsuppressed(result) |
nothing calls this directly
no test coverage detected