2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* UnitTests.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/UnitTest.h"
|
2019-02-18 10:46:59 +08:00
|
|
|
#include "flow/actorcompiler.h" // has to be last include
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
void forceLinkIndexedSetTests();
|
|
|
|
void forceLinkDequeTests();
|
|
|
|
void forceLinkFlowTests();
|
|
|
|
|
|
|
|
struct UnitTestWorkload : TestWorkload {
|
|
|
|
bool enabled;
|
|
|
|
std::string testPattern;
|
|
|
|
int testRunLimit;
|
|
|
|
|
|
|
|
PerfIntCounter testsAvailable, testsExecuted, testsFailed;
|
|
|
|
PerfDoubleCounter totalWallTime, totalSimTime;
|
|
|
|
|
|
|
|
UnitTestWorkload(WorkloadContext const& wcx)
|
|
|
|
: TestWorkload(wcx), testsAvailable("Test Cases Available"), testsExecuted("Test Cases Executed"), testsFailed("Test Cases Failed"), totalWallTime("Total wall clock time (s)"), totalSimTime("Total flow time (s)")
|
|
|
|
{
|
|
|
|
enabled = !clientId; // only do this on the "first" client
|
|
|
|
testPattern = getOption(options, LiteralStringRef("testsMatching"), Value()).toString();
|
|
|
|
testRunLimit = getOption(options, LiteralStringRef("maxTestCases"), -1);
|
|
|
|
forceLinkIndexedSetTests();
|
|
|
|
forceLinkDequeTests();
|
|
|
|
forceLinkFlowTests();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string description() { return "UnitTests"; }
|
|
|
|
virtual Future<Void> setup(Database const& cx) { return Void(); }
|
|
|
|
virtual Future<Void> start(Database const& cx) {
|
|
|
|
if (enabled)
|
|
|
|
return runUnitTests(this);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
virtual Future<bool> check(Database const& cx) { return testsFailed.getValue() == 0; }
|
|
|
|
virtual void getMetrics(vector<PerfMetric>& m) {
|
|
|
|
m.push_back(testsAvailable.getMetric());
|
|
|
|
m.push_back(testsExecuted.getMetric());
|
|
|
|
m.push_back(testsFailed.getMetric());
|
|
|
|
m.push_back(totalWallTime.getMetric());
|
|
|
|
m.push_back(totalSimTime.getMetric());
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> runUnitTests(UnitTestWorkload* self) {
|
|
|
|
state std::vector<UnitTest*> tests;
|
|
|
|
state int allTestCount = 0;
|
|
|
|
|
|
|
|
for (auto t = g_unittests.tests; t != NULL; t = t->next) {
|
2018-10-06 13:09:58 +08:00
|
|
|
if (StringRef(t->name).startsWith(self->testPattern)) {
|
2017-05-26 04:48:44 +08:00
|
|
|
++self->testsAvailable;
|
|
|
|
tests.push_back(t);
|
|
|
|
}
|
|
|
|
}
|
2018-03-15 09:07:05 +08:00
|
|
|
fprintf(stdout, "Found %zu tests\n", tests.size());
|
2017-05-26 04:48:44 +08:00
|
|
|
g_random->randomShuffle(tests);
|
|
|
|
if (self->testRunLimit > 0 && tests.size() > self->testRunLimit)
|
|
|
|
tests.resize(self->testRunLimit);
|
|
|
|
|
|
|
|
state std::vector<UnitTest*>::iterator t;
|
|
|
|
for (t = tests.begin(); t != tests.end(); ++t) {
|
2019-02-18 10:46:59 +08:00
|
|
|
state UnitTest* test = *t;
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("Testing %s\n", test->name);
|
|
|
|
|
|
|
|
state Error result = success();
|
|
|
|
state double start_now = now();
|
|
|
|
state double start_timer = timer();
|
|
|
|
|
|
|
|
try {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(test->func());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
catch (Error& e) {
|
|
|
|
++self->testsFailed;
|
|
|
|
result = e;
|
|
|
|
}
|
|
|
|
++self->testsExecuted;
|
|
|
|
double wallTime = timer() - start_timer;
|
|
|
|
double simTime = now() - start_now;
|
|
|
|
|
|
|
|
self->totalWallTime += wallTime;
|
|
|
|
self->totalSimTime += simTime;
|
|
|
|
TraceEvent(result.code() != error_code_success ? SevError : SevInfo, "UnitTest")
|
2018-08-02 05:30:57 +08:00
|
|
|
.error(result, true)
|
2017-05-26 04:48:44 +08:00
|
|
|
.detail("Name", test->name)
|
|
|
|
.detail("File", test->file).detail("Line", test->line)
|
|
|
|
.detail("WallTime", wallTime)
|
|
|
|
.detail("FlowTime", simTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WorkloadFactory<UnitTestWorkload> UnitTestWorkloadFactory("UnitTests");
|
|
|
|
|
2018-10-06 13:09:58 +08:00
|
|
|
TEST_CASE("/fdbserver/UnitTestWorkload/long delay") {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(60));
|
2017-05-26 04:48:44 +08:00
|
|
|
return Void();
|
2018-03-14 05:54:48 +08:00
|
|
|
}
|