blob: 5e8b9442957738f90d045ab1853582ad032a92ff [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
Stuart Scott01c2b492014-10-08 18:07:28 -070017import com.android.cts.util.AbiUtils;
18
Brian Muramatsu7f64e852011-02-17 16:52:16 -080019import vogar.Expectation;
20import vogar.ExpectationStore;
21import vogar.ModeId;
22
23import java.io.File;
24import java.io.FilenameFilter;
25import java.io.IOException;
26import java.util.Arrays;
27import java.util.HashSet;
28import java.util.Set;
29
30public class VogarUtils {
31
Brian Carlstrom022aff42011-05-17 23:16:51 -070032 public static boolean isVogarKnownFailure(ExpectationStore[] expectationStores,
33 final String testClassName,
34 final String testMethodName) {
35 for (ExpectationStore expectationStore : expectationStores) {
36 if (isVogarKnownFailure(expectationStore, testClassName, testMethodName)) {
37 return true;
38 }
39 }
40 return false;
41 }
42
Stuart Scott01c2b492014-10-08 18:07:28 -070043 /**
44 * @return true iff the class/name is found in the vogar known failure list and it is not
45 * a known failure that is a result of an unsupported abi.
46 */
Brian Muramatsu7f64e852011-02-17 16:52:16 -080047 public static boolean isVogarKnownFailure(ExpectationStore expectationStore,
48 final String testClassName,
49 final String testMethodName) {
Stuart Scott01c2b492014-10-08 18:07:28 -070050 if (expectationStore == null) {
51 return false;
52 }
53 String fullTestName = buildFullTestName(testClassName, testMethodName);
54 Expectation expectation = expectationStore.get(fullTestName);
55 if (expectation == Expectation.SUCCESS) {
56 return false;
57 }
58
59 String description = expectation.getDescription();
60 boolean foundAbi = AbiUtils.parseAbiList(description).size() > 0;
61
62 return expectation != Expectation.SUCCESS && !foundAbi;
Brian Muramatsu7f64e852011-02-17 16:52:16 -080063 }
64
65 public static ExpectationStore provideExpectationStore(String dir) throws IOException {
66 if (dir == null) {
67 return null;
68 }
69 ExpectationStore result = ExpectationStore.parse(getExpectationFiles(dir), ModeId.DEVICE);
70 return result;
71 }
72
73 private static Set<File> getExpectationFiles(String dir) {
74 Set<File> expectSet = new HashSet<File>();
75 File[] files = new File(dir).listFiles(new FilenameFilter() {
76 // ignore obviously temporary files
77 public boolean accept(File dir, String name) {
78 return !name.endsWith("~") && !name.startsWith(".");
79 }
80 });
81 if (files != null) {
82 expectSet.addAll(Arrays.asList(files));
83 }
84 return expectSet;
85 }
Stuart Scott01c2b492014-10-08 18:07:28 -070086
87 /** @return the test name in the form of com.android.myclass.TestClass#testMyMethod */
88 public static String buildFullTestName(String testClass, String testMethodName) {
89 return String.format("%s#%s", testClass, testMethodName);
90 }
91
92 /**
93 * This method looks in the description field of the Vogar entry for the ABI_LIST_MARKER
94 * and returns the list of abis found there.
95 *
96 * @return The Set of supported abis parsed from the {@code expectation}'s description.
97 */
98 public static Set<String> extractSupportedAbis(String architecture, Expectation expectation) {
99 Set<String> supportedAbiSet = AbiUtils.getAbisForArch(architecture);
100 if (expectation == null || expectation.getDescription().isEmpty()) {
101 // Include all abis since there was no limitation found in the description
102 return supportedAbiSet;
103 }
104
105 // Remove any abis that are not supported for the test.
106 supportedAbiSet.removeAll(AbiUtils.parseAbiList(expectation.getDescription()));
107
108 return supportedAbiSet;
109 }
110
111 /**
112 * Determine the correct set of ABIs for the given className/testName.
113 *
114 * @return the set of ABIs that can be expected to pass for the given combination of
115 * {@code architecture}, {@code className} and {@code testName}.
116 */
117 public static Set<String> extractSupportedAbis(String architecture,
118 ExpectationStore[] expectationStores,
119 String className,
120 String testName) {
121
122 String fullTestName = VogarUtils.buildFullTestName(className, testName);
123 Set<String> supportedAbiSet = AbiUtils.getAbisForArch(architecture);
124 for (ExpectationStore expectationStore : expectationStores) {
125 Expectation expectation = expectationStore.get(fullTestName);
126 supportedAbiSet.retainAll(extractSupportedAbis(architecture, expectation));
127 }
128
129 return supportedAbiSet;
130 }
Brian Muramatsu7f64e852011-02-17 16:52:16 -0800131}