Skip to content

Commit 1536774

Browse files
committedApr 28, 2020
tests: Run end to end tests in subtests, replace XDPAction
Currently the end to end tests support checking both the CBPF to C to EBPF and CBPF to EBPF backends. Run these in separate subtests so that we can easily check the result of either, including if both fail. This introduces a "backend" abstraction to allow us to delay compiling / doing anything until we are in the subtest. Have the backend return a result type expressing if the packet matched the filter, as the XDPDrop == packet matched is an arbitrary construct that doesn't map well to other potential backends, such as a native cBPF one.
1 parent 01a9eda commit 1536774

File tree

3 files changed

+124
-94
lines changed

3 files changed

+124
-94
lines changed
 

‎c_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ func TestFunctionName(t *testing.T) {
3232

3333
const entryPoint = "xdp_filter"
3434

35-
// loadC compiles classic BPF to C, which is compiled with clang
36-
// XDPDrop on match, XDPPass otherwise
37-
func loadC(tb testing.TB, insns []bpf.Instruction) *ebpf.ProgramSpec {
38-
tb.Helper()
39-
35+
// cBackend compiles classic BPF to C, which is compiled with clang
36+
func cBackend(tb testing.TB, insns []bpf.Instruction, in []byte) result {
4037
elf, err := buildC(insns, entryPoint)
4138
if err != nil {
4239
tb.Fatal(err)
@@ -48,5 +45,5 @@ func loadC(tb testing.TB, insns []bpf.Instruction) *ebpf.ProgramSpec {
4845
tb.Fatal(err)
4946
}
5047

51-
return spec.Programs[entryPoint]
48+
return testProg(tb, spec.Programs[entryPoint], in)
5249
}

‎ebpf_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@ import (
77
"golang.org/x/net/bpf"
88
)
99

10-
// loadEBPF compiles classic BPF to eBPF
11-
// XDPDrop on match, XDPPass otherwise
12-
func loadEBPF(tb testing.TB, insns []bpf.Instruction) *ebpf.ProgramSpec {
13-
tb.Helper()
14-
10+
// ebpfBacked is backend that compiles classic BPF to eBPF
11+
func ebpfBackend(tb testing.TB, insns []bpf.Instruction, in []byte) result {
1512
prog, err := buildEBPF(insns)
1613
if err != nil {
1714
tb.Fatal(err)
1815
}
1916

2017
tb.Logf("\n%v", prog)
2118

22-
return &ebpf.ProgramSpec{
19+
return testProg(tb, &ebpf.ProgramSpec{
2320
Name: "ebpf_filter",
2421
Type: ebpf.XDP,
2522
Instructions: prog,
2623
License: "BSD",
27-
}
24+
}, in)
2825
}

0 commit comments

Comments
 (0)
Please sign in to comment.