/src/skia/tests/CtsEnforcement.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2022 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 | | #ifndef CtsEnforcement_DEFINED |
9 | | #define CtsEnforcement_DEFINED |
10 | | |
11 | | #include "include/core/SkTypes.h" |
12 | | |
13 | | #include <climits> |
14 | | #include <cstdint> |
15 | | |
16 | | /** |
17 | | * Determines how unit tests are enforced by CTS. Depending on the ApiLevel, a test will be run |
18 | | * in one of 3 states: run without workarounds, run with workarounds or skipped. |
19 | | */ |
20 | | class CtsEnforcement { |
21 | | public: |
22 | | enum ApiLevel : int32_t { |
23 | | /* When used as fStrictVersion, always skip this test. It is not relevant to CTS. |
24 | | * When used as fWorkaroundsVersion, there are no API levels that should run the |
25 | | * test with workarounds. |
26 | | */ |
27 | | kNever = INT32_MAX, |
28 | | /* The kApiLevel_* values are directly correlated with Android **vendor** API levels, which |
29 | | * are distinct from Android SDK API levels. Every new CTS/SkQP release has a corresponding |
30 | | * Android API level that will be captured by these enum values. |
31 | | */ |
32 | | kApiLevel_T = 33, |
33 | | kApiLevel_U = 34, |
34 | | /* Beginning with Android 14-QPR3, vendor API levels (e.g. the ro.vendor.api_level system |
35 | | * property checked by SkQP) now follow a YYYYMM format. |
36 | | * See https://source.android.com/docs/core/architecture/api-flags for more information. |
37 | | */ |
38 | | kApiLevel_202404 = 202404, |
39 | | kApiLevel_202504 = 202504, |
40 | | /* kNextRelease is a placeholder value that all new unit tests should use. It implies that |
41 | | * this test will be enforced in the next Android release. At the time of the release a |
42 | | * new kApiLevel_* value will be added and all current kNextRelease values will be replaced |
43 | | * with that new value. |
44 | | */ |
45 | | kNextRelease = 202604 |
46 | | }; |
47 | | |
48 | | /** |
49 | | * Tests will run in strict (no workarounds) mode if the device API level is >= strictVersion |
50 | | */ |
51 | | constexpr CtsEnforcement(ApiLevel strictVersion) |
52 | 0 | : fStrictVersion(strictVersion), fWorkaroundsVersion(kNever) {} |
53 | | |
54 | | /** |
55 | | * Test will run with workarounds if the device API level is >= workaroundVersion |
56 | | * and < strictVersion |
57 | | */ |
58 | 0 | constexpr CtsEnforcement& withWorkarounds(ApiLevel workaroundVersion) { |
59 | 0 | SkASSERT(workaroundVersion <= fStrictVersion); |
60 | 0 | fWorkaroundsVersion = workaroundVersion; |
61 | 0 | return *this; |
62 | 0 | } |
63 | | |
64 | | enum class RunMode { kSkip = 0, kRunWithWorkarounds = 1, kRunStrict = 2 }; |
65 | | RunMode eval(int apiLevel) const; |
66 | | |
67 | | private: |
68 | | ApiLevel fStrictVersion; |
69 | | ApiLevel fWorkaroundsVersion; |
70 | | }; |
71 | | |
72 | | #endif |