Makoto Onuki | 4a9869d | 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 | ddb5152 | 2023-11-06 13:56:38 -0700 | [diff] [blame^] | 18 | "runtime" |
Makoto Onuki | 4a9869d | 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", ` |
| 29 | java_library_static { |
| 30 | name: "framework-minus-apex.ravenwood", |
| 31 | srcs: ["Framework.java"], |
| 32 | } |
| 33 | java_library_static { |
| 34 | name: "framework-services.ravenwood", |
| 35 | srcs: ["Services.java"], |
| 36 | } |
| 37 | java_library_static { |
| 38 | name: "framework-rules.ravenwood", |
| 39 | srcs: ["Rules.java"], |
| 40 | } |
| 41 | android_ravenwood_libgroup { |
| 42 | name: "ravenwood-runtime", |
| 43 | libs: [ |
| 44 | "framework-minus-apex.ravenwood", |
| 45 | "framework-services.ravenwood", |
| 46 | ], |
| 47 | } |
| 48 | android_ravenwood_libgroup { |
| 49 | name: "ravenwood-utils", |
| 50 | libs: [ |
| 51 | "framework-rules.ravenwood", |
| 52 | ], |
| 53 | } |
| 54 | `), |
| 55 | ) |
| 56 | |
| 57 | var installPathPrefix = "out/soong/host/linux-x86/testcases" |
| 58 | |
| 59 | func TestRavenwoodRuntime(t *testing.T) { |
Jeff Sharkey | ddb5152 | 2023-11-06 13:56:38 -0700 | [diff] [blame^] | 60 | if runtime.GOOS != "linux" { |
| 61 | t.Skip("requires linux") |
| 62 | } |
| 63 | |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 64 | ctx := android.GroupFixturePreparers( |
| 65 | PrepareForIntegrationTestWithJava, |
| 66 | prepareRavenwoodRuntime, |
| 67 | ).RunTest(t) |
| 68 | |
| 69 | // Verify that our runtime depends on underlying libs |
| 70 | CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-minus-apex.ravenwood") |
| 71 | CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-services.ravenwood") |
| 72 | CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood") |
| 73 | |
| 74 | // Verify that we've emitted artifacts in expected location |
| 75 | runtime := ctx.ModuleForTests("ravenwood-runtime", "android_common") |
| 76 | runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar") |
| 77 | runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar") |
| 78 | utils := ctx.ModuleForTests("ravenwood-utils", "android_common") |
| 79 | utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar") |
| 80 | } |
| 81 | |
| 82 | func TestRavenwoodTest(t *testing.T) { |
Jeff Sharkey | ddb5152 | 2023-11-06 13:56:38 -0700 | [diff] [blame^] | 83 | if runtime.GOOS != "linux" { |
| 84 | t.Skip("requires linux") |
| 85 | } |
| 86 | |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame] | 87 | ctx := android.GroupFixturePreparers( |
| 88 | PrepareForIntegrationTestWithJava, |
| 89 | prepareRavenwoodRuntime, |
| 90 | ).RunTestWithBp(t, ` |
| 91 | android_ravenwood_test { |
| 92 | name: "ravenwood-test", |
| 93 | srcs: ["Test.java"], |
| 94 | sdk_version: "test_current", |
| 95 | } |
| 96 | `) |
| 97 | |
| 98 | // Verify that our test depends on underlying libs |
| 99 | CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-buildtime") |
| 100 | CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils") |
| 101 | |
| 102 | module := ctx.ModuleForTests("ravenwood-test", "android_common") |
| 103 | classpath := module.Rule("javac").Args["classpath"] |
| 104 | |
| 105 | // Verify that we're linking against test_current |
| 106 | android.AssertStringDoesContain(t, "classpath", classpath, "android_test_stubs_current.jar") |
| 107 | // Verify that we're linking against utils |
| 108 | android.AssertStringDoesContain(t, "classpath", classpath, "framework-rules.ravenwood.jar") |
| 109 | // Verify that we're *NOT* linking against runtime |
| 110 | android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-minus-apex.ravenwood.jar") |
| 111 | android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-services.ravenwood.jar") |
| 112 | |
| 113 | // Verify that we've emitted test artifacts in expected location |
| 114 | outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar") |
| 115 | module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config") |
| 116 | |
| 117 | // Verify that we're going to install underlying libs |
| 118 | orderOnly := outputJar.OrderOnly.Strings() |
| 119 | android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-minus-apex.ravenwood.jar") |
| 120 | android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-services.ravenwood.jar") |
| 121 | android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar") |
| 122 | } |