fuzz_test.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 java
  15. import (
  16. "path/filepath"
  17. "runtime"
  18. "testing"
  19. "android/soong/android"
  20. "android/soong/cc"
  21. )
  22. var prepForJavaFuzzTest = android.GroupFixturePreparers(
  23. PrepareForTestWithJavaDefaultModules,
  24. cc.PrepareForTestWithCcBuildComponents,
  25. android.FixtureRegisterWithContext(RegisterJavaFuzzBuildComponents),
  26. )
  27. func TestJavaFuzz(t *testing.T) {
  28. result := prepForJavaFuzzTest.RunTestWithBp(t, `
  29. java_fuzz {
  30. name: "foo",
  31. srcs: ["a.java"],
  32. host_supported: true,
  33. device_supported: false,
  34. libs: ["bar"],
  35. static_libs: ["baz"],
  36. jni_libs: [
  37. "libjni",
  38. ],
  39. }
  40. java_library_host {
  41. name: "bar",
  42. srcs: ["b.java"],
  43. }
  44. java_library_host {
  45. name: "baz",
  46. srcs: ["c.java"],
  47. }
  48. cc_library_shared {
  49. name: "libjni",
  50. host_supported: true,
  51. device_supported: false,
  52. stl: "none",
  53. }
  54. `)
  55. osCommonTarget := result.Config.BuildOSCommonTarget.String()
  56. javac := result.ModuleForTests("foo", osCommonTarget).Rule("javac")
  57. combineJar := result.ModuleForTests("foo", osCommonTarget).Description("for javac")
  58. if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
  59. t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
  60. }
  61. baz := result.ModuleForTests("baz", osCommonTarget).Rule("javac").Output.String()
  62. barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac", "bar.jar")
  63. bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac", "baz.jar")
  64. android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barOut)
  65. android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazOut)
  66. if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
  67. t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
  68. }
  69. ctx := result.TestContext
  70. foo := ctx.ModuleForTests("foo", osCommonTarget).Module().(*JavaFuzzTest)
  71. expected := "lib64/libjni.so"
  72. if runtime.GOOS == "darwin" {
  73. expected = "lib64/libjni.dylib"
  74. }
  75. fooJniFilePaths := foo.jniFilePaths
  76. if len(fooJniFilePaths) != 1 || fooJniFilePaths[0].Rel() != expected {
  77. t.Errorf(`expected foo test data relative path [%q], got %q`,
  78. expected, fooJniFilePaths.Strings())
  79. }
  80. }