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") |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 29 | |
| 30 | def assert_eq(expected, actual): |
| 31 | if expected != actual: |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 32 | fail("Expected '%s', got '%s'" % (expected, actual)) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 33 | |
Sasha Smundak | be4ebca | 2021-06-10 12:12:28 -0700 | [diff] [blame] | 34 | # Unit tests for non-trivial runtime functions |
Cole Faust | 2491ad5 | 2022-04-05 16:34:23 -0700 | [diff] [blame^] | 35 | assert_eq(["a", "b", "c"], rblf.mksort("b a c c")) |
| 36 | assert_eq(["a", "b", "c"], rblf.mksort(["b", "a", "c", "c"])) |
| 37 | |
Sasha Smundak | be4ebca | 2021-06-10 12:12:28 -0700 | [diff] [blame] | 38 | assert_eq("", rblf.mkstrip(" \n \t ")) |
| 39 | assert_eq("a b c", rblf.mkstrip(" a b \n c \t")) |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 40 | assert_eq(1, rblf.mkstrip(1)) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 41 | |
Sasha Smundak | 9afdb1c | 2021-07-09 15:11:47 -0700 | [diff] [blame] | 42 | assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2")) |
| 43 | assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"])) |
| 44 | |
Sasha Smundak | 3b25eb1 | 2021-07-12 15:41:28 -0700 | [diff] [blame] | 45 | assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz")) |
| 46 | assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz")) |
| 47 | assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"])) |
| 48 | assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz bcz")) |
| 49 | assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd")) |
| 50 | assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz")) |
| 51 | assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx b")) |
| 52 | assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"])) |
| 53 | assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc")) |
Sasha Smundak | ed1f09c | 2021-08-17 18:16:07 -0700 | [diff] [blame] | 54 | assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"])) |
| 55 | assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"])) |
| 56 | 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] | 57 | |
Sasha Smundak | f00e35e | 2021-08-26 09:42:55 -0700 | [diff] [blame] | 58 | assert_eq([], rblf.filter(["a", "", "b"], "f")) |
Cole Faust | 62878a2 | 2022-03-29 15:48:45 -0700 | [diff] [blame] | 59 | assert_eq(["ab%c", "axyzb%c"], rblf.filter(["a%b%c"], ["ab%c", "axyzb%c", "axyzb%cd", "axyzbwc"])) |
| 60 | assert_eq(["abc", "bcd"], rblf.filter(["a%", "b%"], ["abc", "def", "bcd", "xabc"])) |
| 61 | assert_eq(["b", "ab"], rblf.filter_out(["a", "" ], ["a", "", "b", "ab"])) |
| 62 | assert_eq(["c"], rblf.filter_out(["a", "b" ], ["a", "b", "c"])) |
| 63 | assert_eq(["c"], rblf.filter_out(["a%", "b" ], ["abc", "b", "c"])) |
Sasha Smundak | f00e35e | 2021-08-26 09:42:55 -0700 | [diff] [blame] | 64 | |
Cole Faust | 0cc94d3 | 2021-11-15 14:26:14 -0800 | [diff] [blame] | 65 | assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"])) |
| 66 | assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder")) |
| 67 | assert_eq("", rblf.notdir("/")) |
| 68 | assert_eq("", rblf.notdir("")) |
| 69 | |
Cole Faust | fdff6b1 | 2021-12-08 11:07:17 -0800 | [diff] [blame] | 70 | assert_eq( |
| 71 | ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"], |
| 72 | rblf.expand_wildcard("build/make/tests/board*.rbc") |
| 73 | ) |
| 74 | assert_eq( |
| 75 | ["build/make/tests/run.rbc", "build/make/tests/product.rbc"], |
| 76 | rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/product.rbc") |
| 77 | ) |
| 78 | assert_eq( |
| 79 | ["build/make/tests/run.rbc"], |
| 80 | rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/nonexistent.rbc") |
| 81 | ) |
| 82 | |
Cole Faust | f1f49bb | 2021-12-01 13:49:12 -0800 | [diff] [blame] | 83 | (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] | 84 | assert_eq( |
| 85 | { |
| 86 | "PRODUCT_COPY_FILES": [ |
| 87 | "part_from:part_to", |
| 88 | "device_from:device_to", |
Sasha Smundak | 6b795dc | 2021-08-18 16:32:19 -0700 | [diff] [blame] | 89 | "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] | 90 | "xyz:/etc/xyz", |
| 91 | "x.xml:/etc/x.xml", |
| 92 | "y.xml:/etc/y.xml", |
Sasha Smundak | 6797bfa | 2021-08-19 09:49:49 -0700 | [diff] [blame] | 93 | "from/sub/x:to/x", |
| 94 | "from/sub/y:to/y", |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 95 | ], |
| 96 | "PRODUCT_HOST_PACKAGES": ["host"], |
| 97 | "PRODUCT_PACKAGES": [ |
| 98 | "dev", |
| 99 | "inc", |
Sasha Smundak | 3370ad5 | 2021-08-26 16:59:55 -0700 | [diff] [blame] | 100 | "dev_after", |
| 101 | "board1_in", |
| 102 | "board1_is", |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 103 | ], |
| 104 | "PRODUCT_PRODUCT_PROPERTIES": ["part_properties"] |
| 105 | }, |
| 106 | { k:v for k, v in sorted(config.items()) } |
| 107 | ) |
Sasha Smundak | c106138 | 2021-07-28 12:29:00 -0700 | [diff] [blame] | 108 | |
| 109 | ns = globals["$SOONG_CONFIG_NAMESPACES"] |
| 110 | assert_eq( |
| 111 | { |
| 112 | "NS1": { |
Sasha Smundak | dc15416 | 2021-09-17 15:27:37 -0700 | [diff] [blame] | 113 | "v1": "abc abc_part1", |
Sasha Smundak | c106138 | 2021-07-28 12:29:00 -0700 | [diff] [blame] | 114 | "v2": "def" |
| 115 | }, |
| 116 | "NS2": { |
| 117 | "v3": "xyz" |
| 118 | } |
| 119 | }, |
| 120 | {k:v for k, v in sorted(ns.items()) } |
| 121 | ) |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 122 | |
Cole Faust | f1f49bb | 2021-12-01 13:49:12 -0800 | [diff] [blame] | 123 | assert_eq("Tiramisu", globals["PLATFORM_VERSION"]) |
| 124 | assert_eq("31", globals["PLATFORM_SDK_VERSION"]) |
Cole Faust | 70a886c | 2021-11-08 12:12:45 -0800 | [diff] [blame] | 125 | |
| 126 | assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3")) |
| 127 | assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var")) |
Sasha Smundak | 91fc734 | 2021-11-18 11:20:34 -0800 | [diff] [blame] | 128 | |
| 129 | goals = globals["$dist_for_goals"] |
| 130 | assert_eq( |
| 131 | { |
| 132 | "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")] |
| 133 | }, |
| 134 | { k:v for k,v in sorted(goals.items()) } |
| 135 | ) |
Cole Faust | 3be5b72 | 2021-11-29 14:56:09 -0800 | [diff] [blame] | 136 | |
| 137 | (board_globals, board_config, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init) |
| 138 | assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals) |
| 139 | assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base) |
Cole Faust | 31fce2f | 2022-03-22 15:16:06 -0700 | [diff] [blame] | 140 | |
| 141 | test_single_value_inheritance() |