1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef gm_runner_DEFINED
8#define gm_runner_DEFINED
9
10#include <memory>
11#include <string>
12#include <tuple>
13#include <vector>
14
15#include "skqp_asset_manager.h"
16
17/**
18A Skia GM is a single rendering test that can be executed on any Skia backend Canvas.
19*/
20namespace skiagm {
21class GM;
22}
23
24namespace skiatest {
25struct Test;
26}
27
28namespace gm_runner {
29
30using GMFactory = skiagm::GM* (*)(void*);
31
32using UnitTest = const skiatest::Test*;
33
34enum class SkiaBackend {
35    kGL,
36    kGLES,
37    kVulkan,
38};
39
40enum class Mode {
41    /** This mode is set when used by Android CTS.  All known tests are executed.  */
42    kCompatibilityTestMode,
43    /** This mode is set when used in the test lab.  Some tests are skipped, if
44        they are known to cause crashes in older devices.  All GMs are evaluated
45        with stricter requirements. */
46    kExperimentalMode,
47
48};
49
50/**
51Initialize Skia
52*/
53void InitSkia(Mode, skqp::AssetManager*);
54
55std::vector<SkiaBackend> GetSupportedBackends();
56
57/**
58@return a list of all Skia GMs in lexicographic order.
59*/
60std::vector<GMFactory> GetGMFactories(skqp::AssetManager*);
61
62/**
63@return a list of all Skia GPU unit tests in lexicographic order.
64*/
65std::vector<UnitTest> GetUnitTests();
66
67/**
68@return a descriptive name for the GM.
69*/
70std::string GetGMName(GMFactory);
71
72/**
73@return a descriptive name for the unit test.
74*/
75const char* GetUnitTestName(UnitTest);
76
77/**
78@return a descriptive name for the backend.
79*/
80const char* GetBackendName(SkiaBackend);
81
82enum class Error {
83    None = 0,
84    BadSkiaOutput = 1,
85    BadGMKBData = 2,
86    SkiaFailure = 3,
87};
88
89const char* GetErrorString(Error);
90
91/**
92@return A non-negative float representing how badly the GM failed (or zero for
93        success).  Any error running or evaluating the GM will result in a non-zero
94        error code.
95*/
96std::tuple<float, Error> EvaluateGM(SkiaBackend backend,
97                                    GMFactory gmFact,
98                                    skqp::AssetManager* assetManager,
99                                    const char* reportDirectoryPath);
100
101/**
102@return a (hopefully empty) list of errors produced by this unit test.
103*/
104std::vector<std::string> ExecuteTest(UnitTest);
105
106}  // namespace gm_runner
107
108#endif  // gm_runner_DEFINED
109