blob: 35a3020ec9424587e7f517317e142fcc1a12d878 [file] [log] [blame]
Jihoon Kangf86fe9a2024-06-26 22:18:10 +00001// 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
15package java
16
17import (
18 "android/soong/android"
19 "fmt"
20 "testing"
21)
22
23var 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
28func TestJavaContainersModuleProperties(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -080029 t.Parallel()
Jihoon Kangf86fe9a2024-06-26 22:18:10 +000030 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 Kang0f3b1a72024-08-12 22:47:01 +000069 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 Kangf86fe9a2024-06-26 22:18:10 +000081 `)
82
83 testcases := []struct {
84 moduleName string
85 isSystemContainer bool
86 isVendorContainer bool
87 isProductContainer bool
88 isCts bool
Jihoon Kang0f3b1a72024-08-12 22:47:01 +000089 isUnstable bool
Jihoon Kangf86fe9a2024-06-26 22:18:10 +000090 }{
91 {
92 moduleName: "foo",
93 isSystemContainer: true,
94 isVendorContainer: false,
95 isProductContainer: false,
96 isCts: false,
Jihoon Kang0f3b1a72024-08-12 22:47:01 +000097 isUnstable: false,
Jihoon Kangf86fe9a2024-06-26 22:18:10 +000098 },
99 {
100 moduleName: "foo_vendor",
101 isSystemContainer: false,
102 isVendorContainer: true,
103 isProductContainer: false,
104 isCts: false,
Jihoon Kang0f3b1a72024-08-12 22:47:01 +0000105 isUnstable: false,
Jihoon Kangf86fe9a2024-06-26 22:18:10 +0000106 },
107 {
108 moduleName: "foo_soc_specific",
109 isSystemContainer: false,
110 isVendorContainer: true,
111 isProductContainer: false,
112 isCts: false,
Jihoon Kang0f3b1a72024-08-12 22:47:01 +0000113 isUnstable: false,
Jihoon Kangf86fe9a2024-06-26 22:18:10 +0000114 },
115 {
116 moduleName: "foo_product_specific",
117 isSystemContainer: false,
118 isVendorContainer: false,
119 isProductContainer: true,
120 isCts: false,
Jihoon Kang0f3b1a72024-08-12 22:47:01 +0000121 isUnstable: false,
Jihoon Kangf86fe9a2024-06-26 22:18:10 +0000122 },
123 {
124 moduleName: "foo_cts_test",
125 isSystemContainer: false,
126 isVendorContainer: false,
127 isProductContainer: false,
128 isCts: true,
Jihoon Kang0f3b1a72024-08-12 22:47:01 +0000129 isUnstable: false,
Jihoon Kangf86fe9a2024-06-26 22:18:10 +0000130 },
131 {
132 moduleName: "foo_non_cts_test",
133 isSystemContainer: false,
134 isVendorContainer: false,
135 isProductContainer: false,
136 isCts: false,
Jihoon Kang0f3b1a72024-08-12 22:47:01 +0000137 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 Kangf86fe9a2024-06-26 22:18:10 +0000154 },
155 }
156
157 for _, c := range testcases {
Colin Cross90607e92025-02-11 14:58:07 -0800158 m := result.ModuleForTests(t, c.moduleName, "android_common")
Jihoon Kangf86fe9a2024-06-26 22:18:10 +0000159 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 Kang0f3b1a72024-08-12 22:47:01 +0000164 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 Kangf86fe9a2024-06-26 22:18:10 +0000166 }
167}