forked from cilium/ebpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgroup_test.go
71 lines (57 loc) · 1.63 KB
/
cgroup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package link
import (
"testing"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/internal/testutils"
)
func TestAttachCgroup(t *testing.T) {
cgroup, prog := mustCgroupFixtures(t)
link, err := AttachCgroup(CgroupOptions{
Path: cgroup.Name(),
Attach: ebpf.AttachCGroupInetEgress,
Program: prog,
})
testutils.SkipIfNotSupported(t, err)
if err != nil {
t.Fatal(err)
}
defer link.Close()
if haveBPFLink() == nil {
if _, ok := link.(*linkCgroup); !ok {
t.Fatalf("Have support for bpf_link, but got %T instead of linkCgroup", link)
}
} else {
if _, ok := link.(*progAttachCgroup); !ok {
t.Fatalf("Expected progAttachCgroup, got %T instead", link)
}
}
}
func TestProgAttachCgroup(t *testing.T) {
cgroup, prog := mustCgroupFixtures(t)
link, err := newProgAttachCgroup(cgroup, ebpf.AttachCGroupInetEgress, prog, 0)
if err != nil {
t.Fatal("Can't create link:", err)
}
testLink(t, link, prog)
}
func TestProgAttachCgroupAllowMulti(t *testing.T) {
cgroup, prog := mustCgroupFixtures(t)
link, err := newProgAttachCgroup(cgroup, ebpf.AttachCGroupInetEgress, prog, flagAllowMulti)
testutils.SkipIfNotSupported(t, err)
if err != nil {
t.Fatal("Can't create link:", err)
}
// It's currently not possible for a program to replace
// itself.
prog2 := mustLoadProgram(t, ebpf.CGroupSKB, ebpf.AttachCGroupInetEgress, "")
testLink(t, link, prog2)
}
func TestLinkCgroup(t *testing.T) {
cgroup, prog := mustCgroupFixtures(t)
link, err := newLinkCgroup(cgroup, ebpf.AttachCGroupInetEgress, prog)
testutils.SkipIfNotSupported(t, err)
if err != nil {
t.Fatal("Can't create link:", err)
}
testLink(t, link, prog)
}