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") |
Cole Faust | 31fce2f | 2022-03-22 15:16:06 -0700 | [diff] [blame] | 28 | load("//build/make/tests/single_value_inheritance:test.rbc", test_single_value_inheritance = "test") |
Cole Faust | 8383184 | 2024-04-30 17:30:18 -0700 | [diff] [blame] | 29 | load("//build/make/tests/single_value_inheritance_2:test.rbc", test_single_value_inheritance_2 = "test") |
Cole Faust | 1c08360 | 2022-04-08 18:09:22 -0700 | [diff] [blame] | 30 | load("//build/make/tests/artifact_path_requirements:test.rbc", test_artifact_path_requirements = "test") |
Cole Faust | d370a3f | 2022-04-18 17:18:08 -0700 | [diff] [blame] | 31 | load("//build/make/tests/prefixed_sort_order:test.rbc", test_prefixed_sort_order = "test") |
Cole Faust | f07dcc4 | 2023-01-05 12:02:54 -0800 | [diff] [blame] | 32 | load("//build/make/tests/inherits_in_regular_variables:test.rbc", test_inherits_in_regular_variables = "test") |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 33 | |
| 34 | def assert_eq(expected, actual): |
| 35 | if expected != actual: |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 36 | fail("Expected '%s', got '%s'" % (expected, actual)) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 37 | |
Cole Faust | 1c08360 | 2022-04-08 18:09:22 -0700 | [diff] [blame] | 38 | def assert_dict_subset(expected, actual): |
| 39 | for key, val in expected.items(): |
| 40 | assert_eq(val, actual[key]) |
| 41 | |
Sasha Smundak | be4ebca | 2021-06-10 12:12:28 -0700 | [diff] [blame] | 42 | # Unit tests for non-trivial runtime functions |
Cole Faust | 2491ad5 | 2022-04-05 16:34:23 -0700 | [diff] [blame] | 43 | assert_eq(["a", "b", "c"], rblf.mksort("b a c c")) |
| 44 | assert_eq(["a", "b", "c"], rblf.mksort(["b", "a", "c", "c"])) |
| 45 | |
Sasha Smundak | be4ebca | 2021-06-10 12:12:28 -0700 | [diff] [blame] | 46 | assert_eq("", rblf.mkstrip(" \n \t ")) |
| 47 | assert_eq("a b c", rblf.mkstrip(" a b \n c \t")) |
Cole Faust | 6f6060a | 2022-05-05 11:38:26 -0700 | [diff] [blame] | 48 | assert_eq("1", rblf.mkstrip("1 ")) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 49 | |
Cole Faust | 2b5b3f3 | 2023-02-07 12:28:47 -0800 | [diff] [blame] | 50 | assert_eq(["a", "b"], rblf.words("a b")) |
| 51 | assert_eq(["a", "b", "c"], rblf.words(["a b", "c"])) |
| 52 | # 1-tuple like we use in product variables |
| 53 | assert_eq(["a b", ("c",)], rblf.words(["a b", ("c",)])) |
| 54 | |
Sasha Smundak | 9afdb1c | 2021-07-09 15:11:47 -0700 | [diff] [blame] | 55 | assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2")) |
| 56 | assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"])) |
| 57 | |
Sasha Smundak | 3b25eb1 | 2021-07-12 15:41:28 -0700 | [diff] [blame] | 58 | assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz")) |
| 59 | assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz")) |
| 60 | assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"])) |
| 61 | assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz")) |
| 62 | assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd")) |
| 63 | assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz")) |
| 64 | assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b")) |
| 65 | assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"])) |
| 66 | assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc")) |
Sasha Smundak | ed1f09c | 2021-08-17 18:16:07 -0700 | [diff] [blame] | 67 | assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"])) |
| 68 | assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"])) |
| 69 | 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] | 70 | |
Sasha Smundak | f00e35e | 2021-08-26 09:42:55 -0700 | [diff] [blame] | 71 | assert_eq([], rblf.filter(["a", "", "b"], "f")) |
Cole Faust | 62878a2 | 2022-03-29 15:48:45 -0700 | [diff] [blame] | 72 | assert_eq(["ab%c", "axyzb%c"], rblf.filter(["a%b%c"], ["ab%c", "axyzb%c", "axyzb%cd", "axyzbwc"])) |
| 73 | assert_eq(["abc", "bcd"], rblf.filter(["a%", "b%"], ["abc", "def", "bcd", "xabc"])) |
| 74 | assert_eq(["b", "ab"], rblf.filter_out(["a", "" ], ["a", "", "b", "ab"])) |
| 75 | assert_eq(["c"], rblf.filter_out(["a", "b" ], ["a", "b", "c"])) |
| 76 | assert_eq(["c"], rblf.filter_out(["a%", "b" ], ["abc", "b", "c"])) |
Sasha Smundak | f00e35e | 2021-08-26 09:42:55 -0700 | [diff] [blame] | 77 | |
Cole Faust | 0cc94d3 | 2021-11-15 14:26:14 -0800 | [diff] [blame] | 78 | assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"])) |
| 79 | assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder")) |
| 80 | assert_eq("", rblf.notdir("/")) |
| 81 | assert_eq("", rblf.notdir("")) |
| 82 | |
Cole Faust | 426c744 | 2022-04-19 11:17:28 -0700 | [diff] [blame] | 83 | cwd = rblf_shell('pwd') |
| 84 | assert_eq(cwd+"/foo/bar", rblf.abspath("foo/bar")) |
| 85 | assert_eq(cwd+"/bar", rblf.abspath("foo/.././bar")) |
| 86 | assert_eq(cwd+"/bar", rblf.abspath("foo/..////bar//")) |
| 87 | assert_eq("/foo/baz", rblf.abspath("/foo/bar/../baz")) |
| 88 | assert_eq(cwd+"/foo/bar "+cwd+"/foo/baz", rblf.abspath("foo/bar foo/baz")) |
| 89 | assert_eq("/baz", rblf.abspath("/../../../../../../../../../../../../../../../../baz")) |
| 90 | |
Cole Faust | c93109d | 2022-04-27 17:50:55 -0700 | [diff] [blame] | 91 | assert_eq("foo", rblf.first_word("foo bar")) |
| 92 | assert_eq("foo", rblf.first_word(["foo", "bar"])) |
| 93 | assert_eq("", rblf.first_word("")) |
| 94 | assert_eq("", rblf.first_word([])) |
| 95 | assert_eq("bar", rblf.last_word("foo bar")) |
| 96 | assert_eq("bar", rblf.last_word(["foo", "bar"])) |
| 97 | assert_eq("", rblf.last_word("")) |
| 98 | assert_eq("", rblf.last_word([])) |
| 99 | |
Cole Faust | 6f6060a | 2022-05-05 11:38:26 -0700 | [diff] [blame] | 100 | assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo", "bar"]])) |
| 101 | assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo"], ["bar"]])) |
| 102 | assert_eq([], rblf.flatten_2d_list([])) |
| 103 | |
Cole Faust | fdff6b1 | 2021-12-08 11:07:17 -0800 | [diff] [blame] | 104 | assert_eq( |
| 105 | ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"], |
| 106 | rblf.expand_wildcard("build/make/tests/board*.rbc") |
| 107 | ) |
| 108 | assert_eq( |
| 109 | ["build/make/tests/run.rbc", "build/make/tests/product.rbc"], |
| 110 | rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/product.rbc") |
| 111 | ) |
| 112 | assert_eq( |
| 113 | ["build/make/tests/run.rbc"], |
| 114 | rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/nonexistent.rbc") |
| 115 | ) |
| 116 | |
Cole Faust | 1c08360 | 2022-04-08 18:09:22 -0700 | [diff] [blame] | 117 | (globals, globals_base) = rblf.product_configuration("test/device", init, input_variables_init) |
| 118 | assert_dict_subset({ |
| 119 | "PRODUCTS.test/device.mk.PRODUCT_COPY_FILES": [ |
| 120 | "part_from:part_to", |
| 121 | "device_from:device_to", |
| 122 | "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio/audio_platform_info_noextcodec_snd.xml", |
| 123 | "xyz:/etc/xyz", |
| 124 | "x.xml:/etc/x.xml", |
| 125 | "y.xml:/etc/y.xml", |
| 126 | "from/sub/x:to/x", |
| 127 | "from/sub/y:to/y", |
| 128 | ], |
| 129 | "PRODUCTS.test/device.mk.PRODUCT_HOST_PACKAGES": ["host"], |
| 130 | "PRODUCTS.test/device.mk.PRODUCT_PACKAGES": [ |
| 131 | "dev", |
| 132 | "inc", |
| 133 | "dev_after", |
| 134 | "board1_in", |
| 135 | "board1_is", |
| 136 | ], |
| 137 | "PRODUCTS.test/device.mk.PRODUCT_PRODUCT_PROPERTIES": ["part_properties"] |
| 138 | }, globals) |
Sasha Smundak | c106138 | 2021-07-28 12:29:00 -0700 | [diff] [blame] | 139 | |
| 140 | ns = globals["$SOONG_CONFIG_NAMESPACES"] |
| 141 | assert_eq( |
| 142 | { |
| 143 | "NS1": { |
Sasha Smundak | dc15416 | 2021-09-17 15:27:37 -0700 | [diff] [blame] | 144 | "v1": "abc abc_part1", |
Sasha Smundak | c106138 | 2021-07-28 12:29:00 -0700 | [diff] [blame] | 145 | "v2": "def" |
| 146 | }, |
| 147 | "NS2": { |
Cole Faust | 3736374 | 2023-05-02 10:11:02 -0700 | [diff] [blame] | 148 | "v3": "xyz", |
| 149 | "v4": "xyz" |
Sasha Smundak | c106138 | 2021-07-28 12:29:00 -0700 | [diff] [blame] | 150 | } |
| 151 | }, |
| 152 | {k:v for k, v in sorted(ns.items()) } |
| 153 | ) |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 154 | |
Cole Faust | f1f49bb | 2021-12-01 13:49:12 -0800 | [diff] [blame] | 155 | assert_eq("Tiramisu", globals["PLATFORM_VERSION"]) |
| 156 | assert_eq("31", globals["PLATFORM_SDK_VERSION"]) |
Cole Faust | 70a886c | 2021-11-08 12:12:45 -0800 | [diff] [blame] | 157 | |
| 158 | assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3")) |
| 159 | assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var")) |
Sasha Smundak | 91fc734 | 2021-11-18 11:20:34 -0800 | [diff] [blame] | 160 | |
| 161 | goals = globals["$dist_for_goals"] |
| 162 | assert_eq( |
| 163 | { |
| 164 | "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")] |
| 165 | }, |
| 166 | { k:v for k,v in sorted(goals.items()) } |
| 167 | ) |
Cole Faust | 3be5b72 | 2021-11-29 14:56:09 -0800 | [diff] [blame] | 168 | |
Cole Faust | 1c08360 | 2022-04-08 18:09:22 -0700 | [diff] [blame] | 169 | (board_globals, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init) |
Cole Faust | 3be5b72 | 2021-11-29 14:56:09 -0800 | [diff] [blame] | 170 | assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals) |
| 171 | assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base) |
Cole Faust | 31fce2f | 2022-03-22 15:16:06 -0700 | [diff] [blame] | 172 | |
Cole Faust | 8397c8e | 2022-12-12 18:59:28 -0800 | [diff] [blame] | 173 | g = {"FOO": "a", "BAR": "c", "BAZ": "e"} |
| 174 | cfg = {"FOO": "b", "BAR": "d", "BAZ": "f"} |
Cole Faust | 44de6d8 | 2022-12-13 13:02:10 -0800 | [diff] [blame] | 175 | rblf.clear_var_list(g, struct(cfg=cfg), "FOO BAR NEWVAR") |
Cole Faust | 8397c8e | 2022-12-12 18:59:28 -0800 | [diff] [blame] | 176 | assert_eq("", g["FOO"]) |
| 177 | assert_eq("", cfg["FOO"]) |
| 178 | assert_eq("", g["BAR"]) |
| 179 | assert_eq("", cfg["BAR"]) |
| 180 | assert_eq("e", g["BAZ"]) |
| 181 | assert_eq("f", cfg["BAZ"]) |
Cole Faust | 44de6d8 | 2022-12-13 13:02:10 -0800 | [diff] [blame] | 182 | assert_eq("", g.get("NEWVAR")) |
Cole Faust | 8397c8e | 2022-12-12 18:59:28 -0800 | [diff] [blame] | 183 | |
Cole Faust | 31fce2f | 2022-03-22 15:16:06 -0700 | [diff] [blame] | 184 | test_single_value_inheritance() |
Cole Faust | 8383184 | 2024-04-30 17:30:18 -0700 | [diff] [blame] | 185 | test_single_value_inheritance_2() |
Cole Faust | 1c08360 | 2022-04-08 18:09:22 -0700 | [diff] [blame] | 186 | test_artifact_path_requirements() |
Cole Faust | d370a3f | 2022-04-18 17:18:08 -0700 | [diff] [blame] | 187 | test_prefixed_sort_order() |
Cole Faust | f07dcc4 | 2023-01-05 12:02:54 -0800 | [diff] [blame] | 188 | test_inherits_in_regular_variables() |