github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/internal/kallsyms/kallsyms_test.go (about) 1 package kallsyms 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/go-quicktest/qt" 8 ) 9 10 func TestKernelModule(t *testing.T) { 11 kallsyms := []byte(`0000000000000000 t hid_generic_probe [hid_generic] 12 0000000000000000 T tcp_connect 13 0000000000000000 B empty_zero_page 14 0000000000000000 D kimage_vaddr 15 0000000000000000 R __start_pci_fixups_early 16 0000000000000000 V hv_root_partition 17 0000000000000000 W calibrate_delay_is_known 18 0000000000000000 a nft_counter_seq [nft_counter] 19 0000000000000000 b bootconfig_found 20 0000000000000000 d __func__.10 21 0000000000000000 r __ksymtab_LZ4_decompress_fast`) 22 krdr := bytes.NewBuffer(kallsyms) 23 kmods, err := loadKernelModuleMapping(krdr) 24 qt.Assert(t, qt.IsNil(err)) 25 26 // present and in module 27 kmod := kmods["hid_generic_probe"] 28 if kmod != "hid_generic" { 29 t.Errorf("expected %q got %q", "hid_generic", kmod) 30 } 31 32 // present but not kernel module 33 kmod = kmods["tcp_connect"] 34 if kmod != "" { 35 t.Errorf("expected %q got %q", "", kmod) 36 } 37 38 qt.Assert(t, qt.Equals(kmods["nft_counter_seq"], "")) 39 }