libcore: Split OJ luni tests into separate APK files

All OJ luni tests are now in CtsLibcoreOjTestCases.apk which
is an instrumentation for CtsLibcoreRunner.apk.

The CtsLibcoreOjTestCases.apk has only the dex bytecode from
core-ojtests-public jar included in there and nothing else.

The cts-core-test-runner dependency is loaded dynamically
from CtsLibcoreRunner.apk.

Bug: 27521545
Change-Id: I151fb7f7d375b79a9fa00e89a88c5432157b1ada
diff --git a/tests/libcore/Android.mk b/tests/libcore/Android.mk
index 72b6ebc..00d1223 100644
--- a/tests/libcore/Android.mk
+++ b/tests/libcore/Android.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2015 The Android Open Source Project
+# 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.
@@ -12,55 +12,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsLibcoreTestCases
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    apache-harmony-tests \
-    bouncycastle-nojarjar \
-    conscrypt-tests \
-    core-ojtests-public \
-    core-tests \
-    cts-core-test-runner \
-    jsr166-tests \
-    mockito-target \
-    okhttp-nojarjar \
-    okhttp-tests-nojarjar \
-    tzdata_update-tests
-
-#LOCAL_JAVA_LIBRARIES := android-support-test android.test.runner bouncycastle conscrypt
-
-# 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_JACK_FLAGS := --multi-dex native
-
-LOCAL_PROGUARD_ENABLED := disabled
-
-LOCAL_JNI_SHARED_LIBRARIES := libjavacoretests libsqlite_jni libnativehelper_compat_libc++ libc++
-
-# Include both the 32 and 64 bit versions of libjavacoretests,
-# where applicable.
-LOCAL_MULTILIB := both
-
-# Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
-
-LOCAL_JAVA_RESOURCE_DIRS := resources
-
-LOCAL_JAVA_RESOURCE_FILES := \
-    libcore/expectations/brokentests.txt \
-    libcore/expectations/icebox.txt \
-    libcore/expectations/knownfailures.txt \
-    libcore/expectations/taggedtests.txt
-
-LOCAL_JAVA_LANGUAGE_VERSION := 1.8
-
-include $(BUILD_CTS_SUPPORT_PACKAGE)
+# Build the test APK using its own makefile, and any other CTS-related packages
+include $(call all-subdir-makefiles)
diff --git a/tests/libcore/luni/Android.mk b/tests/libcore/luni/Android.mk
new file mode 100644
index 0000000..02caf32
--- /dev/null
+++ b/tests/libcore/luni/Android.mk
@@ -0,0 +1,63 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := CtsLibcoreTestCases
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    apache-harmony-tests \
+    bouncycastle-nojarjar \
+    conscrypt-tests \
+    core-tests \
+    cts-core-test-runner \
+    jsr166-tests \
+    mockito-target \
+    okhttp-nojarjar \
+    okhttp-tests-nojarjar \
+    tzdata_update-tests
+
+# 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_JACK_FLAGS := --multi-dex native
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_JNI_SHARED_LIBRARIES := libjavacoretests libsqlite_jni libnativehelper_compat_libc++ libc++
+
+# Include both the 32 and 64 bit versions of libjavacoretests,
+# where applicable.
+LOCAL_MULTILIB := both
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_JAVA_RESOURCE_DIRS := resources
+
+LOCAL_JAVA_RESOURCE_FILES := \
+    libcore/expectations/brokentests.txt \
+    libcore/expectations/icebox.txt \
+    libcore/expectations/knownfailures.txt \
+    libcore/expectations/taggedtests.txt
+
+LOCAL_JAVA_LANGUAGE_VERSION := 1.8
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/AndroidManifest.xml b/tests/libcore/luni/AndroidManifest.xml
similarity index 100%
rename from tests/libcore/AndroidManifest.xml
rename to tests/libcore/luni/AndroidManifest.xml
diff --git a/tests/libcore/AndroidTest.xml b/tests/libcore/luni/AndroidTest.xml
similarity index 100%
rename from tests/libcore/AndroidTest.xml
rename to tests/libcore/luni/AndroidTest.xml
diff --git a/tests/libcore/resources/expectations/cts-runner-specific-failures.txt b/tests/libcore/luni/resources/expectations/cts-runner-specific-failures.txt
similarity index 100%
rename from tests/libcore/resources/expectations/cts-runner-specific-failures.txt
rename to tests/libcore/luni/resources/expectations/cts-runner-specific-failures.txt
diff --git a/tests/libcore/ojluni/Android.mk b/tests/libcore/ojluni/Android.mk
new file mode 100644
index 0000000..4311b57
--- /dev/null
+++ b/tests/libcore/ojluni/Android.mk
@@ -0,0 +1,52 @@
+# 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)
+
+LOCAL_PACKAGE_NAME := CtsLibcoreOjTestCases
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    core-ojtests-public
+
+# 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_JACK_FLAGS := --multi-dex native
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+# Include both the 32 and 64 bit versions of libjavacoretests,
+# where applicable.
+LOCAL_MULTILIB := both
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_JAVA_RESOURCE_DIRS := resources
+
+LOCAL_JAVA_RESOURCE_FILES := \
+    libcore/expectations/brokentests.txt \
+    libcore/expectations/icebox.txt \
+    libcore/expectations/knownfailures.txt \
+    libcore/expectations/taggedtests.txt
+
+LOCAL_JAVA_LANGUAGE_VERSION := 1.8
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/ojluni/AndroidManifest.xml b/tests/libcore/ojluni/AndroidManifest.xml
new file mode 100644
index 0000000..5f900a9
--- /dev/null
+++ b/tests/libcore/ojluni/AndroidManifest.xml
@@ -0,0 +1,26 @@
+<?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.libcore.cts.oj">
+    <uses-permission android:name="android.permission.INTERNET" />
+
+    <!-- important: instrument another package which actually contains the CTS core test runner -->
+    <instrumentation android:name="com.android.cts.core.runner.CoreTestRunner"
+                     android:targetPackage="android.libcore.runner"
+                     android:label="CTS Libcore OJ test cases" />
+
+</manifest>
diff --git a/tests/libcore/ojluni/AndroidTest.xml b/tests/libcore/ojluni/AndroidTest.xml
new file mode 100644
index 0000000..1d32530
--- /dev/null
+++ b/tests/libcore/ojluni/AndroidTest.xml
@@ -0,0 +1,41 @@
+<?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.
+-->
+<configuration description="Config for CTS Libcore OJ test cases">
+    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+        <option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/java.io.tmpdir" />
+        <option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/user.home" />
+        <option name="teardown-command" value="rm -rf /data/local/tmp/ctslibcore" />
+    </target_preparer>
+    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.ApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <!-- this has the CoreTestRunner which needs to be in a separate APK -->
+        <option name="test-file-name" value="CtsLibcoreTestRunner.apk" />
+        <!-- this has just the instrumentation which acts as the tests we want to run -->
+        <option name="test-file-name" value="CtsLibcoreOjTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <!-- override AJUR -->
+        <option name="runner" value="com.android.cts.core.runner.CoreTestRunner" />
+        <option name="package" value="android.libcore.cts.oj" />
+        <option name="instrumentation-arg" key="core-listener"
+                value="com.android.cts.runner.CtsTestRunListener"/>
+        <option name="instrumentation-arg" key="core-expectations"
+                value="/knownfailures.txt,/brokentests.txt,/icebox.txt,/taggedtests.txt,/expectations/cts-runner-specific-failures.txt" />
+        <option name="runtime-hint" value="45m"/>
+        <!-- 20x default timeout of 600sec -->
+        <option name="shell-timeout" value="12000000"/>
+    </test>
+</configuration>
diff --git a/tests/libcore/runner/Android.mk b/tests/libcore/runner/Android.mk
new file mode 100644
index 0000000..b338e12
--- /dev/null
+++ b/tests/libcore/runner/Android.mk
@@ -0,0 +1,40 @@
+# 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)
+
+LOCAL_PACKAGE_NAME := CtsLibcoreTestRunner
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    cts-core-test-runner
+
+# 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_JACK_FLAGS := --multi-dex native
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_JAVA_LANGUAGE_VERSION := 1.8
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/runner/AndroidManifest.xml b/tests/libcore/runner/AndroidManifest.xml
new file mode 100644
index 0000000..1a56b90
--- /dev/null
+++ b/tests/libcore/runner/AndroidManifest.xml
@@ -0,0 +1,24 @@
+<?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.libcore.runner">
+    <uses-permission android:name="android.permission.INTERNET" />
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+</manifest>