blob: 2c15b8105cb57b9a3c18532929ea7184ac5ec634 [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")
24load(":device.rbc", "init")
25
26def assert_eq(expected, actual):
27 if expected != actual:
28 fail("Expected %s, got %s" % (expected, actual))
29
Sasha Smundakbe4ebca2021-06-10 12:12:28 -070030# Unit tests for non-trivial runtime functions
31assert_eq("", rblf.mkstrip(" \n \t "))
32assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080033
Sasha Smundak9afdb1c2021-07-09 15:11:47 -070034assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
35assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
36
Sasha Smundak3b25eb12021-07-12 15:41:28 -070037assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz"))
38assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz"))
39assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"]))
40assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz"))
41assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd"))
42assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz"))
43assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b"))
44assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"]))
45assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc"))
Sasha Smundaked1f09c2021-08-17 18:16:07 -070046assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"]))
47assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"]))
48assert_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 -070049
Sasha Smundakf00e35e2021-08-26 09:42:55 -070050assert_eq([], rblf.filter(["a", "", "b"], "f"))
51assert_eq(["", "b"], rblf.filter_out(["a", "" ], ["a", "", "b"] ))
52
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080053globals, config = rblf.product_configuration("test/device", init)
54assert_eq(
55 {
56 "PRODUCT_COPY_FILES": [
57 "part_from:part_to",
58 "device_from:device_to",
Sasha Smundak6b795dc2021-08-18 16:32:19 -070059 "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 -070060 "xyz:/etc/xyz",
61 "x.xml:/etc/x.xml",
62 "y.xml:/etc/y.xml",
Sasha Smundak6797bfa2021-08-19 09:49:49 -070063 "from/sub/x:to/x",
64 "from/sub/y:to/y",
Sasha Smundak5c8b09b2020-11-03 23:44:14 -080065 ],
66 "PRODUCT_HOST_PACKAGES": ["host"],
67 "PRODUCT_PACKAGES": [
68 "dev",
69 "inc",
70 "dev_after"
71 ],
72 "PRODUCT_PRODUCT_PROPERTIES": ["part_properties"]
73 },
74 { k:v for k, v in sorted(config.items()) }
75)
Sasha Smundakc1061382021-07-28 12:29:00 -070076
77ns = globals["$SOONG_CONFIG_NAMESPACES"]
78assert_eq(
79 {
80 "NS1": {
81 "v1": "abc",
82 "v2": "def"
83 },
84 "NS2": {
85 "v3": "xyz"
86 }
87 },
88 {k:v for k, v in sorted(ns.items()) }
89)