Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Jeff Sharkey | a45bf7f | 2023-11-06 13:56:38 -0700 | [diff] [blame] | 18 | "runtime" |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | var prepareRavenwoodRuntime = android.GroupFixturePreparers( |
| 25 | android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { |
| 26 | RegisterRavenwoodBuildComponents(ctx) |
| 27 | }), |
| 28 | android.FixtureAddTextFile("ravenwood/Android.bp", ` |
Makoto Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 29 | 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 Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 40 | 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 Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 58 | jni_libs: ["ravenwood-runtime-jni", "ravenwood-runtime-jni2"], |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 59 | } |
| 60 | android_ravenwood_libgroup { |
| 61 | name: "ravenwood-utils", |
| 62 | libs: [ |
| 63 | "framework-rules.ravenwood", |
| 64 | ], |
| 65 | } |
| 66 | `), |
| 67 | ) |
| 68 | |
| 69 | var installPathPrefix = "out/soong/host/linux-x86/testcases" |
| 70 | |
| 71 | func TestRavenwoodRuntime(t *testing.T) { |
Jeff Sharkey | a45bf7f | 2023-11-06 13:56:38 -0700 | [diff] [blame] | 72 | if runtime.GOOS != "linux" { |
| 73 | t.Skip("requires linux") |
| 74 | } |
| 75 | |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 76 | 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 Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 84 | CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "ravenwood-runtime-jni") |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 85 | 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 Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 91 | runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/ravenwood-runtime-jni.so") |
| 92 | runtime.Output(installPathPrefix + "/ravenwood-runtime/lib64/libred.so") |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 93 | utils := ctx.ModuleForTests("ravenwood-utils", "android_common") |
| 94 | utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar") |
| 95 | } |
| 96 | |
| 97 | func TestRavenwoodTest(t *testing.T) { |
Jeff Sharkey | a45bf7f | 2023-11-06 13:56:38 -0700 | [diff] [blame] | 98 | if runtime.GOOS != "linux" { |
| 99 | t.Skip("requires linux") |
| 100 | } |
| 101 | |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 102 | ctx := android.GroupFixturePreparers( |
| 103 | PrepareForIntegrationTestWithJava, |
| 104 | prepareRavenwoodRuntime, |
| 105 | ).RunTestWithBp(t, ` |
Makoto Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 106 | 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 Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 118 | name: "ravenwood-test", |
| 119 | srcs: ["Test.java"], |
Makoto Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 120 | jni_libs: ["jni-lib", "jni-lib2"], |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 121 | 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 Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 128 | CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "jni-lib") |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 129 | |
| 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 Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 144 | module.Output(installPathPrefix + "/ravenwood-test/lib64/jni-lib.so") |
| 145 | module.Output(installPathPrefix + "/ravenwood-test/lib64/libblue.so") |
Makoto Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 146 | |
| 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 Onuki | 5461e4b | 2024-02-02 13:29:01 -0800 | [diff] [blame] | 151 | 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 Onuki | 32eb133 | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 153 | android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar") |
| 154 | } |