Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1 | // Copyright 2019 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 sdk |
| 16 | |
| 17 | import ( |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 18 | "android/soong/android" |
| 19 | "log" |
| 20 | "os" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 21 | "testing" |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint/proptools" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 24 | ) |
| 25 | |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 26 | // Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE. |
| 27 | func TestMain(m *testing.M) { |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 28 | if android.BuildOs != android.Linux { |
| 29 | // b/145598135 - Generating host snapshots for anything other than linux is not supported. |
| 30 | log.Printf("Skipping as sdk snapshot generation is only supported on %s not %s", android.Linux, android.BuildOs) |
| 31 | os.Exit(0) |
| 32 | } |
| 33 | |
Paul Duffin | abbf63d | 2021-03-18 01:47:31 +0000 | [diff] [blame] | 34 | os.Exit(m.Run()) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 35 | } |
| 36 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 37 | func TestDepNotInRequiredSdks(t *testing.T) { |
| 38 | testSdkError(t, `module "myjavalib".*depends on "otherlib".*that isn't part of the required SDKs:.*`, ` |
| 39 | sdk { |
| 40 | name: "mysdk", |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 41 | java_header_libs: ["sdkmember"], |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | sdk_snapshot { |
| 45 | name: "mysdk@1", |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 46 | java_header_libs: ["sdkmember_mysdk_1"], |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | java_import { |
| 50 | name: "sdkmember", |
| 51 | prefer: false, |
| 52 | host_supported: true, |
| 53 | } |
| 54 | |
| 55 | java_import { |
| 56 | name: "sdkmember_mysdk_1", |
| 57 | sdk_member_name: "sdkmember", |
| 58 | host_supported: true, |
| 59 | } |
| 60 | |
| 61 | java_library { |
| 62 | name: "myjavalib", |
| 63 | srcs: ["Test.java"], |
| 64 | libs: [ |
| 65 | "sdkmember", |
| 66 | "otherlib", |
| 67 | ], |
| 68 | system_modules: "none", |
| 69 | sdk_version: "none", |
| 70 | compile_dex: true, |
| 71 | host_supported: true, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 72 | apex_available: ["myapex"], |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | // this lib is no in mysdk |
| 76 | java_library { |
| 77 | name: "otherlib", |
| 78 | srcs: ["Test.java"], |
| 79 | system_modules: "none", |
| 80 | sdk_version: "none", |
| 81 | compile_dex: true, |
| 82 | host_supported: true, |
| 83 | } |
| 84 | |
| 85 | apex { |
| 86 | name: "myapex", |
| 87 | java_libs: ["myjavalib"], |
| 88 | uses_sdks: ["mysdk@1"], |
| 89 | key: "myapex.key", |
| 90 | certificate: ":myapex.cert", |
| 91 | } |
| 92 | `) |
| 93 | } |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 94 | |
| 95 | // Ensure that prebuilt modules have the same effective visibility as the source |
| 96 | // modules. |
| 97 | func TestSnapshotVisibility(t *testing.T) { |
| 98 | packageBp := ` |
| 99 | package { |
| 100 | default_visibility: ["//other/foo"], |
| 101 | } |
| 102 | |
| 103 | sdk { |
| 104 | name: "mysdk", |
| 105 | visibility: [ |
| 106 | "//other/foo", |
| 107 | // This short form will be replaced with //package:__subpackages__ in the |
| 108 | // generated sdk_snapshot. |
| 109 | ":__subpackages__", |
| 110 | ], |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 111 | prebuilt_visibility: [ |
| 112 | "//prebuilts/mysdk", |
| 113 | ], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 114 | java_header_libs: [ |
| 115 | "myjavalib", |
| 116 | "mypublicjavalib", |
| 117 | "mydefaultedjavalib", |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 118 | "myprivatejavalib", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 119 | ], |
| 120 | } |
| 121 | |
| 122 | java_library { |
| 123 | name: "myjavalib", |
| 124 | // Uses package default visibility |
| 125 | srcs: ["Test.java"], |
| 126 | system_modules: "none", |
| 127 | sdk_version: "none", |
| 128 | } |
| 129 | |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 130 | java_defaults { |
| 131 | name: "java-defaults", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 132 | visibility: ["//other/bar"], |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 135 | java_library { |
| 136 | name: "mypublicjavalib", |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 137 | defaults: ["java-defaults"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 138 | visibility: ["//visibility:public"], |
| 139 | srcs: ["Test.java"], |
| 140 | system_modules: "none", |
| 141 | sdk_version: "none", |
| 142 | } |
| 143 | |
| 144 | java_defaults { |
| 145 | name: "myjavadefaults", |
| 146 | visibility: ["//other/bar"], |
| 147 | } |
| 148 | |
| 149 | java_library { |
| 150 | name: "mydefaultedjavalib", |
| 151 | defaults: ["myjavadefaults"], |
| 152 | srcs: ["Test.java"], |
| 153 | system_modules: "none", |
| 154 | sdk_version: "none", |
| 155 | } |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 156 | |
| 157 | java_library { |
| 158 | name: "myprivatejavalib", |
| 159 | srcs: ["Test.java"], |
| 160 | visibility: ["//visibility:private"], |
| 161 | system_modules: "none", |
| 162 | sdk_version: "none", |
| 163 | } |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 164 | ` |
| 165 | |
| 166 | result := testSdkWithFs(t, ``, |
| 167 | map[string][]byte{ |
| 168 | "package/Test.java": nil, |
| 169 | "package/Android.bp": []byte(packageBp), |
| 170 | }) |
| 171 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 172 | CheckSnapshot(t, result, "mysdk", "package", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 173 | checkAndroidBpContents(` |
| 174 | // This is auto-generated. DO NOT EDIT. |
| 175 | |
| 176 | java_import { |
| 177 | name: "mysdk_myjavalib@current", |
| 178 | sdk_member_name: "myjavalib", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 179 | visibility: [ |
| 180 | "//other/foo", |
| 181 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 182 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 183 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 184 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 185 | jars: ["java/myjavalib.jar"], |
| 186 | } |
| 187 | |
| 188 | java_import { |
| 189 | name: "myjavalib", |
| 190 | prefer: false, |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 191 | visibility: [ |
| 192 | "//other/foo", |
| 193 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 194 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 195 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 196 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 197 | jars: ["java/myjavalib.jar"], |
| 198 | } |
| 199 | |
| 200 | java_import { |
| 201 | name: "mysdk_mypublicjavalib@current", |
| 202 | sdk_member_name: "mypublicjavalib", |
| 203 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 204 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 205 | jars: ["java/mypublicjavalib.jar"], |
| 206 | } |
| 207 | |
| 208 | java_import { |
| 209 | name: "mypublicjavalib", |
| 210 | prefer: false, |
| 211 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 212 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 213 | jars: ["java/mypublicjavalib.jar"], |
| 214 | } |
| 215 | |
| 216 | java_import { |
| 217 | name: "mysdk_mydefaultedjavalib@current", |
| 218 | sdk_member_name: "mydefaultedjavalib", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 219 | visibility: [ |
| 220 | "//other/bar", |
| 221 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 222 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 223 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 224 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 225 | jars: ["java/mydefaultedjavalib.jar"], |
| 226 | } |
| 227 | |
| 228 | java_import { |
| 229 | name: "mydefaultedjavalib", |
| 230 | prefer: false, |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 231 | visibility: [ |
| 232 | "//other/bar", |
| 233 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 234 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 235 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 236 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 237 | jars: ["java/mydefaultedjavalib.jar"], |
| 238 | } |
| 239 | |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 240 | java_import { |
| 241 | name: "mysdk_myprivatejavalib@current", |
| 242 | sdk_member_name: "myprivatejavalib", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 243 | visibility: [ |
| 244 | "//package", |
| 245 | "//prebuilts/mysdk", |
| 246 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 247 | apex_available: ["//apex_available:platform"], |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 248 | jars: ["java/myprivatejavalib.jar"], |
| 249 | } |
| 250 | |
| 251 | java_import { |
| 252 | name: "myprivatejavalib", |
| 253 | prefer: false, |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 254 | visibility: [ |
| 255 | "//package", |
| 256 | "//prebuilts/mysdk", |
| 257 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 258 | apex_available: ["//apex_available:platform"], |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 259 | jars: ["java/myprivatejavalib.jar"], |
| 260 | } |
| 261 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 262 | sdk_snapshot { |
| 263 | name: "mysdk@current", |
| 264 | visibility: [ |
Martin Stjernholm | 01407c5 | 2020-05-13 01:54:21 +0100 | [diff] [blame] | 265 | "//other/foo", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 266 | "//package:__subpackages__", |
| 267 | ], |
| 268 | java_header_libs: [ |
| 269 | "mysdk_myjavalib@current", |
| 270 | "mysdk_mypublicjavalib@current", |
| 271 | "mysdk_mydefaultedjavalib@current", |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 272 | "mysdk_myprivatejavalib@current", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 273 | ], |
| 274 | } |
| 275 | `)) |
| 276 | } |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 277 | |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 278 | func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) { |
| 279 | testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, ` |
| 280 | sdk { |
| 281 | name: "mysdk", |
| 282 | prebuilt_visibility: [ |
| 283 | "//foo", |
| 284 | "//visibility:private", |
| 285 | ], |
| 286 | } |
| 287 | `) |
| 288 | } |
| 289 | |
| 290 | func TestPrebuiltVisibilityProperty_AddPrivate(t *testing.T) { |
| 291 | testSdkError(t, `prebuilt_visibility: "//visibility:private" does not widen the visibility`, ` |
| 292 | sdk { |
| 293 | name: "mysdk", |
| 294 | prebuilt_visibility: [ |
| 295 | "//visibility:private", |
| 296 | ], |
| 297 | java_header_libs: [ |
| 298 | "myjavalib", |
| 299 | ], |
| 300 | } |
| 301 | |
| 302 | java_library { |
| 303 | name: "myjavalib", |
| 304 | // Uses package default visibility |
| 305 | srcs: ["Test.java"], |
| 306 | system_modules: "none", |
| 307 | sdk_version: "none", |
| 308 | } |
| 309 | `) |
| 310 | } |
| 311 | |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 312 | func TestSdkInstall(t *testing.T) { |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 313 | sdk := ` |
| 314 | sdk { |
| 315 | name: "mysdk", |
| 316 | } |
| 317 | ` |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 318 | result := testSdkWithFs(t, sdk, nil) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 319 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 320 | CheckSnapshot(t, result, "mysdk", "", |
| 321 | checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`)) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 322 | } |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 323 | |
| 324 | type EmbeddedPropertiesStruct struct { |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 325 | S_Embedded_Common string `android:"arch_variant"` |
| 326 | S_Embedded_Different string `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | type testPropertiesStruct struct { |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 330 | name string |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 331 | private string |
| 332 | Public_Kept string `sdk:"keep"` |
| 333 | S_Common string |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 334 | S_Different string `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 335 | A_Common []string |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 336 | A_Different []string `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 337 | F_Common *bool |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 338 | F_Different *bool `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 339 | EmbeddedPropertiesStruct |
| 340 | } |
| 341 | |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 342 | func (p *testPropertiesStruct) optimizableProperties() interface{} { |
| 343 | return p |
| 344 | } |
| 345 | |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 346 | func (p *testPropertiesStruct) String() string { |
| 347 | return p.name |
| 348 | } |
| 349 | |
| 350 | var _ propertiesContainer = (*testPropertiesStruct)(nil) |
| 351 | |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 352 | func TestCommonValueOptimization(t *testing.T) { |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 353 | common := &testPropertiesStruct{name: "common"} |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 354 | structs := []propertiesContainer{ |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 355 | &testPropertiesStruct{ |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 356 | name: "struct-0", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 357 | private: "common", |
| 358 | Public_Kept: "common", |
| 359 | S_Common: "common", |
| 360 | S_Different: "upper", |
| 361 | A_Common: []string{"first", "second"}, |
| 362 | A_Different: []string{"alpha", "beta"}, |
| 363 | F_Common: proptools.BoolPtr(false), |
| 364 | F_Different: proptools.BoolPtr(false), |
| 365 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 366 | S_Embedded_Common: "embedded_common", |
| 367 | S_Embedded_Different: "embedded_upper", |
| 368 | }, |
| 369 | }, |
| 370 | &testPropertiesStruct{ |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 371 | name: "struct-1", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 372 | private: "common", |
| 373 | Public_Kept: "common", |
| 374 | S_Common: "common", |
| 375 | S_Different: "lower", |
| 376 | A_Common: []string{"first", "second"}, |
| 377 | A_Different: []string{"alpha", "delta"}, |
| 378 | F_Common: proptools.BoolPtr(false), |
| 379 | F_Different: proptools.BoolPtr(true), |
| 380 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 381 | S_Embedded_Common: "embedded_common", |
| 382 | S_Embedded_Different: "embedded_lower", |
| 383 | }, |
| 384 | }, |
| 385 | } |
| 386 | |
| 387 | extractor := newCommonValueExtractor(common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 388 | |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 389 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 390 | android.AssertDeepEquals(t, "unexpected error", nil, err) |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 391 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 392 | android.AssertDeepEquals(t, "common properties not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 393 | &testPropertiesStruct{ |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 394 | name: "common", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 395 | private: "", |
| 396 | Public_Kept: "", |
| 397 | S_Common: "common", |
| 398 | S_Different: "", |
| 399 | A_Common: []string{"first", "second"}, |
| 400 | A_Different: []string(nil), |
| 401 | F_Common: proptools.BoolPtr(false), |
| 402 | F_Different: nil, |
| 403 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 404 | S_Embedded_Common: "embedded_common", |
| 405 | S_Embedded_Different: "", |
| 406 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 407 | }, |
| 408 | common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 409 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 410 | android.AssertDeepEquals(t, "updated properties[0] not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 411 | &testPropertiesStruct{ |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 412 | name: "struct-0", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 413 | private: "common", |
| 414 | Public_Kept: "common", |
| 415 | S_Common: "", |
| 416 | S_Different: "upper", |
| 417 | A_Common: nil, |
| 418 | A_Different: []string{"alpha", "beta"}, |
| 419 | F_Common: nil, |
| 420 | F_Different: proptools.BoolPtr(false), |
| 421 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 422 | S_Embedded_Common: "", |
| 423 | S_Embedded_Different: "embedded_upper", |
| 424 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 425 | }, |
| 426 | structs[0]) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 427 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 428 | android.AssertDeepEquals(t, "updated properties[1] not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 429 | &testPropertiesStruct{ |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 430 | name: "struct-1", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 431 | private: "common", |
| 432 | Public_Kept: "common", |
| 433 | S_Common: "", |
| 434 | S_Different: "lower", |
| 435 | A_Common: nil, |
| 436 | A_Different: []string{"alpha", "delta"}, |
| 437 | F_Common: nil, |
| 438 | F_Different: proptools.BoolPtr(true), |
| 439 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 440 | S_Embedded_Common: "", |
| 441 | S_Embedded_Different: "embedded_lower", |
| 442 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 443 | }, |
| 444 | structs[1]) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 445 | } |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 446 | |
| 447 | func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) { |
| 448 | common := &testPropertiesStruct{name: "common"} |
| 449 | structs := []propertiesContainer{ |
| 450 | &testPropertiesStruct{ |
| 451 | name: "struct-0", |
| 452 | S_Common: "should-be-but-is-not-common0", |
| 453 | }, |
| 454 | &testPropertiesStruct{ |
| 455 | name: "struct-1", |
| 456 | S_Common: "should-be-but-is-not-common1", |
| 457 | }, |
| 458 | } |
| 459 | |
| 460 | extractor := newCommonValueExtractor(common) |
| 461 | |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 462 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 463 | android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties: |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 464 | "struct-0" has value "should-be-but-is-not-common0" |
| 465 | "struct-1" has value "should-be-but-is-not-common1"`, err) |
| 466 | } |