blob: 221b40f04da61db938a981eafe3cbbd5dbc327cb [file] [log] [blame]
Sasha Smundak5c8b09b2020-11-03 23:44:14 -08001# Copyright 2021 Google LLC
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# https://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
Cole Faust3be5b722021-11-29 14:56:09 -080016# Run test product configuration and verify its result.
17# The main configuration file is product.rbc.
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080018# It inherits part1.rbc and also includes include1.rbc
19# TODO(asmundak): more tests are needed to verify that:
20# * multi-level inheritance works as expected
21# * all runtime functions (wildcard, regex, etc.) work
22
23load("//build/make/core:product_config.rbc", "rblf")
Cole Faustf1f49bb2021-12-01 13:49:12 -080024load(":input_variables.rbc", input_variables_init = "init")
Cole Faust3be5b722021-11-29 14:56:09 -080025load(":product.rbc", "init")
26load(":board.rbc", board_init = "init")
27load(":board_input_vars.rbc", board_input_vars_init = "init")
Cole Faust31fce2f2022-03-22 15:16:06 -070028load("//build/make/tests/single_value_inheritance:test.rbc", test_single_value_inheritance = "test")
Cole Faust83831842024-04-30 17:30:18 -070029load("//build/make/tests/single_value_inheritance_2:test.rbc", test_single_value_inheritance_2 = "test")
Cole Faust1c083602022-04-08 18:09:22 -070030load("//build/make/tests/artifact_path_requirements:test.rbc", test_artifact_path_requirements = "test")
Cole Faustd370a3f2022-04-18 17:18:08 -070031load("//build/make/tests/prefixed_sort_order:test.rbc", test_prefixed_sort_order = "test")
Cole Faustf07dcc42023-01-05 12:02:54 -080032load("//build/make/tests/inherits_in_regular_variables:test.rbc", test_inherits_in_regular_variables = "test")
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080033
34def assert_eq(expected, actual):
35 if expected != actual:
Sasha Smundakb2220c22021-05-04 09:01:16 -070036 fail("Expected '%s', got '%s'" % (expected, actual))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080037
Cole Faust1c083602022-04-08 18:09:22 -070038def assert_dict_subset(expected, actual):
39 for key, val in expected.items():
40 assert_eq(val, actual[key])
41
Sasha Smundakbe4ebca2021-06-10 12:12:28 -070042# Unit tests for non-trivial runtime functions
Cole Faust2491ad52022-04-05 16:34:23 -070043assert_eq(["a", "b", "c"], rblf.mksort("b a c c"))
44assert_eq(["a", "b", "c"], rblf.mksort(["b", "a", "c", "c"]))
45
Sasha Smundakbe4ebca2021-06-10 12:12:28 -070046assert_eq("", rblf.mkstrip(" \n \t "))
47assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
Cole Faust6f6060a2022-05-05 11:38:26 -070048assert_eq("1", rblf.mkstrip("1 "))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080049
Cole Faust2b5b3f32023-02-07 12:28:47 -080050assert_eq(["a", "b"], rblf.words("a b"))
51assert_eq(["a", "b", "c"], rblf.words(["a b", "c"]))
52# 1-tuple like we use in product variables
53assert_eq(["a b", ("c",)], rblf.words(["a b", ("c",)]))
54
Sasha Smundak9afdb1c2021-07-09 15:11:47 -070055assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
56assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
57
Sasha Smundak3b25eb12021-07-12 15:41:28 -070058assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz"))
59assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz"))
60assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"]))
61assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz"))
62assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd"))
63assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz"))
64assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b"))
65assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"]))
66assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc"))
Sasha Smundaked1f09c2021-08-17 18:16:07 -070067assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"]))
68assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"]))
69assert_eq(["from/a:to/a", "from/b:to/b"], rblf.product_copy_files_by_pattern("from/%", "to/%", "a b"))
Sasha Smundak3b25eb12021-07-12 15:41:28 -070070
Sasha Smundakf00e35e2021-08-26 09:42:55 -070071assert_eq([], rblf.filter(["a", "", "b"], "f"))
Cole Faust62878a22022-03-29 15:48:45 -070072assert_eq(["ab%c", "axyzb%c"], rblf.filter(["a%b%c"], ["ab%c", "axyzb%c", "axyzb%cd", "axyzbwc"]))
73assert_eq(["abc", "bcd"], rblf.filter(["a%", "b%"], ["abc", "def", "bcd", "xabc"]))
74assert_eq(["b", "ab"], rblf.filter_out(["a", "" ], ["a", "", "b", "ab"]))
75assert_eq(["c"], rblf.filter_out(["a", "b" ], ["a", "b", "c"]))
76assert_eq(["c"], rblf.filter_out(["a%", "b" ], ["abc", "b", "c"]))
Sasha Smundakf00e35e2021-08-26 09:42:55 -070077
Cole Faust0cc94d32021-11-15 14:26:14 -080078assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"]))
79assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder"))
80assert_eq("", rblf.notdir("/"))
81assert_eq("", rblf.notdir(""))
82
Cole Faust426c7442022-04-19 11:17:28 -070083cwd = rblf_shell('pwd')
84assert_eq(cwd+"/foo/bar", rblf.abspath("foo/bar"))
85assert_eq(cwd+"/bar", rblf.abspath("foo/.././bar"))
86assert_eq(cwd+"/bar", rblf.abspath("foo/..////bar//"))
87assert_eq("/foo/baz", rblf.abspath("/foo/bar/../baz"))
88assert_eq(cwd+"/foo/bar "+cwd+"/foo/baz", rblf.abspath("foo/bar foo/baz"))
89assert_eq("/baz", rblf.abspath("/../../../../../../../../../../../../../../../../baz"))
90
Cole Faustc93109d2022-04-27 17:50:55 -070091assert_eq("foo", rblf.first_word("foo bar"))
92assert_eq("foo", rblf.first_word(["foo", "bar"]))
93assert_eq("", rblf.first_word(""))
94assert_eq("", rblf.first_word([]))
95assert_eq("bar", rblf.last_word("foo bar"))
96assert_eq("bar", rblf.last_word(["foo", "bar"]))
97assert_eq("", rblf.last_word(""))
98assert_eq("", rblf.last_word([]))
99
Cole Faust6f6060a2022-05-05 11:38:26 -0700100assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo", "bar"]]))
101assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo"], ["bar"]]))
102assert_eq([], rblf.flatten_2d_list([]))
103
Cole Faustfdff6b12021-12-08 11:07:17 -0800104assert_eq(
105 ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
106 rblf.expand_wildcard("build/make/tests/board*.rbc")
107)
108assert_eq(
109 ["build/make/tests/run.rbc", "build/make/tests/product.rbc"],
110 rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/product.rbc")
111)
112assert_eq(
113 ["build/make/tests/run.rbc"],
114 rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/nonexistent.rbc")
115)
116
Cole Faust1c083602022-04-08 18:09:22 -0700117(globals, globals_base) = rblf.product_configuration("test/device", init, input_variables_init)
118assert_dict_subset({
119 "PRODUCTS.test/device.mk.PRODUCT_COPY_FILES": [
120 "part_from:part_to",
121 "device_from:device_to",
122 "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio/audio_platform_info_noextcodec_snd.xml",
123 "xyz:/etc/xyz",
124 "x.xml:/etc/x.xml",
125 "y.xml:/etc/y.xml",
126 "from/sub/x:to/x",
127 "from/sub/y:to/y",
128 ],
129 "PRODUCTS.test/device.mk.PRODUCT_HOST_PACKAGES": ["host"],
130 "PRODUCTS.test/device.mk.PRODUCT_PACKAGES": [
131 "dev",
132 "inc",
133 "dev_after",
134 "board1_in",
135 "board1_is",
136 ],
137 "PRODUCTS.test/device.mk.PRODUCT_PRODUCT_PROPERTIES": ["part_properties"]
138}, globals)
Sasha Smundakc1061382021-07-28 12:29:00 -0700139
140ns = globals["$SOONG_CONFIG_NAMESPACES"]
141assert_eq(
142 {
143 "NS1": {
Sasha Smundakdc154162021-09-17 15:27:37 -0700144 "v1": "abc abc_part1",
Sasha Smundakc1061382021-07-28 12:29:00 -0700145 "v2": "def"
146 },
147 "NS2": {
Cole Faust37363742023-05-02 10:11:02 -0700148 "v3": "xyz",
149 "v4": "xyz"
Sasha Smundakc1061382021-07-28 12:29:00 -0700150 }
151 },
152 {k:v for k, v in sorted(ns.items()) }
153)
Sasha Smundakb2220c22021-05-04 09:01:16 -0700154
Cole Faustf1f49bb2021-12-01 13:49:12 -0800155assert_eq("Tiramisu", globals["PLATFORM_VERSION"])
156assert_eq("31", globals["PLATFORM_SDK_VERSION"])
Cole Faust70a886c2021-11-08 12:12:45 -0800157
158assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3"))
159assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var"))
Sasha Smundak91fc7342021-11-18 11:20:34 -0800160
161goals = globals["$dist_for_goals"]
162assert_eq(
163 {
164 "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")]
165 },
166 { k:v for k,v in sorted(goals.items()) }
167)
Cole Faust3be5b722021-11-29 14:56:09 -0800168
Cole Faust1c083602022-04-08 18:09:22 -0700169(board_globals, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init)
Cole Faust3be5b722021-11-29 14:56:09 -0800170assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals)
171assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base)
Cole Faust31fce2f2022-03-22 15:16:06 -0700172
Cole Faust8397c8e2022-12-12 18:59:28 -0800173g = {"FOO": "a", "BAR": "c", "BAZ": "e"}
174cfg = {"FOO": "b", "BAR": "d", "BAZ": "f"}
Cole Faust44de6d82022-12-13 13:02:10 -0800175rblf.clear_var_list(g, struct(cfg=cfg), "FOO BAR NEWVAR")
Cole Faust8397c8e2022-12-12 18:59:28 -0800176assert_eq("", g["FOO"])
177assert_eq("", cfg["FOO"])
178assert_eq("", g["BAR"])
179assert_eq("", cfg["BAR"])
180assert_eq("e", g["BAZ"])
181assert_eq("f", cfg["BAZ"])
Cole Faust44de6d82022-12-13 13:02:10 -0800182assert_eq("", g.get("NEWVAR"))
Cole Faust8397c8e2022-12-12 18:59:28 -0800183
Cole Faust31fce2f2022-03-22 15:16:06 -0700184test_single_value_inheritance()
Cole Faust83831842024-04-30 17:30:18 -0700185test_single_value_inheritance_2()
Cole Faust1c083602022-04-08 18:09:22 -0700186test_artifact_path_requirements()
Cole Faustd370a3f2022-04-18 17:18:08 -0700187test_prefixed_sort_order()
Cole Faustf07dcc42023-01-05 12:02:54 -0800188test_inherits_in_regular_variables()