diff options
-rw-r--r-- | src/com/android/tradefed/util/AbiUtils.java | 18 | ||||
-rw-r--r-- | tests/src/com/android/tradefed/util/AbiUtilsTest.java | 27 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/com/android/tradefed/util/AbiUtils.java b/src/com/android/tradefed/util/AbiUtils.java index 03607f138..693ff5536 100644 --- a/src/com/android/tradefed/util/AbiUtils.java +++ b/src/com/android/tradefed/util/AbiUtils.java @@ -78,6 +78,8 @@ public class AbiUtils { private static final Map<String, String> ABI_TO_ARCH = new HashMap<String, String>(); + private static final Map<String, String> ABI_TO_BASE_ARCH = new HashMap<String, String>(); + static { ABIS_32BIT.add(ABI_ARM_V7A); ABIS_32BIT.add(ABI_X86); @@ -113,6 +115,13 @@ public class AbiUtils { ABI_TO_ARCH.put(ABI_X86_64, ARCH_X86_64); ABI_TO_ARCH.put(ABI_MIPS, BASE_ARCH_MIPS); ABI_TO_ARCH.put(ABI_MIPS64, ARCH_MIPS64); + + ABI_TO_BASE_ARCH.put(ABI_ARM_V7A, BASE_ARCH_ARM); + ABI_TO_BASE_ARCH.put(ABI_ARM_64_V8A, BASE_ARCH_ARM); + ABI_TO_BASE_ARCH.put(ABI_X86, BASE_ARCH_X86); + ABI_TO_BASE_ARCH.put(ABI_X86_64, BASE_ARCH_X86); + ABI_TO_BASE_ARCH.put(ABI_MIPS, BASE_ARCH_MIPS); + ABI_TO_BASE_ARCH.put(ABI_MIPS64, BASE_ARCH_MIPS); } /** @@ -142,8 +151,17 @@ public class AbiUtils { return ABI_TO_ARCH.get(abi); } + /** Returns the base architecture matching the abi. */ + public static String getBaseArchForAbi(String abi) { + if (abi == null || abi.isEmpty()) { + throw new IllegalArgumentException("Abi cannot be null or empty"); + } + return ABI_TO_BASE_ARCH.get(abi); + } + /** * Returns the set of ABIs supported by Compatibility. + * * @return a new Set containing the supported ABIs. */ public static Set<String> getAbisSupportedByCompatibility() { diff --git a/tests/src/com/android/tradefed/util/AbiUtilsTest.java b/tests/src/com/android/tradefed/util/AbiUtilsTest.java index b5e3652d3..b93208e2c 100644 --- a/tests/src/com/android/tradefed/util/AbiUtilsTest.java +++ b/tests/src/com/android/tradefed/util/AbiUtilsTest.java @@ -122,6 +122,33 @@ public class AbiUtilsTest { } @Test + public void getBaseArchForAbi_emptyNull() { + try { + AbiUtils.getBaseArchForAbi(null); + Assert.fail("Should have thrown an exception"); + } catch (IllegalArgumentException expected) { + Assert.assertEquals("Abi cannot be null or empty", expected.getMessage()); + } + try { + AbiUtils.getBaseArchForAbi(""); + Assert.fail("Should have thrown an exception"); + } catch (IllegalArgumentException expected) { + Assert.assertEquals("Abi cannot be null or empty", expected.getMessage()); + } + } + + @Test + public void getBaseArchForAbi() { + assertEquals(AbiUtils.BASE_ARCH_ARM, AbiUtils.getBaseArchForAbi(AbiUtils.ABI_ARM_V7A)); + assertEquals(AbiUtils.BASE_ARCH_ARM, AbiUtils.getBaseArchForAbi(AbiUtils.ABI_ARM_64_V8A)); + assertEquals(AbiUtils.BASE_ARCH_X86, AbiUtils.getBaseArchForAbi(AbiUtils.ABI_X86)); + assertEquals(AbiUtils.BASE_ARCH_X86, AbiUtils.getBaseArchForAbi(AbiUtils.ABI_X86_64)); + assertEquals(AbiUtils.BASE_ARCH_MIPS, AbiUtils.getBaseArchForAbi(AbiUtils.ABI_MIPS)); + assertEquals(AbiUtils.BASE_ARCH_MIPS, AbiUtils.getBaseArchForAbi(AbiUtils.ABI_MIPS64)); + } + + + @Test public void testParseFromProperty() { Set<String> abiSet = new HashSet<>(); abiSet.add("arm64-v8a"); |