blob: 31436c57d849a660dd45fd25d9e0134f0fb767f6 [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
16# Run test configuration and verify its result.
17# The main configuration file is device.rbc.
18# 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")
Sasha Smundakb2220c22021-05-04 09:01:16 -070024load(":version_defaults.rbc", "version_defaults")
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080025load(":device.rbc", "init")
26
27def assert_eq(expected, actual):
28 if expected != actual:
Sasha Smundakb2220c22021-05-04 09:01:16 -070029 fail("Expected '%s', got '%s'" % (expected, actual))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080030
Sasha Smundakbe4ebca2021-06-10 12:12:28 -070031# Unit tests for non-trivial runtime functions
32assert_eq("", rblf.mkstrip(" \n \t "))
33assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
Sasha Smundakb2220c22021-05-04 09:01:16 -070034assert_eq(1, rblf.mkstrip(1))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080035
Sasha Smundak9afdb1c2021-07-09 15:11:47 -070036assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
37assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
38
Sasha Smundak3b25eb12021-07-12 15:41:28 -070039assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz"))
40assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz"))
41assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"]))
42assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz"))
43assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd"))
44assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz"))
45assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b"))
46assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"]))
47assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc"))
Sasha Smundaked1f09c2021-08-17 18:16:07 -070048assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"]))
49assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"]))
50assert_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 -070051
Sasha Smundakf00e35e2021-08-26 09:42:55 -070052assert_eq([], rblf.filter(["a", "", "b"], "f"))
53assert_eq(["", "b"], rblf.filter_out(["a", "" ], ["a", "", "b"] ))
54
Cole Faust0cc94d32021-11-15 14:26:14 -080055assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"]))
56assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder"))
57assert_eq("", rblf.notdir("/"))
58assert_eq("", rblf.notdir(""))
59
Sasha Smundakb2220c22021-05-04 09:01:16 -070060(globals, config, globals_base) = rblf.product_configuration("test/device", init, version_defaults)
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080061assert_eq(
62 {
63 "PRODUCT_COPY_FILES": [
64 "part_from:part_to",
65 "device_from:device_to",
Sasha Smundak6b795dc2021-08-18 16:32:19 -070066 "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 -070067 "xyz:/etc/xyz",
68 "x.xml:/etc/x.xml",
69 "y.xml:/etc/y.xml",
Sasha Smundak6797bfa2021-08-19 09:49:49 -070070 "from/sub/x:to/x",
71 "from/sub/y:to/y",
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080072 ],
73 "PRODUCT_HOST_PACKAGES": ["host"],
74 "PRODUCT_PACKAGES": [
75 "dev",
76 "inc",
Sasha Smundak3370ad52021-08-26 16:59:55 -070077 "dev_after",
78 "board1_in",
79 "board1_is",
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080080 ],
81 "PRODUCT_PRODUCT_PROPERTIES": ["part_properties"]
82 },
83 { k:v for k, v in sorted(config.items()) }
84)
Sasha Smundakc1061382021-07-28 12:29:00 -070085
86ns = globals["$SOONG_CONFIG_NAMESPACES"]
87assert_eq(
88 {
89 "NS1": {
Sasha Smundakdc154162021-09-17 15:27:37 -070090 "v1": "abc abc_part1",
Sasha Smundakc1061382021-07-28 12:29:00 -070091 "v2": "def"
92 },
93 "NS2": {
94 "v3": "xyz"
95 }
96 },
97 {k:v for k, v in sorted(ns.items()) }
98)
Sasha Smundakb2220c22021-05-04 09:01:16 -070099
100assert_eq("S", globals["PLATFORM_VERSION"])
101assert_eq(30, globals["PLATFORM_SDK_VERSION"])
Cole Faust70a886c2021-11-08 12:12:45 -0800102
103assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3"))
104assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var"))
Sasha Smundak91fc7342021-11-18 11:20:34 -0800105
106goals = globals["$dist_for_goals"]
107assert_eq(
108 {
109 "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")]
110 },
111 { k:v for k,v in sorted(goals.items()) }
112)