blob: fea2ad0598cc8bc2c8c69688608e76e3036b0c0a [file] [log] [blame]
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -07001// 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"
Ivan Lozano2b081132020-09-08 12:46:52 -040020
21 "android/soong/android"
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070022)
23
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070024func TestRustTest(t *testing.T) {
25 ctx := testRust(t, `
26 rust_test_host {
27 name: "my_test",
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -070028 srcs: ["foo.rs"],
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -070029 }`)
30
Ivan Lozanofc80fe72020-06-11 13:25:36 -040031 testingModule := ctx.ModuleForTests("my_test", "linux_glibc_x86_64")
32 expectedOut := "my_test/linux_glibc_x86_64/my_test"
33 outPath := testingModule.Output("my_test").Output.String()
34 if !strings.Contains(outPath, expectedOut) {
35 t.Errorf("wrong output path: %v; expected: %v", outPath, expectedOut)
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -070036 }
37}
Ivan Lozano2b081132020-09-08 12:46:52 -040038
39func TestRustTestLinkage(t *testing.T) {
40 ctx := testRust(t, `
41 rust_test {
42 name: "my_test",
43 srcs: ["foo.rs"],
44 rustlibs: ["libfoo"],
45 rlibs: ["libbar"],
46 }
47 rust_library {
48 name: "libfoo",
49 srcs: ["foo.rs"],
50 crate_name: "foo",
51 }
52 rust_library {
53 name: "libbar",
54 srcs: ["foo.rs"],
55 crate_name: "bar",
56 }`)
57
58 testingModule := ctx.ModuleForTests("my_test", "android_arm64_armv8-a").Module().(*Module)
59
60 if !android.InList("libfoo.rlib-std", testingModule.Properties.AndroidMkRlibs) {
61 t.Errorf("rlib-std variant for libfoo not detected as a rustlib-defined rlib dependency for device rust_test module")
62 }
63 if !android.InList("libbar.rlib-std", testingModule.Properties.AndroidMkRlibs) {
64 t.Errorf("rlib-std variant for libbar not detected as an rlib dependency for device rust_test module")
65 }
66 if !android.InList("libstd", testingModule.Properties.AndroidMkRlibs) {
67 t.Errorf("Device rust_test module 'my_test' does not link libstd as an rlib")
68 }
69}