6f96cf4bde
DOCS_PREVIEW= https://skia.org/dev/testing/tests?cl=1696723002 https://skia.org/dev/testing/tests?cl=1696723002#bench GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1696723002 NOTRY=true Review URL: https://codereview.chromium.org/1696723002
2.8 KiB
2.8 KiB
Writing Skia Tests
Writing a Unit Test
-
Add a file
tests/NewUnitTest.cpp
:/* * Copyright ........ * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file. */ #include "Test.h" DEF_TEST(NewUnitTest, reporter) { if (1 + 1 != 2) { ERRORF(reporter, "%d + %d != %d", 1, 1, 2); } bool lifeIsGood = true; REPORTER_ASSERT(reporter, lifeIsGood); }
-
Recompile and run test:
python bin/sync-and-gyp ninja -C out/Debug dm out/Debug/dm --match NewUnitTest
Writing a Rendering Test
-
Add a file
gm/newgmtest.cpp
:/* * Copyright ........ * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file. */ #include "gm.h" DEF_SIMPLE_GM(newgmtest, canvas, 128, 128) { canvas->clear(SK_ColorWHITE); SkPaint p; p.setStrokeWidth(2); canvas->drawLine(16, 16, 112, 112, p); }
-
Recompile and run test:
python bin/sync-and-gyp ninja -C out/Debug dm out/Debug/dm --match newgmtest
-
Run the GM inside SampleApp:
python bin/sync-and-gyp ninja -C out/Debug SampleApp out/Debug/SampleApp --slide GM:newgmtest
On MacOS, try this:
out/Debug/SampleApp.app/Contents/MacOS/SampleApp --slide GM:newgmtest
Writing a Benchmark Test
-
Add a file
bench/FooBench.cpp
:/* * 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" 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 { while (loops-- > 0) { canvas->drawLine(0.0f, 0.0f, 100.0f, 100.0f, SkPaint()); } } }; } // namespace DEF_BENCH(return new FooBench;)
-
Recompile and run nanobench:
python bin/sync-and-gyp ninja -C out/Release nanobench out/Release/nanobench --match Foo