blob: 0a1b08926e3bd01c9c1f7ab83c74b0f1db2acd5f [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 }
69 prebuilt_font {
70 name: "Font.ttf",
71 src: "Font.ttf",
Makoto Onuki3380f6d2024-05-10 16:00:28 -070072 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -070073 android_ravenwood_libgroup {
74 name: "ravenwood-runtime",
75 libs: [
76 "framework-minus-apex.ravenwood",
77 "framework-services.ravenwood",
78 ],
Makoto Onuki2ca84272024-02-10 00:15:21 +000079 jni_libs: [
80 "ravenwood-runtime-jni1",
81 "ravenwood-runtime-jni2",
82 ],
Makoto Onuki3380f6d2024-05-10 16:00:28 -070083 data: [
John Wu680cd732024-09-13 20:59:05 +000084 ":app1",
85 ],
86 fonts: [
87 ":Font.ttf"
Makoto Onuki3380f6d2024-05-10 16:00:28 -070088 ],
Makoto Onuki4a9869d2023-10-20 10:42:47 -070089 }
90 android_ravenwood_libgroup {
91 name: "ravenwood-utils",
92 libs: [
93 "framework-rules.ravenwood",
94 ],
95 }
96 `),
97)
98
99var installPathPrefix = "out/soong/host/linux-x86/testcases"
100
101func TestRavenwoodRuntime(t *testing.T) {
Jeff Sharkeyddb51522023-11-06 13:56:38 -0700102 if runtime.GOOS != "linux" {
103 t.Skip("requires linux")
104 }
105
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700106 ctx := android.GroupFixturePreparers(
107 PrepareForIntegrationTestWithJava,
John Wu680cd732024-09-13 20:59:05 +0000108 etc.PrepareForTestWithPrebuiltEtc,
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700109 prepareRavenwoodRuntime,
110 ).RunTest(t)
111
112 // Verify that our runtime depends on underlying libs
113 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-minus-apex.ravenwood")
114 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-services.ravenwood")
Makoto Onuki68676572024-02-02 13:29:01 -0800115 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "ravenwood-runtime-jni")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700116 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood")
117
118 // Verify that we've emitted artifacts in expected location
119 runtime := ctx.ModuleForTests("ravenwood-runtime", "android_common")
120 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
121 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000122 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni1.so")
Makoto Onuki68676572024-02-02 13:29:01 -0800123 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/libred.so")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000124 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni3.so")
Makoto Onuki3380f6d2024-05-10 16:00:28 -0700125 runtime.Output(installPathPrefix + "/ravenwood-runtime/ravenwood-data/app1.apk")
John Wu680cd732024-09-13 20:59:05 +0000126 runtime.Output(installPathPrefix + "/ravenwood-runtime/fonts/Font.ttf")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700127 utils := ctx.ModuleForTests("ravenwood-utils", "android_common")
128 utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar")
129}
130
131func TestRavenwoodTest(t *testing.T) {
Jeff Sharkeyddb51522023-11-06 13:56:38 -0700132 if runtime.GOOS != "linux" {
133 t.Skip("requires linux")
134 }
135
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700136 ctx := android.GroupFixturePreparers(
137 PrepareForIntegrationTestWithJava,
John Wu680cd732024-09-13 20:59:05 +0000138 etc.PrepareForTestWithPrebuiltEtc,
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700139 prepareRavenwoodRuntime,
140 ).RunTestWithBp(t, `
John Wu680cd732024-09-13 20:59:05 +0000141 cc_library_shared {
142 name: "jni-lib1",
143 host_supported: true,
144 srcs: ["jni.cpp"],
145 }
146 cc_library_shared {
147 name: "jni-lib2",
148 host_supported: true,
149 srcs: ["jni.cpp"],
150 stem: "libblue",
151 shared_libs: [
152 "jni-lib3",
153 ],
154 }
155 cc_library_shared {
156 name: "jni-lib3",
157 host_supported: true,
158 srcs: ["jni.cpp"],
159 stem: "libpink",
160 }
161 android_ravenwood_test {
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700162 name: "ravenwood-test",
163 srcs: ["Test.java"],
Makoto Onuki2ca84272024-02-10 00:15:21 +0000164 jni_libs: [
165 "jni-lib1",
166 "jni-lib2",
167 "ravenwood-runtime-jni2",
168 ],
Makoto Onuki3380f6d2024-05-10 16:00:28 -0700169 resource_apk: "app2",
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700170 sdk_version: "test_current",
171 }
172 `)
173
174 // Verify that our test depends on underlying libs
175 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-buildtime")
176 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils")
Makoto Onuki68676572024-02-02 13:29:01 -0800177 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "jni-lib")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700178
179 module := ctx.ModuleForTests("ravenwood-test", "android_common")
180 classpath := module.Rule("javac").Args["classpath"]
181
182 // Verify that we're linking against test_current
183 android.AssertStringDoesContain(t, "classpath", classpath, "android_test_stubs_current.jar")
184 // Verify that we're linking against utils
185 android.AssertStringDoesContain(t, "classpath", classpath, "framework-rules.ravenwood.jar")
186 // Verify that we're *NOT* linking against runtime
187 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-minus-apex.ravenwood.jar")
188 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-services.ravenwood.jar")
189
190 // Verify that we've emitted test artifacts in expected location
191 outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar")
192 module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000193 module.Output(installPathPrefix + "/ravenwood-test/lib64/jni-lib1.so")
Makoto Onuki68676572024-02-02 13:29:01 -0800194 module.Output(installPathPrefix + "/ravenwood-test/lib64/libblue.so")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000195 module.Output(installPathPrefix + "/ravenwood-test/lib64/libpink.so")
Makoto Onuki3380f6d2024-05-10 16:00:28 -0700196 module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-res.apk")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000197
198 // ravenwood-runtime*.so are included in the runtime, so it shouldn't be emitted.
199 for _, o := range module.AllOutputs() {
200 android.AssertStringDoesNotContain(t, "runtime libs shouldn't be included", o, "/ravenwood-test/lib64/ravenwood-runtime")
201 }
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700202
203 // Verify that we're going to install underlying libs
204 orderOnly := outputJar.OrderOnly.Strings()
205 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
206 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-services.ravenwood.jar")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000207 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/ravenwood-runtime-jni1.so")
Makoto Onuki68676572024-02-02 13:29:01 -0800208 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/libred.so")
Makoto Onuki2ca84272024-02-10 00:15:21 +0000209 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/ravenwood-runtime-jni3.so")
Makoto Onuki4a9869d2023-10-20 10:42:47 -0700210 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar")
211}