satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 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 apex |
| 16 | |
| 17 | import ( |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 18 | "android/soong/dexpreopt" |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/java" |
| 23 | ) |
| 24 | |
| 25 | var prepareForTestWithSystemserverclasspathFragment = android.GroupFixturePreparers( |
| 26 | java.PrepareForTestWithDexpreopt, |
| 27 | PrepareForTestWithApexBuildComponents, |
| 28 | ) |
| 29 | |
| 30 | func TestSystemserverclasspathFragmentContents(t *testing.T) { |
| 31 | result := android.GroupFixturePreparers( |
| 32 | prepareForTestWithSystemserverclasspathFragment, |
| 33 | prepareForTestWithMyapex, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 34 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 35 | ).RunTestWithBp(t, ` |
| 36 | apex { |
| 37 | name: "myapex", |
| 38 | key: "myapex.key", |
| 39 | systemserverclasspath_fragments: [ |
| 40 | "mysystemserverclasspathfragment", |
| 41 | ], |
| 42 | updatable: false, |
| 43 | } |
| 44 | |
| 45 | apex_key { |
| 46 | name: "myapex.key", |
| 47 | public_key: "testkey.avbpubkey", |
| 48 | private_key: "testkey.pem", |
| 49 | } |
| 50 | |
| 51 | java_library { |
| 52 | name: "foo", |
| 53 | srcs: ["b.java"], |
| 54 | installable: true, |
| 55 | apex_available: [ |
| 56 | "myapex", |
| 57 | ], |
| 58 | } |
| 59 | |
| 60 | systemserverclasspath_fragment { |
| 61 | name: "mysystemserverclasspathfragment", |
| 62 | contents: [ |
| 63 | "foo", |
| 64 | ], |
| 65 | apex_available: [ |
| 66 | "myapex", |
| 67 | ], |
| 68 | } |
| 69 | `) |
| 70 | |
| 71 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 72 | "etc/classpaths/systemserverclasspath.pb", |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 73 | "javalib/foo.jar", |
| 74 | }) |
| 75 | |
| 76 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 77 | `myapex.key`, |
| 78 | `mysystemserverclasspathfragment`, |
| 79 | }) |
| 80 | } |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 81 | |
| 82 | func TestSystemserverclasspathFragmentNoGeneratedProto(t *testing.T) { |
| 83 | result := android.GroupFixturePreparers( |
| 84 | prepareForTestWithSystemserverclasspathFragment, |
| 85 | prepareForTestWithMyapex, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 86 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 87 | ).RunTestWithBp(t, ` |
| 88 | apex { |
| 89 | name: "myapex", |
| 90 | key: "myapex.key", |
| 91 | systemserverclasspath_fragments: [ |
| 92 | "mysystemserverclasspathfragment", |
| 93 | ], |
| 94 | updatable: false, |
| 95 | } |
| 96 | |
| 97 | apex_key { |
| 98 | name: "myapex.key", |
| 99 | public_key: "testkey.avbpubkey", |
| 100 | private_key: "testkey.pem", |
| 101 | } |
| 102 | |
| 103 | java_library { |
| 104 | name: "foo", |
| 105 | srcs: ["b.java"], |
| 106 | installable: true, |
| 107 | apex_available: [ |
| 108 | "myapex", |
| 109 | ], |
| 110 | } |
| 111 | |
| 112 | systemserverclasspath_fragment { |
| 113 | name: "mysystemserverclasspathfragment", |
| 114 | generate_classpaths_proto: false, |
| 115 | contents: [ |
| 116 | "foo", |
| 117 | ], |
| 118 | apex_available: [ |
| 119 | "myapex", |
| 120 | ], |
| 121 | } |
| 122 | `) |
| 123 | |
| 124 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 125 | "javalib/foo.jar", |
| 126 | }) |
| 127 | |
| 128 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 129 | `myapex.key`, |
| 130 | `mysystemserverclasspathfragment`, |
| 131 | }) |
| 132 | } |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame^] | 133 | |
| 134 | func TestSystemServerClasspathFragmentWithContentNotInMake(t *testing.T) { |
| 135 | android.GroupFixturePreparers( |
| 136 | prepareForTestWithSystemserverclasspathFragment, |
| 137 | prepareForTestWithMyapex, |
| 138 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 139 | ). |
| 140 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 141 | `in contents must also be declared in PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS`)). |
| 142 | RunTestWithBp(t, ` |
| 143 | apex { |
| 144 | name: "myapex", |
| 145 | key: "myapex.key", |
| 146 | systemserverclasspath_fragments: [ |
| 147 | "mysystemserverclasspathfragment", |
| 148 | ], |
| 149 | updatable: false, |
| 150 | } |
| 151 | |
| 152 | apex_key { |
| 153 | name: "myapex.key", |
| 154 | public_key: "testkey.avbpubkey", |
| 155 | private_key: "testkey.pem", |
| 156 | } |
| 157 | |
| 158 | java_library { |
| 159 | name: "foo", |
| 160 | srcs: ["b.java"], |
| 161 | installable: true, |
| 162 | apex_available: ["myapex"], |
| 163 | } |
| 164 | |
| 165 | java_library { |
| 166 | name: "bar", |
| 167 | srcs: ["b.java"], |
| 168 | installable: true, |
| 169 | apex_available: ["myapex"], |
| 170 | } |
| 171 | |
| 172 | systemserverclasspath_fragment { |
| 173 | name: "mysystemserverclasspathfragment", |
| 174 | contents: [ |
| 175 | "foo", |
| 176 | "bar", |
| 177 | ], |
| 178 | apex_available: [ |
| 179 | "myapex", |
| 180 | ], |
| 181 | } |
| 182 | `) |
| 183 | } |