Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTs for recovery and progs #27

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ EBPF_TEST_MAP_BINARY := test-data/test.map.bpf.elf
EBPF_TEST_LIC_SOURCE := test-data/test_license.bpf.c
EBPF_TEST_LIC_BINARY := test-data/test_license.bpf.elf
EBPF_TEST_INV_MAP_SOURCE := test-data/invalid_map.bpf.c
EBPF_TEST_INV_MAP_BINARY := test-data/invalid_map.bpf.elf
EBPF_TEST_INV_MAP_BINARY := test-data/invalid_map.bpf.elf
EBPF_TEST_RECOVERY_SOURCE := test-data/recoverydata.bpf.c
EBPF_TEST_RECOVERY_BINARY := test-data/recoverydata.bpf.elf
build-bpf: ## Build BPF
$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_SOURCE) -o $(EBPF_BINARY)
$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_TEST_SOURCE) -o $(EBPF_TEST_BINARY)
$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_TEST_MAP_SOURCE) -o $(EBPF_TEST_MAP_BINARY)
$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_TEST_LIC_SOURCE) -o $(EBPF_TEST_LIC_BINARY)
$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_TEST_INV_MAP_SOURCE) -o $(EBPF_TEST_INV_MAP_BINARY)
$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_TEST_RECOVERY_SOURCE) -o $(EBPF_TEST_RECOVERY_BINARY)

vmlinuxh:
bpftool btf dump file /sys/kernel/btf/vmlinux format c > $(abspath ./test-data/vmlinux.h)
Expand Down
13 changes: 9 additions & 4 deletions pkg/elfparser/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ func (e *elfLoader) parseProg(loadedMaps map[string]ebpf_maps.BpfMap) (map[strin
return nil, fmt.Errorf("failed to get progEntry Data")
}

if len(data) == 0 {
log.Infof("Missing data in prog Section")
return nil, fmt.Errorf("missing data in prog section")
}

var linkedMaps map[int]string
//Apply relocation
if e.reloSectionMap[progIndex] == nil {
Expand Down Expand Up @@ -731,8 +736,8 @@ func (b *bpfSDKClient) RecoverGlobalMaps() (map[string]ebpf_maps.BpfMap, error)
return nil, fmt.Errorf("error walking the bpfdirectory %v", err)
}
} else {
log.Infof("error checking BPF FS, might not be mounted %v", err)
return nil, fmt.Errorf("error checking BPF FS might not be mounted %v", err)
log.Infof("error checking BPF FS, please make sure it is mounted %v", err)
return nil, fmt.Errorf("error checking BPF FS, please make sure it is mounted")
}
return loadedGlobalMaps, nil
}
Expand Down Expand Up @@ -904,8 +909,8 @@ func (b *bpfSDKClient) RecoverAllBpfProgramsAndMaps() (map[string]BpfData, error
}
}
} else {
log.Infof("error checking BPF FS, might not be mounted %v", err)
return nil, fmt.Errorf("error checking BPF FS might not be mounted %v", err)
log.Infof("error checking BPF FS, please make sure it is mounted %v", err)
return nil, fmt.Errorf("error checking BPF FS, please make sure it is mounted")
}
//Return DS here
return loadedPrograms, nil
Expand Down
Loading
Loading