| 1 | package ebpf |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "sort" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/go-quicktest/qt" |
| 9 | ) |
| 10 | |
| 11 | func TestLoadNativeImage(t *testing.T) { |
| 12 | for _, tc := range []struct { |
| 13 | file string |
| 14 | maps []string |
| 15 | programs []string |
| 16 | }{ |
| 17 | { |
| 18 | "testdata/windows/cgroup_sock_addr.sys", |
| 19 | []string{ |
| 20 | "egress_connection_policy_map", |
| 21 | "ingress_connection_policy_map", |
| 22 | "socket_cookie_map", |
| 23 | }, |
| 24 | []string{ |
| 25 | "authorize_connect4", |
| 26 | "authorize_connect6", |
| 27 | "authorize_recv_accept4", |
| 28 | "authorize_recv_accept6", |
| 29 | }, |
| 30 | }, |
| 31 | } { |
| 32 | t.Run(filepath.Base(tc.file), func(t *testing.T) { |
| 33 | coll, err := LoadCollection(tc.file) |
| 34 | qt.Assert(t, qt.IsNil(err)) |
| 35 | defer coll.Close() |
| 36 | |
| 37 | var mapNames []string |
| 38 | for name, obj := range coll.Maps { |
| 39 | qt.Assert(t, qt.Equals(obj.name, name)) |
| 40 | mapNames = append(mapNames, name) |
| 41 | } |
| 42 | sort.Strings(mapNames) |
| 43 | qt.Assert(t, qt.DeepEquals(mapNames, tc.maps)) |
| 44 | |
| 45 | var programNames []string |
| 46 | for name, obj := range coll.Programs { |
| 47 | qt.Assert(t, qt.Equals(obj.name, name)) |
| 48 | programNames = append(programNames, name) |
| 49 | } |
| 50 | sort.Strings(programNames) |
| 51 | qt.Assert(t, qt.DeepEquals(programNames, tc.programs)) |
| 52 | }) |
| 53 | } |
| 54 | } |