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"
|
|
|
|
|
|
|
|
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:
|
2009-04-09 04:06:54 +00:00
|
|
|
DebugfReporter(bool androidMode) : fAndroidMode(androidMode) {}
|
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
void setIndexOfTotal(int index, int total) {
|
|
|
|
fIndex = index;
|
|
|
|
fTotal = total;
|
|
|
|
}
|
2009-02-27 16:24:51 +00:00
|
|
|
protected:
|
|
|
|
virtual void onStart(Test* test) {
|
2009-04-09 04:06:54 +00:00
|
|
|
this->dumpState(test, kStarting_State);
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
virtual void onReport(const char desc[], Reporter::Result result) {
|
2009-04-09 04:06:54 +00:00
|
|
|
if (!fAndroidMode) {
|
|
|
|
SkDebugf("\t%s: %s\n", result2string(result), desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual void onEnd(Test* test) {
|
|
|
|
this->dumpState(test, this->getCurrSuccess() ?
|
|
|
|
kSucceeded_State : kFailed_State);
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2009-04-01 20:26:42 +00:00
|
|
|
private:
|
2009-04-09 04:06:54 +00:00
|
|
|
enum State {
|
|
|
|
kStarting_State = 1,
|
|
|
|
kSucceeded_State = 0,
|
|
|
|
kFailed_State = -2
|
|
|
|
};
|
|
|
|
|
|
|
|
void dumpState(Test* test, State state) {
|
|
|
|
if (fAndroidMode) {
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: test=%s\n", test->getName());
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: class=com.skia\n");
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: current=%d\n", fIndex+1);
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS: numtests=%d\n", fTotal);
|
|
|
|
SkDebugf("INSTRUMENTATION_STATUS_CODE: %d\n", state);
|
|
|
|
} else {
|
|
|
|
if (kStarting_State == state) {
|
|
|
|
SkDebugf("[%d/%d] %s...\n", fIndex+1, fTotal, test->getName());
|
|
|
|
} else if (kFailed_State == state) {
|
|
|
|
SkDebugf("---- FAILED\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 20:26:42 +00:00
|
|
|
int fIndex, fTotal;
|
2009-04-09 04:06:54 +00:00
|
|
|
bool fAndroidMode;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main (int argc, char * const argv[]) {
|
2009-03-07 03:39:23 +00:00
|
|
|
SkAutoGraphics ag;
|
2011-09-02 15:06:44 +00:00
|
|
|
|
2009-04-09 04:06:54 +00:00
|
|
|
bool androidMode = false;
|
2011-09-02 15:06:44 +00:00
|
|
|
const char* matchStr = NULL;
|
|
|
|
|
|
|
|
char* const* stop = argv + argc;
|
|
|
|
for (++argv; argv < stop; ++argv) {
|
|
|
|
if (strcmp(*argv, "-android") == 0) {
|
2009-04-09 04:06:54 +00:00
|
|
|
androidMode = true;
|
2011-09-02 15:06:44 +00:00
|
|
|
|
|
|
|
} else if (strcmp(*argv, "--match") == 0) {
|
|
|
|
++argv;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
matchStr = *argv;
|
|
|
|
}
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-07 03:39:23 +00:00
|
|
|
|
2009-04-09 04:06:54 +00:00
|
|
|
DebugfReporter reporter(androidMode);
|
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
|
|
|
|
|
|
|
if (!androidMode) {
|
2011-09-02 15:06:44 +00:00
|
|
|
SkDebugf("Finished %d tests, %d failures, %d skipped.\n",
|
|
|
|
count, failCount, skipCount);
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2011-09-02 15:06:44 +00:00
|
|
|
return (failCount == 0) ? 0 : 1;
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|