bpf_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. "io/ioutil"
  17. "os"
  18. "testing"
  19. "android/soong/android"
  20. "android/soong/cc"
  21. )
  22. var buildDir string
  23. func setUp() {
  24. var err error
  25. buildDir, err = ioutil.TempDir("", "genrule_test")
  26. if err != nil {
  27. panic(err)
  28. }
  29. }
  30. func tearDown() {
  31. os.RemoveAll(buildDir)
  32. }
  33. func TestMain(m *testing.M) {
  34. run := func() int {
  35. setUp()
  36. defer tearDown()
  37. return m.Run()
  38. }
  39. os.Exit(run())
  40. }
  41. func testConfig(buildDir string, env map[string]string, bp string) android.Config {
  42. mockFS := map[string][]byte{
  43. "bpf.c": nil,
  44. "BpfTest.cpp": nil,
  45. }
  46. return cc.TestConfig(buildDir, android.Android, env, bp, mockFS)
  47. }
  48. func testContext(config android.Config) *android.TestContext {
  49. ctx := cc.CreateTestContext()
  50. ctx.RegisterModuleType("bpf", BpfFactory)
  51. ctx.Register(config)
  52. return ctx
  53. }
  54. func TestBpfDataDependency(t *testing.T) {
  55. bp := `
  56. bpf {
  57. name: "bpf.o",
  58. srcs: ["bpf.c"],
  59. }
  60. cc_test {
  61. name: "vts_test_binary_bpf_module",
  62. srcs: ["BpfTest.cpp"],
  63. data: [":bpf.o"],
  64. gtest: false,
  65. }
  66. `
  67. config := testConfig(buildDir, nil, bp)
  68. ctx := testContext(config)
  69. _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
  70. if errs == nil {
  71. _, errs = ctx.PrepareBuildActions(config)
  72. }
  73. if errs != nil {
  74. t.Fatal(errs)
  75. }
  76. // We only verify the above BP configuration is processed successfully since the data property
  77. // value is not available for testing from this package.
  78. // TODO(jungjw): Add a check for data or move this test to the cc package.
  79. }