1 /* 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 17 import com.android.cts.util.AbiUtils; 18 19 import vogar.Expectation; 20 import vogar.ExpectationStore; 21 import vogar.ModeId; 22 23 import java.io.File; 24 import java.io.FilenameFilter; 25 import java.io.IOException; 26 import java.util.Arrays; 27 import java.util.HashSet; 28 import java.util.Set; 29 30 public class VogarUtils { 31 isVogarKnownFailure(ExpectationStore[] expectationStores, final String testClassName, final String testMethodName)32 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 43 /** 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 */ isVogarKnownFailure(ExpectationStore expectationStore, final String testClassName, final String testMethodName)47 public static boolean isVogarKnownFailure(ExpectationStore expectationStore, 48 final String testClassName, 49 final String testMethodName) { 50 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; 63 } 64 provideExpectationStore(String dir)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 getExpectationFiles(String dir)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 } 86 87 /** @return the test name in the form of com.android.myclass.TestClass#testMyMethod */ buildFullTestName(String testClass, String testMethodName)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 */ extractSupportedAbis(String architecture, Expectation expectation)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 */ extractSupportedAbis(String architecture, ExpectationStore[] expectationStores, String className, String testName)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 } 131 } 132