Skip to content

Commit

Permalink
UTs for recovery and progs (#27)
Browse files Browse the repository at this point in the history
* UTs for recovery and progs

* PR feedbacks
  • Loading branch information
jayanthvn authored Aug 22, 2023
1 parent f53b681 commit 3c81de2
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 69 deletions.
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

0 comments on commit 3c81de2

Please sign in to comment.