From 8033525f3f74d3c765b633929c5bf47dc69fd409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Thu, 16 Jan 2020 11:24:12 +0100 Subject: [PATCH] Basic test for ebpf added --- GetRuntimeAddresses/ebpf/ebpf_test.go | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 GetRuntimeAddresses/ebpf/ebpf_test.go diff --git a/GetRuntimeAddresses/ebpf/ebpf_test.go b/GetRuntimeAddresses/ebpf/ebpf_test.go new file mode 100644 index 0000000..0c27d21 --- /dev/null +++ b/GetRuntimeAddresses/ebpf/ebpf_test.go @@ -0,0 +1,73 @@ +package ebpf + +import ( + "testing" +) + +func TestBPF(t *testing.T) { + var mfd MapFD + + const beef = 0xbeef0000 + const dead = 0xdead0000 + + t.Run("CreateMap", func(t *testing.T) { + var err error + mfd, err = CreateMap() + if err != nil { + t.Fatal(err) + } + }) + + var count = 64 + + t.Run("Add", func(t *testing.T) { + for i := 1; i <= count; i++ { + err := mfd.Add(i, uint64(beef+i)) + if err != nil { + t.Fatal(err) + } + } + }) + + t.Run("GetMap1", func(t *testing.T) { + m, err := mfd.GetMap() + if err != nil { + t.Fatal(err) + } else if len(m) != count { + t.Fatalf("expected len(m) == %d, but got %d: %v", count, len(m), m) + } + for i := 1; i <= count; i++ { + if v, ok := m[i]; !ok { + t.Fatalf("value for index %d not found in map", i) + } else if v != uint64(beef+i) { + t.Fatalf("value for index %d should be %x but found %x", i, beef+i, v) + } + } + }) + + t.Run("Set", func(t *testing.T) { + for i := 1; i <= count; i++ { + err := mfd.Set(i, uint64(dead+i)) + if err != nil { + t.Fatal(err) + } + } + }) + + t.Run("GetMap2", func(t *testing.T) { + m, err := mfd.GetMap() + + if err != nil { + t.Fatal(err) + } else if len(m) != count { + t.Fatalf("expected len(m) == %d, but got %d: %v", count, len(m), m) + } + for i := 1; i <= count; i++ { + if v, ok := m[i]; !ok { + t.Fatalf("value for index %d not found in map", i) + } else if v != uint64(dead+i) { + t.Fatalf("value for index %d should be %x but found %x", i, dead+i, v) + } + } + }) +}