1 /* 2 * Copyright (C) 2018 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 com.android.tradefed.testtype.suite.module; 17 18 import com.android.tradefed.device.DeviceNotAvailableException; 19 import com.android.tradefed.device.ITestDevice; 20 import com.android.tradefed.device.StubDevice; 21 import com.android.tradefed.invoker.IInvocationContext; 22 import com.android.tradefed.log.LogUtil.CLog; 23 import com.android.tradefed.testtype.IAbi; 24 import com.android.tradefed.util.AbiFormatter; 25 import com.android.tradefed.util.AbiUtils; 26 27 /** 28 * A module controller to check if a device support native bridge. If it does support it and we 29 * detect a native bridge situation the module will be skipped. 30 */ 31 public class NativeBridgeModuleController extends BaseModuleController { 32 33 public static final String NATIVE_BRIDGE_PROP = "ro.dalvik.vm.native.bridge"; 34 35 @Override shouldRun(IInvocationContext context)36 public RunStrategy shouldRun(IInvocationContext context) { 37 for (ITestDevice device : context.getDevices()) { 38 if (device.getIDevice() instanceof StubDevice) { 39 continue; 40 } 41 try { 42 String bridge = device.getProperty(NATIVE_BRIDGE_PROP); 43 if ("0".equals(bridge.trim())) { 44 continue; 45 } 46 IAbi moduleAbi = getModuleAbi(); 47 String moduleArch = AbiUtils.getBaseArchForAbi(moduleAbi.getName()); 48 49 String primaryAbiString = AbiFormatter.getDefaultAbi(device, ""); 50 String deviceArch = AbiUtils.getBaseArchForAbi(primaryAbiString.trim()); 51 if (deviceArch.equals(moduleArch)) { 52 continue; 53 } 54 // If the current architecture of the module does not match the primary architecture 55 // of the device then we are in a native bridge situation and should skip the module 56 CLog.d( 57 "Skipping module %s to avoid running the tests against the native bridge.", 58 getModuleName()); 59 return RunStrategy.FULL_MODULE_BYPASS; 60 } catch (DeviceNotAvailableException e) { 61 CLog.e("Couldn't check native bridge on %s", device.getSerialNumber()); 62 CLog.e(e); 63 } 64 } 65 return RunStrategy.RUN; 66 } 67 } 68