aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/host/host_test.go
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2019-04-03 17:35:33 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-04-04 14:56:48 +0200
commit1ee782d53c445be1996975e1c7fd2b7bb063d4b7 (patch)
tree59d8cc23f56d818ae8198a0636d7ffe9634e65f6 /pkg/host/host_test.go
parent6a475fffec57cc3b1e51794c0ebed7d169f12349 (diff)
host: add kallsyms parsing tests
Start with a few simple tests that can be extended when needed.
Diffstat (limited to 'pkg/host/host_test.go')
-rw-r--r--pkg/host/host_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/pkg/host/host_test.go b/pkg/host/host_test.go
index c8190dac5..43e063eaf 100644
--- a/pkg/host/host_test.go
+++ b/pkg/host/host_test.go
@@ -46,6 +46,70 @@ func TestDetectSupportedSyscalls(t *testing.T) {
}
}
+func TestKallsymsParse(t *testing.T) {
+ tests := []struct {
+ Arch string
+ Kallsyms []byte
+ Syscalls []string
+ }{
+ {
+ "amd64",
+ []byte(`
+ffffffff817cdcc0 T __sys_bind
+ffffffff817cdda0 T __x64_sys_bind
+ffffffff817cddc0 T __ia32_sys_bind
+ffffffff817cdde0 T __sys_listen
+ffffffff817cde80 T __x64_sys_listen
+ffffffff817cde90 T __ia32_sys_listen
+ffffffff817cdea0 T __sys_accept4
+ffffffff817ce080 T __x64_sys_accept4
+ffffffff817ce0a0 T __ia32_sys_accept4
+ `),
+ []string{"bind", "listen", "accept4"},
+ },
+ {
+ "arm64",
+ []byte(`
+ffff000010a3ddf8 T __sys_bind
+ffff000010a3def8 T __arm64_sys_bind
+ffff000010a3df20 T __sys_listen
+ffff000010a3dfd8 T __arm64_sys_listen
+ffff000010a3e000 T __sys_accept4
+ffff000010a3e1f0 T __arm64_sys_accept4
+ `),
+ []string{"bind", "listen", "accept4"},
+ },
+ {
+ "ppc64le",
+ []byte(`
+c0000000011ec810 T __sys_bind
+c0000000011eca10 T sys_bind
+c0000000011eca10 T __se_sys_bind
+c0000000011eca70 T __sys_listen
+c0000000011ecc10 T sys_listen
+c0000000011ecc10 T __se_sys_listen
+c0000000011ecc70 T __sys_accept4
+c0000000011ed050 T sys_accept4
+c0000000011ed050 T __se_sys_accept4
+ `),
+ []string{"bind", "listen", "accept4"},
+ },
+ }
+
+ for _, test := range tests {
+ syscallSet := parseKallsyms(test.Kallsyms, test.Arch)
+ if len(syscallSet) != len(test.Syscalls) {
+ t.Fatalf("wrong number of parse syscalls, expected: %v, got: %v",
+ len(test.Syscalls), len(syscallSet))
+ }
+ for _, syscall := range test.Syscalls {
+ if _, ok := syscallSet[syscall]; !ok {
+ t.Fatalf("syscall %v not found in parsed syscall list", syscall)
+ }
+ }
+ }
+}
+
func TestCheck(t *testing.T) {
t.Parallel()
target, err := prog.GetTarget(runtime.GOOS, runtime.GOARCH)