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-19 13:24:28 +00:00
|
|
|
#include "SkRunnable.h"
|
|
|
|
#include "SkThreadPool.h"
|
|
|
|
#include "SkTArray.h"
|
|
|
|
#include "SkTemplates.h"
|
2009-02-27 16:24:51 +00:00
|
|
|
#include "Test.h"
|
2013-02-25 20:24:24 +00:00
|
|
|
#include "SkOSFile.h"
|
2009-02-27 16:24:51 +00:00
|
|
|
|
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();
|
|
|
|
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-04-01 20:26:42 +00:00
|
|
|
static int Count() {
|
|
|
|
const TestRegistry* reg = TestRegistry::Head();
|
|
|
|
int count = 0;
|
|
|
|
while (reg) {
|
|
|
|
count += 1;
|
|
|
|
reg = reg->next();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
private:
|
|
|
|
Reporter* fReporter;
|
|
|
|
const TestRegistry* fReg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* result2string(Reporter::Result result) {
|
|
|
|
return result == Reporter::kPassed ? "passed" : "FAILED";
|
|
|
|
}
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
class DebugfReporter : public Reporter {
|
2009-04-01 20:26:42 +00:00
|
|
|
public:
|
2013-04-18 18:47:37 +00:00
|
|
|
DebugfReporter(bool allowExtendedTest, bool allowThreaded)
|
2013-04-19 13:24:28 +00:00
|
|
|
: fNextIndex(0)
|
2013-04-10 15:57:31 +00:00
|
|
|
, fTotal(0)
|
2013-04-18 18:47:37 +00:00
|
|
|
, fAllowExtendedTest(allowExtendedTest)
|
|
|
|
, fAllowThreaded(allowThreaded) {
|
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
|
|
|
|
|
|
|
virtual bool allowExtendedTest() const {
|
2013-04-11 07:01:45 +00:00
|
|
|
return fAllowExtendedTest;
|
2013-04-10 15:57:31 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:37 +00:00
|
|
|
virtual bool allowThreaded() const {
|
|
|
|
return fAllowThreaded;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
SkDebugf("[%d/%d] %s...\n", index+1, fTotal, test->getName());
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
virtual void onReport(const char desc[], Reporter::Result result) {
|
2012-11-29 16:29:58 +00:00
|
|
|
SkDebugf("\t%s: %s\n", result2string(result), desc);
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2013-04-19 13:24:28 +00:00
|
|
|
|
|
|
|
virtual void onEnd(Test* test) {
|
|
|
|
if (!test->passed()) {
|
|
|
|
SkDebugf("---- FAILED\n");
|
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;
|
|
|
|
int fTotal;
|
2013-04-10 15:57:31 +00:00
|
|
|
bool fAllowExtendedTest;
|
2013-04-18 18:47:37 +00:00
|
|
|
bool fAllowThreaded;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
2013-02-25 20:24:24 +00:00
|
|
|
static const char* make_canonical_dir_path(const char* path, SkString* storage) {
|
|
|
|
if (path) {
|
|
|
|
// clean it up so it always has a trailing searator
|
|
|
|
size_t len = strlen(path);
|
|
|
|
if (0 == len) {
|
|
|
|
path = NULL;
|
|
|
|
} else if (SkPATH_SEPARATOR != path[len - 1]) {
|
|
|
|
// resize to len + 1, to make room for searator
|
|
|
|
storage->set(path, len + 1);
|
|
|
|
storage->writable_str()[len] = SkPATH_SEPARATOR;
|
|
|
|
path = storage->c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2013-03-20 13:48:20 +00:00
|
|
|
static SkString gTmpDir;
|
2013-02-25 20:24:24 +00:00
|
|
|
|
2013-03-20 13:48:20 +00:00
|
|
|
const SkString& Test::GetTmpDir() {
|
2013-02-25 20:24:24 +00:00
|
|
|
return gTmpDir;
|
|
|
|
}
|
|
|
|
|
2013-03-20 13:48:20 +00:00
|
|
|
static SkString gResourcePath;
|
|
|
|
|
|
|
|
const SkString& Test::GetResourcePath() {
|
|
|
|
return gResourcePath;
|
|
|
|
}
|
|
|
|
|
2013-04-11 18:27:52 +00:00
|
|
|
DEFINE_string2(match, m, NULL, "substring of test name to run.");
|
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-04-19 13:24:28 +00:00
|
|
|
DEFINE_bool2(threaded, z, false, "allow tests to use multiple threads 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
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
if (!FLAGS_tmpDir.isEmpty()) {
|
|
|
|
make_canonical_dir_path(FLAGS_tmpDir[0], &gTmpDir);
|
|
|
|
}
|
|
|
|
if (!FLAGS_resourcePath.isEmpty()) {
|
|
|
|
make_canonical_dir_path(FLAGS_resourcePath[0], &gResourcePath);
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
header.appendf(" --match %s", FLAGS_match[0]);
|
2011-10-26 15:25:18 +00:00
|
|
|
}
|
2013-03-20 13:48:20 +00:00
|
|
|
if (!gTmpDir.isEmpty()) {
|
|
|
|
header.appendf(" --tmpDir %s", gTmpDir.c_str());
|
|
|
|
}
|
|
|
|
if (!gResourcePath.isEmpty()) {
|
|
|
|
header.appendf(" --resourcePath %s", gResourcePath.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
|
2012-11-29 16:29:58 +00:00
|
|
|
SkDebugf("%s\n", header.c_str());
|
2011-10-26 15:25:18 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:37 +00:00
|
|
|
DebugfReporter reporter(FLAGS_extendedTest, FLAGS_threaded);
|
2009-02-27 16:24:51 +00:00
|
|
|
Iter iter(&reporter);
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
const int count = Iter::Count();
|
2013-04-19 13:24:28 +00:00
|
|
|
reporter.setTotal(count);
|
|
|
|
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
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
SkAutoTDelete<Test> test(iter.next());
|
2013-04-11 18:27:52 +00:00
|
|
|
if (!FLAGS_match.isEmpty() && !strstr(test->getName(), FLAGS_match[0])) {
|
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",
|
|
|
|
count, 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
|