| 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 ( | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 18 | "os" | 
|  | 19 | "testing" | 
|  | 20 |  | 
|  | 21 | "android/soong/android" | 
| Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame] | 22 | "android/soong/cc" | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 23 | ) | 
|  | 24 |  | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 25 | func TestMain(m *testing.M) { | 
| Paul Duffin | 854d661 | 2021-03-16 13:36:55 +0000 | [diff] [blame] | 26 | os.Exit(m.Run()) | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 29 | var prepareForBpfTest = android.GroupFixturePreparers( | 
| Paul Duffin | 12c7eb8 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 30 | cc.PrepareForTestWithCcDefaultModules, | 
|  | 31 | android.FixtureMergeMockFs( | 
|  | 32 | map[string][]byte{ | 
| Ken Chen | 5372a24 | 2022-07-07 17:48:06 +0800 | [diff] [blame] | 33 | "bpf.c":              nil, | 
|  | 34 | "bpf_invalid_name.c": nil, | 
|  | 35 | "BpfTest.cpp":        nil, | 
| Paul Duffin | 12c7eb8 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 36 | }, | 
|  | 37 | ), | 
|  | 38 | PrepareForTestWithBpf, | 
|  | 39 | ) | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 40 |  | 
|  | 41 | func TestBpfDataDependency(t *testing.T) { | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 42 | bp := ` | 
|  | 43 | bpf { | 
|  | 44 | name: "bpf.o", | 
|  | 45 | srcs: ["bpf.c"], | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | cc_test { | 
|  | 49 | name: "vts_test_binary_bpf_module", | 
|  | 50 | srcs: ["BpfTest.cpp"], | 
|  | 51 | data: [":bpf.o"], | 
| Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame] | 52 | gtest: false, | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 53 | } | 
|  | 54 | ` | 
|  | 55 |  | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 56 | prepareForBpfTest.RunTestWithBp(t, bp) | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 57 |  | 
|  | 58 | // We only verify the above BP configuration is processed successfully since the data property | 
|  | 59 | // value is not available for testing from this package. | 
|  | 60 | // TODO(jungjw): Add a check for data or move this test to the cc package. | 
|  | 61 | } | 
| Ken Chen | 5372a24 | 2022-07-07 17:48:06 +0800 | [diff] [blame] | 62 |  | 
|  | 63 | func TestBpfSourceName(t *testing.T) { | 
|  | 64 | bp := ` | 
|  | 65 | bpf { | 
|  | 66 | name: "bpf_invalid_name.o", | 
|  | 67 | srcs: ["bpf_invalid_name.c"], | 
|  | 68 | } | 
|  | 69 | ` | 
|  | 70 | prepareForBpfTest.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( | 
|  | 71 | `\QAndroid.bp:2:3: module "bpf_invalid_name.o" variant "android_common": invalid character '_' in source name\E`)). | 
|  | 72 | RunTestWithBp(t, bp) | 
|  | 73 | } |