diff options
author | Neil Fuller <nfuller@google.com> | 2017-07-18 06:00:42 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-18 06:00:42 +0000 |
commit | e27548d774ec6b6d46c3c30e8e6390bf43d5e802 (patch) | |
tree | 30dbb81c2a521970fd294f1b78bb0639278cdc21 | |
parent | 60e21b58e04e0f1a38cfb074a3620fe80e89678e (diff) | |
parent | 3050988c471e3b7a9811c090b56d43a86ac62726 (diff) | |
download | TimeZoneData-e27548d774ec6b6d46c3c30e8e6390bf43d5e802.tar.gz |
Stop using Java resources in xTS test jar am: 57b633a1a4 am: 8d9db20bbc am: a1fdfe3b63
am: 3050988c47
Change-Id: I52839e266e43282696d2c24a131f1fe09e382d4f
-rw-r--r-- | oem_template/data_app/build_oem_data_app.mk | 10 | ||||
-rw-r--r-- | oem_template/data_app/testing/Android.mk | 8 | ||||
-rw-r--r-- | oem_template/data_app/testing/build_oem_test_data_app.mk | 30 | ||||
-rw-r--r-- | oem_template/xts/Android.mk | 7 | ||||
-rw-r--r-- | oem_template/xts/embed_apk_as_resource.mk | 46 | ||||
-rw-r--r-- | testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java | 66 |
6 files changed, 65 insertions, 102 deletions
diff --git a/oem_template/data_app/build_oem_data_app.mk b/oem_template/data_app/build_oem_data_app.mk index 1daca86..e82867d 100644 --- a/oem_template/data_app/build_oem_data_app.mk +++ b/oem_template/data_app/build_oem_data_app.mk @@ -20,8 +20,9 @@ # contains the app res/ dir. # TIME_ZONE_DATA_APP_SUFFIX - the suffix to apply to the package name. Can be # empty, or contain things like _test1 for test .apk files. -# TIME_ZONE_DATA_APP_VERSION_CODE - the version code for the .apk -# TIME_ZONE_DATA_APP_VERSION_NAME - the version name for the .apk +# TIME_ZONE_DATA_APP_VERSION_CODE - the version code for the .apk. +# TIME_ZONE_DATA_APP_VERSION_NAME - the version name for the .apk. +# LOCAL_COMPATIBILITY_SUITE - if the package is to be included in xTS tests. # LOCAL_MODULE_TAGS := optional @@ -48,5 +49,6 @@ LOCAL_PRIVILEGED_MODULE := true # OEM-INSTRUCTION: Configure your own certificate. LOCAL_CERTIFICATE := -include $(BUILD_PACKAGE) - +# If LOCAL_COMPATIBILITY_SUITE is unset this is the same as BUILD_PACKAGE so +# can be used for building test or production packages. +include $(BUILD_CTS_PACKAGE) diff --git a/oem_template/data_app/testing/Android.mk b/oem_template/data_app/testing/Android.mk index 9b2eae2..11be369 100644 --- a/oem_template/data_app/testing/Android.mk +++ b/oem_template/data_app/testing/Android.mk @@ -17,9 +17,6 @@ LOCAL_PATH := $(call my-dir) -# The location of the "real" app. -OEM_APP_PATH := $(LOCAL_PATH)/.. - # Paths used to find files shared with AOSP. aosp_test_data_path := packages/apps/TimeZoneData/testing/data @@ -36,7 +33,8 @@ TIME_ZONE_DATA_APP_VERSION_NAME := test1 # When built, explicitly put it in the data partition since this is for tests, not the system image. LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) -include $(OEM_APP_PATH)/build_oem_data_app.mk +include $(LOCAL_PATH)/build_oem_test_data_app.mk + # Target to build the "test 2" time zone data app. include $(CLEAR_VARS) @@ -51,7 +49,7 @@ TIME_ZONE_DATA_APP_VERSION_NAME := test2 # When built, explicitly put it in the data partition since this is for tests, not the system image. LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) -include $(OEM_APP_PATH)/build_oem_data_app.mk +include $(LOCAL_PATH)/build_oem_test_data_app.mk # Tidy up variables. aosp_test_data_path :=
\ No newline at end of file diff --git a/oem_template/data_app/testing/build_oem_test_data_app.mk b/oem_template/data_app/testing/build_oem_test_data_app.mk new file mode 100644 index 0000000..4ed18ef --- /dev/null +++ b/oem_template/data_app/testing/build_oem_test_data_app.mk @@ -0,0 +1,30 @@ +# Copyright (C) 2017 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. +# +# An .mk include file that contains the boilerplate needed to build test, +# OEM-specific Time Zone Data apps. +# +# Users should set: +# TIME_ZONE_DATA_APP_SUFFIX - the suffix to apply to the package name. +# Should contain things like _test1 for test .apk files. +# TIME_ZONE_DATA_APP_VERSION_CODE - the version code for the .apk. +# TIME_ZONE_DATA_APP_VERSION_NAME - the version name for the .apk. +# + +OEM_APP_PATH := $(LOCAL_PATH)/.. + +# OEM-INSTRUCTION: Change this to the appropriate test suite(s). +LOCAL_COMPATIBILITY_SUITE := xts + +include $(OEM_APP_PATH)/build_oem_data_app.mk diff --git a/oem_template/xts/Android.mk b/oem_template/xts/Android.mk index cc80e00..25be082 100644 --- a/oem_template/xts/Android.mk +++ b/oem_template/xts/Android.mk @@ -26,11 +26,4 @@ LOCAL_MODULE := XtsTimeZoneTestCases LOCAL_STATIC_JAVA_LIBRARIES := time_zone_data_app_testing -# Embed the .apk files needed by the tests as resources. -EMBED_APK_MODULE_NAME := TimeZoneData_test1 -include $(LOCAL_PATH)/embed_apk_as_resource.mk - -EMBED_APK_MODULE_NAME := TimeZoneData_test2 -include $(LOCAL_PATH)/embed_apk_as_resource.mk - include $(BUILD_HOST_JAVA_LIBRARY) diff --git a/oem_template/xts/embed_apk_as_resource.mk b/oem_template/xts/embed_apk_as_resource.mk deleted file mode 100644 index 18a01bd..0000000 --- a/oem_template/xts/embed_apk_as_resource.mk +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) 2017 Google Inc. -# -# 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. - -# An .mk inclusion file that adds a .apk to a java library target as a resource. -# -# Inputs: -# LOCAL_MODULE should be set before including this file. -# EMBED_APK_MODULE_NAME - the name of the BUILD_PACKAGE MODULE_NAME to be included. -# -# Outputs: -# The dependencies for the required .apk are configured. -# LOCAL_JAVA_RESOURCE_FILES is extended to include the .apk. - -# Location of the package.apk file we want. -embed_apk_package := $(call intermediates-dir-for, APPS, $(EMBED_APK_MODULE_NAME))/package.apk - -# Location to copy the package.apk. -embed_container_intermediates := $(call intermediates-dir-for, JAVA_LIBRARIES, $(LOCAL_MODULE)) -embed_res_dir := $(embed_container_intermediates)/embed_$(EMBED_APK_MODULE_NAME)_res -embed_res_file := $(embed_res_dir)/$(EMBED_APK_MODULE_NAME)$(COMMON_ANDROID_PACKAGE_SUFFIX) - -# Copy the files / establish the dependency on the .apk. -$(embed_res_file) : PRIVATE_RES_FILE := $(embed_res_file) -$(embed_res_file) : $(embed_apk_package) - @echo "Embed apk into $(LOCAL_MODULE)" - $(hide) rm -rf $(dir $(PRIVATE_RES_FILE)) - $(hide) mkdir -p $(dir $(PRIVATE_RES_FILE)) - $(hide) cp $< $(PRIVATE_RES_FILE) - -LOCAL_JAVA_RESOURCE_FILES += $(embed_res_file) - -# Tidy up variables. -embed_apk_package := -embed_res_dir := -embed_res_file :=
\ No newline at end of file diff --git a/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java b/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java index 04e4ff4..e8384e6 100644 --- a/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java +++ b/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java @@ -15,15 +15,15 @@ */ package com.android.timezone.xts; +import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; +import com.android.tradefed.build.IBuildInfo; import com.android.tradefed.config.Option; import com.android.tradefed.log.LogUtil; import com.android.tradefed.testtype.DeviceTestCase; +import com.android.tradefed.testtype.IBuildReceiver; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -57,7 +57,7 @@ import java.util.function.BooleanSupplier; * */ // TODO(nfuller): Switch this to JUnit4 when HostTest supports @Option with JUnit4. -public class TimeZoneUpdateHostTest extends DeviceTestCase { +public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildReceiver { // These must match equivalent values in RulesManagerService dumpsys code. private static final String STAGED_OPERATION_NONE = "None"; @@ -67,16 +67,17 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase { private static final int ALLOWED_BOOT_DELAY = 60000; - private File tempDir; + private IBuildInfo mBuildInfo; + private File mTempDir; @Option(name = "oem-data-app-package-name", description="The OEM-specific package name for the data app", mandatory = true) - private String oemDataAppPackageName; + private String mOemDataAppPackageName; private String getTimeZoneDataPackageName() { - assertNotNull(oemDataAppPackageName); - return oemDataAppPackageName; + assertNotNull(mOemDataAppPackageName); + return mOemDataAppPackageName; } @Option(name = "oem-data-app-apk-prefix", @@ -84,11 +85,16 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase { + "for TimeZoneDataOemCorp_test1.apk the prefix would be" + "\"TimeZoneDataOemCorp\"", mandatory = true) - private String oemDataAppApkPrefix; + private String mOemDataAppApkPrefix; - private String getTimeZoneDataApkResourceName(String testId) { - assertNotNull(oemDataAppApkPrefix); - return "/" + oemDataAppApkPrefix + "_" + testId + ".apk"; + private String getTimeZoneDataApkName(String testId) { + assertNotNull(mOemDataAppApkPrefix); + return mOemDataAppApkPrefix + "_" + testId + ".apk"; + } + + @Override + public void setBuild(IBuildInfo buildInfo) { + mBuildInfo = buildInfo; } @Override @@ -107,14 +113,14 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase { // @Before public void createTempDir() throws Exception { - tempDir = File.createTempFile("timeZoneUpdateTest", null); - assertTrue(tempDir.delete()); - assertTrue(tempDir.mkdir()); + mTempDir = File.createTempFile("timeZoneUpdateTest", null); + assertTrue(mTempDir.delete()); + assertTrue(mTempDir.mkdir()); } // @After public void deleteTempDir() throws Exception { - Files.walkFileTree(tempDir.toPath(), new SimpleFileVisitor<Path>() { + Files.walkFileTree(mTempDir.toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { @@ -370,31 +376,11 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase { } private File getTimeZoneDataApkFile(String testId) throws Exception { - String resourceName = getTimeZoneDataApkResourceName(testId); - return extractResourceToFile(resourceName); - } + CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(mBuildInfo); + String fileName = getTimeZoneDataApkName(testId); - private File extractResourceToFile(String resourceName) throws Exception { - File tempFile = File.createTempFile("temp", ".apk", tempDir); - try (InputStream is = getClass().getResourceAsStream(resourceName); - FileOutputStream os = new FileOutputStream(tempFile)) { - if (is == null) { - fail("No resource found with name " + resourceName); - } - copy(is, os); - } - return tempFile; - } - - /** - * Copies all of the bytes from {@code in} to {@code out}. Neither stream is closed. - */ - private static void copy(InputStream in, OutputStream out) throws IOException { - byte[] buffer = new byte[8192]; - int c; - while ((c = in.read(buffer)) != -1) { - out.write(buffer, 0, c); - } + // TODO(nfuller): Replace with getTestFile(fileName) when it's available in aosp/master. + return new File(buildHelper.getTestsDir(), fileName); } private boolean isPackageInstalled(String pkg) throws Exception { |