Chromium Code Reviews| Index: site/dev/testing/tests.md |
| diff --git a/site/dev/testing/tests.md b/site/dev/testing/tests.md |
| index 1b440ad7ac5f130aabf6a7e96d430c2772b25bce..68065f758d6543373476c4196033f415363a9b57 100644 |
| --- a/site/dev/testing/tests.md |
| +++ b/site/dev/testing/tests.md |
| @@ -1,5 +1,11 @@ |
| -Writing Unit and Rendering Tests |
| -================================ |
| +Writing Skia Tests |
| +================== |
| + |
| ++ [Unit Tests](#test) |
| ++ [Rendering Tests](#gm) |
| ++ [Benchmark Tests](#bench) |
| + |
| +<span id="test"></span> |
| Writing a Unit Test |
| ------------------- |
| @@ -29,6 +35,8 @@ Writing a Unit Test |
| ninja -C out/Debug dm |
| out/Debug/dm --match NewUnitTest |
| +<span id="gm"></span> |
| + |
| Writing a Rendering Test |
| ------------------------ |
| @@ -65,3 +73,50 @@ Writing a Rendering Test |
| On MacOS, try this: |
| out/Debug/SampleApp.app/Contents/MacOS/SampleApp --slide GM:newgmtest |
| + |
| +<span id="bench"></span> |
| + |
| +Writing a Benchmark Test |
| +------------------------ |
| + |
| +1. Add a file `bench/FooBench.cpp`: |
| + |
| + <!--?prettify lang=cc?--> |
| + |
| + /* |
| + * Copyright ........ |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file. |
| + */ |
| + #include "Benchmark.h" |
| + #include "SkCanvas.h" |
| + #include "SkRandom.h" |
| + namespace { |
| + class FooBench : public Benchmark { |
| + public: |
| + FooBench() {} |
| + virtual ~FooBench() {} |
| + protected: |
| + const char* onGetName() override { return "Foo"; } |
| + SkIPoint onGetSize() override { return SkIPoint{100, 100}; } |
| + void onDraw(int loops, SkCanvas* canvas) override { |
| + SkRandom r; |
| + while (loops-- > 0) { |
| + canvas->drawLine(r.nextRangeF(0.0f, 100.0f), |
|
mtklein
2016/02/12 15:59:32
Oh boy, this is also a bad idea. Those calls to n
hal.canary
2016/02/12 16:05:03
how's this?
|
| + r.nextRangeF(0.0f, 100.0f), |
| + r.nextRangeF(0.0f, 100.0f), |
| + r.nextRangeF(0.0f, 100.0f), |
| + SkPaint()); |
| + } |
| + } |
| + }; |
| + } // namespace |
| + DEF_BENCH(return new FooBench;) |
| + |
| + |
| +2. Recompile and run nanobench: |
| + |
| + python bin/sync-and-gyp |
| + ninja -C out/Release nanobench |
| + out/Release/nanobench --match Foo |