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.
|
|
|
|
*/
|
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 {
|
|
|
|
return fAllowExtendedTest;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** 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
|
|
|
bool allowExtendedTest = false;
|
|
|
|
bool verboseOutput = false;
|
|
|
|
|
2012-07-22 22:33:05 +00:00
|
|
|
SkGraphics::Init();
|
2011-09-02 15:06:44 +00:00
|
|
|
|
|
|
|
const char* matchStr = NULL;
|
|
|
|
|
|
|
|
char* const* stop = argv + argc;
|
|
|
|
for (++argv; argv < stop; ++argv) {
|
2013-04-10 15:57:31 +00:00
|
|
|
if (0 == strcmp(*argv, "--match") || 0 == strcmp(*argv, "-m")) {
|
2011-09-02 15:06:44 +00:00
|
|
|
++argv;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
matchStr = *argv;
|
2013-02-25 20:24:24 +00:00
|
|
|
} else {
|
|
|
|
SkDebugf("no following argument to --match\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-04-10 15:57:31 +00:00
|
|
|
} else if (0 == strcmp(*argv, "--tmpDir") || 0 == strcmp(*argv, "-t")) {
|
2013-02-25 20:24:24 +00:00
|
|
|
++argv;
|
|
|
|
if (argv < stop && **argv) {
|
2013-03-20 13:48:20 +00:00
|
|
|
make_canonical_dir_path(*argv, &gTmpDir);
|
2013-02-25 20:24:24 +00:00
|
|
|
} else {
|
|
|
|
SkDebugf("no following argument to --tmpDir\n");
|
|
|
|
return -1;
|
2011-09-02 15:06:44 +00:00
|
|
|
}
|
2013-04-10 15:57:31 +00:00
|
|
|
} else if (0 == strcmp(*argv, "--resourcePath") || 0 == strcmp(*argv, "-i")) {
|
2013-03-20 13:48:20 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
make_canonical_dir_path(*argv, &gResourcePath);
|
|
|
|
}
|
2013-04-10 15:57:31 +00:00
|
|
|
} else if (0 == strcmp(*argv, "--extendedTest") || 0 == strcmp(*argv, "-x")) {
|
|
|
|
allowExtendedTest = true;
|
|
|
|
} else if (0 == strcmp(*argv, "--verbose") || 0 == strcmp(*argv, "-v")) {
|
|
|
|
verboseOutput = true;
|
|
|
|
} else {
|
|
|
|
if (0 != strcmp(*argv, "--help") && 0 != strcmp(*argv, "-h")
|
|
|
|
&& 0 != strcmp(*argv, "-?")) {
|
|
|
|
SkDebugf("Unknown option %s. ", *argv);
|
|
|
|
}
|
|
|
|
SkDebugf("Skia UnitTests options are:\n");
|
|
|
|
SkDebugf(" -m --match [test-name-substring]\n");
|
|
|
|
SkDebugf(" -t --tmpDir [dir]\n");
|
|
|
|
SkDebugf(" -i --resourcePath [dir]\n");
|
|
|
|
SkDebugf(" -x --extendedTest\n");
|
|
|
|
SkDebugf(" -v --verbose\n");
|
|
|
|
return 1;
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-07 03:39:23 +00:00
|
|
|
|
2011-10-26 15:25:18 +00:00
|
|
|
{
|
|
|
|
SkString header("Skia UnitTests:");
|
|
|
|
if (matchStr) {
|
|
|
|
header.appendf(" --match %s", matchStr);
|
|
|
|
}
|
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-10 15:57:31 +00:00
|
|
|
DebugfReporter reporter(allowExtendedTest);
|
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);
|
2011-09-02 15:06:44 +00:00
|
|
|
if (NULL != matchStr && !strstr(test->getName(), matchStr)) {
|
|
|
|
++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();
|
|
|
|
if (verboseOutput && testCount > 0) {
|
|
|
|
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
|