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 17:27:58 +00:00
|
|
|
#include "../tools/flags/SkCommandLineFlags.h"
|
2009-03-07 03:39:23 +00:00
|
|
|
#include "SkGraphics.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-10 15:57:31 +00:00
|
|
|
DebugfReporter(bool allowExtendedTest)
|
|
|
|
: fIndex(0)
|
|
|
|
, fTotal(0)
|
|
|
|
, fAllowExtendedTest(allowExtendedTest) {
|
|
|
|
}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
void setIndexOfTotal(int index, int total) {
|
|
|
|
fIndex = index;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
protected:
|
|
|
|
virtual void onStart(Test* test) {
|
2012-11-29 16:29:58 +00:00
|
|
|
SkDebugf("[%d/%d] %s...\n", fIndex+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-02-27 19:17:41 +00:00
|
|
|
virtual void onEnd(Test*) {
|
2012-11-29 16:29:58 +00:00
|
|
|
if (!this->getCurrSuccess()) {
|
|
|
|
SkDebugf("---- FAILED\n");
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-29 16:29:58 +00:00
|
|
|
private:
|
2009-04-01 20:26:42 +00:00
|
|
|
int fIndex, fTotal;
|
2013-04-10 15:57:31 +00:00
|
|
|
bool fAllowExtendedTest;
|
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.");
|
|
|
|
DEFINE_bool2(verbose, v, false, "enable verbose output.");
|
|
|
|
|
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-11 16:54:09 +00:00
|
|
|
DebugfReporter reporter(FLAGS_extendedTest);
|
2009-02-27 16:24:51 +00:00
|
|
|
Iter iter(&reporter);
|
|
|
|
Test* test;
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
const int count = Iter::Count();
|
|
|
|
int index = 0;
|
2011-09-02 15:06:44 +00:00
|
|
|
int failCount = 0;
|
|
|
|
int skipCount = 0;
|
2009-02-27 16:24:51 +00:00
|
|
|
while ((test = iter.next()) != NULL) {
|
2009-04-01 20:26:42 +00:00
|
|
|
reporter.setIndexOfTotal(index, count);
|
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;
|
|
|
|
} else {
|
|
|
|
if (!test->run()) {
|
|
|
|
++failCount;
|
|
|
|
}
|
|
|
|
}
|
2009-02-27 16:24:51 +00:00
|
|
|
SkDELETE(test);
|
2009-04-01 20:26:42 +00:00
|
|
|
index += 1;
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
2012-11-29 16:29:58 +00:00
|
|
|
SkDebugf("Finished %d tests, %d failures, %d skipped.\n",
|
|
|
|
count, failCount, skipCount);
|
2013-04-10 15:57:31 +00:00
|
|
|
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
|