blob: e8c4caae36c8bf3901f9a0d26eadaf9100560335 [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 Faust1c083602022-04-08 18:09:22 -070029load("//build/make/tests/artifact_path_requirements:test.rbc", test_artifact_path_requirements = "test")
Cole Faustd370a3f2022-04-18 17:18:08 -070030load("//build/make/tests/prefixed_sort_order:test.rbc", test_prefixed_sort_order = "test")
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080031
32def assert_eq(expected, actual):
33 if expected != actual:
Sasha Smundakb2220c22021-05-04 09:01:16 -070034 fail("Expected '%s', got '%s'" % (expected, actual))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080035
Cole Faust1c083602022-04-08 18:09:22 -070036def assert_dict_subset(expected, actual):
37 for key, val in expected.items():
38 assert_eq(val, actual[key])
39
Sasha Smundakbe4ebca2021-06-10 12:12:28 -070040# Unit tests for non-trivial runtime functions
Cole Faust2491ad52022-04-05 16:34:23 -070041assert_eq(["a", "b", "c"], rblf.mksort("b a c c"))
42assert_eq(["a", "b", "c"], rblf.mksort(["b", "a", "c", "c"]))
43
Sasha Smundakbe4ebca2021-06-10 12:12:28 -070044assert_eq("", rblf.mkstrip(" \n \t "))
45assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
Cole Faust6f6060a2022-05-05 11:38:26 -070046assert_eq("1", rblf.mkstrip("1 "))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080047
Sasha Smundak9afdb1c2021-07-09 15:11:47 -070048assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
49assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
50
Sasha Smundak3b25eb12021-07-12 15:41:28 -070051assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz"))
52assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz"))
53assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"]))
54assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz"))
55assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd"))
56assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz"))
57assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b"))
58assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"]))
59assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc"))
Sasha Smundaked1f09c2021-08-17 18:16:07 -070060assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"]))
61assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"]))
62assert_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 -070063
Sasha Smundakf00e35e2021-08-26 09:42:55 -070064assert_eq([], rblf.filter(["a", "", "b"], "f"))
Cole Faust62878a22022-03-29 15:48:45 -070065assert_eq(["ab%c", "axyzb%c"], rblf.filter(["a%b%c"], ["ab%c", "axyzb%c", "axyzb%cd", "axyzbwc"]))
66assert_eq(["abc", "bcd"], rblf.filter(["a%", "b%"], ["abc", "def", "bcd", "xabc"]))
67assert_eq(["b", "ab"], rblf.filter_out(["a", "" ], ["a", "", "b", "ab"]))
68assert_eq(["c"], rblf.filter_out(["a", "b" ], ["a", "b", "c"]))
69assert_eq(["c"], rblf.filter_out(["a%", "b" ], ["abc", "b", "c"]))
Sasha Smundakf00e35e2021-08-26 09:42:55 -070070
Cole Faust0cc94d32021-11-15 14:26:14 -080071assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"]))
72assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder"))
73assert_eq("", rblf.notdir("/"))
74assert_eq("", rblf.notdir(""))
75
Cole Faust426c7442022-04-19 11:17:28 -070076cwd = rblf_shell('pwd')
77assert_eq(cwd+"/foo/bar", rblf.abspath("foo/bar"))
78assert_eq(cwd+"/bar", rblf.abspath("foo/.././bar"))
79assert_eq(cwd+"/bar", rblf.abspath("foo/..////bar//"))
80assert_eq("/foo/baz", rblf.abspath("/foo/bar/../baz"))
81assert_eq(cwd+"/foo/bar "+cwd+"/foo/baz", rblf.abspath("foo/bar foo/baz"))
82assert_eq("/baz", rblf.abspath("/../../../../../../../../../../../../../../../../baz"))
83
Cole Faustc93109d2022-04-27 17:50:55 -070084assert_eq("foo", rblf.first_word("foo bar"))
85assert_eq("foo", rblf.first_word(["foo", "bar"]))
86assert_eq("", rblf.first_word(""))
87assert_eq("", rblf.first_word([]))
88assert_eq("bar", rblf.last_word("foo bar"))
89assert_eq("bar", rblf.last_word(["foo", "bar"]))
90assert_eq("", rblf.last_word(""))
91assert_eq("", rblf.last_word([]))
92
Cole Faust6f6060a2022-05-05 11:38:26 -070093assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo", "bar"]]))
94assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo"], ["bar"]]))
95assert_eq([], rblf.flatten_2d_list([]))
96
Cole Faustfdff6b12021-12-08 11:07:17 -080097assert_eq(
98 ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
99 rblf.expand_wildcard("build/make/tests/board*.rbc")
100)
101assert_eq(
102 ["build/make/tests/run.rbc", "build/make/tests/product.rbc"],
103 rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/product.rbc")
104)
105assert_eq(
106 ["build/make/tests/run.rbc"],
107 rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/nonexistent.rbc")
108)
109
Cole Faust1c083602022-04-08 18:09:22 -0700110(globals, globals_base) = rblf.product_configuration("test/device", init, input_variables_init)
111assert_dict_subset({
112 "PRODUCTS.test/device.mk.PRODUCT_COPY_FILES": [
113 "part_from:part_to",
114 "device_from:device_to",
115 "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio/audio_platform_info_noextcodec_snd.xml",
116 "xyz:/etc/xyz",
117 "x.xml:/etc/x.xml",
118 "y.xml:/etc/y.xml",
119 "from/sub/x:to/x",
120 "from/sub/y:to/y",
121 ],
122 "PRODUCTS.test/device.mk.PRODUCT_HOST_PACKAGES": ["host"],
123 "PRODUCTS.test/device.mk.PRODUCT_PACKAGES": [
124 "dev",
125 "inc",
126 "dev_after",
127 "board1_in",
128 "board1_is",
129 ],
130 "PRODUCTS.test/device.mk.PRODUCT_PRODUCT_PROPERTIES": ["part_properties"]
131}, globals)
Sasha Smundakc1061382021-07-28 12:29:00 -0700132
133ns = globals["$SOONG_CONFIG_NAMESPACES"]
134assert_eq(
135 {
136 "NS1": {
Sasha Smundakdc154162021-09-17 15:27:37 -0700137 "v1": "abc abc_part1",
Sasha Smundakc1061382021-07-28 12:29:00 -0700138 "v2": "def"
139 },
140 "NS2": {
141 "v3": "xyz"
142 }
143 },
144 {k:v for k, v in sorted(ns.items()) }
145)
Sasha Smundakb2220c22021-05-04 09:01:16 -0700146
Cole Faustf1f49bb2021-12-01 13:49:12 -0800147assert_eq("Tiramisu", globals["PLATFORM_VERSION"])
148assert_eq("31", globals["PLATFORM_SDK_VERSION"])
Cole Faust70a886c2021-11-08 12:12:45 -0800149
150assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3"))
151assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var"))
Sasha Smundak91fc7342021-11-18 11:20:34 -0800152
153goals = globals["$dist_for_goals"]
154assert_eq(
155 {
156 "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")]
157 },
158 { k:v for k,v in sorted(goals.items()) }
159)
Cole Faust3be5b722021-11-29 14:56:09 -0800160
Cole Faust1c083602022-04-08 18:09:22 -0700161(board_globals, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init)
Cole Faust3be5b722021-11-29 14:56:09 -0800162assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals)
163assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base)
Cole Faust31fce2f2022-03-22 15:16:06 -0700164
Cole Faust8397c8e2022-12-12 18:59:28 -0800165g = {"FOO": "a", "BAR": "c", "BAZ": "e"}
166cfg = {"FOO": "b", "BAR": "d", "BAZ": "f"}
Cole Faust44de6d82022-12-13 13:02:10 -0800167rblf.clear_var_list(g, struct(cfg=cfg), "FOO BAR NEWVAR")
Cole Faust8397c8e2022-12-12 18:59:28 -0800168assert_eq("", g["FOO"])
169assert_eq("", cfg["FOO"])
170assert_eq("", g["BAR"])
171assert_eq("", cfg["BAR"])
172assert_eq("e", g["BAZ"])
173assert_eq("f", cfg["BAZ"])
Cole Faust44de6d82022-12-13 13:02:10 -0800174assert_eq("", g.get("NEWVAR"))
Cole Faust8397c8e2022-12-12 18:59:28 -0800175
Cole Faust31fce2f2022-03-22 15:16:06 -0700176test_single_value_inheritance()
Cole Faust1c083602022-04-08 18:09:22 -0700177test_artifact_path_requirements()
Cole Faustd370a3f2022-04-18 17:18:08 -0700178test_prefixed_sort_order()