blob: 77c62daf9300c026c33309c7e2a746fb162fa9ab [file] [log] [blame]
Brian Muramatsu7f64e852011-02-17 16:52:16 -08001/*
2 * Copyright (C) 2011 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
17import vogar.Expectation;
18import vogar.ExpectationStore;
19import vogar.ModeId;
Brian Carlstromd16b8642015-06-18 22:21:41 -070020import vogar.Result;
Brian Muramatsu7f64e852011-02-17 16:52:16 -080021
Stuart Scott92423df2015-07-08 14:36:12 +000022import com.android.compatibility.common.util.AbiUtils;
23
Brian Muramatsu7f64e852011-02-17 16:52:16 -080024import java.io.File;
25import java.io.FilenameFilter;
26import java.io.IOException;
27import java.util.Arrays;
28import java.util.HashSet;
29import java.util.Set;
30
31public class VogarUtils {
32
Brian Carlstrom022aff42011-05-17 23:16:51 -070033 public static boolean isVogarKnownFailure(ExpectationStore[] expectationStores,
34 final String testClassName,
35 final String testMethodName) {
36 for (ExpectationStore expectationStore : expectationStores) {
37 if (isVogarKnownFailure(expectationStore, testClassName, testMethodName)) {
38 return true;
39 }
40 }
41 return false;
42 }
43
Stuart Scott01c2b492014-10-08 18:07:28 -070044 /**
45 * @return true iff the class/name is found in the vogar known failure list and it is not
46 * a known failure that is a result of an unsupported abi.
47 */
Brian Muramatsu7f64e852011-02-17 16:52:16 -080048 public static boolean isVogarKnownFailure(ExpectationStore expectationStore,
49 final String testClassName,
50 final String testMethodName) {
Stuart Scott01c2b492014-10-08 18:07:28 -070051 if (expectationStore == null) {
52 return false;
53 }
54 String fullTestName = buildFullTestName(testClassName, testMethodName);
55 Expectation expectation = expectationStore.get(fullTestName);
Brian Carlstromd16b8642015-06-18 22:21:41 -070056 if (expectation.getResult() == Result.SUCCESS) {
Stuart Scott01c2b492014-10-08 18:07:28 -070057 return false;
58 }
59
60 String description = expectation.getDescription();
61 boolean foundAbi = AbiUtils.parseAbiList(description).size() > 0;
62
Brian Carlstromd16b8642015-06-18 22:21:41 -070063 return expectation.getResult() != Result.SUCCESS && !foundAbi;
Brian Muramatsu7f64e852011-02-17 16:52:16 -080064 }
65
66 public static ExpectationStore provideExpectationStore(String dir) throws IOException {
67 if (dir == null) {
68 return null;
69 }
70 ExpectationStore result = ExpectationStore.parse(getExpectationFiles(dir), ModeId.DEVICE);
71 return result;
72 }
73
74 private static Set<File> getExpectationFiles(String dir) {
75 Set<File> expectSet = new HashSet<File>();
76 File[] files = new File(dir).listFiles(new FilenameFilter() {
77 // ignore obviously temporary files
78 public boolean accept(File dir, String name) {
79 return !name.endsWith("~") && !name.startsWith(".");
80 }
81 });
82 if (files != null) {
83 expectSet.addAll(Arrays.asList(files));
84 }
85 return expectSet;
86 }
Stuart Scott01c2b492014-10-08 18:07:28 -070087
88 /** @return the test name in the form of com.android.myclass.TestClass#testMyMethod */
89 public static String buildFullTestName(String testClass, String testMethodName) {
90 return String.format("%s#%s", testClass, testMethodName);
91 }
92
93 /**
94 * This method looks in the description field of the Vogar entry for the ABI_LIST_MARKER
95 * and returns the list of abis found there.
96 *
97 * @return The Set of supported abis parsed from the {@code expectation}'s description.
98 */
99 public static Set<String> extractSupportedAbis(String architecture, Expectation expectation) {
100 Set<String> supportedAbiSet = AbiUtils.getAbisForArch(architecture);
101 if (expectation == null || expectation.getDescription().isEmpty()) {
102 // Include all abis since there was no limitation found in the description
103 return supportedAbiSet;
104 }
105
106 // Remove any abis that are not supported for the test.
107 supportedAbiSet.removeAll(AbiUtils.parseAbiList(expectation.getDescription()));
108
109 return supportedAbiSet;
110 }
111
112 /**
113 * Determine the correct set of ABIs for the given className/testName.
114 *
115 * @return the set of ABIs that can be expected to pass for the given combination of
116 * {@code architecture}, {@code className} and {@code testName}.
117 */
118 public static Set<String> extractSupportedAbis(String architecture,
119 ExpectationStore[] expectationStores,
120 String className,
121 String testName) {
122
Brian Carlstromd16b8642015-06-18 22:21:41 -0700123 String fullTestName = buildFullTestName(className, testName);
Stuart Scott01c2b492014-10-08 18:07:28 -0700124 Set<String> supportedAbiSet = AbiUtils.getAbisForArch(architecture);
125 for (ExpectationStore expectationStore : expectationStores) {
126 Expectation expectation = expectationStore.get(fullTestName);
127 supportedAbiSet.retainAll(extractSupportedAbis(architecture, expectation));
128 }
129
130 return supportedAbiSet;
131 }
Brian Carlstromd16b8642015-06-18 22:21:41 -0700132
133 /**
134 * Returns the greatest timeout in minutes for the test in all
135 * expectation stores, or 0 if no timeout was found.
136 */
137 public static int timeoutInMinutes(ExpectationStore[] expectationStores,
138 final String testClassName,
139 final String testMethodName) {
140 int timeoutInMinutes = 0;
141 for (ExpectationStore expectationStore : expectationStores) {
142 timeoutInMinutes = Math.max(timeoutInMinutes,
143 timeoutInMinutes(expectationStore,
144 testClassName,
145 testMethodName));
146 }
147 return timeoutInMinutes;
148 }
149
150 /**
151 * Returns the timeout in minutes for the test in the expectation
152 * stores, or 0 if no timeout was found.
153 */
154 public static int timeoutInMinutes(ExpectationStore expectationStore,
155 final String testClassName,
156 final String testMethodName) {
157 if (expectationStore == null) {
158 return 0;
159 }
160 String fullTestName = buildFullTestName(testClassName, testMethodName);
161 return timeoutInMinutes(expectationStore.get(fullTestName));
162 }
163
164 /**
165 * Returns the timeout in minutes for the expectation. Currently a
166 * tag of large results in a 60 minute timeout, otherwise 0 is
167 * returned to indicate a default timeout should be used.
168 */
169 public static int timeoutInMinutes(Expectation expectation) {
170 return expectation.getTags().contains("large") ? 60 : 0;
171 }
Brian Muramatsu7f64e852011-02-17 16:52:16 -0800172}