blob: 107be0995ab80aec07f378e534166e2a105dccfa [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"))
Sasha Smundakb2220c22021-05-04 09:01:16 -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 Faustfdff6b12021-12-08 11:07:17 -080093assert_eq(
94 ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
95 rblf.expand_wildcard("build/make/tests/board*.rbc")
96)
97assert_eq(
98 ["build/make/tests/run.rbc", "build/make/tests/product.rbc"],
99 rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/product.rbc")
100)
101assert_eq(
102 ["build/make/tests/run.rbc"],
103 rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/nonexistent.rbc")
104)
105
Cole Faust1c083602022-04-08 18:09:22 -0700106(globals, globals_base) = rblf.product_configuration("test/device", init, input_variables_init)
107assert_dict_subset({
108 "PRODUCTS.test/device.mk.PRODUCT_COPY_FILES": [
109 "part_from:part_to",
110 "device_from:device_to",
111 "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio/audio_platform_info_noextcodec_snd.xml",
112 "xyz:/etc/xyz",
113 "x.xml:/etc/x.xml",
114 "y.xml:/etc/y.xml",
115 "from/sub/x:to/x",
116 "from/sub/y:to/y",
117 ],
118 "PRODUCTS.test/device.mk.PRODUCT_HOST_PACKAGES": ["host"],
119 "PRODUCTS.test/device.mk.PRODUCT_PACKAGES": [
120 "dev",
121 "inc",
122 "dev_after",
123 "board1_in",
124 "board1_is",
125 ],
126 "PRODUCTS.test/device.mk.PRODUCT_PRODUCT_PROPERTIES": ["part_properties"]
127}, globals)
Sasha Smundakc1061382021-07-28 12:29:00 -0700128
129ns = globals["$SOONG_CONFIG_NAMESPACES"]
130assert_eq(
131 {
132 "NS1": {
Sasha Smundakdc154162021-09-17 15:27:37 -0700133 "v1": "abc abc_part1",
Sasha Smundakc1061382021-07-28 12:29:00 -0700134 "v2": "def"
135 },
136 "NS2": {
137 "v3": "xyz"
138 }
139 },
140 {k:v for k, v in sorted(ns.items()) }
141)
Sasha Smundakb2220c22021-05-04 09:01:16 -0700142
Cole Faustf1f49bb2021-12-01 13:49:12 -0800143assert_eq("Tiramisu", globals["PLATFORM_VERSION"])
144assert_eq("31", globals["PLATFORM_SDK_VERSION"])
Cole Faust70a886c2021-11-08 12:12:45 -0800145
146assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3"))
147assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var"))
Sasha Smundak91fc7342021-11-18 11:20:34 -0800148
149goals = globals["$dist_for_goals"]
150assert_eq(
151 {
152 "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")]
153 },
154 { k:v for k,v in sorted(goals.items()) }
155)
Cole Faust3be5b722021-11-29 14:56:09 -0800156
Cole Faust1c083602022-04-08 18:09:22 -0700157(board_globals, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init)
Cole Faust3be5b722021-11-29 14:56:09 -0800158assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals)
159assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base)
Cole Faust31fce2f2022-03-22 15:16:06 -0700160
161test_single_value_inheritance()
Cole Faust1c083602022-04-08 18:09:22 -0700162test_artifact_path_requirements()
Cole Faustd370a3f2022-04-18 17:18:08 -0700163test_prefixed_sort_order()