1// Copyright 2019 The Android Open Source Project 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 rust 16 17import ( 18 "strings" 19 "testing" 20 21 "android/soong/android" 22) 23 24func TestRustTest(t *testing.T) { 25 ctx := testRust(t, ` 26 rust_test_host { 27 name: "my_test", 28 srcs: ["foo.rs"], 29 data: ["data.txt"], 30 }`) 31 32 testingModule := ctx.ModuleForTests("my_test", "linux_glibc_x86_64") 33 expectedOut := "my_test/linux_glibc_x86_64/my_test" 34 outPath := testingModule.Output("my_test").Output.String() 35 if !strings.Contains(outPath, expectedOut) { 36 t.Errorf("wrong output path: %v; expected: %v", outPath, expectedOut) 37 } 38 39 dataPaths := testingModule.Module().(*Module).compiler.(*testDecorator).dataPaths() 40 if len(dataPaths) != 1 { 41 t.Errorf("expected exactly one test data file. test data files: [%s]", dataPaths) 42 return 43 } 44} 45 46func TestRustTestLinkage(t *testing.T) { 47 ctx := testRust(t, ` 48 rust_test { 49 name: "my_test", 50 srcs: ["foo.rs"], 51 rustlibs: ["libfoo"], 52 rlibs: ["libbar"], 53 } 54 rust_library { 55 name: "libfoo", 56 srcs: ["foo.rs"], 57 crate_name: "foo", 58 } 59 rust_library { 60 name: "libbar", 61 srcs: ["foo.rs"], 62 crate_name: "bar", 63 }`) 64 65 testingModule := ctx.ModuleForTests("my_test", "android_arm64_armv8-a").Module().(*Module) 66 67 if !android.InList("libfoo.rlib-std", testingModule.Properties.AndroidMkRlibs) { 68 t.Errorf("rlib-std variant for libfoo not detected as a rustlib-defined rlib dependency for device rust_test module") 69 } 70 if !android.InList("libbar.rlib-std", testingModule.Properties.AndroidMkRlibs) { 71 t.Errorf("rlib-std variant for libbar not detected as an rlib dependency for device rust_test module") 72 } 73 if !android.InList("libstd", testingModule.Properties.AndroidMkRlibs) { 74 t.Errorf("Device rust_test module 'my_test' does not link libstd as an rlib") 75 } 76} 77