am 05b8357d: Initial checkin for TradeFederation based CTS harness.

Merge commit '05b8357d9c8fe7c09f9711d929ae684b78cef85e' into gingerbread-plus-aosp

* commit '05b8357d9c8fe7c09f9711d929ae684b78cef85e':
  Initial checkin for TradeFederation based CTS harness.
diff --git a/.gitignore b/.gitignore
index 542ab17..ca65e7d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 *.pyc
 *.~*
+bin
diff --git a/tools/tradefed-host/.classpath b/tools/tradefed-host/.classpath
new file mode 100644
index 0000000..67d42b5
--- /dev/null
+++ b/tools/tradefed-host/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/tradefed-prebuilt"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/ddmlib-prebuilt"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tools/tradefed-host/.project b/tools/tradefed-host/.project
new file mode 100644
index 0000000..990c63e
--- /dev/null
+++ b/tools/tradefed-host/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cts-tradefed-host</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/tools/tradefed-host/Android.mk b/tools/tradefed-host/Android.mk
new file mode 100644
index 0000000..a05ed40
--- /dev/null
+++ b/tools/tradefed-host/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# Only compile source java files in this lib.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE := cts-tradefed
+LOCAL_MODULE_TAGS := optional
+LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+# Build all sub-directories
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsBuildHelper.java b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsBuildHelper.java
new file mode 100644
index 0000000..d8aabc5
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsBuildHelper.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.tradefed.targetsetup;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+/**
+ * Helper class for retrieving files from the CTS install.
+ * <p/>
+ * Encapsulates the filesystem layout of the CTS installation.
+ */
+public class CtsBuildHelper {
+
+    static final String CTS_DIR_NAME = "android-cts";
+    /** The root location of the extracted CTS package */
+    private final File mRootDir;
+    /** the {@link CTS_DIR_NAME} directory */
+    private final File mCtsDir;
+
+    /**
+     * Creates a {@link CtsBuildHelper}.
+     *
+     * @param rootDir the parent folder that contains the "android-cts" directory and all its
+     *            contents.
+     * @throws FileNotFoundException if file does not exist
+     */
+    public CtsBuildHelper(File rootDir) throws FileNotFoundException {
+        mRootDir = rootDir;
+        mCtsDir = new File(mRootDir, CTS_DIR_NAME);
+        if (!mCtsDir.exists()) {
+            throw new FileNotFoundException(String.format(
+                    "CTS install folder %s does not exist", mCtsDir.getAbsolutePath()));
+        }
+    }
+
+    /**
+     * @return a {@link File} representing the parent folder of the CTS installation
+     */
+    public File getRootDir() {
+        return mRootDir;
+    }
+
+    /**
+     * @return a {@link File} representing the "android-cts" folder of the CTS installation
+     */
+    public File getCtsDir() {
+        return mCtsDir;
+    }
+
+    /**
+     * @return a {@link File} representing the test application file with given name
+     * @throws FileNotFoundException if file does not exist
+     */
+    public File getTestApp(String appFileName) throws FileNotFoundException {
+        File apkFile = new File(new File(getRepositoryDir(), "testcases"), appFileName);
+        if (!apkFile.exists()) {
+            throw new FileNotFoundException(String.format("CTS test app file %s does not exist",
+                    apkFile.getAbsolutePath()));
+        }
+        return apkFile;
+    }
+
+    private File getRepositoryDir() {
+        return new File(getCtsDir(), "repository");
+    }
+
+    /**
+     * @return a {@link File} representing the test plan file with given name
+     * @throws FileNotFoundException if file does not exist
+     */
+    public File getTestPlan(String testPlanFileName) throws FileNotFoundException {
+        File planFile = new File(new File(getRepositoryDir(), "plans"), testPlanFileName);
+        if (!planFile.exists()) {
+            throw new FileNotFoundException(String.format("CTS test plan file %s does not exist",
+                    planFile.getAbsolutePath()));
+        }
+        return planFile;
+    }
+
+    /**
+     * @return a {@link File} representing the results directory.
+     */
+    public File getResultsDir() {
+        return new File(getRepositoryDir(), "results");
+    }
+}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsBuildProvider.java b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsBuildProvider.java
new file mode 100644
index 0000000..90fb8ba
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsBuildProvider.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.cts.tradefed.targetsetup;
+
+import com.android.tradefed.config.Option;
+import com.android.tradefed.targetsetup.FolderBuildInfo;
+import com.android.tradefed.targetsetup.IBuildInfo;
+import com.android.tradefed.targetsetup.IBuildProvider;
+import com.android.tradefed.targetsetup.IFolderBuildInfo;
+import com.android.tradefed.targetsetup.TargetSetupError;
+
+import java.io.File;
+
+/**
+ * A simple {@link IBuildProvider} that uses a pre-existing CTS install.
+ */
+public class CtsBuildProvider implements IBuildProvider {
+
+    @Option(name="cts-install-path", description="the path to the cts installation to use")
+    private File mCtsRootDir;
+
+    /**
+     * {@inheritDoc}
+     */
+    public IBuildInfo getBuild() throws TargetSetupError {
+        if (mCtsRootDir == null) {
+            throw new IllegalArgumentException("Missing --cts-install-path");
+        }
+        IFolderBuildInfo ctsBuild = new FolderBuildInfo(0, "cts", "cts");
+        ctsBuild.setRootDir(mCtsRootDir);
+        return ctsBuild;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void buildNotTested(IBuildInfo info) {
+        // ignore
+    }
+}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsDeviceSetup.java b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsDeviceSetup.java
new file mode 100644
index 0000000..65f09f3
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsDeviceSetup.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.cts.tradefed.targetsetup;
+
+import com.android.ddmlib.Log;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.targetsetup.BuildError;
+import com.android.tradefed.targetsetup.DeviceSetup;
+import com.android.tradefed.targetsetup.IBuildInfo;
+import com.android.tradefed.targetsetup.IDeviceBuildInfo;
+import com.android.tradefed.targetsetup.IFolderBuildInfo;
+import com.android.tradefed.targetsetup.ITargetPreparer;
+import com.android.tradefed.targetsetup.TargetSetupError;
+
+import java.io.FileNotFoundException;
+
+/**
+ * A {@link ITargetPreparer} that accepts a device and a CTS build (represented as a
+ * {@link IDeviceBuildInfo} and a {@link IFolderBuildInfo} respectively.
+ * <p/>
+ * This class is NOT intended for 'official' CTS runs against a production device as the steps
+ * performed by this class require a debug build (aka 'adb root' must succeed).
+ */
+public class CtsDeviceSetup extends DeviceSetup {
+
+    private static final String LOG_TAG = "CtsDeviceSetup";
+
+    // TODO: read this from a configuration file rather than hard-coding
+    private static final String ACCESSIBILITY_SERVICE_APK_FILE_NAME =
+        "CtsDelegatingAccessibilityService.apk";
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
+            DeviceNotAvailableException, BuildError {
+        // call super class to setup device. This will disable screen guard, etc
+        super.setUp(device, buildInfo);
+
+        if (!(buildInfo instanceof IFolderBuildInfo)) {
+            throw new IllegalArgumentException("Provided buildInfo is not a IFolderBuildInfo");
+        }
+        Log.i(LOG_TAG, String.format("Setting up %s to run CTS tests", device.getSerialNumber()));
+
+        IFolderBuildInfo ctsBuild = (IFolderBuildInfo)buildInfo;
+        try {
+            CtsBuildHelper buildHelper = new CtsBuildHelper(ctsBuild.getRootDir());
+
+            // perform CTS setup steps that only work if adb is root
+
+            // TODO: turn on mock locations
+            CtsSetup ctsSetup = new CtsSetup();
+            enableAccessibilityService(device, buildHelper, ctsSetup);
+
+            // end root setup steps
+
+            // perform CTS setup common with production builds
+            ctsSetup.setUp(device, buildInfo);
+        } catch (FileNotFoundException e) {
+            throw new TargetSetupError("Invalid CTS installation", e);
+        }
+    }
+
+    private void enableAccessibilityService(ITestDevice device, CtsBuildHelper ctsBuild,
+            CtsSetup ctsSetup) throws DeviceNotAvailableException, TargetSetupError,
+            FileNotFoundException {
+        ctsSetup.installApk(device, ctsBuild.getTestApp(ACCESSIBILITY_SERVICE_APK_FILE_NAME));
+        // TODO: enable Settings > Accessibility > Accessibility > Delegating Accessibility
+        // Service
+    }
+}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsSetup.java b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsSetup.java
new file mode 100644
index 0000000..7af703b
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/targetsetup/CtsSetup.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.cts.tradefed.targetsetup;
+
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.targetsetup.BuildError;
+import com.android.tradefed.targetsetup.IBuildInfo;
+import com.android.tradefed.targetsetup.IFolderBuildInfo;
+import com.android.tradefed.targetsetup.ITargetPreparer;
+import com.android.tradefed.targetsetup.TargetSetupError;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+/**
+ * A {@link ITargetPreparer} that sets up a device for CTS testing.
+ * <p/>
+ * All the actions performed in this class must work on a production device.
+ */
+public class CtsSetup implements ITargetPreparer {
+
+    private static final String RUNNER_APK_NAME = "android.core.tests.runner.apk";
+    // TODO: read this from configuration file rather than hardcoding
+    private static final String TEST_STUBS_APK = "CtsTestStubs.apk";
+
+    /**
+     * Factory method to create a {@link CtsBuildHelper}.
+     * <p/>
+     * Exposed for unit testing.
+     */
+    CtsBuildHelper createBuildHelper(File rootDir) throws FileNotFoundException {
+        return new CtsBuildHelper(rootDir);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
+            BuildError, DeviceNotAvailableException {
+        if (!(buildInfo instanceof IFolderBuildInfo)) {
+            throw new IllegalArgumentException("Provided buildInfo is not a IFolderBuildInfo");
+        }
+        IFolderBuildInfo ctsBuildInfo = (IFolderBuildInfo)buildInfo;
+        try {
+            CtsBuildHelper buildHelper = createBuildHelper(ctsBuildInfo.getRootDir());
+            installCtsPrereqs(device, buildHelper);
+            gatherDeviceStats(device, buildHelper);
+        } catch (FileNotFoundException e) {
+            throw new TargetSetupError("Invalid CTS installation", e);
+        }
+    }
+
+    /**
+     * Installs an apkFile on device.
+     *
+     * @param device the {@link ITestDevice}
+     * @param apkFile the apk {@link File}
+     * @throws DeviceNotAvailableException
+     * @throws TargetSetupError if apk cannot be installed successfully
+     */
+    void installApk(ITestDevice device, File apkFile)
+            throws DeviceNotAvailableException, TargetSetupError {
+        String errorCode = device.installPackage(apkFile, true);
+        if (errorCode != null) {
+            // TODO: retry ?
+            throw new TargetSetupError(String.format(
+                    "Failed to install %s on device %s. Reason: %s", apkFile.getName(),
+                    device.getSerialNumber(), errorCode));
+        }
+    }
+
+    /**
+     * Install pre-requisite apks for running tests
+     *
+     * @throws TargetSetupError if the pre-requisite apks fail to install
+     * @throws DeviceNotAvailableException
+     * @throws FileNotFoundException
+     */
+    private void installCtsPrereqs(ITestDevice device, CtsBuildHelper ctsBuild)
+            throws DeviceNotAvailableException, TargetSetupError, FileNotFoundException {
+        installApk(device, ctsBuild.getTestApp(TEST_STUBS_APK));
+        installApk(device, ctsBuild.getTestApp(RUNNER_APK_NAME));
+    }
+
+    private void gatherDeviceStats(ITestDevice device, CtsBuildHelper ctsBuild) {
+        // TODO: implement this
+        // install TestDeviceSetup.apk, run its instrumentation, parse results, store them in the
+        // CtsBuildInfo, then uninstall TestDeviceSetup.apk
+    }
+}
diff --git a/tools/tradefed-host/tests/.classpath b/tools/tradefed-host/tests/.classpath
new file mode 100644
index 0000000..d14e02b
--- /dev/null
+++ b/tools/tradefed-host/tests/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/cts-tradefed-host"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/easymock"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/ddmlib-prebuilt"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/tradefed-prebuilt"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tools/tradefed-host/tests/.project b/tools/tradefed-host/tests/.project
new file mode 100644
index 0000000..1c385d8
--- /dev/null
+++ b/tools/tradefed-host/tests/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cts-tradefed-host-tests</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/tools/tradefed-host/tests/Android.mk b/tools/tradefed-host/tests/Android.mk
new file mode 100644
index 0000000..d3b94cd
--- /dev/null
+++ b/tools/tradefed-host/tests/Android.mk
@@ -0,0 +1,29 @@
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# Only compile source java files in this lib.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE := cts-tradefed-tests
+LOCAL_MODULE_TAGS := optional
+LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt cts-tradefed
+LOCAL_STATIC_JAVA_LIBRARIES := easymock
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+
diff --git a/tools/tradefed-host/tests/src/com/android/cts/tradefed/targetsetup/CtsSetupTest.java b/tools/tradefed-host/tests/src/com/android/cts/tradefed/targetsetup/CtsSetupTest.java
new file mode 100644
index 0000000..932f3dc
--- /dev/null
+++ b/tools/tradefed-host/tests/src/com/android/cts/tradefed/targetsetup/CtsSetupTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.cts.tradefed.targetsetup;
+
+import com.android.ddmlib.Log;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.targetsetup.BuildError;
+import com.android.tradefed.targetsetup.IBuildInfo;
+import com.android.tradefed.targetsetup.IFolderBuildInfo;
+import com.android.tradefed.targetsetup.TargetSetupError;
+
+import org.easymock.EasyMock;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for {@link CtsSetup}.
+ */
+public class CtsSetupTest extends TestCase {
+
+    private static final String LOG_TAG = "CtsSetupTest";
+
+    private CtsSetup mSetup;
+    private ITestDevice mMockDevice;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mSetup = new CtsSetup() {
+            @Override
+            CtsBuildHelper createBuildHelper(File rootDir) {
+                try {
+                    return StubCtsBuildHelper.createStubHelper();
+                } catch (IOException e) {
+                    Log.e(LOG_TAG, e);
+                    fail("failed to create stub helper");
+                    return null;
+                }
+            }
+        };
+        mMockDevice = EasyMock.createMock(ITestDevice.class);
+    }
+
+    /**
+     * Test {@link CtsSetup#setUp(ITestDevice, IBuildInfo)} when provided buildInfo is the incorrect
+     * type
+     */
+    public void testSetUp_wrongBuildInfo() throws TargetSetupError, BuildError,
+            DeviceNotAvailableException {
+        try {
+            mSetup.setUp(mMockDevice, EasyMock.createMock(IBuildInfo.class));
+            fail("IllegalArgumentException not thrown");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test normal case for {@link CtsSetup#setUp(ITestDevice, IBuildInfo)}
+     */
+    public void testSetUp() throws TargetSetupError, BuildError, DeviceNotAvailableException {
+        IFolderBuildInfo ctsBuild = EasyMock.createMock(IFolderBuildInfo.class);
+        EasyMock.expect(ctsBuild.getRootDir()).andReturn(
+                new File("tmp")).anyTimes();
+        EasyMock.expect(ctsBuild.getBuildId()).andStubReturn(0);
+        EasyMock.expect(
+                mMockDevice.installPackage((File)EasyMock.anyObject(), EasyMock.anyBoolean()))
+                .andReturn(null)
+                .anyTimes();
+        EasyMock.replay(ctsBuild, mMockDevice);
+        mSetup.setUp(mMockDevice, ctsBuild);
+    }
+}
diff --git a/tools/tradefed-host/tests/src/com/android/cts/tradefed/targetsetup/StubCtsBuildHelper.java b/tools/tradefed-host/tests/src/com/android/cts/tradefed/targetsetup/StubCtsBuildHelper.java
new file mode 100644
index 0000000..f17bd5a
--- /dev/null
+++ b/tools/tradefed-host/tests/src/com/android/cts/tradefed/targetsetup/StubCtsBuildHelper.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.cts.tradefed.targetsetup;
+
+import com.android.tradefed.util.FileUtil;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * Stub implementation of CtsBuildHelper that returns empty files for all methods
+ */
+public class StubCtsBuildHelper extends CtsBuildHelper {
+
+    public static StubCtsBuildHelper createStubHelper() throws IOException {
+        File tmpFolder= FileUtil.createTempDir("ctstmp");
+        File ctsinstall = new File(tmpFolder, CtsBuildHelper.CTS_DIR_NAME);
+        ctsinstall.mkdirs();
+        return new StubCtsBuildHelper(tmpFolder);
+    }
+
+    private StubCtsBuildHelper(File rootDir) throws FileNotFoundException {
+        super(rootDir);
+    }
+
+    @Override
+    public File getTestApp(String appFileName) throws FileNotFoundException {
+        return new File("tmp");
+    }
+
+    @Override
+    public File getTestPlan(String testPlanFileName) throws FileNotFoundException {
+        return new File("tmp");
+    }
+}