blob: d6493bcfabbd8c4652bcaf43c1ace3287d023391 [file] [log] [blame]
Makoto Onuki4a9869d2023-10-20 10:42:47 -07001// Copyright 2022 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Jeff Sharkeyddb51522023-11-06 13:56:38 -070018 "runtime"
Makoto Onuki4a9869d2023-10-20 10:42:47 -070019 "testing"
20
21 "android/soong/android"
John Wu680cd732024-09-13 20:59:05 +000022 "android/soong/etc"
Makoto Onuki4a9869d2023-10-20 10:42:47 -070023)
24
25var prepareRavenwoodRuntime = android.GroupFixturePreparers(
26 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
27 RegisterRavenwoodBuildComponents(ctx)
28 }),
29 android.FixtureAddTextFile("ravenwood/Android.bp", `
Makoto Onuki68676572024-02-02 13:29:01 -080030 cc_library_shared {
Makoto Onuki2ca84272024-02-10 00:15:21 +000031 name: "ravenwood-runtime-jni1",
Makoto Onuki68676572024-02-02 13:29:01 -080032 host_supported: true,
33 srcs: ["jni.cpp"],
34 }
35 cc_library_shared {
36 name: "ravenwood-runtime-jni2",
37 host_supported: true,
38 srcs: ["jni.cpp"],
39 stem: "libred",
Makoto Onuki2ca84272024-02-10 00:15:21 +000040 shared_libs: [
41 "ravenwood-runtime-jni3",
42 ],
43 }
44 cc_library_shared {
45 name: "ravenwood-runtime-jni3",
46 host_supported: true,
47 srcs: ["jni.cpp"],
Makoto Onuki68676572024-02-02 13:29:01 -080048 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -070049 java_library_static {
50 name: "framework-minus-apex.ravenwood",
51 srcs: ["Framework.java"],
52 }
53 java_library_static {
54 name: "framework-services.ravenwood",
55 srcs: ["Services.java"],
56 }
57 java_library_static {
58 name: "framework-rules.ravenwood",
59 srcs: ["Rules.java"],
60 }
Makoto Onuki3380f6d2024-05-10 16:00:28 -070061 android_app {
62 name: "app1",
John Wu680cd732024-09-13 20:59:05 +000063 sdk_version: "current",
Makoto Onuki3380f6d2024-05-10 16:00:28 -070064 }
65 android_app {
66 name: "app2",
John Wu680cd732024-09-13 20:59:05 +000067 sdk_version: "current",
68 }
Makoto Onukied392f72024-09-17 09:56:33 -070069 android_app {
70 name: "app3",
71 sdk_version: "current",
72 }
John Wu680cd732024-09-13 20:59:05 +000073 prebuilt_font {
74 name: "Font.ttf",
75 src: "Font.ttf",
Makoto Onuki3380f6d2024-05-10 16:00:28 -070076 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -070077 android_ravenwood_libgroup {
78 name: "ravenwood-runtime",
79 libs: [
80 "framework-minus-apex.ravenwood",
81 "framework-services.ravenwood",
82 ],
Makoto Onuki2ca84272024-02-10 00:15:21 +000083 jni_libs: [
84 "ravenwood-runtime-jni1",
85 "ravenwood-runtime-jni2",
86 ],
Makoto Onuki3380f6d2024-05-10 16:00:28 -070087 data: [
John Wu680cd732024-09-13 20:59:05 +000088 ":app1",
89 ],
90 fonts: [
91 ":Font.ttf"
Makoto Onuki3380f6d2024-05-10 16:00:28 -070092 ],
Makoto Onuki4a9869d2023-10-20 10:42:47 -070093 }
94 android_ravenwood_libgroup {
95 name: "ravenwood-utils",
96 libs: [
97 "framework-rules.ravenwood",
98 ],
99 }
100 `),
101)
102
Cole Faust6b7075f2024-12-17 10:42:42 -0800103var installPathPrefix = "out/host/linux-x86/testcases"
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700104
105func TestRavenwoodRuntime(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -0800106 t.Parallel()
Jeff Sharkeyddb51522023-11-06 13:56:38 -0700107 if runtime.GOOS != "linux" {
108 t.Skip("requires linux")
109 }
110
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700111 ctx := android.GroupFixturePreparers(
112 PrepareForIntegrationTestWithJava,
John Wu680cd732024-09-13 20:59:05 +0000113 etc.PrepareForTestWithPrebuiltEtc,
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700114 prepareRavenwoodRuntime,
115 ).RunTest(t)
116
117 // Verify that our runtime depends on underlying libs
118 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-minus-apex.ravenwood")
119 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-services.ravenwood")
Makoto Onuki68676572024-02-02 13:29:01 -0800120 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "ravenwood-runtime-jni")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700121 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood")
122
123 // Verify that we've emitted artifacts in expected location
Colin Cross90607e92025-02-11 14:58:07 -0800124 runtime := ctx.ModuleForTests(t, "ravenwood-runtime", "android_common")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700125 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
126 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000127 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni1.so")
Makoto Onuki68676572024-02-02 13:29:01 -0800128 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/libred.so")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000129 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni3.so")
Makoto Onuki3380f6d2024-05-10 16:00:28 -0700130 runtime.Output(installPathPrefix + "/ravenwood-runtime/ravenwood-data/app1.apk")
John Wu680cd732024-09-13 20:59:05 +0000131 runtime.Output(installPathPrefix + "/ravenwood-runtime/fonts/Font.ttf")
Colin Cross90607e92025-02-11 14:58:07 -0800132 utils := ctx.ModuleForTests(t, "ravenwood-utils", "android_common")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700133 utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar")
134}
135
136func TestRavenwoodTest(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -0800137 t.Parallel()
Jeff Sharkeyddb51522023-11-06 13:56:38 -0700138 if runtime.GOOS != "linux" {
139 t.Skip("requires linux")
140 }
141
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700142 ctx := android.GroupFixturePreparers(
143 PrepareForIntegrationTestWithJava,
John Wu680cd732024-09-13 20:59:05 +0000144 etc.PrepareForTestWithPrebuiltEtc,
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700145 prepareRavenwoodRuntime,
146 ).RunTestWithBp(t, `
John Wu680cd732024-09-13 20:59:05 +0000147 cc_library_shared {
148 name: "jni-lib1",
149 host_supported: true,
150 srcs: ["jni.cpp"],
151 }
152 cc_library_shared {
153 name: "jni-lib2",
154 host_supported: true,
155 srcs: ["jni.cpp"],
156 stem: "libblue",
157 shared_libs: [
158 "jni-lib3",
159 ],
160 }
161 cc_library_shared {
162 name: "jni-lib3",
163 host_supported: true,
164 srcs: ["jni.cpp"],
165 stem: "libpink",
166 }
John Wu878b2fc2024-10-28 22:29:35 +0000167 java_defaults {
168 name: "ravenwood-test-defaults",
169 jni_libs: ["jni-lib2"],
170 }
John Wu680cd732024-09-13 20:59:05 +0000171 android_ravenwood_test {
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700172 name: "ravenwood-test",
173 srcs: ["Test.java"],
John Wu878b2fc2024-10-28 22:29:35 +0000174 defaults: ["ravenwood-test-defaults"],
Makoto Onuki2ca84272024-02-10 00:15:21 +0000175 jni_libs: [
176 "jni-lib1",
Makoto Onuki2ca84272024-02-10 00:15:21 +0000177 "ravenwood-runtime-jni2",
178 ],
Makoto Onuki3380f6d2024-05-10 16:00:28 -0700179 resource_apk: "app2",
Makoto Onukied392f72024-09-17 09:56:33 -0700180 inst_resource_apk: "app3",
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700181 sdk_version: "test_current",
John Wufe462932024-11-10 02:55:53 +0000182 target_sdk_version: "34",
183 package_name: "a.b.c",
184 inst_package_name: "x.y.z",
185 }
186 android_ravenwood_test {
187 name: "ravenwood-test-empty",
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700188 }
189 `)
190
191 // Verify that our test depends on underlying libs
192 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-buildtime")
193 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils")
Makoto Onuki68676572024-02-02 13:29:01 -0800194 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "jni-lib")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700195
Colin Cross90607e92025-02-11 14:58:07 -0800196 module := ctx.ModuleForTests(t, "ravenwood-test", "android_common")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700197 classpath := module.Rule("javac").Args["classpath"]
198
199 // Verify that we're linking against test_current
200 android.AssertStringDoesContain(t, "classpath", classpath, "android_test_stubs_current.jar")
201 // Verify that we're linking against utils
202 android.AssertStringDoesContain(t, "classpath", classpath, "framework-rules.ravenwood.jar")
203 // Verify that we're *NOT* linking against runtime
204 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-minus-apex.ravenwood.jar")
205 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-services.ravenwood.jar")
206
207 // Verify that we've emitted test artifacts in expected location
208 outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar")
209 module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config")
John Wufe462932024-11-10 02:55:53 +0000210 module.Output(installPathPrefix + "/ravenwood-test/ravenwood.properties")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000211 module.Output(installPathPrefix + "/ravenwood-test/lib64/jni-lib1.so")
Makoto Onuki68676572024-02-02 13:29:01 -0800212 module.Output(installPathPrefix + "/ravenwood-test/lib64/libblue.so")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000213 module.Output(installPathPrefix + "/ravenwood-test/lib64/libpink.so")
Makoto Onuki3380f6d2024-05-10 16:00:28 -0700214 module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-res.apk")
Makoto Onukied392f72024-09-17 09:56:33 -0700215 module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-inst-res.apk")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000216
Colin Cross90607e92025-02-11 14:58:07 -0800217 module = ctx.ModuleForTests(t, "ravenwood-test-empty", "android_common")
John Wufe462932024-11-10 02:55:53 +0000218 module.Output(installPathPrefix + "/ravenwood-test-empty/ravenwood.properties")
219
Makoto Onuki2ca84272024-02-10 00:15:21 +0000220 // ravenwood-runtime*.so are included in the runtime, so it shouldn't be emitted.
221 for _, o := range module.AllOutputs() {
222 android.AssertStringDoesNotContain(t, "runtime libs shouldn't be included", o, "/ravenwood-test/lib64/ravenwood-runtime")
223 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700224
225 // Verify that we're going to install underlying libs
226 orderOnly := outputJar.OrderOnly.Strings()
227 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
228 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-services.ravenwood.jar")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000229 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/ravenwood-runtime-jni1.so")
Makoto Onuki68676572024-02-02 13:29:01 -0800230 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/libred.so")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000231 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/ravenwood-runtime-jni3.so")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700232 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar")
Ronald Braunstein238a3e32025-03-12 17:03:08 -0700233
234 // Ensure they are listed as "test" modules for code coverage
235 expectedTestOnlyModules := []string{
236 "ravenwood-test",
237 "ravenwood-test-empty",
238 }
239 expectedTopLevelTests := []string{
240 "ravenwood-test",
241 "ravenwood-test-empty",
242 }
243 assertTestOnlyAndTopLevel(t, ctx, expectedTestOnlyModules, expectedTopLevelTests)
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700244}