blob: 53eda160df691f397fb327917b04d078a58cb22b [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")
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080028
29def assert_eq(expected, actual):
30 if expected != actual:
Sasha Smundakb2220c22021-05-04 09:01:16 -070031 fail("Expected '%s', got '%s'" % (expected, actual))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080032
Sasha Smundakbe4ebca2021-06-10 12:12:28 -070033# Unit tests for non-trivial runtime functions
34assert_eq("", rblf.mkstrip(" \n \t "))
35assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
Sasha Smundakb2220c22021-05-04 09:01:16 -070036assert_eq(1, rblf.mkstrip(1))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080037
Sasha Smundak9afdb1c2021-07-09 15:11:47 -070038assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
39assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
40
Sasha Smundak3b25eb12021-07-12 15:41:28 -070041assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz"))
42assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz"))
43assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"]))
44assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz"))
45assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd"))
46assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz"))
47assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b"))
48assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"]))
49assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc"))
Sasha Smundaked1f09c2021-08-17 18:16:07 -070050assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"]))
51assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"]))
52assert_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 -070053
Sasha Smundakf00e35e2021-08-26 09:42:55 -070054assert_eq([], rblf.filter(["a", "", "b"], "f"))
55assert_eq(["", "b"], rblf.filter_out(["a", "" ], ["a", "", "b"] ))
56
Cole Faust0cc94d32021-11-15 14:26:14 -080057assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"]))
58assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder"))
59assert_eq("", rblf.notdir("/"))
60assert_eq("", rblf.notdir(""))
61
Cole Faustf1f49bb2021-12-01 13:49:12 -080062(globals, config, globals_base) = rblf.product_configuration("test/device", init, input_variables_init)
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080063assert_eq(
64 {
65 "PRODUCT_COPY_FILES": [
66 "part_from:part_to",
67 "device_from:device_to",
Sasha Smundak6b795dc2021-08-18 16:32:19 -070068 "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio/audio_platform_info_noextcodec_snd.xml",
Sasha Smundaka93e3d92021-07-28 14:34:33 -070069 "xyz:/etc/xyz",
70 "x.xml:/etc/x.xml",
71 "y.xml:/etc/y.xml",
Sasha Smundak6797bfa2021-08-19 09:49:49 -070072 "from/sub/x:to/x",
73 "from/sub/y:to/y",
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080074 ],
75 "PRODUCT_HOST_PACKAGES": ["host"],
76 "PRODUCT_PACKAGES": [
77 "dev",
78 "inc",
Sasha Smundak3370ad52021-08-26 16:59:55 -070079 "dev_after",
80 "board1_in",
81 "board1_is",
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080082 ],
83 "PRODUCT_PRODUCT_PROPERTIES": ["part_properties"]
84 },
85 { k:v for k, v in sorted(config.items()) }
86)
Sasha Smundakc1061382021-07-28 12:29:00 -070087
88ns = globals["$SOONG_CONFIG_NAMESPACES"]
89assert_eq(
90 {
91 "NS1": {
Sasha Smundakdc154162021-09-17 15:27:37 -070092 "v1": "abc abc_part1",
Sasha Smundakc1061382021-07-28 12:29:00 -070093 "v2": "def"
94 },
95 "NS2": {
96 "v3": "xyz"
97 }
98 },
99 {k:v for k, v in sorted(ns.items()) }
100)
Sasha Smundakb2220c22021-05-04 09:01:16 -0700101
Cole Faustf1f49bb2021-12-01 13:49:12 -0800102assert_eq("Tiramisu", globals["PLATFORM_VERSION"])
103assert_eq("31", globals["PLATFORM_SDK_VERSION"])
Cole Faust70a886c2021-11-08 12:12:45 -0800104
105assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3"))
106assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var"))
Sasha Smundak91fc7342021-11-18 11:20:34 -0800107
108goals = globals["$dist_for_goals"]
109assert_eq(
110 {
111 "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")]
112 },
113 { k:v for k,v in sorted(goals.items()) }
114)
Cole Faust3be5b722021-11-29 14:56:09 -0800115
116(board_globals, board_config, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init)
117assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals)
118assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base)