Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 1 | // Copyright 2024 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 ( |
| 18 | "android/soong/android" |
| 19 | "fmt" |
| 20 | "testing" |
| 21 | ) |
| 22 | |
| 23 | var checkContainerMatch = func(t *testing.T, name string, container string, expected bool, actual bool) { |
| 24 | errorMessage := fmt.Sprintf("module %s container %s value differ", name, container) |
| 25 | android.AssertBoolEquals(t, errorMessage, expected, actual) |
| 26 | } |
| 27 | |
| 28 | func TestJavaContainersModuleProperties(t *testing.T) { |
| 29 | result := android.GroupFixturePreparers( |
| 30 | prepareForJavaTest, |
| 31 | ).RunTestWithBp(t, ` |
| 32 | java_library { |
| 33 | name: "foo", |
| 34 | srcs: ["A.java"], |
| 35 | } |
| 36 | java_library { |
| 37 | name: "foo_vendor", |
| 38 | srcs: ["A.java"], |
| 39 | vendor: true, |
| 40 | sdk_version: "current", |
| 41 | } |
| 42 | java_library { |
| 43 | name: "foo_soc_specific", |
| 44 | srcs: ["A.java"], |
| 45 | soc_specific: true, |
| 46 | sdk_version: "current", |
| 47 | } |
| 48 | java_library { |
| 49 | name: "foo_product_specific", |
| 50 | srcs: ["A.java"], |
| 51 | product_specific: true, |
| 52 | sdk_version: "current", |
| 53 | } |
| 54 | java_test { |
| 55 | name: "foo_cts_test", |
| 56 | srcs: ["A.java"], |
| 57 | test_suites: [ |
| 58 | "cts", |
| 59 | ], |
| 60 | } |
| 61 | java_test { |
| 62 | name: "foo_non_cts_test", |
| 63 | srcs: ["A.java"], |
| 64 | test_suites: [ |
| 65 | "general-tests", |
| 66 | ], |
| 67 | } |
| 68 | `) |
| 69 | |
| 70 | testcases := []struct { |
| 71 | moduleName string |
| 72 | isSystemContainer bool |
| 73 | isVendorContainer bool |
| 74 | isProductContainer bool |
| 75 | isCts bool |
| 76 | }{ |
| 77 | { |
| 78 | moduleName: "foo", |
| 79 | isSystemContainer: true, |
| 80 | isVendorContainer: false, |
| 81 | isProductContainer: false, |
| 82 | isCts: false, |
| 83 | }, |
| 84 | { |
| 85 | moduleName: "foo_vendor", |
| 86 | isSystemContainer: false, |
| 87 | isVendorContainer: true, |
| 88 | isProductContainer: false, |
| 89 | isCts: false, |
| 90 | }, |
| 91 | { |
| 92 | moduleName: "foo_soc_specific", |
| 93 | isSystemContainer: false, |
| 94 | isVendorContainer: true, |
| 95 | isProductContainer: false, |
| 96 | isCts: false, |
| 97 | }, |
| 98 | { |
| 99 | moduleName: "foo_product_specific", |
| 100 | isSystemContainer: false, |
| 101 | isVendorContainer: false, |
| 102 | isProductContainer: true, |
| 103 | isCts: false, |
| 104 | }, |
| 105 | { |
| 106 | moduleName: "foo_cts_test", |
| 107 | isSystemContainer: false, |
| 108 | isVendorContainer: false, |
| 109 | isProductContainer: false, |
| 110 | isCts: true, |
| 111 | }, |
| 112 | { |
| 113 | moduleName: "foo_non_cts_test", |
| 114 | isSystemContainer: false, |
| 115 | isVendorContainer: false, |
| 116 | isProductContainer: false, |
| 117 | isCts: false, |
| 118 | }, |
| 119 | } |
| 120 | |
| 121 | for _, c := range testcases { |
| 122 | m := result.ModuleForTests(c.moduleName, "android_common") |
| 123 | containers, _ := android.OtherModuleProvider(result.TestContext.OtherModuleProviderAdaptor(), m.Module(), android.ContainersInfoProvider) |
| 124 | belongingContainers := containers.BelongingContainers() |
| 125 | checkContainerMatch(t, c.moduleName, "system", c.isSystemContainer, android.InList(android.SystemContainer, belongingContainers)) |
| 126 | checkContainerMatch(t, c.moduleName, "vendor", c.isVendorContainer, android.InList(android.VendorContainer, belongingContainers)) |
| 127 | checkContainerMatch(t, c.moduleName, "product", c.isProductContainer, android.InList(android.ProductContainer, belongingContainers)) |
| 128 | } |
| 129 | } |