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