blob: 7f3653df91d40ff17be49d23fca971ab7bcdba32 [file] [log] [blame]
Neill Kapron41efab72024-07-31 22:17:36 +00001// Copyright 2024 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
15package libbpf_prog
16
17import (
18 "os"
19 "testing"
20
21 "android/soong/android"
22 "android/soong/cc"
23)
24
25func TestMain(m *testing.M) {
26 os.Exit(m.Run())
27}
28
29var prepareForLibbpfProgTest = android.GroupFixturePreparers(
30 cc.PrepareForTestWithCcDefaultModules,
31 android.FixtureMergeMockFs(
32 map[string][]byte{
33 "bpf.c": nil,
34 "bpf_invalid_name.c": nil,
35 "BpfTest.cpp": nil,
36 },
37 ),
38 PrepareForTestWithLibbpfProg,
39)
40
41func TestLibbpfProgDataDependency(t *testing.T) {
42 bp := `
43 libbpf_prog {
44 name: "bpf.o",
45 srcs: ["bpf.c"],
46 }
47
48 cc_test {
49 name: "vts_test_binary_bpf_module",
Cole Faust65cb40a2024-10-21 15:41:42 -070050 compile_multilib: "first",
Neill Kapron41efab72024-07-31 22:17:36 +000051 srcs: ["BpfTest.cpp"],
52 data: [":bpf.o"],
53 gtest: false,
54 }
55 `
56
57 prepareForLibbpfProgTest.RunTestWithBp(t, bp)
58}
59
60func TestLibbpfProgSourceName(t *testing.T) {
61 bp := `
62 libbpf_prog {
63 name: "bpf_invalid_name.o",
64 srcs: ["bpf_invalid_name.c"],
65 }
66 `
67 prepareForLibbpfProgTest.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
68 `invalid character '_' in source name`)).
69 RunTestWithBp(t, bp)
70}