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) { |
Colin Cross | 844cb6a | 2025-01-29 15:53:21 -0800 | [diff] [blame] | 29 | t.Parallel() |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 30 | result := android.GroupFixturePreparers( |
| 31 | prepareForJavaTest, |
| 32 | ).RunTestWithBp(t, ` |
| 33 | java_library { |
| 34 | name: "foo", |
| 35 | srcs: ["A.java"], |
| 36 | } |
| 37 | java_library { |
| 38 | name: "foo_vendor", |
| 39 | srcs: ["A.java"], |
| 40 | vendor: true, |
| 41 | sdk_version: "current", |
| 42 | } |
| 43 | java_library { |
| 44 | name: "foo_soc_specific", |
| 45 | srcs: ["A.java"], |
| 46 | soc_specific: true, |
| 47 | sdk_version: "current", |
| 48 | } |
| 49 | java_library { |
| 50 | name: "foo_product_specific", |
| 51 | srcs: ["A.java"], |
| 52 | product_specific: true, |
| 53 | sdk_version: "current", |
| 54 | } |
| 55 | java_test { |
| 56 | name: "foo_cts_test", |
| 57 | srcs: ["A.java"], |
| 58 | test_suites: [ |
| 59 | "cts", |
| 60 | ], |
| 61 | } |
| 62 | java_test { |
| 63 | name: "foo_non_cts_test", |
| 64 | srcs: ["A.java"], |
| 65 | test_suites: [ |
| 66 | "general-tests", |
| 67 | ], |
| 68 | } |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 69 | java_library { |
| 70 | name: "bar", |
| 71 | static_libs: [ |
| 72 | "framework-minus-apex", |
| 73 | ], |
| 74 | } |
| 75 | java_library { |
| 76 | name: "baz", |
| 77 | static_libs: [ |
| 78 | "bar", |
| 79 | ], |
| 80 | } |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 81 | `) |
| 82 | |
| 83 | testcases := []struct { |
| 84 | moduleName string |
| 85 | isSystemContainer bool |
| 86 | isVendorContainer bool |
| 87 | isProductContainer bool |
| 88 | isCts bool |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 89 | isUnstable bool |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 90 | }{ |
| 91 | { |
| 92 | moduleName: "foo", |
| 93 | isSystemContainer: true, |
| 94 | isVendorContainer: false, |
| 95 | isProductContainer: false, |
| 96 | isCts: false, |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 97 | isUnstable: false, |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 98 | }, |
| 99 | { |
| 100 | moduleName: "foo_vendor", |
| 101 | isSystemContainer: false, |
| 102 | isVendorContainer: true, |
| 103 | isProductContainer: false, |
| 104 | isCts: false, |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 105 | isUnstable: false, |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 106 | }, |
| 107 | { |
| 108 | moduleName: "foo_soc_specific", |
| 109 | isSystemContainer: false, |
| 110 | isVendorContainer: true, |
| 111 | isProductContainer: false, |
| 112 | isCts: false, |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 113 | isUnstable: false, |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 114 | }, |
| 115 | { |
| 116 | moduleName: "foo_product_specific", |
| 117 | isSystemContainer: false, |
| 118 | isVendorContainer: false, |
| 119 | isProductContainer: true, |
| 120 | isCts: false, |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 121 | isUnstable: false, |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 122 | }, |
| 123 | { |
| 124 | moduleName: "foo_cts_test", |
| 125 | isSystemContainer: false, |
| 126 | isVendorContainer: false, |
| 127 | isProductContainer: false, |
| 128 | isCts: true, |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 129 | isUnstable: false, |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 130 | }, |
| 131 | { |
| 132 | moduleName: "foo_non_cts_test", |
| 133 | isSystemContainer: false, |
| 134 | isVendorContainer: false, |
| 135 | isProductContainer: false, |
| 136 | isCts: false, |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 137 | isUnstable: false, |
| 138 | }, |
| 139 | { |
| 140 | moduleName: "bar", |
| 141 | isSystemContainer: true, |
| 142 | isVendorContainer: false, |
| 143 | isProductContainer: false, |
| 144 | isCts: false, |
| 145 | isUnstable: true, |
| 146 | }, |
| 147 | { |
| 148 | moduleName: "baz", |
| 149 | isSystemContainer: true, |
| 150 | isVendorContainer: false, |
| 151 | isProductContainer: false, |
| 152 | isCts: false, |
| 153 | isUnstable: true, |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 154 | }, |
| 155 | } |
| 156 | |
| 157 | for _, c := range testcases { |
Colin Cross | 90607e9 | 2025-02-11 14:58:07 -0800 | [diff] [blame] | 158 | m := result.ModuleForTests(t, c.moduleName, "android_common") |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 159 | containers, _ := android.OtherModuleProvider(result.TestContext.OtherModuleProviderAdaptor(), m.Module(), android.ContainersInfoProvider) |
| 160 | belongingContainers := containers.BelongingContainers() |
| 161 | checkContainerMatch(t, c.moduleName, "system", c.isSystemContainer, android.InList(android.SystemContainer, belongingContainers)) |
| 162 | checkContainerMatch(t, c.moduleName, "vendor", c.isVendorContainer, android.InList(android.VendorContainer, belongingContainers)) |
| 163 | checkContainerMatch(t, c.moduleName, "product", c.isProductContainer, android.InList(android.ProductContainer, belongingContainers)) |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame] | 164 | checkContainerMatch(t, c.moduleName, "cts", c.isCts, android.InList(android.CtsContainer, belongingContainers)) |
| 165 | checkContainerMatch(t, c.moduleName, "unstable", c.isUnstable, android.InList(android.UnstableContainer, belongingContainers)) |
Jihoon Kang | f86fe9a | 2024-06-26 22:18:10 +0000 | [diff] [blame] | 166 | } |
| 167 | } |