bpf_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2018 Google Inc. All rights reserved.
  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 bpf
  15. import (
  16. "os"
  17. "testing"
  18. "android/soong/android"
  19. "android/soong/cc"
  20. )
  21. func TestMain(m *testing.M) {
  22. os.Exit(m.Run())
  23. }
  24. var prepareForBpfTest = android.GroupFixturePreparers(
  25. cc.PrepareForTestWithCcDefaultModules,
  26. android.FixtureMergeMockFs(
  27. map[string][]byte{
  28. "bpf.c": nil,
  29. "bpf_invalid_name.c": nil,
  30. "BpfTest.cpp": nil,
  31. },
  32. ),
  33. PrepareForTestWithBpf,
  34. )
  35. func TestBpfDataDependency(t *testing.T) {
  36. bp := `
  37. bpf {
  38. name: "bpf.o",
  39. srcs: ["bpf.c"],
  40. }
  41. cc_test {
  42. name: "vts_test_binary_bpf_module",
  43. srcs: ["BpfTest.cpp"],
  44. data: [":bpf.o"],
  45. gtest: false,
  46. }
  47. `
  48. prepareForBpfTest.RunTestWithBp(t, bp)
  49. // We only verify the above BP configuration is processed successfully since the data property
  50. // value is not available for testing from this package.
  51. // TODO(jungjw): Add a check for data or move this test to the cc package.
  52. }
  53. func TestBpfSourceName(t *testing.T) {
  54. bp := `
  55. bpf {
  56. name: "bpf_invalid_name.o",
  57. srcs: ["bpf_invalid_name.c"],
  58. }
  59. `
  60. prepareForBpfTest.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
  61. `\QAndroid.bp:2:3: module "bpf_invalid_name.o" variant "android_common": invalid character '_' in source name\E`)).
  62. RunTestWithBp(t, bp)
  63. }
  64. func TestBpfWithBazel(t *testing.T) {
  65. bp := `
  66. bpf {
  67. name: "bpf.o",
  68. srcs: ["bpf.c"],
  69. bazel_module: { label: "//bpf" },
  70. }
  71. `
  72. result := android.GroupFixturePreparers(
  73. prepareForBpfTest, android.FixtureModifyConfig(func(config android.Config) {
  74. config.BazelContext = android.MockBazelContext{
  75. OutputBaseDir: "outputbase",
  76. LabelToOutputFiles: map[string][]string{
  77. "//bpf": []string{"bpf.o"}}}
  78. })).RunTestWithBp(t, bp)
  79. output := result.Module("bpf.o", "android_common").(*bpf)
  80. expectedOutputFiles := []string{"outputbase/execroot/__main__/bpf.o"}
  81. android.AssertDeepEquals(t, "output files", expectedOutputFiles, output.objs.Strings())
  82. }