• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.os.cts;
17 
18 import android.os.Flags;
19 import android.platform.test.annotations.RequiresFlagsEnabled;
20 import android.platform.test.flag.junit.CheckFlagsRule;
21 import android.platform.test.flag.junit.DeviceFlagsValueProvider;
22 
23 import androidx.test.ext.junit.runners.AndroidJUnit4;
24 import androidx.test.platform.app.InstrumentationRegistry;
25 
26 import com.android.compatibility.common.util.DeviceReportLog;
27 import com.android.compatibility.common.util.ResultType;
28 import com.android.compatibility.common.util.ResultUnit;
29 import com.android.cts.backportedfixes.ApprovedBackportedFixes;
30 import com.android.cts.backportedfixes.BackportedFixRule;
31 import com.android.cts.backportedfixes.BackportedFixTest;
32 import com.android.cts.backportedfixes.bitset.BitSets;
33 import com.android.cts.backportedfixes.support.BackportedFixesPropertiesCompat;
34 
35 import org.junit.Assert;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.rules.TestRule;
39 import org.junit.runner.RunWith;
40 
41 import java.util.BitSet;
42 import java.util.SortedSet;
43 
44 /**
45  * Tests for backported fixes used in {@link BuildTest}.
46  *
47  * <p>
48  * Additional test for backported fixes should go in the test suite appropriate to the
49  * affected code and be annotated {@link BackportedFixTest}.
50  */
51 @RunWith(AndroidJUnit4.class)
52 public class BackportedFixesTest {
53 
54     @Rule(order = 0)
55     public final CheckFlagsRule checkFlagsRule =
56             DeviceFlagsValueProvider.createCheckFlagsRule();
57     @Rule(order = 1)
58     public TestRule mKnownIssueRule = new BackportedFixRule();
59 
60     @RequiresFlagsEnabled(Flags.FLAG_API_FOR_BACKPORTED_FIXES)
61     @BackportedFixTest(350037023L)
62     @Test
alwaysFixed()63     public void alwaysFixed() {
64         // always passes
65 
66         // Log all approved and applied fixes.
67         var bitset = BackportedFixesPropertiesCompat.alias_bitset();
68         var aliases =
69                 BitSets.toIndices(
70                         BitSet.valueOf(bitset.stream().mapToLong(Long::longValue).toArray()));
71         logFixesApplied(aliases);
72     }
73 
74     @RequiresFlagsEnabled(Flags.FLAG_API_FOR_BACKPORTED_FIXES)
75     @BackportedFixTest(350037348L)
76     @Test
neverFixed()77     public void neverFixed() {
78         Assert.fail(
79                 "This is never fixed on device. However because it is not declared fixed it "
80                         + "will be an AssumptionFailure instead");
81     }
82 
logFixesApplied(SortedSet<Integer> aliases)83     private static void logFixesApplied(SortedSet<Integer> aliases) {
84         var approvedFixes = ApprovedBackportedFixes.getInstance();
85         DeviceReportLog reportLog =
86                 new DeviceReportLog("BackportedFixesTestCases", "fixes_applied_on_device");
87         reportLog.addValues(
88                 "applied_aliases",
89                 aliases.stream().mapToInt(Integer::intValue).toArray(),
90                 ResultType.NEUTRAL,
91                 ResultUnit.NONE);
92         reportLog.addValues(
93                 "applied_fixes",
94                 aliases.stream().mapToLong(approvedFixes::getId).sorted().toArray(),
95                 ResultType.NEUTRAL,
96                 ResultUnit.NONE);
97         reportLog.addValues(
98                 "approved_fixes",
99                 approvedFixes.getAllIssues().stream().mapToLong(Long::longValue).sorted().toArray(),
100                 ResultType.NEUTRAL,
101                 ResultUnit.NONE);
102         reportLog.submit(InstrumentationRegistry.getInstrumentation());
103     }
104 }
105