blob: a71391cad5fafd76d4840bfd74565516543bb3f3 [file] [log] [blame]
Makoto Onuki32eb1332023-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 Sharkeya45bf7f2023-11-06 13:56:38 -070018 "runtime"
Makoto Onuki32eb1332023-10-20 10:42:47 -070019 "testing"
20
21 "android/soong/android"
22)
23
24var prepareRavenwoodRuntime = android.GroupFixturePreparers(
25 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
26 RegisterRavenwoodBuildComponents(ctx)
27 }),
28 android.FixtureAddTextFile("ravenwood/Android.bp", `
Makoto Onuki5461e4b2024-02-02 13:29:01 -080029 cc_library_shared {
30 name: "ravenwood-runtime-jni",
31 host_supported: true,
32 srcs: ["jni.cpp"],
33 }
34 cc_library_shared {
35 name: "ravenwood-runtime-jni2",
36 host_supported: true,
37 srcs: ["jni.cpp"],
38 stem: "libred",
39 }
Makoto Onuki32eb1332023-10-20 10:42:47 -070040 java_library_static {
41 name: "framework-minus-apex.ravenwood",
42 srcs: ["Framework.java"],
43 }
44 java_library_static {
45 name: "framework-services.ravenwood",
46 srcs: ["Services.java"],
47 }
48 java_library_static {
49 name: "framework-rules.ravenwood",
50 srcs: ["Rules.java"],
51 }
52 android_ravenwood_libgroup {
53 name: "ravenwood-runtime",
54 libs: [
55 "framework-minus-apex.ravenwood",
56 "framework-services.ravenwood",
57 ],
Makoto Onuki5461e4b2024-02-02 13:29:01 -080058 jni_libs: ["ravenwood-runtime-jni", "ravenwood-runtime-jni2"],
Makoto Onuki32eb1332023-10-20 10:42:47 -070059 }
60 android_ravenwood_libgroup {
61 name: "ravenwood-utils",
62 libs: [
63 "framework-rules.ravenwood",
64 ],
65 }
66 `),
67)
68
69var installPathPrefix = "out/soong/host/linux-x86/testcases"
70
71func TestRavenwoodRuntime(t *testing.T) {
Jeff Sharkeya45bf7f2023-11-06 13:56:38 -070072 if runtime.GOOS != "linux" {
73 t.Skip("requires linux")
74 }
75
Makoto Onuki32eb1332023-10-20 10:42:47 -070076 ctx := android.GroupFixturePreparers(
77 PrepareForIntegrationTestWithJava,
78 prepareRavenwoodRuntime,
79 ).RunTest(t)
80
81 // Verify that our runtime depends on underlying libs
82 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-minus-apex.ravenwood")
83 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-services.ravenwood")
Makoto Onuki5461e4b2024-02-02 13:29:01 -080084 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "ravenwood-runtime-jni")
Makoto Onuki32eb1332023-10-20 10:42:47 -070085 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood")
86
87 // Verify that we've emitted artifacts in expected location
88 runtime := ctx.ModuleForTests("ravenwood-runtime", "android_common")
89 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
90 runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar")
Makoto Onuki5461e4b2024-02-02 13:29:01 -080091 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni.so")
92 runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/libred.so")
Makoto Onuki32eb1332023-10-20 10:42:47 -070093 utils := ctx.ModuleForTests("ravenwood-utils", "android_common")
94 utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar")
95}
96
97func TestRavenwoodTest(t *testing.T) {
Jeff Sharkeya45bf7f2023-11-06 13:56:38 -070098 if runtime.GOOS != "linux" {
99 t.Skip("requires linux")
100 }
101
Makoto Onuki32eb1332023-10-20 10:42:47 -0700102 ctx := android.GroupFixturePreparers(
103 PrepareForIntegrationTestWithJava,
104 prepareRavenwoodRuntime,
105 ).RunTestWithBp(t, `
Makoto Onuki5461e4b2024-02-02 13:29:01 -0800106 cc_library_shared {
107 name: "jni-lib",
108 host_supported: true,
109 srcs: ["jni.cpp"],
110 }
111 cc_library_shared {
112 name: "jni-lib2",
113 host_supported: true,
114 srcs: ["jni.cpp"],
115 stem: "libblue",
116 }
117 android_ravenwood_test {
Makoto Onuki32eb1332023-10-20 10:42:47 -0700118 name: "ravenwood-test",
119 srcs: ["Test.java"],
Makoto Onuki5461e4b2024-02-02 13:29:01 -0800120 jni_libs: ["jni-lib", "jni-lib2"],
Makoto Onuki32eb1332023-10-20 10:42:47 -0700121 sdk_version: "test_current",
122 }
123 `)
124
125 // Verify that our test depends on underlying libs
126 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-buildtime")
127 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils")
Makoto Onuki5461e4b2024-02-02 13:29:01 -0800128 CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "jni-lib")
Makoto Onuki32eb1332023-10-20 10:42:47 -0700129
130 module := ctx.ModuleForTests("ravenwood-test", "android_common")
131 classpath := module.Rule("javac").Args["classpath"]
132
133 // Verify that we're linking against test_current
134 android.AssertStringDoesContain(t, "classpath", classpath, "android_test_stubs_current.jar")
135 // Verify that we're linking against utils
136 android.AssertStringDoesContain(t, "classpath", classpath, "framework-rules.ravenwood.jar")
137 // Verify that we're *NOT* linking against runtime
138 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-minus-apex.ravenwood.jar")
139 android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-services.ravenwood.jar")
140
141 // Verify that we've emitted test artifacts in expected location
142 outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar")
143 module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config")
Makoto Onuki5461e4b2024-02-02 13:29:01 -0800144 module.Output(installPathPrefix + "/ravenwood-test/lib64/jni-lib.so")
145 module.Output(installPathPrefix + "/ravenwood-test/lib64/libblue.so")
Makoto Onuki32eb1332023-10-20 10:42:47 -0700146
147 // Verify that we're going to install underlying libs
148 orderOnly := outputJar.OrderOnly.Strings()
149 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-minus-apex.ravenwood.jar")
150 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-services.ravenwood.jar")
Makoto Onuki5461e4b2024-02-02 13:29:01 -0800151 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/ravenwood-runtime-jni.so")
152 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/lib64/libred.so")
Makoto Onuki32eb1332023-10-20 10:42:47 -0700153 android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar")
154}