benchmark_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2021 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. package rust
  15. import (
  16. "strings"
  17. "testing"
  18. "android/soong/android"
  19. )
  20. func TestRustBenchmark(t *testing.T) {
  21. ctx := testRust(t, `
  22. rust_benchmark_host {
  23. name: "my_bench",
  24. srcs: ["foo.rs"],
  25. }`)
  26. testingModule := ctx.ModuleForTests("my_bench", "linux_glibc_x86_64")
  27. expectedOut := "my_bench/linux_glibc_x86_64/my_bench"
  28. outPath := testingModule.Output("my_bench").Output.String()
  29. if !strings.Contains(outPath, expectedOut) {
  30. t.Errorf("wrong output path: %v; expected: %v", outPath, expectedOut)
  31. }
  32. }
  33. func TestRustBenchmarkLinkage(t *testing.T) {
  34. ctx := testRust(t, `
  35. rust_benchmark {
  36. name: "my_bench",
  37. srcs: ["foo.rs"],
  38. }`)
  39. testingModule := ctx.ModuleForTests("my_bench", "android_arm64_armv8-a").Module().(*Module)
  40. if !android.InList("libcriterion.rlib-std", testingModule.Properties.AndroidMkRlibs) {
  41. t.Errorf("rlib-std variant for libcriterion not detected as a rustlib-defined rlib dependency for device rust_benchmark module")
  42. }
  43. if !android.InList("libstd", testingModule.Properties.AndroidMkRlibs) {
  44. t.Errorf("Device rust_benchmark module 'my_bench' does not link libstd as an rlib")
  45. }
  46. }