1 /*
2 * Copyright 2015 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
8 #include "tests/CtsEnforcement.h"
9 #include "tests/Test.h"
10
11 struct GrContextOptions;
12
13 // This is an example of a normal test. It should not require any GPU backends, that is, it is a
14 // CPU test.
DEF_TEST(TestNormal,reporter)15 DEF_TEST(TestNormal, reporter) {
16 REPORTER_ASSERT(reporter, reporter);
17 }
18
19 // This is an example of a conditional test with a true condition.
20 DEF_CONDITIONAL_TEST(TestTrueCondition, reporter, 1 == 1) {
21 REPORTER_ASSERT(reporter, reporter);
22 }
23
24 // This is an example of a conditional test with a false condition.
25 DEF_CONDITIONAL_TEST(TestFalseCondition, reporter, 1 == 0) {
26 ERRORF(reporter, "DEF_CONDITIONAL_TEST executed a test with a false condition");
27 }
28
29 // This is an example of a GPU test that runs if any Ganesh backend is compiled in. The test itself
30 // is responsible for making the relevant GrDirectContext (e.g. using
31 // sk_gpu_test::GrContextFactory).
DEF_GANESH_TEST(TestGpuFactory,reporter,factory,CtsEnforcement::kNever)32 DEF_GANESH_TEST(TestGpuFactory, reporter, factory, CtsEnforcement::kNever) {
33 REPORTER_ASSERT(reporter, reporter);
34 }
35
36 // This is an example of a GPU test that tests a property that should work for all Ganesh contexts.
37 // Note: Some of the contexts might not produce a rendering output.
DEF_GANESH_TEST_FOR_ALL_CONTEXTS(TestGpuAllContexts,reporter,ctxInfo,CtsEnforcement::kNever)38 DEF_GANESH_TEST_FOR_ALL_CONTEXTS(TestGpuAllContexts, reporter, ctxInfo, CtsEnforcement::kNever) {
39 REPORTER_ASSERT(reporter, reporter);
40 REPORTER_ASSERT(reporter, ctxInfo.directContext());
41 }
42
43 // This is an example of a GPU test that tests a property that should work for all Ganesh contexts
44 // that produce a rendering output.
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContexts,reporter,ctxInfo,CtsEnforcement::kNever)45 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContexts,
46 reporter,
47 ctxInfo,
48 CtsEnforcement::kNever) {
49 REPORTER_ASSERT(reporter, reporter);
50 REPORTER_ASSERT(reporter, ctxInfo.directContext());
51 }
52
53 // This is an example of a GPU test that tests a property that uses the mock Ganesh context.
54 // It should be used if the test tests some behavior that is mocked with the mock context.
DEF_GANESH_TEST_FOR_MOCK_CONTEXT(TestMockContext,reporter,ctxInfo)55 DEF_GANESH_TEST_FOR_MOCK_CONTEXT(TestMockContext, reporter, ctxInfo) {
56 REPORTER_ASSERT(reporter, reporter);
57 REPORTER_ASSERT(reporter, ctxInfo.directContext());
58 }
59
60 // Conditional variant of DEF_GANESH_TEST_FOR_ALL_CONTEXTS. It will only execute if the provided
61 // condition parameter is true.
DEF_CONDITIONAL_GANESH_TEST_FOR_ALL_CONTEXTS(TestGpuAllContextsWithTrueCondition,reporter,ctxInfo,true,CtsEnforcement::kNever)62 DEF_CONDITIONAL_GANESH_TEST_FOR_ALL_CONTEXTS(
63 TestGpuAllContextsWithTrueCondition, reporter, ctxInfo, true, CtsEnforcement::kNever) {
64 REPORTER_ASSERT(reporter, reporter);
65 REPORTER_ASSERT(reporter, ctxInfo.directContext());
66 }
67
DEF_CONDITIONAL_GANESH_TEST_FOR_ALL_CONTEXTS(TestGpuAllContextsWithFalseCondition,reporter,ctxInfo,false,CtsEnforcement::kNever)68 DEF_CONDITIONAL_GANESH_TEST_FOR_ALL_CONTEXTS(
69 TestGpuAllContextsWithFalseCondition, reporter, ctxInfo, false, CtsEnforcement::kNever) {
70 ERRORF(reporter, "DEF_CONDITIONAL_GANESH_TEST_FOR_ALL_CONTEXTS ran with a false condition");
71 }
72
73 // Conditional variant of DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS. It will only execute if the
74 // provided condition parameter is true.
DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContextsWithTrueCondition,reporter,ctxInfo,true,CtsEnforcement::kNever)75 DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContextsWithTrueCondition,
76 reporter,
77 ctxInfo,
78 true,
79 CtsEnforcement::kNever) {
80 REPORTER_ASSERT(reporter, reporter);
81 REPORTER_ASSERT(reporter, ctxInfo.directContext());
82 }
83
DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContextsWithFalseCondition,reporter,ctxInfo,false,CtsEnforcement::kNever)84 DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContextsWithFalseCondition,
85 reporter,
86 ctxInfo,
87 false,
88 CtsEnforcement::kNever) {
89 ERRORF(reporter,
90 "DEF_CONDITIONAL_GANESH_TEST_FOR_RENDERING_CONTEXTS ran "
91 "with a false condition");
92 }
93
DEF_TEST(TestCtsEnforcement,reporter)94 DEF_TEST(TestCtsEnforcement, reporter) {
95 auto verifyRunMode = [&](CtsEnforcement e, int apiLevel, CtsEnforcement::RunMode runMode) {
96 REPORTER_ASSERT(reporter, e.eval(apiLevel) == runMode);
97 };
98
99 CtsEnforcement e1 = CtsEnforcement::kNever;
100 verifyRunMode(e1, 0, CtsEnforcement::RunMode::kSkip);
101 verifyRunMode(e1, CtsEnforcement::kApiLevel_T, CtsEnforcement::RunMode::kSkip);
102 verifyRunMode(e1, CtsEnforcement::kNextRelease, CtsEnforcement::RunMode::kSkip);
103
104 CtsEnforcement e2 = CtsEnforcement::kApiLevel_T;
105 verifyRunMode(e2, 0, CtsEnforcement::RunMode::kSkip);
106 verifyRunMode(e2, CtsEnforcement::kApiLevel_T, CtsEnforcement::RunMode::kRunStrict);
107 verifyRunMode(e2, CtsEnforcement::kNextRelease, CtsEnforcement::RunMode::kRunStrict);
108
109 CtsEnforcement e3 = CtsEnforcement::kNextRelease;
110 verifyRunMode(e3, 0, CtsEnforcement::RunMode::kSkip);
111 verifyRunMode(e3, CtsEnforcement::kApiLevel_T, CtsEnforcement::RunMode::kSkip);
112 verifyRunMode(e3, CtsEnforcement::kNextRelease, CtsEnforcement::RunMode::kRunStrict);
113
114 CtsEnforcement e4 = CtsEnforcement(CtsEnforcement::kNextRelease)
115 .withWorkarounds(CtsEnforcement::kApiLevel_T);
116 verifyRunMode(e4, 0, CtsEnforcement::RunMode::kSkip);
117 verifyRunMode(e4, CtsEnforcement::kApiLevel_T, CtsEnforcement::RunMode::kRunWithWorkarounds);
118 verifyRunMode(e4, CtsEnforcement::kNextRelease, CtsEnforcement::RunMode::kRunStrict);
119 }
120