Remove special runner in print tests
* use UiAutomation#executeShellCommand to replace calls in
special test runner
* remove print test type & special harness since the test is now
a regular instrumentation test
Bug: 19125024
Change-Id: I99ae800ab147fec9a49d1ca15662272f39b21235
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 9f594df..8d79b6f 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -203,9 +203,6 @@
CtsDeviceJank \
CtsPrintInstrument
-cts_device_executables := \
- print-instrument
-
cts_target_junit_tests := \
CtsJdwp
diff --git a/tests/print/Android.mk b/tests/print/Android.mk
deleted file mode 100644
index fea7dc0..0000000
--- a/tests/print/Android.mk
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2014 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)
-
-##################################################
-# Build the print instrument library
-##################################################
-include $(CLEAR_VARS)
-LOCAL_MODULE := CtsPrintInstrument
-LOCAL_SRC_FILES := $(call all-subdir-java-files) \
- src/android/print/cts/IPrivilegedOperations.aidl
-LOCAL_MODULE_TAGS := optional
-LOCAL_DEX_PREOPT := false
-
-include $(BUILD_JAVA_LIBRARY)
-
-# Copy the shell script to run the print instrument Jar to the CTS out folder.
-$(CTS_TESTCASES_OUT)/$(LOCAL_MODULE).jar : $(LOCAL_BUILT_MODULE) | $(ACP)
- $(copy-file-to-target)
-
-# Copy the built print instrument library Jar to the CTS out folder.
-$(CTS_TESTCASES_OUT)/print-instrument : $(LOCAL_PATH)/print-instrument | $(ACP)
- $(copy-file-to-target)
-
diff --git a/tests/print/print-instrument b/tests/print/print-instrument
deleted file mode 100755
index a79cb8a..0000000
--- a/tests/print/print-instrument
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2014 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.
-
-# Script to start "print-instrument" on the device
-#
-# The script sets up an alternative dalvik cache when running as
-# non-root. Jar files needs to be dexopt'd to run in Dalvik. For
-# plain jar files, this is done at first use. shell user does not
-# have write permission to default system Dalvik cache so we
-# redirect to an alternative cache.
-
-RUN_BASE=/data/local/tmp
-
-# If not running as root, use an alternative dex cache.
-if [ ${USER_ID} -ne 0 ]; then
- tmp_cache=${RUN_BASE}/dalvik-cache
- if [ ! -d ${tmp_cache} ]; then
- mkdir -p ${tmp_cache}
- fi
- export ANDROID_DATA=${RUN_BASE}
-fi
-
-# Run print-instrument.
-export CLASSPATH=${RUN_BASE}/CtsPrintInstrument.jar
-
-exec app_process ${RUN_BASE} android.print.cts.PrintInstrument ${@}
diff --git a/tests/print/src/android/print/cts/IPrivilegedOperations.aidl b/tests/print/src/android/print/cts/IPrivilegedOperations.aidl
deleted file mode 100644
index 93c8c3e..0000000
--- a/tests/print/src/android/print/cts/IPrivilegedOperations.aidl
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2014 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 android.print.cts;
-
-interface IPrivilegedOperations {
- boolean clearApplicationUserData(String packageName);
-}
diff --git a/tests/print/src/android/print/cts/PrintInstrument.java b/tests/print/src/android/print/cts/PrintInstrument.java
deleted file mode 100644
index 1c568a1..0000000
--- a/tests/print/src/android/print/cts/PrintInstrument.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright (C) 2014 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 android.print.cts;
-
-import android.app.ActivityManagerNative;
-import android.app.IActivityManager;
-import android.app.IInstrumentationWatcher;
-import android.app.Instrumentation;
-import android.app.UiAutomationConnection;
-import android.content.ComponentName;
-import android.content.pm.IPackageDataObserver;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.util.AndroidException;
-import android.view.IWindowManager;
-
-import com.android.internal.os.BaseCommand;
-
-import java.io.PrintStream;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-public final class PrintInstrument extends BaseCommand {
-
- private static final String ARG_PRIVILEGED_OPS = "ARG_PRIVILEGED_OPS";
-
- private IActivityManager mAm;
-
- public static void main(String[] args) {
- PrintInstrument instrumenter = new PrintInstrument();
- instrumenter.run(args);
- }
-
- @Override
- public void onRun() throws Exception {
- mAm = ActivityManagerNative.getDefault();
- if (mAm == null) {
- System.err.println(NO_SYSTEM_ERROR_CODE);
- throw new AndroidException("Can't connect to activity manager;"
- + " is the system running?");
- }
-
- String op = nextArgRequired();
-
- if (op.equals("instrument")) {
- runInstrument();
- } else {
- showError("Error: unknown command '" + op + "'");
- }
- }
-
- @Override
- public void onShowUsage(PrintStream out) {
- /* do nothing */
- }
-
- @SuppressWarnings("deprecation")
- private void runInstrument() throws Exception {
- String profileFile = null;
- boolean wait = false;
- boolean rawMode = false;
- boolean no_window_animation = false;
- int userId = UserHandle.USER_CURRENT;
- Bundle args = new Bundle();
- String argKey = null, argValue = null;
- IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
-
- String opt;
- while ((opt=nextOption()) != null) {
- if (opt.equals("-p")) {
- profileFile = nextArgRequired();
- } else if (opt.equals("-w")) {
- wait = true;
- } else if (opt.equals("-r")) {
- rawMode = true;
- } else if (opt.equals("-e")) {
- argKey = nextArgRequired();
- argValue = nextArgRequired();
- args.putString(argKey, argValue);
- } else if (opt.equals("--no_window_animation")
- || opt.equals("--no-window-animation")) {
- no_window_animation = true;
- } else if (opt.equals("--user")) {
- userId = parseUserArg(nextArgRequired());
- } else {
- System.err.println("Error: Unknown option: " + opt);
- return;
- }
- }
-
- if (userId == UserHandle.USER_ALL) {
- System.err.println("Error: Can't start instrumentation with user 'all'");
- return;
- }
-
- String cnArg = nextArgRequired();
- ComponentName cn = ComponentName.unflattenFromString(cnArg);
- if (cn == null) throw new IllegalArgumentException("Bad component name: " + cnArg);
-
- InstrumentationWatcher watcher = null;
- UiAutomationConnection connection = null;
- if (wait) {
- watcher = new InstrumentationWatcher();
- watcher.setRawOutput(rawMode);
- connection = new UiAutomationConnection();
- }
-
- float[] oldAnims = null;
- if (no_window_animation) {
- oldAnims = wm.getAnimationScales();
- wm.setAnimationScale(0, 0.0f);
- wm.setAnimationScale(1, 0.0f);
- }
-
- args.putIBinder(ARG_PRIVILEGED_OPS, new PrivilegedOperations(mAm));
-
- if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId, null)) {
- throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
- }
-
- if (watcher != null) {
- if (!watcher.waitForFinish()) {
- System.out.println("INSTRUMENTATION_ABORTED: System has crashed.");
- }
- }
-
- if (oldAnims != null) {
- wm.setAnimationScales(oldAnims);
- }
- }
-
- private int parseUserArg(String arg) {
- int userId;
- if ("all".equals(arg)) {
- userId = UserHandle.USER_ALL;
- } else if ("current".equals(arg) || "cur".equals(arg)) {
- userId = UserHandle.USER_CURRENT;
- } else {
- userId = Integer.parseInt(arg);
- }
- return userId;
- }
-
- private class InstrumentationWatcher extends IInstrumentationWatcher.Stub {
- private boolean mFinished = false;
- private boolean mRawMode = false;
-
- /**
- * Set or reset "raw mode". In "raw mode", all bundles are dumped. In "pretty mode",
- * if a bundle includes Instrumentation.REPORT_KEY_STREAMRESULT, just print that.
- * @param rawMode true for raw mode, false for pretty mode.
- */
- public void setRawOutput(boolean rawMode) {
- mRawMode = rawMode;
- }
-
- @Override
- public void instrumentationStatus(ComponentName name, int resultCode, Bundle results) {
- synchronized (this) {
- // pretty printer mode?
- String pretty = null;
- if (!mRawMode && results != null) {
- pretty = results.getString(Instrumentation.REPORT_KEY_STREAMRESULT);
- }
- if (pretty != null) {
- System.out.print(pretty);
- } else {
- if (results != null) {
- for (String key : results.keySet()) {
- System.out.println(
- "INSTRUMENTATION_STATUS: " + key + "=" + results.get(key));
- }
- }
- System.out.println("INSTRUMENTATION_STATUS_CODE: " + resultCode);
- }
- notifyAll();
- }
- }
-
- @Override
- public void instrumentationFinished(ComponentName name, int resultCode,
- Bundle results) {
- synchronized (this) {
- // pretty printer mode?
- String pretty = null;
- if (!mRawMode && results != null) {
- pretty = results.getString(Instrumentation.REPORT_KEY_STREAMRESULT);
- }
- if (pretty != null) {
- System.out.println(pretty);
- } else {
- if (results != null) {
- for (String key : results.keySet()) {
- System.out.println(
- "INSTRUMENTATION_RESULT: " + key + "=" + results.get(key));
- }
- }
- System.out.println("INSTRUMENTATION_CODE: " + resultCode);
- }
- mFinished = true;
- notifyAll();
- }
- }
-
- public boolean waitForFinish() {
- synchronized (this) {
- while (!mFinished) {
- try {
- if (!mAm.asBinder().pingBinder()) {
- return false;
- }
- wait(1000);
- } catch (InterruptedException e) {
- throw new IllegalStateException(e);
- }
- }
- }
- return true;
- }
- }
-
- private static final class PrivilegedOperations extends IPrivilegedOperations.Stub {
- private final IActivityManager mAm;
-
- public PrivilegedOperations(IActivityManager am) {
- mAm = am;
- }
-
- @Override
- public boolean clearApplicationUserData(final String clearedPackageName)
- throws RemoteException {
- final long identity = Binder.clearCallingIdentity();
- try {
- final AtomicBoolean success = new AtomicBoolean();
- final CountDownLatch completionLatch = new CountDownLatch(1);
-
- mAm.clearApplicationUserData(clearedPackageName,
- new IPackageDataObserver.Stub() {
- @Override
- public void onRemoveCompleted(String packageName, boolean succeeded) {
- if (clearedPackageName.equals(packageName) && succeeded) {
- success.set(true);
- } else {
- success.set(false);
- }
- completionLatch.countDown();
- }
- }, UserHandle.USER_CURRENT);
-
- try {
- completionLatch.await();
- } catch (InterruptedException ie) {
- /* ignore */
- }
-
- return success.get();
- } finally {
- Binder.restoreCallingIdentity(identity);
- }
- }
- }
-}
diff --git a/tests/tests/print/Android.mk b/tests/tests/print/Android.mk
index 516f6a0..d50c307 100644
--- a/tests/tests/print/Android.mk
+++ b/tests/tests/print/Android.mk
@@ -18,16 +18,12 @@
LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(call all-java-files-under, src) \
- src/android/print/cts/IPrivilegedOperations.aidl
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := CtsPrintTestCases
LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ctstestrunner ub-uiautomator
-# This test runner sets up/cleans up the device before/after running the tests.
-LOCAL_CTS_TEST_RUNNER := com.android.cts.tradefed.testtype.PrintTestRunner
-
LOCAL_SDK_VERSION := current
include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/print/src/android/print/cts/BasePrintTest.java b/tests/tests/print/src/android/print/cts/BasePrintTest.java
index c73bb64..2d3a573 100644
--- a/tests/tests/print/src/android/print/cts/BasePrintTest.java
+++ b/tests/tests/print/src/android/print/cts/BasePrintTest.java
@@ -60,6 +60,7 @@
import org.mockito.stubbing.Answer;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
@@ -73,12 +74,12 @@
private static final long OPERATION_TIMEOUT = 100000000;
- private static final String ARG_PRIVILEGED_OPS = "ARG_PRIVILEGED_OPS";
-
private static final String PRINT_SPOOLER_PACKAGE_NAME = "com.android.printspooler";
protected static final String PRINT_JOB_NAME = "Test";
+ private static final String PM_CLEAR_SUCCESS_OUTPUT = "Success";
+
private PrintDocumentActivity mActivity;
private Locale mOldLocale;
@@ -94,6 +95,7 @@
public void setUp() throws Exception {
// Make sure we start with a clean slate.
clearPrintSpoolerData();
+ enablePrintServices();
// Workaround for dexmaker bug: https://code.google.com/p/dexmaker/issues/detail?id=2
// Dexmaker is used by mockito.
@@ -139,6 +141,7 @@
resources.updateConfiguration(newConfiguration, displayMetrics);
}
+ disablePrintServices();
// Make sure the spooler is cleaned.
clearPrintSpoolerData();
}
@@ -306,9 +309,34 @@
}
protected void clearPrintSpoolerData() throws Exception {
- IPrivilegedOperations privilegedOps = IPrivilegedOperations.Stub.asInterface(
- getParams().getBinder(ARG_PRIVILEGED_OPS));
- privilegedOps.clearApplicationUserData(PRINT_SPOOLER_PACKAGE_NAME);
+ assertTrue("failed to clear print spooler data",
+ runShellCommand(String.format("pm clear %s", PRINT_SPOOLER_PACKAGE_NAME))
+ .contains(PM_CLEAR_SUCCESS_OUTPUT));
+ }
+
+ protected String runShellCommand(String cmd) throws Exception {
+ ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation().executeShellCommand(cmd);
+ byte[] buf = new byte[512];
+ int bytesRead;
+ FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
+ StringBuffer stdout = new StringBuffer();
+ while ((bytesRead = fis.read(buf)) != -1) {
+ stdout.append(new String(buf, 0, bytesRead));
+ }
+ fis.close();
+ return stdout.toString();
+ }
+
+ private void enablePrintServices() throws Exception {
+ String pkgName = getInstrumentation().getContext().getPackageName();
+ String enabledServicesValue = String.format("%s/%s:%s/%s",
+ pkgName, FirstPrintService.class.getCanonicalName(),
+ pkgName, SecondPrintService.class.getCanonicalName());
+ runShellCommand("settings put secure enabled_print_services " + enabledServicesValue);
+ }
+
+ private void disablePrintServices() throws Exception {
+ runShellCommand("settings put secure enabled_print_services \"\"");
}
protected void verifyLayoutCall(InOrder inOrder, PrintDocumentAdapter mock,
diff --git a/tests/tests/print/src/android/print/cts/IPrivilegedOperations.aidl b/tests/tests/print/src/android/print/cts/IPrivilegedOperations.aidl
deleted file mode 100644
index 93c8c3e..0000000
--- a/tests/tests/print/src/android/print/cts/IPrivilegedOperations.aidl
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2014 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 android.print.cts;
-
-interface IPrivilegedOperations {
- boolean clearApplicationUserData(String packageName);
-}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/PrintTestRemoteTestRunner.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/PrintTestRemoteTestRunner.java
deleted file mode 100644
index 8c43031..0000000
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/PrintTestRemoteTestRunner.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright (C) 2014 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.testtype;
-
-import com.android.ddmlib.AdbCommandRejectedException;
-import com.android.ddmlib.IShellEnabledDevice;
-import com.android.ddmlib.Log;
-import com.android.ddmlib.ShellCommandUnresponsiveException;
-import com.android.ddmlib.TimeoutException;
-import com.android.ddmlib.testrunner.IRemoteAndroidTestRunner;
-import com.android.ddmlib.testrunner.ITestRunListener;
-import com.android.ddmlib.testrunner.InstrumentationResultParser;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.TimeUnit;
-
-public class PrintTestRemoteTestRunner implements IRemoteAndroidTestRunner {
-
- private final String mPackageName;
- private final String mRunnerName;
- private IShellEnabledDevice mRemoteDevice;
- // default to no timeout
- private long mMaxTimeToOutputResponse = 0;
- private TimeUnit mMaxTimeUnits = TimeUnit.MILLISECONDS;
- private String mRunName = null;
-
- /** map of name-value instrumentation argument pairs */
- private Map<String, String> mArgMap;
- private InstrumentationResultParser mParser;
-
- private static final String LOG_TAG = "RemoteAndroidTest";
- private static final String DEFAULT_RUNNER_NAME = "android.test.InstrumentationTestRunner";
-
- private static final char CLASS_SEPARATOR = ',';
- private static final char METHOD_SEPARATOR = '#';
- private static final char RUNNER_SEPARATOR = '/';
-
- // defined instrumentation argument names
- private static final String CLASS_ARG_NAME = "class";
- private static final String LOG_ARG_NAME = "log";
- private static final String DEBUG_ARG_NAME = "debug";
- private static final String COVERAGE_ARG_NAME = "coverage";
- private static final String PACKAGE_ARG_NAME = "package";
- private static final String SIZE_ARG_NAME = "size";
-
- // This command starts a shell Java program (installed by this class)
- // in the folder owned by the shell user. This app creates a proxy
- // which does privileged operations such as wiping a package's user
- // data and then starts the tests passing the proxy. This enables
- // the tests to clear the print spooler data.
- private static final String INSTRUMENTATION_COMMAND =
- "chmod 755 /data/local/tmp/print-instrument && "
- + "/data/local/tmp/print-instrument instrument -w -r %1$s %2$s";
-
- /**
- * Creates a remote Android test runner.
- *
- * @param packageName the Android application package that contains the
- * tests to run
- * @param runnerName the instrumentation test runner to execute. If null,
- * will use default runner
- * @param remoteDevice the Android device to execute tests on
- */
- public PrintTestRemoteTestRunner(String packageName, String runnerName,
- IShellEnabledDevice remoteDevice) {
-
- mPackageName = packageName;
- mRunnerName = runnerName;
- mRemoteDevice = remoteDevice;
- mArgMap = new Hashtable<String, String>();
- }
-
- /**
- * Alternate constructor. Uses default instrumentation runner.
- *
- * @param packageName the Android application package that contains the
- * tests to run
- * @param remoteDevice the Android device to execute tests on
- */
- public PrintTestRemoteTestRunner(String packageName, IShellEnabledDevice remoteDevice) {
- this(packageName, null, remoteDevice);
- }
-
- @Override
- public String getPackageName() {
- return mPackageName;
- }
-
- @Override
- public String getRunnerName() {
- if (mRunnerName == null) {
- return DEFAULT_RUNNER_NAME;
- }
- return mRunnerName;
- }
-
- /**
- * Returns the complete instrumentation component path.
- */
- private String getRunnerPath() {
- return getPackageName() + RUNNER_SEPARATOR + getRunnerName();
- }
-
- @Override
- public void setClassName(String className) {
- addInstrumentationArg(CLASS_ARG_NAME, className);
- }
-
- @Override
- public void setClassNames(String[] classNames) {
- StringBuilder classArgBuilder = new StringBuilder();
-
- for (int i = 0; i < classNames.length; i++) {
- if (i != 0) {
- classArgBuilder.append(CLASS_SEPARATOR);
- }
- classArgBuilder.append(classNames[i]);
- }
- setClassName(classArgBuilder.toString());
- }
-
- @Override
- public void setMethodName(String className, String testName) {
- setClassName(className + METHOD_SEPARATOR + testName);
- }
-
- @Override
- public void setTestPackageName(String packageName) {
- addInstrumentationArg(PACKAGE_ARG_NAME, packageName);
- }
-
- @Override
- public void addInstrumentationArg(String name, String value) {
- if (name == null || value == null) {
- throw new IllegalArgumentException("name or value arguments cannot be null");
- }
- mArgMap.put(name, value);
- }
-
- @Override
- public void removeInstrumentationArg(String name) {
- if (name == null) {
- throw new IllegalArgumentException("name argument cannot be null");
- }
- mArgMap.remove(name);
- }
-
- @Override
- public void addBooleanArg(String name, boolean value) {
- addInstrumentationArg(name, Boolean.toString(value));
- }
-
- @Override
- public void setLogOnly(boolean logOnly) {
- addBooleanArg(LOG_ARG_NAME, logOnly);
- }
-
- @Override
- public void setDebug(boolean debug) {
- addBooleanArg(DEBUG_ARG_NAME, debug);
- }
-
- @Override
- public void setCoverage(boolean coverage) {
- addBooleanArg(COVERAGE_ARG_NAME, coverage);
- }
-
- public void setTestCollection(boolean b) {
- throw new UnsupportedOperationException("Test Collection mode is not supported");
- }
-
- @Override
- public void setTestSize(TestSize size) {
- addInstrumentationArg(SIZE_ARG_NAME, ""/*size.getRunnerValue()*/);
- }
-
- @Override
- public void setMaxtimeToOutputResponse(int maxTimeToOutputResponse) {
- setMaxTimeToOutputResponse(maxTimeToOutputResponse, TimeUnit.MILLISECONDS);
- }
-
- @Override
- public void setMaxTimeToOutputResponse(long maxTimeToOutputResponse, TimeUnit maxTimeUnits) {
- mMaxTimeToOutputResponse = maxTimeToOutputResponse;
- mMaxTimeUnits = maxTimeUnits;
- }
-
- @Override
- public void setRunName(String runName) {
- mRunName = runName;
- }
-
- @Override
- public void run(ITestRunListener... listeners) throws TimeoutException,
- AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
- run(Arrays.asList(listeners));
- }
-
- @Override
- public void run(Collection<ITestRunListener> listeners) throws TimeoutException,
- AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
- final String runCaseCommandStr = String.format(INSTRUMENTATION_COMMAND,
- getArgsCommand(), getRunnerPath());
- Log.i(LOG_TAG,
- String.format("Running %1$s on %2$s", runCaseCommandStr, mRemoteDevice.getName()));
- String runName = mRunName == null ? mPackageName : mRunName;
- mParser = new InstrumentationResultParser(runName, listeners);
-
- try {
- mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser, mMaxTimeToOutputResponse,
- mMaxTimeUnits);
- } catch (IOException e) {
- Log.w(LOG_TAG, String.format("IOException %1$s when running tests %2$s on %3$s",
- e.toString(), getPackageName(), mRemoteDevice.getName()));
- // rely on parser to communicate results to listeners
- mParser.handleTestRunFailed(e.toString());
- throw e;
- } catch (ShellCommandUnresponsiveException e) {
- Log.w(LOG_TAG, String.format(
- "ShellCommandUnresponsiveException %1$s when running tests %2$s on %3$s",
- e.toString(), getPackageName(), mRemoteDevice.getName()));
- mParser.handleTestRunFailed(String
- .format("Failed to receive adb shell test output within %1$d ms. "
- + "Test may have timed out, or adb connection to device became"
- + "unresponsive", mMaxTimeToOutputResponse));
- throw e;
- } catch (TimeoutException e) {
- Log.w(LOG_TAG, String.format("TimeoutException when running tests %1$s on %2$s",
- getPackageName(), mRemoteDevice.getName()));
- mParser.handleTestRunFailed(e.toString());
- throw e;
- } catch (AdbCommandRejectedException e) {
- Log.w(LOG_TAG, String.format(
- "AdbCommandRejectedException %1$s when running tests %2$s on %3$s",
- e.toString(), getPackageName(), mRemoteDevice.getName()));
- mParser.handleTestRunFailed(e.toString());
- throw e;
- }
- }
-
- @Override
- public void cancel() {
- if (mParser != null) {
- mParser.cancel();
- }
- }
-
- /**
- * Returns the full instrumentation command line syntax for the provided
- * instrumentation arguments. Returns an empty string if no arguments were
- * specified.
- */
- private String getArgsCommand() {
- StringBuilder commandBuilder = new StringBuilder();
- for (Entry<String, String> argPair : mArgMap.entrySet()) {
- final String argCmd = String.format(" -e %1$s %2$s", argPair.getKey(),
- argPair.getValue());
- commandBuilder.append(argCmd);
- }
- return commandBuilder.toString();
- }
-}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/PrintTestRunner.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/PrintTestRunner.java
deleted file mode 100644
index 44d2d3a..0000000
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/PrintTestRunner.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright (C) 2014 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.testtype;
-
-import com.android.cts.tradefed.build.CtsBuildHelper;
-import com.android.cts.tradefed.targetprep.SettingsToggler;
-import com.android.cts.util.AbiUtils;
-import com.android.ddmlib.testrunner.IRemoteAndroidTestRunner;
-import com.android.ddmlib.testrunner.IRemoteAndroidTestRunner.TestSize;
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.result.ITestInvocationListener;
-import com.android.tradefed.testtype.IAbi;
-import com.android.tradefed.testtype.IBuildReceiver;
-import com.android.tradefed.testtype.IDeviceTest;
-import com.android.tradefed.testtype.IRemoteTest;
-import com.android.tradefed.util.StringEscapeUtils;
-
-import java.io.FileNotFoundException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Running the print tests requires modification of secure settings. Secure
- * settings cannot be changed from device CTS tests since system signature
- * permission is required. Such settings can be modified by the shell user,
- * so a host side test driver is used for enabling these services, running
- * the tests, and disabling the services.
- */
-public class PrintTestRunner implements IBuildReceiver, IRemoteTest, IDeviceTest {
-
- private static final String PRINT_TEST_AND_SERVICES_APP_NAME =
- "CtsPrintTestCases.apk";
-
- private static final String PRINT_TESTS_PACKAGE_NAME =
- "com.android.cts.print";
-
- private static final String FIRST_PRINT_SERVICE_NAME =
- "android.print.cts.services.FirstPrintService";
-
- private static final String SECOND_PRINT_SERVICE_NAME =
- "android.print.cts.services.SecondPrintService";
-
- private static final String SHELL_USER_FOLDER = "data/local/tmp";
-
- private static final String PRINT_INSTRUMENT_JAR = "CtsPrintInstrument.jar";
-
- private static final String PRINT_INSTRUMENT_SCRIPT = "print-instrument";
-
- private ITestDevice mDevice;
-
- private CtsBuildHelper mCtsBuild;
-
- private IAbi mAbi;
- private String mPackageName;
- private String mRunnerName = "android.test.InstrumentationTestRunner";
- private String mTestClassName;
- private String mTestMethodName;
- private String mTestPackageName;
- private int mTestTimeout = 10 * 60 * 1000; // 10 minutes
- private String mTestSize;
- private String mRunName = null;
- private Map<String, String> mInstrArgMap = new HashMap<String, String>();
-
- /**
- * @param abi The ABI to run the test on
- */
- public void setAbi(IAbi abi) {
- mAbi = abi;
- }
-
- @Override
- public void setBuild(IBuildInfo buildInfo) {
- mCtsBuild = CtsBuildHelper.createBuildHelper(buildInfo);
- }
-
- @Override
- public void setDevice(ITestDevice device) {
- mDevice = device;
- }
-
- @Override
- public ITestDevice getDevice() {
- return mDevice;
- }
-
- public void setPackageName(String packageName) {
- mPackageName = packageName;
- }
-
- public void setRunnerName(String runnerName) {
- mRunnerName = runnerName;
- }
-
- public void setClassName(String testClassName) {
- mTestClassName = testClassName;
- }
-
- public void setMethodName(String testMethodName) {
- mTestMethodName = StringEscapeUtils.escapeShell(testMethodName);
- }
-
- public void setTestPackageName(String testPackageName) {
- mTestPackageName = testPackageName;
- }
-
- public void setTestSize(String size) {
- mTestSize = size;
- }
-
- public void setRunName(String runName) {
- mRunName = runName;
- }
-
- @Override
- public void run(final ITestInvocationListener listener) throws DeviceNotAvailableException {
- installShellProgramAndScriptFiles();
- installTestsAndServicesApk();
- enablePrintServices();
- doRunTests(listener);
- disablePrintServices();
- uninstallTestsAndServicesApk();
- uninstallShellProgramAndScriptFiles();
- }
-
- private void doRunTests(ITestInvocationListener listener)
- throws DeviceNotAvailableException {
- if (mPackageName == null) {
- throw new IllegalArgumentException("package name has not been set");
- }
- if (mDevice == null) {
- throw new IllegalArgumentException("Device has not been set");
- }
-
- IRemoteAndroidTestRunner runner = new PrintTestRemoteTestRunner(mPackageName,
- mRunnerName, mDevice.getIDevice());
-
- if (mTestClassName != null) {
- if (mTestMethodName != null) {
- runner.setMethodName(mTestClassName, mTestMethodName);
- } else {
- runner.setClassName(mTestClassName);
- }
- } else if (mTestPackageName != null) {
- runner.setTestPackageName(mTestPackageName);
- }
- if (mTestSize != null) {
- runner.setTestSize(TestSize.getTestSize(mTestSize));
- }
- runner.setMaxTimeToOutputResponse(mTestTimeout, TimeUnit.MILLISECONDS);
- if (mRunName != null) {
- runner.setRunName(mRunName);
- }
- for (Map.Entry<String, String> argEntry : mInstrArgMap.entrySet()) {
- runner.addInstrumentationArg(argEntry.getKey(), argEntry.getValue());
- }
-
- mDevice.runInstrumentationTests(runner, listener);
- }
-
- private void installShellProgramAndScriptFiles() throws DeviceNotAvailableException {
- installFile(PRINT_INSTRUMENT_JAR);
- installFile(PRINT_INSTRUMENT_SCRIPT);
- }
-
- private void installFile(String fileName) throws DeviceNotAvailableException {
- try {
- final boolean success = getDevice().pushFile(mCtsBuild.getTestApp(
- fileName), SHELL_USER_FOLDER + "/" + fileName);
- if (!success) {
- throw new IllegalArgumentException("Failed to install "
- + fileName + " on " + getDevice().getSerialNumber());
- }
- } catch (FileNotFoundException fnfe) {
- throw new IllegalArgumentException("Cannot find file: " + fileName);
- }
- }
-
- private void uninstallShellProgramAndScriptFiles() throws DeviceNotAvailableException {
- getDevice().executeShellCommand("rm " + SHELL_USER_FOLDER + "/"
- + PRINT_INSTRUMENT_JAR);
- getDevice().executeShellCommand("rm " + SHELL_USER_FOLDER + "/"
- + PRINT_INSTRUMENT_SCRIPT);
- }
-
- private void installTestsAndServicesApk() throws DeviceNotAvailableException {
- try {
- String[] options = {AbiUtils.createAbiFlag(mAbi.getName())};
- String installCode = getDevice().installPackage(mCtsBuild.getTestApp(
- PRINT_TEST_AND_SERVICES_APP_NAME), true, options);
- if (installCode != null) {
- throw new IllegalArgumentException("Failed to install "
- + PRINT_TEST_AND_SERVICES_APP_NAME + " on " + getDevice().getSerialNumber()
- + ". Reason: " + installCode);
- }
- } catch (FileNotFoundException fnfe) {
- throw new IllegalArgumentException("Cannot find file: "
- + PRINT_TEST_AND_SERVICES_APP_NAME);
- }
- }
-
- private void uninstallTestsAndServicesApk() throws DeviceNotAvailableException {
- getDevice().uninstallPackage(PRINT_TESTS_PACKAGE_NAME);
- }
-
- private void enablePrintServices() throws DeviceNotAvailableException {
- String enabledServicesValue = PRINT_TESTS_PACKAGE_NAME + "/" + FIRST_PRINT_SERVICE_NAME
- + ":" + PRINT_TESTS_PACKAGE_NAME + "/" + SECOND_PRINT_SERVICE_NAME;
- SettingsToggler.setSecureString(getDevice(), "enabled_print_services",
- enabledServicesValue);
- }
-
- private void disablePrintServices() throws DeviceNotAvailableException {
- SettingsToggler.setSecureString(getDevice(), "enabled_print_services", "");
- }
-}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
index 9ef6257..ee75c7d 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
@@ -53,8 +53,6 @@
"com.android.cts.tradefed.testtype.AccessibilityTestRunner";
public static final String ACCESSIBILITY_SERVICE_TEST =
"com.android.cts.tradefed.testtype.AccessibilityServiceTestRunner";
- public static final String PRINT_TEST =
- "com.android.cts.tradefed.testtype.PrintTestRunner";
public static final String DISPLAY_TEST =
"com.android.cts.tradefed.testtype.DisplayTestRunner";
public static final String UIAUTOMATOR_TEST = "uiAutomator";
@@ -255,9 +253,6 @@
} else if (ACCESSIBILITY_TEST.equals(mTestType)) {
AccessibilityTestRunner test = new AccessibilityTestRunner();
return setInstrumentationTest(test, testCaseDir);
- } else if (PRINT_TEST.equals(mTestType)) {
- PrintTestRunner test = new PrintTestRunner();
- return setPrintTest(test, testCaseDir);
} else if (ACCESSIBILITY_SERVICE_TEST.equals(mTestType)) {
@SuppressWarnings("deprecation")
AccessibilityServiceTestRunner test = new AccessibilityServiceTestRunner();
@@ -291,19 +286,6 @@
}
}
- private PrintTestRunner setPrintTest(PrintTestRunner printTest,
- File testCaseDir) {
- printTest.setRunName(mAppPackageName);
- printTest.setPackageName(mAppNameSpace);
- printTest.setRunnerName(mRunner);
- printTest.setTestPackageName(mTestPackageName);
- printTest.setClassName(mClassName);
- printTest.setMethodName(mMethodName);
- printTest.setAbi(mAbi);
- mDigest = generateDigest(testCaseDir, String.format("%s.apk", mName));
- return printTest;
- }
-
/**
* Populates given {@link CtsInstrumentationApkTest} with data from the package xml.
*