Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 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 | |
| 15 | package bpf |
| 16 | |
| 17 | import ( |
| 18 | "io/ioutil" |
| 19 | "os" |
| 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame^] | 23 | "android/soong/cc" |
Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | var buildDir string |
| 27 | |
| 28 | func setUp() { |
| 29 | var err error |
| 30 | buildDir, err = ioutil.TempDir("", "genrule_test") |
| 31 | if err != nil { |
| 32 | panic(err) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func tearDown() { |
| 37 | os.RemoveAll(buildDir) |
| 38 | } |
| 39 | |
| 40 | func TestMain(m *testing.M) { |
| 41 | run := func() int { |
| 42 | setUp() |
| 43 | defer tearDown() |
| 44 | |
| 45 | return m.Run() |
| 46 | } |
| 47 | |
| 48 | os.Exit(run()) |
| 49 | } |
| 50 | |
| 51 | func testContext(bp string) *android.TestContext { |
Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 52 | mockFS := map[string][]byte{ |
Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 53 | "bpf.c": nil, |
| 54 | "BpfTest.cpp": nil, |
| 55 | } |
| 56 | |
Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame^] | 57 | ctx := cc.CreateTestContext(bp, mockFS, android.Android) |
| 58 | ctx.RegisterModuleType("bpf", android.ModuleFactoryAdaptor(bpfFactory)) |
| 59 | ctx.Register() |
Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 60 | |
| 61 | return ctx |
| 62 | } |
| 63 | |
| 64 | func TestBpfDataDependency(t *testing.T) { |
| 65 | config := android.TestArchConfig(buildDir, nil) |
| 66 | bp := ` |
| 67 | bpf { |
| 68 | name: "bpf.o", |
| 69 | srcs: ["bpf.c"], |
| 70 | } |
| 71 | |
| 72 | cc_test { |
| 73 | name: "vts_test_binary_bpf_module", |
| 74 | srcs: ["BpfTest.cpp"], |
| 75 | data: [":bpf.o"], |
Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame^] | 76 | gtest: false, |
Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 77 | } |
| 78 | ` |
| 79 | |
| 80 | ctx := testContext(bp) |
| 81 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 82 | if errs == nil { |
| 83 | _, errs = ctx.PrepareBuildActions(config) |
| 84 | } |
| 85 | if errs != nil { |
| 86 | t.Fatal(errs) |
| 87 | } |
| 88 | |
| 89 | // We only verify the above BP configuration is processed successfully since the data property |
| 90 | // value is not available for testing from this package. |
| 91 | // TODO(jungjw): Add a check for data or move this test to the cc package. |
| 92 | } |