2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-04-11 16:54:09 +00:00
|
|
|
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "OverwriteLine.h"
|
2013-04-11 20:11:40 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2009-03-07 03:39:23 +00:00
|
|
|
#include "SkGraphics.h"
|
2013-04-22 16:43:07 +00:00
|
|
|
#include "SkOSFile.h"
|
2013-04-19 13:24:28 +00:00
|
|
|
#include "SkTArray.h"
|
|
|
|
#include "SkTemplates.h"
|
2013-04-22 16:43:07 +00:00
|
|
|
#include "SkThreadPool.h"
|
|
|
|
#include "SkTime.h"
|
2009-02-27 16:24:51 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2012-09-07 18:24:43 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContext.h"
|
|
|
|
#endif
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
using namespace skiatest;
|
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \
|
|
|
|
"Multiple matches may be separated by spaces.\n" \
|
|
|
|
"~ causes a matching test to always be skipped\n" \
|
|
|
|
"^ requires the start of the test to match\n" \
|
|
|
|
"$ requires the end of the test to match\n" \
|
|
|
|
"^ and $ requires an exact match\n" \
|
|
|
|
"If a test does not match any list entry,\n" \
|
|
|
|
"it is skipped unless some list entry starts with ~");
|
|
|
|
DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use.");
|
|
|
|
DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
|
|
|
|
DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
|
2014-01-23 17:21:19 +00:00
|
|
|
DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
|
2014-01-02 16:19:53 +00:00
|
|
|
DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
|
|
|
|
DEFINE_bool2(verbose, v, false, "enable verbose output.");
|
2014-01-28 20:02:45 +00:00
|
|
|
DEFINE_bool(cpu, true, "whether or not to run CPU tests.");
|
|
|
|
DEFINE_bool(gpu, true, "whether or not to run GPU tests.");
|
2014-01-02 16:19:53 +00:00
|
|
|
DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
|
|
|
|
"Run threadsafe tests on a threadpool with this many threads.");
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
// need to explicitly declare this, or we get some weird infinite loop llist
|
|
|
|
template TestRegistry* TestRegistry::gHead;
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
class Iter {
|
|
|
|
public:
|
2014-01-02 16:19:53 +00:00
|
|
|
Iter() { this->reset(); }
|
|
|
|
void reset() { fReg = TestRegistry::Head(); }
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
Test* next(Reporter* r) {
|
2009-02-27 16:24:51 +00:00
|
|
|
if (fReg) {
|
|
|
|
TestRegistry::Factory fact = fReg->factory();
|
|
|
|
fReg = fReg->next();
|
|
|
|
Test* test = fact(NULL);
|
2014-01-02 16:19:53 +00:00
|
|
|
test->setReporter(r);
|
2009-02-27 16:24:51 +00:00
|
|
|
return test;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
private:
|
|
|
|
const TestRegistry* fReg;
|
|
|
|
};
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
class DebugfReporter : public Reporter {
|
2009-04-01 20:26:42 +00:00
|
|
|
public:
|
2014-01-02 16:19:53 +00:00
|
|
|
explicit DebugfReporter(int total) : fDone(0), fTotal(total) {}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
virtual bool allowExtendedTest() const SK_OVERRIDE { return FLAGS_extendedTest; }
|
|
|
|
virtual bool allowThreaded() const SK_OVERRIDE { return !FLAGS_single; }
|
|
|
|
virtual bool verbose() const SK_OVERRIDE { return FLAGS_verbose; }
|
2013-07-08 17:17:02 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
protected:
|
2014-01-02 16:19:53 +00:00
|
|
|
virtual void onReportFailed(const SkString& desc) SK_OVERRIDE {
|
|
|
|
SkDebugf("\nFAILED: %s", desc.c_str());
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2013-10-01 18:43:50 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
virtual void onEnd(Test* test) SK_OVERRIDE {
|
|
|
|
const int done = 1 + sk_atomic_inc(&fDone);
|
2013-04-19 13:24:28 +00:00
|
|
|
|
|
|
|
if (!test->passed()) {
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf("\n---- %s FAILED", test->getName());
|
2013-04-22 16:43:07 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
SkString prefix(kSkOverwriteLine);
|
|
|
|
SkString time;
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
prefix.printf("\n");
|
|
|
|
time.printf("%5dms ", test->elapsedMs());
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf("%s[%3d/%3d] %s%s", prefix.c_str(), done, fTotal, time.c_str(), test->getName());
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2013-04-19 13:24:28 +00:00
|
|
|
|
2012-11-29 16:29:58 +00:00
|
|
|
private:
|
2014-01-02 16:19:53 +00:00
|
|
|
int32_t fDone; // atomic
|
|
|
|
const int fTotal;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
2013-06-06 14:59:56 +00:00
|
|
|
SkString Test::GetTmpDir() {
|
|
|
|
const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0];
|
|
|
|
return SkString(tmpDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString Test::GetResourcePath() {
|
|
|
|
const char* resourcePath = FLAGS_resourcePath.isEmpty() ? NULL : FLAGS_resourcePath[0];
|
|
|
|
return SkString(resourcePath);
|
|
|
|
}
|
|
|
|
|
2013-04-19 13:24:28 +00:00
|
|
|
// Deletes self when run.
|
|
|
|
class SkTestRunnable : public SkRunnable {
|
|
|
|
public:
|
|
|
|
// Takes ownership of test.
|
|
|
|
SkTestRunnable(Test* test, int32_t* failCount) : fTest(test), fFailCount(failCount) {}
|
|
|
|
|
|
|
|
virtual void run() {
|
|
|
|
fTest->run();
|
|
|
|
if(!fTest->passed()) {
|
|
|
|
sk_atomic_inc(fFailCount);
|
|
|
|
}
|
|
|
|
SkDELETE(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkAutoTDelete<Test> fTest;
|
|
|
|
int32_t* fFailCount;
|
|
|
|
};
|
2013-04-11 16:54:09 +00:00
|
|
|
|
2014-01-28 20:02:45 +00:00
|
|
|
static bool should_run(const char* testName, bool isGPUTest) {
|
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, testName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!FLAGS_cpu && !isGPUTest) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!FLAGS_gpu && isGPUTest) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
2013-04-11 16:54:09 +00:00
|
|
|
SkCommandLineFlags::SetUsage("");
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
|
2013-01-15 20:37:04 +00:00
|
|
|
#if SK_ENABLE_INST_COUNT
|
2014-01-23 17:21:19 +00:00
|
|
|
if (FLAGS_leaks) {
|
|
|
|
gPrintInstCount = true;
|
|
|
|
}
|
2012-07-22 22:33:05 +00:00
|
|
|
#endif
|
2013-04-10 15:57:31 +00:00
|
|
|
|
2012-07-22 22:33:05 +00:00
|
|
|
SkGraphics::Init();
|
2011-09-02 15:06:44 +00:00
|
|
|
|
2011-10-26 15:25:18 +00:00
|
|
|
{
|
|
|
|
SkString header("Skia UnitTests:");
|
2013-04-11 18:27:52 +00:00
|
|
|
if (!FLAGS_match.isEmpty()) {
|
2013-05-02 13:14:40 +00:00
|
|
|
header.appendf(" --match");
|
|
|
|
for (int index = 0; index < FLAGS_match.count(); ++index) {
|
|
|
|
header.appendf(" %s", FLAGS_match[index]);
|
|
|
|
}
|
2011-10-26 15:25:18 +00:00
|
|
|
}
|
2013-06-06 14:59:56 +00:00
|
|
|
SkString tmpDir = Test::GetTmpDir();
|
|
|
|
if (!tmpDir.isEmpty()) {
|
|
|
|
header.appendf(" --tmpDir %s", tmpDir.c_str());
|
2013-03-20 13:48:20 +00:00
|
|
|
}
|
2013-06-06 14:59:56 +00:00
|
|
|
SkString resourcePath = Test::GetResourcePath();
|
|
|
|
if (!resourcePath.isEmpty()) {
|
|
|
|
header.appendf(" --resourcePath %s", resourcePath.c_str());
|
2013-02-25 20:24:24 +00:00
|
|
|
}
|
2011-10-26 15:25:18 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
header.append(" SK_DEBUG");
|
|
|
|
#else
|
|
|
|
header.append(" SK_RELEASE");
|
|
|
|
#endif
|
2013-08-29 20:20:39 +00:00
|
|
|
header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf(header.c_str());
|
2011-10-26 15:25:18 +00:00
|
|
|
}
|
|
|
|
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2013-04-22 16:43:07 +00:00
|
|
|
// Count tests first.
|
|
|
|
int total = 0;
|
|
|
|
int toRun = 0;
|
|
|
|
Test* test;
|
2013-07-24 17:24:23 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
Iter iter;
|
|
|
|
while ((test = iter.next(NULL/*reporter not needed*/)) != NULL) {
|
2013-04-22 16:43:07 +00:00
|
|
|
SkAutoTDelete<Test> owned(test);
|
2014-01-28 20:02:45 +00:00
|
|
|
if (should_run(test->getName(), test->isGPUTest())) {
|
2013-04-22 16:43:07 +00:00
|
|
|
toRun++;
|
|
|
|
}
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now run them.
|
|
|
|
iter.reset();
|
2013-04-19 13:24:28 +00:00
|
|
|
int32_t failCount = 0;
|
2011-09-02 15:06:44 +00:00
|
|
|
int skipCount = 0;
|
2013-04-19 13:24:28 +00:00
|
|
|
|
2013-10-10 18:49:04 +00:00
|
|
|
SkThreadPool threadpool(FLAGS_threads);
|
2013-04-19 13:24:28 +00:00
|
|
|
SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnable
|
2014-01-02 16:19:53 +00:00
|
|
|
|
|
|
|
DebugfReporter reporter(toRun);
|
2013-04-22 16:43:07 +00:00
|
|
|
for (int i = 0; i < total; i++) {
|
2014-01-02 16:19:53 +00:00
|
|
|
SkAutoTDelete<Test> test(iter.next(&reporter));
|
2014-01-28 20:02:45 +00:00
|
|
|
if (!should_run(test->getName(), test->isGPUTest())) {
|
2011-09-02 15:06:44 +00:00
|
|
|
++skipCount;
|
2014-01-28 20:02:45 +00:00
|
|
|
} else if (!test->isGPUTest()) {
|
2013-04-19 13:24:28 +00:00
|
|
|
unsafeTests.push_back() = test.detach();
|
2011-09-02 15:06:44 +00:00
|
|
|
} else {
|
2013-10-10 18:49:04 +00:00
|
|
|
threadpool.add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCount)));
|
2011-09-02 15:06:44 +00:00
|
|
|
}
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
2013-04-19 13:24:28 +00:00
|
|
|
// Run the tests that aren't threadsafe.
|
|
|
|
for (int i = 0; i < unsafeTests.count(); i++) {
|
|
|
|
SkNEW_ARGS(SkTestRunnable, (unsafeTests[i], &failCount))->run();
|
|
|
|
}
|
|
|
|
|
2013-10-10 18:49:04 +00:00
|
|
|
// Block until threaded tests finish.
|
|
|
|
threadpool.wait();
|
2013-04-19 13:24:28 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
SkDebugf("\nFinished %d tests, %d failures, %d skipped. (%d internal tests)",
|
|
|
|
toRun, failCount, skipCount, reporter.countTests());
|
2013-04-10 15:57:31 +00:00
|
|
|
}
|
2012-07-22 22:33:05 +00:00
|
|
|
SkGraphics::Term();
|
2013-02-04 16:13:32 +00:00
|
|
|
GpuTest::DestroyContexts();
|
2012-07-22 22:33:05 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf("\n");
|
2011-09-02 15:06:44 +00:00
|
|
|
return (failCount == 0) ? 0 : 1;
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2012-10-02 18:33:14 +00:00
|
|
|
|
2012-11-01 17:43:44 +00:00
|
|
|
#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
|
2012-10-02 18:33:14 +00:00
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|