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
|
|
|
|
2014-06-18 18:44:15 +00:00
|
|
|
#include "CrashHandler.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "OverwriteLine.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "Resources.h"
|
2014-07-22 17:15:34 +00:00
|
|
|
#include "SkCommonFlags.h"
|
2009-03-07 03:39:23 +00:00
|
|
|
#include "SkGraphics.h"
|
2013-04-22 16:43:07 +00:00
|
|
|
#include "SkOSFile.h"
|
2014-10-29 19:36:45 +00:00
|
|
|
#include "SkRunnable.h"
|
2013-04-19 13:24:28 +00:00
|
|
|
#include "SkTArray.h"
|
SkThreadPool ~~> SkTaskGroup
SkTaskGroup is like SkThreadPool except the threads stay in
one global pool. Each SkTaskGroup itself is tiny (4 bytes)
and its wait() method applies only to tasks add()ed to that
instance, not the whole thread pool.
This means we don't need to bring up new thread pools when
tests themselves want to use multithreading (e.g. pathops,
quilt). We just create a new SkTaskGroup and wait for that
to complete. This should be more efficient, and allow us
to expand where we use threads to really latency sensitive
places. E.g. we can probably now use these in nanobench
for CPU .skp rendering.
Now that all threads are sharing the same pool, I think we
can remove most of the custom mechanism pathops tests use
to control threading. They'll just ride on the global pool
with all other tests now.
This (temporarily?) removes the GPU multithreading feature
from DM, which we don't use.
On my desktop, DM runs a little faster (57s -> 55s) in
Debug, and a lot faster in Release (36s -> 24s). The bots
show speedups of similar proportions, cutting more than a
minute off the N4/Release and Win7/Debug runtimes.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/9c7207b5dc71dc5a96a2eb107d401133333d5b6f
R=caryclark@google.com, bsalomon@google.com, bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531653002
2014-09-03 22:34:37 +00:00
|
|
|
#include "SkTaskGroup.h"
|
2013-04-19 13:24:28 +00:00
|
|
|
#include "SkTemplates.h"
|
2013-04-22 16:43:07 +00:00
|
|
|
#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"
|
2014-02-26 16:31:22 +00:00
|
|
|
#include "GrContextFactory.h"
|
2012-09-07 18:24:43 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
using namespace skiatest;
|
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
|
|
|
|
|
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:
|
2014-01-02 16:19:53 +00:00
|
|
|
Iter() { this->reset(); }
|
|
|
|
void reset() { fReg = TestRegistry::Head(); }
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
Test* next(Reporter* r) {
|
2009-02-27 16:24:51 +00:00
|
|
|
if (fReg) {
|
|
|
|
TestRegistry::Factory fact = fReg->factory();
|
|
|
|
fReg = fReg->next();
|
|
|
|
Test* test = fact(NULL);
|
2014-01-02 16:19:53 +00:00
|
|
|
test->setReporter(r);
|
2009-02-27 16:24:51 +00:00
|
|
|
return test;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
private:
|
|
|
|
const TestRegistry* fReg;
|
|
|
|
};
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
class DebugfReporter : public Reporter {
|
2009-04-01 20:26:42 +00:00
|
|
|
public:
|
2014-01-02 16:19:53 +00:00
|
|
|
explicit DebugfReporter(int total) : fDone(0), fTotal(total) {}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
virtual bool allowExtendedTest() const SK_OVERRIDE { return FLAGS_extendedTest; }
|
2014-01-28 21:15:42 +00:00
|
|
|
virtual bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; }
|
2013-07-08 17:17:02 +00:00
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
protected:
|
When running DM, write test failures to json.
Add skiatest::Failure to keep track of data about a test failure.
Reporter::reportFailed and ::onReportFailed now take Failure as a
parameter. This allows the implementation to treat the failure as it
wishes. Provide a helper to format the failure the same as prior to
the change.
Update the macros for calling reportFailed (REPORTER_ASSERT etc) to
create a Failure object.
Convert a direct call to reportFailed to the macro ERRORF.
Write Failures to Json.
Sample output when running dm on the dummy test crrev.com/705723004:
{
"test_results" : {
"failures" : [
{
"condition" : "0 > 3",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 10,
"message" : ""
},
{
"condition" : "false",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 4,
"message" : ""
},
{
"condition" : "1 == 3",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 5,
"message" : "I can too count!"
},
{
"condition" : "",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 6,
"message" : "seven is 7"
},
{
"condition" : "1 == 3",
"file_name" : "../../tests/DummyTest.cpp",
"line_no" : 14,
"message" : "I can too count!"
}
]
}
}
Report all of the failures from one test.
Previously, if one test had multiple failures, only one was reportered.
e.g:
Failures:
test Dummy: ../../tests/DummyTest.cpp:6 seven is 7
test Dummy2: ../../tests/DummyTest.cpp:10 0 > 3
test Dummy3: ../../tests/DummyTest.cpp:14 I can too count!: 1 == 3
3 failures.
Now, we get all the messages:
Failures:
test Dummy: ../../tests/DummyTest.cpp:4 false
../../tests/DummyTest.cpp:5 I can too count!: 1 == 3
../../tests/DummyTest.cpp:6 seven is 7
test Dummy2: ../../tests/DummyTest.cpp:10 0 > 3
test Dummy3: ../../tests/DummyTest.cpp:14 I can too count!: 1 == 3
3 failures.
(Note that we still state "3 failures" because 3 DM::Tasks failed.)
BUG=skia:3082
BUG=skia:2454
Review URL: https://codereview.chromium.org/694703005
2014-11-07 14:07:32 +00:00
|
|
|
virtual void onReportFailed(const skiatest::Failure& failure) SK_OVERRIDE {
|
|
|
|
SkString desc;
|
|
|
|
failure.getFailureString(&desc);
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf("\nFAILED: %s", desc.c_str());
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2013-10-01 18:43:50 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
virtual void onEnd(Test* test) SK_OVERRIDE {
|
|
|
|
const int done = 1 + sk_atomic_inc(&fDone);
|
2013-04-19 13:24:28 +00:00
|
|
|
|
|
|
|
if (!test->passed()) {
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf("\n---- %s FAILED", test->getName());
|
2013-04-22 16:43:07 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
SkString prefix(kSkOverwriteLine);
|
|
|
|
SkString time;
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
prefix.printf("\n");
|
|
|
|
time.printf("%5dms ", test->elapsedMs());
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf("%s[%3d/%3d] %s%s", prefix.c_str(), done, fTotal, time.c_str(), 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:
|
2014-01-02 16:19:53 +00:00
|
|
|
int32_t fDone; // atomic
|
|
|
|
const int fTotal;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2014-01-30 15:30:50 +00:00
|
|
|
static bool should_run(const char* testName, bool isGPUTest) {
|
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, testName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!FLAGS_cpu && !isGPUTest) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!FLAGS_gpu && isGPUTest) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-22 17:15:34 +00:00
|
|
|
int test_main();
|
|
|
|
int test_main() {
|
2014-06-18 18:44:15 +00:00
|
|
|
SetupCrashHandler();
|
2013-04-11 16:54:09 +00:00
|
|
|
|
2013-01-15 20:37:04 +00:00
|
|
|
#if SK_ENABLE_INST_COUNT
|
2014-01-23 17:21:19 +00:00
|
|
|
if (FLAGS_leaks) {
|
|
|
|
gPrintInstCount = true;
|
|
|
|
}
|
2012-07-22 22:33:05 +00:00
|
|
|
#endif
|
2013-04-10 15:57:31 +00:00
|
|
|
|
2014-11-07 14:12:30 +00:00
|
|
|
SkAutoGraphics ag;
|
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
|
|
|
}
|
2014-06-18 21:32:48 +00:00
|
|
|
SkString resourcePath = GetResourcePath();
|
2013-06-06 14:59:56 +00:00
|
|
|
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
|
2013-08-29 20:20:39 +00:00
|
|
|
header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
|
2014-04-14 17:08:59 +00:00
|
|
|
if (FLAGS_veryVerbose) {
|
|
|
|
header.appendf("\n");
|
|
|
|
}
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf(header.c_str());
|
2011-10-26 15:25:18 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
Iter iter;
|
|
|
|
while ((test = iter.next(NULL/*reporter not needed*/)) != NULL) {
|
2013-04-22 16:43:07 +00:00
|
|
|
SkAutoTDelete<Test> owned(test);
|
2014-01-30 15:30:50 +00:00
|
|
|
if (should_run(test->getName(), test->isGPUTest())) {
|
2013-04-22 16:43:07 +00:00
|
|
|
toRun++;
|
|
|
|
}
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
SkThreadPool ~~> SkTaskGroup
SkTaskGroup is like SkThreadPool except the threads stay in
one global pool. Each SkTaskGroup itself is tiny (4 bytes)
and its wait() method applies only to tasks add()ed to that
instance, not the whole thread pool.
This means we don't need to bring up new thread pools when
tests themselves want to use multithreading (e.g. pathops,
quilt). We just create a new SkTaskGroup and wait for that
to complete. This should be more efficient, and allow us
to expand where we use threads to really latency sensitive
places. E.g. we can probably now use these in nanobench
for CPU .skp rendering.
Now that all threads are sharing the same pool, I think we
can remove most of the custom mechanism pathops tests use
to control threading. They'll just ride on the global pool
with all other tests now.
This (temporarily?) removes the GPU multithreading feature
from DM, which we don't use.
On my desktop, DM runs a little faster (57s -> 55s) in
Debug, and a lot faster in Release (36s -> 24s). The bots
show speedups of similar proportions, cutting more than a
minute off the N4/Release and Win7/Debug runtimes.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/9c7207b5dc71dc5a96a2eb107d401133333d5b6f
R=caryclark@google.com, bsalomon@google.com, bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531653002
2014-09-03 22:34:37 +00:00
|
|
|
SkTaskGroup::Enabler enabled(FLAGS_threads);
|
|
|
|
SkTaskGroup cpuTests;
|
2014-02-26 16:31:22 +00:00
|
|
|
SkTArray<Test*> gpuTests; // Always passes ownership to an SkTestRunnable
|
2014-01-02 16:19:53 +00:00
|
|
|
|
|
|
|
DebugfReporter reporter(toRun);
|
2013-04-22 16:43:07 +00:00
|
|
|
for (int i = 0; i < total; i++) {
|
2014-01-02 16:19:53 +00:00
|
|
|
SkAutoTDelete<Test> test(iter.next(&reporter));
|
2014-01-30 15:30:50 +00:00
|
|
|
if (!should_run(test->getName(), test->isGPUTest())) {
|
2011-09-02 15:06:44 +00:00
|
|
|
++skipCount;
|
2014-01-30 15:30:50 +00:00
|
|
|
} else if (test->isGPUTest()) {
|
2014-02-26 16:31:22 +00:00
|
|
|
gpuTests.push_back() = test.detach();
|
2011-09-02 15:06:44 +00:00
|
|
|
} else {
|
SkThreadPool ~~> SkTaskGroup
SkTaskGroup is like SkThreadPool except the threads stay in
one global pool. Each SkTaskGroup itself is tiny (4 bytes)
and its wait() method applies only to tasks add()ed to that
instance, not the whole thread pool.
This means we don't need to bring up new thread pools when
tests themselves want to use multithreading (e.g. pathops,
quilt). We just create a new SkTaskGroup and wait for that
to complete. This should be more efficient, and allow us
to expand where we use threads to really latency sensitive
places. E.g. we can probably now use these in nanobench
for CPU .skp rendering.
Now that all threads are sharing the same pool, I think we
can remove most of the custom mechanism pathops tests use
to control threading. They'll just ride on the global pool
with all other tests now.
This (temporarily?) removes the GPU multithreading feature
from DM, which we don't use.
On my desktop, DM runs a little faster (57s -> 55s) in
Debug, and a lot faster in Release (36s -> 24s). The bots
show speedups of similar proportions, cutting more than a
minute off the N4/Release and Win7/Debug runtimes.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/9c7207b5dc71dc5a96a2eb107d401133333d5b6f
R=caryclark@google.com, bsalomon@google.com, bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531653002
2014-09-03 22:34:37 +00:00
|
|
|
cpuTests.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
|
|
|
|
2014-02-26 16:31:22 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
// Give GPU tests a context factory if that makes sense on this machine.
|
|
|
|
GrContextFactory grContextFactory;
|
|
|
|
for (int i = 0; i < gpuTests.count(); i++) {
|
|
|
|
gpuTests[i]->setGrContextFactory(&grContextFactory);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Run GPU tests on this thread.
|
|
|
|
for (int i = 0; i < gpuTests.count(); i++) {
|
|
|
|
SkNEW_ARGS(SkTestRunnable, (gpuTests[i], &failCount))->run();
|
2013-04-19 13:24:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 18:49:04 +00:00
|
|
|
// Block until threaded tests finish.
|
SkThreadPool ~~> SkTaskGroup
SkTaskGroup is like SkThreadPool except the threads stay in
one global pool. Each SkTaskGroup itself is tiny (4 bytes)
and its wait() method applies only to tasks add()ed to that
instance, not the whole thread pool.
This means we don't need to bring up new thread pools when
tests themselves want to use multithreading (e.g. pathops,
quilt). We just create a new SkTaskGroup and wait for that
to complete. This should be more efficient, and allow us
to expand where we use threads to really latency sensitive
places. E.g. we can probably now use these in nanobench
for CPU .skp rendering.
Now that all threads are sharing the same pool, I think we
can remove most of the custom mechanism pathops tests use
to control threading. They'll just ride on the global pool
with all other tests now.
This (temporarily?) removes the GPU multithreading feature
from DM, which we don't use.
On my desktop, DM runs a little faster (57s -> 55s) in
Debug, and a lot faster in Release (36s -> 24s). The bots
show speedups of similar proportions, cutting more than a
minute off the N4/Release and Win7/Debug runtimes.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/9c7207b5dc71dc5a96a2eb107d401133333d5b6f
R=caryclark@google.com, bsalomon@google.com, bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531653002
2014-09-03 22:34:37 +00:00
|
|
|
cpuTests.wait();
|
2013-04-19 13:24:28 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
SkDebugf("\nFinished %d tests, %d failures, %d skipped. (%d internal tests)",
|
|
|
|
toRun, failCount, skipCount, reporter.countTests());
|
2013-04-10 15:57:31 +00:00
|
|
|
}
|
2012-07-22 22:33:05 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
SkDebugf("\n");
|
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)
|
2014-07-22 17:15:34 +00:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
return test_main();
|
2012-10-02 18:33:14 +00:00
|
|
|
}
|
|
|
|
#endif
|