upload android base code part4
This commit is contained in:
parent
b9e30e05b1
commit
78ea2404cd
23455 changed files with 5250148 additions and 0 deletions
32
android/cts/hostsidetests/sample/Android.mk
Normal file
32
android/cts/hostsidetests/sample/Android.mk
Normal file
|
@ -0,0 +1,32 @@
|
|||
# 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)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
# tag this module as a cts test artifact
|
||||
LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
|
||||
|
||||
LOCAL_MODULE := CtsSampleHostTestCases
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed compatibility-host-util
|
||||
|
||||
include $(BUILD_HOST_JAVA_LIBRARY)
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
25
android/cts/hostsidetests/sample/AndroidTest.xml
Normal file
25
android/cts/hostsidetests/sample/AndroidTest.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2015 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.
|
||||
-->
|
||||
<configuration description="Config for CTS Sample host test cases">
|
||||
<option name="config-descriptor:metadata" key="component" value="misc" />
|
||||
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||
<option name="cleanup-apks" value="true" />
|
||||
<option name="test-file-name" value="CtsSampleDeviceApp.apk" />
|
||||
</target_preparer>
|
||||
<test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
|
||||
<option name="jar" value="CtsSampleHostTestCases.jar" />
|
||||
</test>
|
||||
</configuration>
|
37
android/cts/hostsidetests/sample/app/Android.mk
Normal file
37
android/cts/hostsidetests/sample/app/Android.mk
Normal file
|
@ -0,0 +1,37 @@
|
|||
# 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)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
# Don't include this package in any target
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
# When built, explicitly put it in the data partition.
|
||||
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
|
||||
|
||||
LOCAL_DEX_PREOPT := false
|
||||
|
||||
LOCAL_PROGUARD_ENABLED := disabled
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
# tag this module as a cts test artifact
|
||||
LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
|
||||
|
||||
LOCAL_PACKAGE_NAME := CtsSampleDeviceApp
|
||||
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
include $(BUILD_PACKAGE)
|
31
android/cts/hostsidetests/sample/app/AndroidManifest.xml
Executable file
31
android/cts/hostsidetests/sample/app/AndroidManifest.xml
Executable file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="android.sample.app">
|
||||
|
||||
<application>
|
||||
<activity android:name=".SampleDeviceActivity" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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.sample.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.Override;
|
||||
|
||||
/**
|
||||
* A simple activity which logs to Logcat.
|
||||
*/
|
||||
public class SampleDeviceActivity extends Activity {
|
||||
|
||||
private static final String TAG = SampleDeviceActivity.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* The test string to log.
|
||||
*/
|
||||
private static final String TEST_STRING = "SampleTestString";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
// Log the test string to Logcat.
|
||||
Log.i(TAG, TEST_STRING);
|
||||
}
|
||||
|
||||
}
|
39
android/cts/hostsidetests/sample/app2/Android.mk
Normal file
39
android/cts/hostsidetests/sample/app2/Android.mk
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Copyright (C) 2016 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)
|
||||
|
||||
# Don't include this package in any target
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
# When built, explicitly put it in the data partition.
|
||||
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
|
||||
|
||||
LOCAL_DEX_PREOPT := false
|
||||
|
||||
LOCAL_PROGUARD_ENABLED := disabled
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
# tag this module as a cts test artifact
|
||||
LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
|
||||
|
||||
LOCAL_PACKAGE_NAME := CtsSampleDeviceApp2
|
||||
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
include $(BUILD_PACKAGE)
|
29
android/cts/hostsidetests/sample/app2/AndroidManifest.xml
Normal file
29
android/cts/hostsidetests/sample/app2/AndroidManifest.xml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* Copyright (C) 2016 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="android.sample.cts.app2">
|
||||
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
<instrumentation
|
||||
android:name="android.support.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="android.sample.cts.app2" />
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.sample.cts.app2;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
/**
|
||||
* Device-side tests for CtsSampleHostTestCases
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SampleDeviceTest {
|
||||
|
||||
@Test
|
||||
public void testPasses() throws Exception {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssumeFails() throws Exception {
|
||||
Assume.assumeTrue(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFails() throws Exception {
|
||||
Assert.assertTrue(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.sample.cts;
|
||||
|
||||
import com.android.compatibility.common.util.DeviceInfo;
|
||||
import com.android.compatibility.common.util.HostInfoStore;
|
||||
import com.android.tradefed.device.ITestDevice;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SampleHostDeviceInfo extends DeviceInfo {
|
||||
|
||||
private ITestDevice mDevice;
|
||||
|
||||
@Override
|
||||
protected void collectDeviceInfo(HostInfoStore store) throws Exception {
|
||||
|
||||
mDevice = getDevice();
|
||||
|
||||
store.startGroup("product");
|
||||
store.addResult("model", getProperty("ro.product.model"));
|
||||
store.addResult("brand", getProperty("ro.product.brand"));
|
||||
store.addResult("name", getProperty("ro.product.name"));
|
||||
store.addResult("device", getProperty("ro.product.device"));
|
||||
store.addResult("board", getProperty("ro.product.board"));
|
||||
|
||||
String abi = getProperty("ro.product.cpu.abilist");
|
||||
store.addListResult("abi", Arrays.asList(abi.split(",")));
|
||||
store.endGroup(); // product
|
||||
|
||||
store.startGroup("version");
|
||||
store.addResult("sdk", getProperty("ro.build.version.sdk"));
|
||||
store.addResult("codename", getProperty("ro.build.version.codename"));
|
||||
store.addResult("security_patch", getProperty("ro.build.version.security_patch"));
|
||||
store.addResult("base_os", getProperty("ro.build.version.base_os"));
|
||||
store.endGroup(); // version
|
||||
}
|
||||
|
||||
private String getProperty(String prop) throws Exception {
|
||||
return mDevice.executeShellCommand("getprop " + prop).replace("\n", "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.sample.cts;
|
||||
|
||||
import com.android.compatibility.common.tradefed.testtype.CompatibilityHostTestBase;
|
||||
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test that collects test results from test package android.sample.cts.app2.
|
||||
*
|
||||
* When this test builds, it also builds a support APK containing
|
||||
* {@link android.sample.cts.app2.SampleDeviceTest}, the results of which are
|
||||
* collected from the hostside and reported accordingly.
|
||||
*/
|
||||
@RunWith(DeviceJUnit4ClassRunner.class)
|
||||
public class SampleHostJUnit4DeviceTest extends CompatibilityHostTestBase {
|
||||
|
||||
private static final String TEST_PKG = "android.sample.cts.app2";
|
||||
private static final String TEST_CLASS = TEST_PKG + "." + "SampleDeviceTest";
|
||||
private static final String TEST_APP = "CtsSampleDeviceApp2.apk";
|
||||
|
||||
private static final String TEST_PASSES = "testPasses";
|
||||
private static final String TEST_ASSUME_FAILS = "testAssumeFails";
|
||||
private static final String TEST_FAILS = "testFails";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
installPackage(TEST_APP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunDeviceTestsPasses() throws Exception {
|
||||
Assert.assertTrue(runDeviceTests(TEST_PKG, TEST_CLASS, TEST_PASSES));
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
public void testRunDeviceTestsFails() throws Exception {
|
||||
Assert.assertTrue(runDeviceTests(TEST_PKG, TEST_CLASS, TEST_FAILS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunDeviceTestsAssumeFails() throws Exception {
|
||||
Assert.assertTrue(runDeviceTests(TEST_PKG, TEST_CLASS, TEST_ASSUME_FAILS));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
uninstallPackage(TEST_PKG);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.sample.cts;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import com.android.tradefed.device.ITestDevice;
|
||||
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
|
||||
import com.android.tradefed.testtype.IDeviceTest;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Test to check the APK logs to Logcat.
|
||||
*
|
||||
* When this test builds, it also builds {@link android.sample.app.SampleDeviceActivity} into an
|
||||
* APK which it then installed at runtime and started. The activity simply prints a message to
|
||||
* Logcat and then gets uninstalled.
|
||||
*
|
||||
* Instead of extending DeviceTestCase, this JUnit4 test extends IDeviceTest and is run with
|
||||
* tradefed's DeviceJUnit4ClassRunner
|
||||
*/
|
||||
@RunWith(DeviceJUnit4ClassRunner.class)
|
||||
public class SampleHostJUnit4Test implements IDeviceTest {
|
||||
|
||||
/**
|
||||
* The package name of the APK.
|
||||
*/
|
||||
private static final String PACKAGE = "android.sample.app";
|
||||
|
||||
/**
|
||||
* The class name of the main activity in the APK.
|
||||
*/
|
||||
private static final String CLASS = "SampleDeviceActivity";
|
||||
|
||||
/**
|
||||
* The command to launch the main activity.
|
||||
*/
|
||||
private static final String START_COMMAND = String.format(
|
||||
"am start -W -a android.intent.action.MAIN -n %s/%s.%s", PACKAGE, PACKAGE, CLASS);
|
||||
|
||||
/**
|
||||
* The command to clear the main activity.
|
||||
*/
|
||||
private static final String CLEAR_COMMAND = String.format("pm clear %s", PACKAGE);
|
||||
|
||||
/**
|
||||
* The test string to look for.
|
||||
*/
|
||||
private static final String TEST_STRING = "SampleTestString";
|
||||
|
||||
private ITestDevice mDevice;
|
||||
|
||||
@Override
|
||||
public void setDevice(ITestDevice device) {
|
||||
mDevice = device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITestDevice getDevice() {
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the string was successfully logged to Logcat from the activity.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testLogcat() throws Exception {
|
||||
ITestDevice device = getDevice();
|
||||
assertNotNull("Device not set", device);
|
||||
// Clear activity
|
||||
device.executeShellCommand(CLEAR_COMMAND);
|
||||
// Clear logcat.
|
||||
device.executeAdbCommand("logcat", "-c");
|
||||
// Start the APK and wait for it to complete.
|
||||
device.executeShellCommand(START_COMMAND);
|
||||
// Dump logcat.
|
||||
String logs = device.executeAdbCommand("logcat", "-v", "brief", "-d", CLASS + ":I", "*:S");
|
||||
// Search for string.
|
||||
String testString = "";
|
||||
Scanner in = new Scanner(logs);
|
||||
while (in.hasNextLine()) {
|
||||
String line = in.nextLine();
|
||||
if(line.startsWith("I/"+CLASS)) {
|
||||
testString = line.split(":")[1].trim();
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
// Assert the logged string matches the test string.
|
||||
assertEquals("Incorrect test string", TEST_STRING, testString);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* 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.sample.cts;
|
||||
|
||||
import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
|
||||
import com.android.compatibility.common.util.MeasureRun;
|
||||
import com.android.compatibility.common.util.MeasureTime;
|
||||
import com.android.compatibility.common.util.MetricsReportLog;
|
||||
import com.android.compatibility.common.util.ResultType;
|
||||
import com.android.compatibility.common.util.ResultUnit;
|
||||
import com.android.compatibility.common.util.Stat;
|
||||
import com.android.tradefed.build.IBuildInfo;
|
||||
import com.android.tradefed.device.ITestDevice;
|
||||
import com.android.tradefed.testtype.DeviceTestCase;
|
||||
import com.android.tradefed.testtype.IAbi;
|
||||
import com.android.tradefed.testtype.IAbiReceiver;
|
||||
import com.android.tradefed.testtype.IBuildReceiver;
|
||||
import com.android.tradefed.util.CommandResult;
|
||||
import com.android.tradefed.util.CommandStatus;
|
||||
import com.android.tradefed.util.FileUtil;
|
||||
import com.android.tradefed.util.RunUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Test to measure the transfer time of a file from the host to the device.
|
||||
*/
|
||||
public class SampleHostResultTest extends DeviceTestCase implements IAbiReceiver, IBuildReceiver {
|
||||
|
||||
private static final String TAG = SampleHostResultTest.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Name of the report log to store test metrics.
|
||||
*/
|
||||
private static final String REPORT_LOG_NAME = "SampleHostTestMetrics";
|
||||
|
||||
/**
|
||||
* The number of times to repeat the test.
|
||||
*/
|
||||
private static final int REPEAT = 5;
|
||||
|
||||
/**
|
||||
* The device-side location to write the file to.
|
||||
*/
|
||||
private static final String FILE_PATH = "/data/local/tmp/%s";
|
||||
|
||||
/**
|
||||
* The name of the file to transfer.
|
||||
*
|
||||
* In this case we will transfer this test's module config.
|
||||
*/
|
||||
private static final String FILE_NAME = "CtsSampleHostTestCases.config";
|
||||
|
||||
/**
|
||||
* A helper to access resources in the build.
|
||||
*/
|
||||
private CompatibilityBuildHelper mBuildHelper;
|
||||
|
||||
/**
|
||||
* A reference to the device under test.
|
||||
*/
|
||||
private ITestDevice mDevice;
|
||||
|
||||
/**
|
||||
* A reference to the ABI under test.
|
||||
*/
|
||||
private IAbi mAbi;
|
||||
|
||||
@Override
|
||||
public void setAbi(IAbi abi) {
|
||||
mAbi = abi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBuild(IBuildInfo buildInfo) {
|
||||
// Get the build, this is used to access the APK.
|
||||
mBuildHelper = new CompatibilityBuildHelper(buildInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// Get the device, this gives a handle to run commands and install APKs.
|
||||
mDevice = getDevice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Measures the time taken to transfer a file to the device and then back.
|
||||
*
|
||||
* The workload is repeated several times and the report is populated with the result.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testTransferTime() throws Exception {
|
||||
final ITestDevice device = mDevice;
|
||||
// Create the device side path where the file will be transfered.
|
||||
final String devicePath = String.format(FILE_PATH, "tmp_testPushPull.txt");
|
||||
// Get this test's module config file from the build.
|
||||
final File testFile = mBuildHelper.getTestFile(FILE_NAME);
|
||||
double[] result = MeasureTime.measure(REPEAT, new MeasureRun() {
|
||||
@Override
|
||||
public void prepare(int i) throws Exception {
|
||||
device.executeShellCommand(String.format("rm %s", devicePath));
|
||||
}
|
||||
@Override
|
||||
public void run(int i) throws Exception {
|
||||
// Create a temporary file to compare with.
|
||||
File tmpFile = FileUtil.createTempFile("tmp", "txt");
|
||||
try {
|
||||
// Push the file across and ensure it exists.
|
||||
assertTrue("Could not push file", device.pushFile(testFile, devicePath));
|
||||
assertTrue("Unsuccessful transfer", device.doesFileExist(devicePath));
|
||||
// Pull the file back and ensure it is the same.
|
||||
assertTrue("Could not pull file", device.pullFile(devicePath, tmpFile));
|
||||
assertFilesAreEqual(testFile, tmpFile);
|
||||
} finally {
|
||||
// Clean up.
|
||||
tmpFile.delete();
|
||||
device.executeShellCommand(String.format("rm %s", devicePath));
|
||||
}
|
||||
}
|
||||
});
|
||||
// Compute the stats.
|
||||
Stat.StatResult stat = Stat.getStat(result);
|
||||
// Get the report for this test and add the results to record.
|
||||
String streamName = "test_transfer_time_metrics";
|
||||
MetricsReportLog report = new MetricsReportLog(
|
||||
mBuildHelper.getBuildInfo(), mAbi.getName(),
|
||||
String.format("%s#testTransferTime", getClass().getCanonicalName()),
|
||||
REPORT_LOG_NAME, streamName);
|
||||
report.addValues("times", result, ResultType.LOWER_BETTER, ResultUnit.MS);
|
||||
report.addValue("min", stat.mMin, ResultType.LOWER_BETTER, ResultUnit.MS);
|
||||
report.addValue("max", stat.mMax, ResultType.LOWER_BETTER, ResultUnit.MS);
|
||||
// Set a summary.
|
||||
report.setSummary("average", stat.mAverage, ResultType.LOWER_BETTER, ResultUnit.MS);
|
||||
// Send the report to Tradefed.
|
||||
report.submit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the two given files are equal using the diff utility.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private static void assertFilesAreEqual(File first, File second) throws Exception {
|
||||
CommandResult result = RunUtil.getDefault().runTimedCmd(5000, "diff",
|
||||
first.getAbsolutePath(), second.getAbsolutePath());
|
||||
assertTrue("Diff failed to run", result.getStatus() == CommandStatus.SUCCESS);
|
||||
assertTrue("Files are not equivalent", "".equals(result.getStdout()));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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.sample.cts;
|
||||
|
||||
import com.android.tradefed.device.ITestDevice;
|
||||
import com.android.tradefed.testtype.DeviceTestCase;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Test to check the APK logs to Logcat.
|
||||
*
|
||||
* When this test builds, it also builds {@link android.sample.app.SampleDeviceActivity} into an APK
|
||||
* which it then installed at runtime and started. The activity simply prints a message to Logcat
|
||||
* and then gets uninstalled.
|
||||
*/
|
||||
public class SampleHostTest extends DeviceTestCase {
|
||||
|
||||
/**
|
||||
* The package name of the APK.
|
||||
*/
|
||||
private static final String PACKAGE = "android.sample.app";
|
||||
|
||||
/**
|
||||
* The class name of the main activity in the APK.
|
||||
*/
|
||||
private static final String CLASS = "SampleDeviceActivity";
|
||||
|
||||
/**
|
||||
* The command to launch the main activity.
|
||||
*/
|
||||
private static final String START_COMMAND = String.format(
|
||||
"am start -W -a android.intent.action.MAIN -n %s/%s.%s", PACKAGE, PACKAGE, CLASS);
|
||||
|
||||
/**
|
||||
* The command to clear the main activity.
|
||||
*/
|
||||
private static final String CLEAR_COMMAND = String.format("pm clear %s", PACKAGE);
|
||||
|
||||
/**
|
||||
* The test string to look for.
|
||||
*/
|
||||
private static final String TEST_STRING = "SampleTestString";
|
||||
|
||||
/**
|
||||
* Tests the string was successfully logged to Logcat from the activity.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testLogcat() throws Exception {
|
||||
ITestDevice device = getDevice();
|
||||
// Clear activity
|
||||
device.executeShellCommand(CLEAR_COMMAND);
|
||||
// Clear logcat.
|
||||
device.executeAdbCommand("logcat", "-c");
|
||||
// Start the APK and wait for it to complete.
|
||||
device.executeShellCommand(START_COMMAND);
|
||||
// Dump logcat.
|
||||
String logs = device.executeAdbCommand("logcat", "-v", "brief", "-d", CLASS + ":I", "*:S");
|
||||
// Search for string.
|
||||
String testString = "";
|
||||
Scanner in = new Scanner(logs);
|
||||
while (in.hasNextLine()) {
|
||||
String line = in.nextLine();
|
||||
if(line.startsWith("I/"+CLASS)) {
|
||||
testString = line.split(":")[1].trim();
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
// Assert the logged string matches the test string.
|
||||
assertEquals("Incorrect test string", TEST_STRING, testString);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue