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 15package android_sdk 16 17import ( 18 "fmt" 19 "runtime" 20 "sort" 21 "testing" 22 23 "android/soong/android" 24 "android/soong/cc" 25 26 "github.com/google/blueprint/pathtools" 27) 28 29var fixture = android.GroupFixturePreparers( 30 android.PrepareForIntegrationTestWithAndroid, 31 cc.PrepareForIntegrationTestWithCc, 32 android.FixtureRegisterWithContext(registerBuildComponents), 33) 34 35func TestSdkRepoHostDeps(t *testing.T) { 36 if runtime.GOOS != "linux" { 37 t.Skipf("Skipping sdk_repo_host testing that is only supported on linux not %s", runtime.GOOS) 38 } 39 40 result := fixture.RunTestWithBp(t, ` 41 android_sdk_repo_host { 42 name: "platform-tools", 43 } 44 `) 45 46 // produces "sdk-repo-{OS}-platform-tools.zip" 47 result.ModuleForTests("platform-tools", "linux_glibc_common").Output("sdk-repo-linux-platform-tools.zip") 48} 49 50func TestRemapPackageSpecs(t *testing.T) { 51 testcases := []struct { 52 name string 53 input []string 54 remaps []remapProperties 55 output []string 56 err string 57 }{ 58 { 59 name: "basic remap", 60 input: []string{"a", "c"}, 61 remaps: []remapProperties{ 62 {From: "a", To: "b"}, 63 }, 64 output: []string{"b", "c"}, 65 }, 66 { 67 name: "non-matching remap", 68 input: []string{"a"}, 69 remaps: []remapProperties{ 70 {From: "b", To: "c"}, 71 }, 72 output: []string{"a"}, 73 }, 74 { 75 name: "glob", 76 input: []string{"bin/d", "liba.so", "libb.so", "lib/c.so"}, 77 remaps: []remapProperties{ 78 {From: "lib*.so", To: "lib/"}, 79 }, 80 output: []string{"bin/d", "lib/c.so", "lib/liba.so", "lib/libb.so"}, 81 }, 82 { 83 name: "bad glob", 84 input: []string{"a"}, 85 remaps: []remapProperties{ 86 {From: "**", To: "./"}, 87 }, 88 err: fmt.Sprintf("Error parsing \"**\": %v", pathtools.GlobLastRecursiveErr.Error()), 89 }, 90 { 91 name: "globbed dirs", 92 input: []string{"a/b/c"}, 93 remaps: []remapProperties{ 94 {From: "a/*/c", To: "./"}, 95 }, 96 output: []string{"b/c"}, 97 }, 98 } 99 100 for _, test := range testcases { 101 t.Run(test.name, func(t *testing.T) { 102 specs := map[string]android.PackagingSpec{} 103 for _, input := range test.input { 104 spec := android.PackagingSpec{} 105 spec.SetRelPathInPackage(input) 106 specs[input] = spec 107 } 108 109 err := remapPackageSpecs(specs, test.remaps) 110 111 if test.err != "" { 112 android.AssertErrorMessageEquals(t, "", test.err, err) 113 } else { 114 outputs := []string{} 115 for path, spec := range specs { 116 android.AssertStringEquals(t, "path does not match rel path", path, spec.RelPathInPackage()) 117 outputs = append(outputs, path) 118 } 119 sort.Strings(outputs) 120 android.AssertArrayString(t, "outputs mismatch", test.output, outputs) 121 } 122 }) 123 } 124} 125