Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 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 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | "testing" |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 24 | func TestRustTest(t *testing.T) { |
Colin Cross | 323dc60 | 2020-09-18 14:25:31 -0700 | [diff] [blame] | 25 | t.Parallel() |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 26 | ctx := testRust(t, ` |
| 27 | rust_test_host { |
| 28 | name: "my_test", |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 29 | srcs: ["foo.rs"], |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 30 | }`) |
| 31 | |
Ivan Lozano | fc80fe7 | 2020-06-11 13:25:36 -0400 | [diff] [blame] | 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) |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 37 | } |
| 38 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 39 | |
| 40 | func TestRustTestLinkage(t *testing.T) { |
Colin Cross | 323dc60 | 2020-09-18 14:25:31 -0700 | [diff] [blame] | 41 | t.Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 42 | ctx := testRust(t, ` |
| 43 | rust_test { |
| 44 | name: "my_test", |
| 45 | srcs: ["foo.rs"], |
| 46 | rustlibs: ["libfoo"], |
| 47 | rlibs: ["libbar"], |
| 48 | } |
| 49 | rust_library { |
| 50 | name: "libfoo", |
| 51 | srcs: ["foo.rs"], |
| 52 | crate_name: "foo", |
| 53 | } |
| 54 | rust_library { |
| 55 | name: "libbar", |
| 56 | srcs: ["foo.rs"], |
| 57 | crate_name: "bar", |
| 58 | }`) |
| 59 | |
| 60 | testingModule := ctx.ModuleForTests("my_test", "android_arm64_armv8-a").Module().(*Module) |
| 61 | |
| 62 | if !android.InList("libfoo.rlib-std", testingModule.Properties.AndroidMkRlibs) { |
| 63 | t.Errorf("rlib-std variant for libfoo not detected as a rustlib-defined rlib dependency for device rust_test module") |
| 64 | } |
| 65 | if !android.InList("libbar.rlib-std", testingModule.Properties.AndroidMkRlibs) { |
| 66 | t.Errorf("rlib-std variant for libbar not detected as an rlib dependency for device rust_test module") |
| 67 | } |
| 68 | if !android.InList("libstd", testingModule.Properties.AndroidMkRlibs) { |
| 69 | t.Errorf("Device rust_test module 'my_test' does not link libstd as an rlib") |
| 70 | } |
| 71 | } |