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 | |
Cole Faust | 3be5b72 | 2021-11-29 14:56:09 -0800 | [diff] [blame] | 16 | # Run test product configuration and verify its result. |
| 17 | # The main configuration file is product.rbc. |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 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") |
Cole Faust | f1f49bb | 2021-12-01 13:49:12 -0800 | [diff] [blame^] | 24 | load(":input_variables.rbc", input_variables_init = "init") |
Cole Faust | 3be5b72 | 2021-11-29 14:56:09 -0800 | [diff] [blame] | 25 | load(":product.rbc", "init") |
| 26 | load(":board.rbc", board_init = "init") |
| 27 | load(":board_input_vars.rbc", board_input_vars_init = "init") |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 28 | |
| 29 | def assert_eq(expected, actual): |
| 30 | if expected != actual: |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 31 | fail("Expected '%s', got '%s'" % (expected, actual)) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 32 | |
Sasha Smundak | be4ebca | 2021-06-10 12:12:28 -0700 | [diff] [blame] | 33 | # Unit tests for non-trivial runtime functions |
| 34 | assert_eq("", rblf.mkstrip(" \n \t ")) |
| 35 | assert_eq("a b c", rblf.mkstrip(" a b \n c \t")) |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 36 | assert_eq(1, rblf.mkstrip(1)) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 37 | |
Sasha Smundak | 9afdb1c | 2021-07-09 15:11:47 -0700 | [diff] [blame] | 38 | assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2")) |
| 39 | assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"])) |
| 40 | |
Sasha Smundak | 3b25eb1 | 2021-07-12 15:41:28 -0700 | [diff] [blame] | 41 | assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz")) |
| 42 | assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz")) |
| 43 | assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"])) |
| 44 | assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz")) |
| 45 | assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd")) |
| 46 | assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz")) |
| 47 | assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b")) |
| 48 | assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"])) |
| 49 | assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc")) |
Sasha Smundak | ed1f09c | 2021-08-17 18:16:07 -0700 | [diff] [blame] | 50 | assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"])) |
| 51 | assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"])) |
| 52 | assert_eq(["from/a:to/a", "from/b:to/b"], rblf.product_copy_files_by_pattern("from/%", "to/%", "a b")) |
Sasha Smundak | 3b25eb1 | 2021-07-12 15:41:28 -0700 | [diff] [blame] | 53 | |
Sasha Smundak | f00e35e | 2021-08-26 09:42:55 -0700 | [diff] [blame] | 54 | assert_eq([], rblf.filter(["a", "", "b"], "f")) |
| 55 | assert_eq(["", "b"], rblf.filter_out(["a", "" ], ["a", "", "b"] )) |
| 56 | |
Cole Faust | 0cc94d3 | 2021-11-15 14:26:14 -0800 | [diff] [blame] | 57 | assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"])) |
| 58 | assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder")) |
| 59 | assert_eq("", rblf.notdir("/")) |
| 60 | assert_eq("", rblf.notdir("")) |
| 61 | |
Cole Faust | f1f49bb | 2021-12-01 13:49:12 -0800 | [diff] [blame^] | 62 | (globals, config, globals_base) = rblf.product_configuration("test/device", init, input_variables_init) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 63 | assert_eq( |
| 64 | { |
| 65 | "PRODUCT_COPY_FILES": [ |
| 66 | "part_from:part_to", |
| 67 | "device_from:device_to", |
Sasha Smundak | 6b795dc | 2021-08-18 16:32:19 -0700 | [diff] [blame] | 68 | "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio/audio_platform_info_noextcodec_snd.xml", |
Sasha Smundak | a93e3d9 | 2021-07-28 14:34:33 -0700 | [diff] [blame] | 69 | "xyz:/etc/xyz", |
| 70 | "x.xml:/etc/x.xml", |
| 71 | "y.xml:/etc/y.xml", |
Sasha Smundak | 6797bfa | 2021-08-19 09:49:49 -0700 | [diff] [blame] | 72 | "from/sub/x:to/x", |
| 73 | "from/sub/y:to/y", |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 74 | ], |
| 75 | "PRODUCT_HOST_PACKAGES": ["host"], |
| 76 | "PRODUCT_PACKAGES": [ |
| 77 | "dev", |
| 78 | "inc", |
Sasha Smundak | 3370ad5 | 2021-08-26 16:59:55 -0700 | [diff] [blame] | 79 | "dev_after", |
| 80 | "board1_in", |
| 81 | "board1_is", |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 82 | ], |
| 83 | "PRODUCT_PRODUCT_PROPERTIES": ["part_properties"] |
| 84 | }, |
| 85 | { k:v for k, v in sorted(config.items()) } |
| 86 | ) |
Sasha Smundak | c106138 | 2021-07-28 12:29:00 -0700 | [diff] [blame] | 87 | |
| 88 | ns = globals["$SOONG_CONFIG_NAMESPACES"] |
| 89 | assert_eq( |
| 90 | { |
| 91 | "NS1": { |
Sasha Smundak | dc15416 | 2021-09-17 15:27:37 -0700 | [diff] [blame] | 92 | "v1": "abc abc_part1", |
Sasha Smundak | c106138 | 2021-07-28 12:29:00 -0700 | [diff] [blame] | 93 | "v2": "def" |
| 94 | }, |
| 95 | "NS2": { |
| 96 | "v3": "xyz" |
| 97 | } |
| 98 | }, |
| 99 | {k:v for k, v in sorted(ns.items()) } |
| 100 | ) |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 101 | |
Cole Faust | f1f49bb | 2021-12-01 13:49:12 -0800 | [diff] [blame^] | 102 | assert_eq("Tiramisu", globals["PLATFORM_VERSION"]) |
| 103 | assert_eq("31", globals["PLATFORM_SDK_VERSION"]) |
Cole Faust | 70a886c | 2021-11-08 12:12:45 -0800 | [diff] [blame] | 104 | |
| 105 | assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3")) |
| 106 | assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var")) |
Sasha Smundak | 91fc734 | 2021-11-18 11:20:34 -0800 | [diff] [blame] | 107 | |
| 108 | goals = globals["$dist_for_goals"] |
| 109 | assert_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 Faust | 3be5b72 | 2021-11-29 14:56:09 -0800 | [diff] [blame] | 115 | |
| 116 | (board_globals, board_config, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init) |
| 117 | assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals) |
| 118 | assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base) |