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
|
|
|
|
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 "SkRunnable.h"
|
|
|
|
#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;
|
|
|
|
|
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:
|
|
|
|
Iter(Reporter* r) : fReporter(r) {
|
|
|
|
r->ref();
|
2013-04-22 16:43:07 +00:00
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
2009-02-27 16:24:51 +00:00
|
|
|
fReg = TestRegistry::Head();
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
~Iter() {
|
|
|
|
fReporter->unref();
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
Test* next() {
|
|
|
|
if (fReg) {
|
|
|
|
TestRegistry::Factory fact = fReg->factory();
|
|
|
|
fReg = fReg->next();
|
|
|
|
Test* test = fact(NULL);
|
|
|
|
test->setReporter(fReporter);
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
private:
|
|
|
|
Reporter* fReporter;
|
|
|
|
const TestRegistry* fReg;
|
|
|
|
};
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
class DebugfReporter : public Reporter {
|
2009-04-01 20:26:42 +00:00
|
|
|
public:
|
2013-07-08 17:17:02 +00:00
|
|
|
DebugfReporter(bool allowExtendedTest, bool allowThreaded, bool verbose)
|
2013-04-19 13:24:28 +00:00
|
|
|
: fNextIndex(0)
|
2013-04-22 16:43:07 +00:00
|
|
|
, fPending(0)
|
2013-04-10 15:57:31 +00:00
|
|
|
, fTotal(0)
|
2013-04-18 18:47:37 +00:00
|
|
|
, fAllowExtendedTest(allowExtendedTest)
|
2013-07-08 17:17:02 +00:00
|
|
|
, fAllowThreaded(allowThreaded)
|
|
|
|
, fVerbose(verbose) {
|
2013-04-10 15:57:31 +00:00
|
|
|
}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
2013-04-19 13:24:28 +00:00
|
|
|
void setTotal(int total) {
|
2009-04-01 20:26:42 +00:00
|
|
|
fTotal = total;
|
|
|
|
}
|
2013-04-10 15:57:31 +00:00
|
|
|
|
2013-04-22 17:35:55 +00:00
|
|
|
virtual bool allowExtendedTest() const SK_OVERRIDE {
|
2013-04-11 07:01:45 +00:00
|
|
|
return fAllowExtendedTest;
|
2013-04-10 15:57:31 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 17:35:55 +00:00
|
|
|
virtual bool allowThreaded() const SK_OVERRIDE {
|
2013-04-18 18:47:37 +00:00
|
|
|
return fAllowThreaded;
|
|
|
|
}
|
|
|
|
|
2013-07-08 17:17:02 +00:00
|
|
|
virtual bool verbose() const SK_OVERRIDE {
|
|
|
|
return fVerbose;
|
|
|
|
}
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
protected:
|
|
|
|
virtual void onStart(Test* test) {
|
2013-04-19 13:24:28 +00:00
|
|
|
const int index = sk_atomic_inc(&fNextIndex);
|
2013-04-22 16:43:07 +00:00
|
|
|
sk_atomic_inc(&fPending);
|
|
|
|
SkDebugf("[%3d/%3d] (%d) %s\n", index+1, fTotal, fPending, test->getName());
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2013-06-18 20:50:34 +00:00
|
|
|
virtual void onReportFailed(const SkString& desc) {
|
|
|
|
SkDebugf("\tFAILED: %s\n", desc.c_str());
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2013-04-19 13:24:28 +00:00
|
|
|
|
|
|
|
virtual void onEnd(Test* test) {
|
|
|
|
if (!test->passed()) {
|
2013-04-22 16:43:07 +00:00
|
|
|
SkDebugf("---- %s FAILED\n", test->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_atomic_dec(&fPending);
|
|
|
|
if (fNextIndex == fTotal) {
|
|
|
|
// Just waiting on straggler tests. Shame them by printing their name and runtime.
|
|
|
|
SkDebugf(" (%d) %5.1fs %s\n",
|
|
|
|
fPending, test->elapsedMs() / 1e3, 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:
|
2013-04-19 13:24:28 +00:00
|
|
|
int32_t fNextIndex;
|
2013-04-22 16:43:07 +00:00
|
|
|
int32_t fPending;
|
2013-04-19 13:24:28 +00:00
|
|
|
int fTotal;
|
2013-04-10 15:57:31 +00:00
|
|
|
bool fAllowExtendedTest;
|
2013-04-18 18:47:37 +00:00
|
|
|
bool fAllowThreaded;
|
2013-07-08 17:17:02 +00:00
|
|
|
bool fVerbose;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
2013-05-02 13:14:40 +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 ~");
|
2013-04-11 16:54:09 +00:00
|
|
|
DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use.");
|
|
|
|
DEFINE_string2(resourcePath, i, NULL, "directory for test resources.");
|
|
|
|
DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
|
2013-07-16 16:11:16 +00:00
|
|
|
DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
|
2013-04-11 16:54:09 +00:00
|
|
|
DEFINE_bool2(verbose, v, false, "enable verbose output.");
|
2013-04-22 15:23:14 +00:00
|
|
|
DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
|
|
|
|
"Run threadsafe tests on a threadpool with this many threads.");
|
2013-04-19 13:24:28 +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
|
|
|
|
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
|
2012-07-22 22:33:05 +00:00
|
|
|
gPrintInstCount = true;
|
|
|
|
#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
|
|
|
|
#ifdef SK_SCALAR_IS_FIXED
|
|
|
|
header.append(" SK_SCALAR_IS_FIXED");
|
|
|
|
#else
|
|
|
|
header.append(" SK_SCALAR_IS_FLOAT");
|
|
|
|
#endif
|
2013-08-29 20:20:39 +00:00
|
|
|
header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
|
2012-11-29 16:29:58 +00:00
|
|
|
SkDebugf("%s\n", header.c_str());
|
2011-10-26 15:25:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 16:11:16 +00:00
|
|
|
DebugfReporter reporter(FLAGS_extendedTest, !FLAGS_single, FLAGS_verbose);
|
2009-02-27 16:24:51 +00:00
|
|
|
Iter iter(&reporter);
|
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
|
|
|
|
2013-04-22 16:43:07 +00:00
|
|
|
while ((test = iter.next()) != NULL) {
|
|
|
|
SkAutoTDelete<Test> owned(test);
|
2013-07-24 17:24:23 +00:00
|
|
|
|
2013-08-30 15:52:46 +00:00
|
|
|
if(!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
|
2013-04-22 16:43:07 +00:00
|
|
|
toRun++;
|
|
|
|
}
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
reporter.setTotal(toRun);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
SkAutoTDelete<SkThreadPool> threadpool(SkNEW_ARGS(SkThreadPool, (FLAGS_threads)));
|
|
|
|
SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnable
|
2013-04-22 16:43:07 +00:00
|
|
|
for (int i = 0; i < total; i++) {
|
2013-04-19 13:24:28 +00:00
|
|
|
SkAutoTDelete<Test> test(iter.next());
|
2013-08-30 15:52:46 +00:00
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
|
2011-09-02 15:06:44 +00:00
|
|
|
++skipCount;
|
2013-04-19 13:24:28 +00:00
|
|
|
} else if (!test->isThreadsafe()) {
|
|
|
|
unsafeTests.push_back() = test.detach();
|
2011-09-02 15:06:44 +00:00
|
|
|
} else {
|
2013-04-19 13:24:28 +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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blocks until threaded tests finish.
|
|
|
|
threadpool.free();
|
|
|
|
|
2012-11-29 16:29:58 +00:00
|
|
|
SkDebugf("Finished %d tests, %d failures, %d skipped.\n",
|
2013-04-22 16:43:07 +00:00
|
|
|
toRun, failCount, skipCount);
|
2013-04-19 13:24:28 +00:00
|
|
|
const int testCount = reporter.countTests();
|
2013-04-11 16:54:09 +00:00
|
|
|
if (FLAGS_verbose && testCount > 0) {
|
2013-04-10 15:57:31 +00:00
|
|
|
SkDebugf("Ran %d Internal tests.\n", testCount);
|
|
|
|
}
|
2012-09-07 18:24:43 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
|
|
|
GrContext *gr = GpuTest::GetContext();
|
|
|
|
|
|
|
|
gr->printCacheStats();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
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
|