Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 1 | # 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 | |
| 23 | load("//build/make/core:product_config.rbc", "rblf") |
| 24 | load(":device.rbc", "init") |
| 25 | |
| 26 | def assert_eq(expected, actual): |
| 27 | if expected != actual: |
| 28 | fail("Expected %s, got %s" % (expected, actual)) |
| 29 | |
Sasha Smundak | be4ebca | 2021-06-10 12:12:28 -0700 | [diff] [blame] | 30 | # Unit tests for non-trivial runtime functions |
| 31 | assert_eq("", rblf.mkstrip(" \n \t ")) |
| 32 | assert_eq("a b c", rblf.mkstrip(" a b \n c \t")) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 33 | |
Sasha Smundak | 9afdb1c | 2021-07-09 15:11:47 -0700 | [diff] [blame] | 34 | assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2")) |
| 35 | assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"])) |
| 36 | |
Sasha Smundak | 3b25eb1 | 2021-07-12 15:41:28 -0700 | [diff] [blame] | 37 | assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz")) |
| 38 | assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz")) |
| 39 | assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"])) |
| 40 | assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz")) |
| 41 | assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd")) |
| 42 | assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz")) |
| 43 | assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b")) |
| 44 | assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"])) |
| 45 | assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc")) |
| 46 | |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 47 | globals, config = rblf.product_configuration("test/device", init) |
| 48 | assert_eq( |
| 49 | { |
| 50 | "PRODUCT_COPY_FILES": [ |
| 51 | "part_from:part_to", |
| 52 | "device_from:device_to", |
| 53 | "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio_platform_info_noextcodec_snd.xml", |
| 54 | "xyz" |
| 55 | ], |
| 56 | "PRODUCT_HOST_PACKAGES": ["host"], |
| 57 | "PRODUCT_PACKAGES": [ |
| 58 | "dev", |
| 59 | "inc", |
| 60 | "dev_after" |
| 61 | ], |
| 62 | "PRODUCT_PRODUCT_PROPERTIES": ["part_properties"] |
| 63 | }, |
| 64 | { k:v for k, v in sorted(config.items()) } |
| 65 | ) |