platform_build_soong/bpf/bpf_test.go
Ken Chen 5372a24375 Disallow '_' in bpf source name
Current design:
1. The bpf compiled object name is derived from the source name
   (e.g. foo.c -> foo.o).
2. Full bpf program/map name are concatenated by object name + '_' +
   program/map name in run-time. (e.g. obj name: x.o; program name: y_z;
   full bpf program name will be x_y_z)

Issue:
x.o with map y_z and x_y.o with map z can cause naming collision in
run-time, since both result in x_y_z. This commit prevents it from
happening with a build-time check.

Bug: 236706995
Test: m
Change-Id: Ic03bfcf07a5748ed63246b71d5ae8de0405e658a
2022-07-07 20:02:28 +08:00

73 lines
1.8 KiB
Go

// Copyright 2018 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package bpf
import (
"os"
"testing"
"android/soong/android"
"android/soong/cc"
)
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
var prepareForBpfTest = android.GroupFixturePreparers(
cc.PrepareForTestWithCcDefaultModules,
android.FixtureMergeMockFs(
map[string][]byte{
"bpf.c": nil,
"bpf_invalid_name.c": nil,
"BpfTest.cpp": nil,
},
),
PrepareForTestWithBpf,
)
func TestBpfDataDependency(t *testing.T) {
bp := `
bpf {
name: "bpf.o",
srcs: ["bpf.c"],
}
cc_test {
name: "vts_test_binary_bpf_module",
srcs: ["BpfTest.cpp"],
data: [":bpf.o"],
gtest: false,
}
`
prepareForBpfTest.RunTestWithBp(t, bp)
// We only verify the above BP configuration is processed successfully since the data property
// value is not available for testing from this package.
// TODO(jungjw): Add a check for data or move this test to the cc package.
}
func TestBpfSourceName(t *testing.T) {
bp := `
bpf {
name: "bpf_invalid_name.o",
srcs: ["bpf_invalid_name.c"],
}
`
prepareForBpfTest.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
`\QAndroid.bp:2:3: module "bpf_invalid_name.o" variant "android_common": invalid character '_' in source name\E`)).
RunTestWithBp(t, bp)
}