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"
|
2015-09-29 18:47:45 +00:00
|
|
|
#include "SkAtomics.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"
|
2016-10-04 14:01:04 +00:00
|
|
|
#include "SkPathOpsDebug.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;
|
2016-03-31 01:56:19 +00:00
|
|
|
using namespace sk_gpu_test;
|
2009-02-27 16:24:51 +00:00
|
|
|
|
2014-01-02 16:19:53 +00:00
|
|
|
DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
|
2016-10-04 14:01:04 +00:00
|
|
|
#if DEBUG_COIN
|
|
|
|
DEFINE_bool2(coinTest, c, false, "detect unused coincidence algorithms.");
|
|
|
|
#endif
|
2014-01-02 16:19:53 +00:00
|
|
|
|
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;
|
2015-10-16 16:03:38 +00:00
|
|
|
void (*gVerboseFinalize)() = nullptr;
|
2009-04-01 18:31:44 +00:00
|
|
|
|
2015-01-20 17:30:20 +00:00
|
|
|
// The threads report back to this object when they are done.
|
|
|
|
class Status {
|
2009-02-27 16:24:51 +00:00
|
|
|
public:
|
2015-01-20 17:30:20 +00:00
|
|
|
explicit Status(int total)
|
|
|
|
: fDone(0), fTestCount(0), fFailCount(0), fTotal(total) {}
|
|
|
|
// Threadsafe.
|
|
|
|
void endTest(const char* testName,
|
|
|
|
bool success,
|
|
|
|
SkMSec elapsed,
|
|
|
|
int testCount) {
|
2014-01-02 16:19:53 +00:00
|
|
|
const int done = 1 + sk_atomic_inc(&fDone);
|
2015-01-20 17:30:20 +00:00
|
|
|
for (int i = 0; i < testCount; ++i) {
|
|
|
|
sk_atomic_inc(&fTestCount);
|
|
|
|
}
|
|
|
|
if (!success) {
|
|
|
|
SkDebugf("\n---- %s FAILED", testName);
|
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");
|
2015-01-20 17:30:20 +00:00
|
|
|
time.printf("%5dms ", elapsed);
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2015-01-20 17:30:20 +00:00
|
|
|
SkDebugf("%s[%3d/%3d] %s%s", prefix.c_str(), done, fTotal, time.c_str(),
|
|
|
|
testName);
|
2009-04-09 04:06:54 +00:00
|
|
|
}
|
2013-04-19 13:24:28 +00:00
|
|
|
|
2015-01-20 17:30:20 +00:00
|
|
|
void reportFailure() { sk_atomic_inc(&fFailCount); }
|
|
|
|
|
|
|
|
int32_t testCount() { return fTestCount; }
|
|
|
|
int32_t failCount() { return fFailCount; }
|
|
|
|
|
2012-11-29 16:29:58 +00:00
|
|
|
private:
|
2014-01-02 16:19:53 +00:00
|
|
|
int32_t fDone; // atomic
|
2015-01-20 17:30:20 +00:00
|
|
|
int32_t fTestCount; // atomic
|
|
|
|
int32_t fFailCount; // atomic
|
2014-01-02 16:19:53 +00:00
|
|
|
const int fTotal;
|
2009-02-27 16:24:51 +00:00
|
|
|
};
|
|
|
|
|
2016-02-17 03:06:15 +00:00
|
|
|
class SkTestRunnable {
|
2013-04-19 13:24:28 +00:00
|
|
|
public:
|
2015-01-20 17:30:20 +00:00
|
|
|
SkTestRunnable(const Test& test,
|
|
|
|
Status* status,
|
2015-08-27 14:41:13 +00:00
|
|
|
GrContextFactory* grContextFactory = nullptr)
|
2015-01-20 17:30:20 +00:00
|
|
|
: fTest(test), fStatus(status), fGrContextFactory(grContextFactory) {}
|
2013-04-19 13:24:28 +00:00
|
|
|
|
2016-02-17 03:06:15 +00:00
|
|
|
void operator()() {
|
2015-01-20 17:30:20 +00:00
|
|
|
struct TestReporter : public skiatest::Reporter {
|
|
|
|
public:
|
2016-10-04 14:59:29 +00:00
|
|
|
TestReporter() : fStats(nullptr), fError(false), fTestCount(0) {}
|
2015-03-26 01:17:31 +00:00
|
|
|
void bumpTestCount() override { ++fTestCount; }
|
|
|
|
bool allowExtendedTest() const override {
|
2015-01-20 17:30:20 +00:00
|
|
|
return FLAGS_extendedTest;
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
bool verbose() const override { return FLAGS_veryVerbose; }
|
|
|
|
void reportFailed(const skiatest::Failure& failure) override {
|
2015-01-20 17:30:20 +00:00
|
|
|
SkDebugf("\nFAILED: %s", failure.toString().c_str());
|
|
|
|
fError = true;
|
|
|
|
}
|
2016-10-04 14:01:04 +00:00
|
|
|
void* stats() { return fStats; }
|
|
|
|
void* fStats;
|
2015-01-20 17:30:20 +00:00
|
|
|
bool fError;
|
|
|
|
int fTestCount;
|
|
|
|
} reporter;
|
|
|
|
|
Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow.
The following are currently unused in Android, Google3, Chromium, and Mozilla:
- SkEvent
- SkTime::GetMSecs
- SK_TIME_FACTOR (also unused in Skia)
- SkAutoTime
I left uses of SkMSec more-or-less intact for SkEvent, SkAnimator, and SkInterpolator. SkInterpolator is used in Chromium, so I did not want to change the API. The views/ and animator/ code is crufty, so it didn't seem worthwhile to refactor it. Instead, I added SkEvent::GetMSecsSinceStartup, which is likely to be adequate for use in SampleApp.
I also left SkMSec where it is used to measure a duration rather than a timestamp. With the exception of SkMovie, which is used in Android, all of the uses appear to measure the execution time of a piece of code, which I would hope does not exceed 2^31 milliseconds.
Added skiatest::Timer to support a common idiom in tests where we want to measure the wallclock time in integer milliseconds. (Not used in tests/PathOpsSkpClipTest.cpp because it redefines things in Test.h.)
Removed tabs in tests/StrokerTest.cpp.
BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811613004
Review URL: https://codereview.chromium.org/1811613004
2016-03-25 19:59:53 +00:00
|
|
|
const Timer timer;
|
2015-01-20 17:30:20 +00:00
|
|
|
fTest.proc(&reporter, fGrContextFactory);
|
Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow.
The following are currently unused in Android, Google3, Chromium, and Mozilla:
- SkEvent
- SkTime::GetMSecs
- SK_TIME_FACTOR (also unused in Skia)
- SkAutoTime
I left uses of SkMSec more-or-less intact for SkEvent, SkAnimator, and SkInterpolator. SkInterpolator is used in Chromium, so I did not want to change the API. The views/ and animator/ code is crufty, so it didn't seem worthwhile to refactor it. Instead, I added SkEvent::GetMSecsSinceStartup, which is likely to be adequate for use in SampleApp.
I also left SkMSec where it is used to measure a duration rather than a timestamp. With the exception of SkMovie, which is used in Android, all of the uses appear to measure the execution time of a piece of code, which I would hope does not exceed 2^31 milliseconds.
Added skiatest::Timer to support a common idiom in tests where we want to measure the wallclock time in integer milliseconds. (Not used in tests/PathOpsSkpClipTest.cpp because it redefines things in Test.h.)
Removed tabs in tests/StrokerTest.cpp.
BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811613004
Review URL: https://codereview.chromium.org/1811613004
2016-03-25 19:59:53 +00:00
|
|
|
SkMSec elapsed = timer.elapsedMsInt();
|
2015-01-20 17:30:20 +00:00
|
|
|
if (reporter.fError) {
|
|
|
|
fStatus->reportFailure();
|
2013-04-19 13:24:28 +00:00
|
|
|
}
|
2015-01-20 17:30:20 +00:00
|
|
|
fStatus->endTest(fTest.name, !reporter.fError, elapsed,
|
|
|
|
reporter.fTestCount);
|
2013-04-19 13:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-01-20 17:30:20 +00:00
|
|
|
Test fTest;
|
|
|
|
Status* fStatus;
|
|
|
|
GrContextFactory* fGrContextFactory;
|
2013-04-19 13:24:28 +00:00
|
|
|
};
|
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
|
|
|
|
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
|
|
|
}
|
2015-01-20 17:30:20 +00:00
|
|
|
SkString tmpDir = skiatest::GetTmpDir();
|
2013-06-06 14:59:56 +00:00
|
|
|
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
|
2014-04-14 17:08:59 +00:00
|
|
|
if (FLAGS_veryVerbose) {
|
|
|
|
header.appendf("\n");
|
|
|
|
}
|
2015-02-19 14:32:12 +00:00
|
|
|
SkDebugf("%s", 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;
|
2013-07-24 17:24:23 +00:00
|
|
|
|
2015-01-20 17:30:20 +00:00
|
|
|
for (const TestRegistry* iter = TestRegistry::Head(); iter;
|
|
|
|
iter = iter->next()) {
|
|
|
|
const Test& test = iter->factory();
|
|
|
|
if (should_run(test.name, test.needsGpu)) {
|
2013-04-22 16:43:07 +00:00
|
|
|
toRun++;
|
|
|
|
}
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now run them.
|
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;
|
2015-01-20 17:30:20 +00:00
|
|
|
SkTArray<const Test*> gpuTests;
|
2014-01-02 16:19:53 +00:00
|
|
|
|
2015-01-20 17:30:20 +00:00
|
|
|
Status status(toRun);
|
|
|
|
for (const TestRegistry* iter = TestRegistry::Head(); iter;
|
|
|
|
iter = iter->next()) {
|
|
|
|
const Test& test = iter->factory();
|
|
|
|
if (!should_run(test.name, test.needsGpu)) {
|
2011-09-02 15:06:44 +00:00
|
|
|
++skipCount;
|
2015-01-20 17:30:20 +00:00
|
|
|
} else if (test.needsGpu) {
|
|
|
|
gpuTests.push_back(&test);
|
2011-09-02 15:06:44 +00:00
|
|
|
} else {
|
2016-02-17 03:06:15 +00:00
|
|
|
cpuTests.add(SkTestRunnable(test, &status));
|
2011-09-02 15:06:44 +00:00
|
|
|
}
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2009-04-09 04:06:54 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
GrContextFactory* grContextFactoryPtr = nullptr;
|
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;
|
2015-01-20 17:30:20 +00:00
|
|
|
grContextFactoryPtr = &grContextFactory;
|
|
|
|
|
2014-02-26 16:31:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Run GPU tests on this thread.
|
|
|
|
for (int i = 0; i < gpuTests.count(); i++) {
|
2016-02-17 03:06:15 +00:00
|
|
|
SkTestRunnable(*gpuTests[i], &status, grContextFactoryPtr)();
|
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) {
|
2015-01-20 17:30:20 +00:00
|
|
|
SkDebugf(
|
|
|
|
"\nFinished %d tests, %d failures, %d skipped. "
|
|
|
|
"(%d internal tests)",
|
|
|
|
toRun, status.failCount(), skipCount, status.testCount());
|
2015-10-16 16:03:38 +00:00
|
|
|
if (gVerboseFinalize) {
|
|
|
|
(*gVerboseFinalize)();
|
|
|
|
}
|
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");
|
2016-10-04 14:01:04 +00:00
|
|
|
#if DEBUG_COIN
|
|
|
|
if (FLAGS_coinTest) {
|
|
|
|
SkPathOpsDebug::DumpCoinDict();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-20 17:30:20 +00:00
|
|
|
return (status.failCount() == 0) ? 0 : 1;
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
2012-10-02 18:33:14 +00:00
|
|
|
|
2015-04-02 19:16:36 +00:00
|
|
|
#if !defined(SK_BUILD_FOR_IOS)
|
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
|