blob: 5c9bd65306cd16f8fcc2f49ebd55fd4be9f3d3ac [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -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 Lozano042504f2020-08-18 14:31:23 -040020
21 "android/soong/android"
Ivan Lozanoffee3342019-08-27 12:03:00 -070022)
23
Ivan Lozano042504f2020-08-18 14:31:23 -040024// Test that rustlibs default linkage is correct for binaries.
25func TestBinaryLinkage(t *testing.T) {
26 ctx := testRust(t, `
27 rust_binary {
28 name: "fizz-buzz",
29 srcs: ["foo.rs"],
30 rustlibs: ["libfoo"],
31 host_supported: true,
32 }
33 rust_library {
34 name: "libfoo",
35 srcs: ["foo.rs"],
36 crate_name: "foo",
37 host_supported: true,
38 }`)
39
40 fizzBuzzHost := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
41 fizzBuzzDevice := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Module().(*Module)
42
43 if !android.InList("libfoo", fizzBuzzHost.Properties.AndroidMkRlibs) {
44 t.Errorf("rustlibs dependency libfoo should be an rlib dep for host modules")
45 }
46
47 if !android.InList("libfoo", fizzBuzzDevice.Properties.AndroidMkDylibs) {
48 t.Errorf("rustlibs dependency libfoo should be an dylib dep for device modules")
49 }
50}
51
52// Test that the path returned by HostToolPath is correct
53func TestHostToolPath(t *testing.T) {
Ivan Lozanoffee3342019-08-27 12:03:00 -070054 ctx := testRust(t, `
55 rust_binary_host {
Ivan Lozano042504f2020-08-18 14:31:23 -040056 name: "fizz-buzz",
Ivan Lozanoffee3342019-08-27 12:03:00 -070057 srcs: ["foo.rs"],
Ivan Lozano042504f2020-08-18 14:31:23 -040058 }`)
Ivan Lozanoffee3342019-08-27 12:03:00 -070059
Ivan Lozano042504f2020-08-18 14:31:23 -040060 path := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module).HostToolPath()
61 if g, w := path.String(), "/host/linux-x86/bin/fizz-buzz"; !strings.Contains(g, w) {
62 t.Errorf("wrong host tool path, expected %q got %q", w, g)
63 }
64}
65
66// Test that the flags being passed to rust_binary modules are as expected
67func TestBinaryFlags(t *testing.T) {
68 ctx := testRust(t, `
Ivan Lozanoffee3342019-08-27 12:03:00 -070069 rust_binary_host {
70 name: "fizz-buzz",
71 srcs: ["foo.rs"],
72 }`)
73
74 fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Output("fizz-buzz")
Ivan Lozanoffee3342019-08-27 12:03:00 -070075
Ivan Lozano042504f2020-08-18 14:31:23 -040076 flags := fizzBuzz.Args["rustcFlags"]
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070077 if strings.Contains(flags, "--test") {
78 t.Errorf("extra --test flag, rustcFlags: %#v", flags)
79 }
Ivan Lozanoffee3342019-08-27 12:03:00 -070080}