Inseob Kim | 5eb7ee9 | 2022-04-27 10:30:34 +0900 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 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 | // http://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 | package cc |
| 16 | |
| 17 | import ( |
| 18 | _ "fmt" |
| 19 | _ "sort" |
| 20 | |
| 21 | "testing" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | "android/soong/multitree" |
| 25 | ) |
| 26 | |
| 27 | func TestCcApiStubLibraryOutputFiles(t *testing.T) { |
| 28 | bp := ` |
| 29 | cc_api_stub_library { |
| 30 | name: "foo", |
| 31 | symbol_file: "foo.map.txt", |
| 32 | first_version: "29", |
| 33 | } |
| 34 | ` |
| 35 | result := prepareForCcTest.RunTestWithBp(t, bp) |
| 36 | outputs := result.ModuleForTests("foo", "android_arm64_armv8-a_shared").AllOutputs() |
| 37 | expected_file_suffixes := []string{".c", "stub.map", ".o", ".so"} |
| 38 | for _, expected_file_suffix := range expected_file_suffixes { |
| 39 | android.AssertBoolEquals(t, expected_file_suffix+" file not found in output", true, android.SuffixInList(outputs, expected_file_suffix)) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func TestCcApiStubLibraryVariants(t *testing.T) { |
| 44 | bp := ` |
| 45 | cc_api_stub_library { |
| 46 | name: "foo", |
| 47 | symbol_file: "foo.map.txt", |
| 48 | first_version: "29", |
| 49 | } |
| 50 | ` |
| 51 | result := prepareForCcTest.RunTestWithBp(t, bp) |
| 52 | variants := result.ModuleVariantsForTests("foo") |
| 53 | expected_variants := []string{"29", "30", "S", "Tiramisu"} //TODO: make this test deterministic by using fixtures |
| 54 | for _, expected_variant := range expected_variants { |
| 55 | android.AssertBoolEquals(t, expected_variant+" variant not found in foo", true, android.SubstringInList(variants, expected_variant)) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func TestCcLibraryUsesCcApiStubLibrary(t *testing.T) { |
| 60 | bp := ` |
| 61 | cc_api_stub_library { |
| 62 | name: "foo", |
| 63 | symbol_file: "foo.map.txt", |
| 64 | first_version: "29", |
| 65 | } |
| 66 | cc_library { |
| 67 | name: "foo_user", |
| 68 | shared_libs: [ |
| 69 | "foo#29", |
| 70 | ], |
| 71 | } |
| 72 | |
| 73 | ` |
| 74 | prepareForCcTest.RunTestWithBp(t, bp) |
| 75 | } |
| 76 | |
| 77 | func TestApiSurfaceOutputs(t *testing.T) { |
| 78 | bp := ` |
| 79 | api_surface { |
| 80 | name: "mysdk", |
| 81 | contributions: [ |
| 82 | "foo", |
| 83 | ], |
| 84 | } |
| 85 | |
| 86 | cc_api_contribution { |
| 87 | name: "foo", |
| 88 | symbol_file: "foo.map.txt", |
| 89 | first_version: "29", |
| 90 | } |
| 91 | ` |
| 92 | result := android.GroupFixturePreparers( |
| 93 | prepareForCcTest, |
| 94 | multitree.PrepareForTestWithApiSurface, |
| 95 | ).RunTestWithBp(t, bp) |
| 96 | mysdk := result.ModuleForTests("mysdk", "") |
| 97 | |
| 98 | actual_surface_inputs := mysdk.Rule("phony").BuildParams.Inputs.Strings() |
| 99 | expected_file_suffixes := []string{"mysdk/foo/foo.map.txt"} |
| 100 | for _, expected_file_suffix := range expected_file_suffixes { |
| 101 | android.AssertBoolEquals(t, expected_file_suffix+" file not found in input", true, android.SuffixInList(actual_surface_inputs, expected_file_suffix)) |
| 102 | } |
| 103 | |
| 104 | // check args/inputs to rule |
| 105 | /*api_surface_gen_rule_args := result.ModuleForTests("mysdk", "").Rule("genApiSurfaceBuildFiles").Args |
| 106 | android.AssertStringEquals(t, "name", "foo.mysdk", api_surface_gen_rule_args["name"]) |
| 107 | android.AssertStringEquals(t, "symbol_file", "foo.map.txt", api_surface_gen_rule_args["symbol_file"])*/ |
| 108 | } |