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 package com.android.framework.tests; 18 19 import com.android.tradefed.build.IBuildInfo; 20 import com.android.tradefed.build.IDeviceBuildInfo; 21 import com.android.tradefed.config.ConfigurationException; 22 import com.android.tradefed.config.IConfiguration; 23 import com.android.tradefed.config.IConfigurationReceiver; 24 import com.android.tradefed.config.Option; 25 import com.android.tradefed.device.DeviceNotAvailableException; 26 import com.android.tradefed.device.ITestDevice; 27 import com.android.tradefed.targetprep.BaseTargetPreparer; 28 import com.android.tradefed.targetprep.BuildError; 29 import com.android.tradefed.targetprep.TargetSetupError; 30 import com.android.tradefed.util.FileUtil; 31 32 import java.io.File; 33 34 /** 35 * A ITargetPreparer that forwards the location of the tests/data/app dir from the {@link 36 * IDeviceBuildInfo} as an {@link Option}. 37 */ 38 public class TestDirForwarder extends BaseTargetPreparer implements IConfigurationReceiver { 39 40 private IConfiguration mConfig = null; 41 42 /** {@inheritDoc} */ 43 @Override setUp(ITestDevice device, IBuildInfo buildInfo)44 public void setUp(ITestDevice device, IBuildInfo buildInfo) 45 throws TargetSetupError, BuildError, DeviceNotAvailableException { 46 if (!(buildInfo instanceof IDeviceBuildInfo)) { 47 throw new IllegalArgumentException("buildInfo is not a IDeviceBuildInfo"); 48 } 49 if (mConfig == null) { 50 // should never happen 51 throw new IllegalArgumentException("missing config"); 52 } 53 IDeviceBuildInfo deviceBuild = (IDeviceBuildInfo) buildInfo; 54 File testAppDir = FileUtil.getFileForPath(deviceBuild.getTestsDir(), "DATA", "app"); 55 // option with name test-app-path must exist! 56 try { 57 mConfig.injectOptionValue("test-app-path", testAppDir.getAbsolutePath()); 58 } catch (ConfigurationException e) { 59 throw new TargetSetupError( 60 "Mis-configuration: no object which consumes test-app-path " + "option", 61 e, 62 device.getDeviceDescriptor()); 63 } 64 } 65 66 /** {@inheritDoc} */ 67 @Override setConfiguration(IConfiguration config)68 public void setConfiguration(IConfiguration config) { 69 mConfig = config; 70 } 71 } 72