From 98ec0fac71e338386c382c58b867402a5dc7dc14 Mon Sep 17 00:00:00 2001 From: Andrew Donnellan Date: Fri, 3 May 2019 14:56:44 +1000 Subject: pkg/host: Add test for kallsymsRenameMap Signed-off-by: Andrew Donnellan --- pkg/host/host_linux_test.go | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'pkg/host/host_linux_test.go') diff --git a/pkg/host/host_linux_test.go b/pkg/host/host_linux_test.go index 8ccf3e178..2064a10e3 100644 --- a/pkg/host/host_linux_test.go +++ b/pkg/host/host_linux_test.go @@ -52,9 +52,10 @@ func TestSupportedSyscalls(t *testing.T) { func TestKallsymsParse(t *testing.T) { tests := []struct { - Arch string - Kallsyms []byte - Syscalls []string + Arch string + Kallsyms []byte + ParsedSyscalls []string + SupportedSyscalls []string }{ { "amd64", @@ -70,6 +71,7 @@ ffffffff817ce080 T __x64_sys_accept4 ffffffff817ce0a0 T __ia32_sys_accept4 `), []string{"bind", "listen", "accept4"}, + []string{"bind", "listen", "accept4"}, }, { "arm64", @@ -82,6 +84,7 @@ ffff000010a3e000 T __sys_accept4 ffff000010a3e1f0 T __arm64_sys_accept4 `), []string{"bind", "listen", "accept4"}, + []string{"bind", "listen", "accept4"}, }, { "ppc64le", @@ -97,6 +100,7 @@ c0000000011ed050 T sys_accept4 c0000000011ed050 T __se_sys_accept4 `), []string{"bind", "listen", "accept4"}, + []string{"bind", "listen", "accept4"}, }, { "arm", @@ -110,19 +114,38 @@ c037c7d0 T sys_gettid c037c7f8 T sys_getppid `), []string{"setfsgid", "getpid", "gettid", "getppid"}, + []string{"setfsgid", "getpid", "gettid", "getppid"}, + }, + // Test kallsymsRenameMap + { + "ppc64le", + []byte(` +c00000000037eb00 T sys_newstat + `), + []string{"newstat"}, + []string{"stat"}, }, } for _, test := range tests { syscallSet := parseKallsyms(test.Kallsyms, test.Arch) - if len(syscallSet) != len(test.Syscalls) { + if len(syscallSet) != len(test.ParsedSyscalls) { t.Fatalf("wrong number of parse syscalls, expected: %v, got: %v", - len(test.Syscalls), len(syscallSet)) + len(test.ParsedSyscalls), len(syscallSet)) } - for _, syscall := range test.Syscalls { + for _, syscall := range test.ParsedSyscalls { if _, ok := syscallSet[syscall]; !ok { t.Fatalf("syscall %v not found in parsed syscall list", syscall) } } + for _, syscall := range test.SupportedSyscalls { + if newname := kallsymsRenameMap[syscall]; newname != "" { + syscall = newname + } + + if _, ok := syscallSet[syscall]; !ok { + t.Fatalf("syscall %v not found in supported syscall list", syscall) + } + } } } -- cgit mrf-deployment