...
1
2
3
4
5 package bpf_test
6
7 import (
8 "testing"
9
10 "golang.org/x/net/bpf"
11 )
12
13 func TestVMLoadExtensionNotImplemented(t *testing.T) {
14 _, _, err := testVM(t, []bpf.Instruction{
15 bpf.LoadExtension{
16 Num: 100,
17 },
18 bpf.RetA{},
19 })
20 if errStr(err) != "extension 100 not implemented" {
21 t.Fatalf("unexpected error: %v", err)
22 }
23 }
24
25 func TestVMLoadExtensionExtLen(t *testing.T) {
26 vm, done, err := testVM(t, []bpf.Instruction{
27 bpf.LoadExtension{
28 Num: bpf.ExtLen,
29 },
30 bpf.RetA{},
31 })
32 if err != nil {
33 t.Fatalf("failed to load BPF program: %v", err)
34 }
35 defer done()
36
37 out, err := vm.Run([]byte{
38 0xff, 0xff, 0xff, 0xff,
39 0xff, 0xff, 0xff, 0xff,
40 0, 1, 2, 3,
41 })
42 if err != nil {
43 t.Fatalf("unexpected error while running program: %v", err)
44 }
45 if want, got := 4, out; want != got {
46 t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
47 want, got)
48 }
49 }
50
View as plain text