Skip to content

Commit

Permalink
Merge Main to Release-1.0 (#51)
Browse files Browse the repository at this point in the history
* Mocks for public APIs

* PR feedback

* Make the sdk client global for mocks

* Update sdk client for NA mocks (#26)

* Update sdk client

* fix var

* API interface change and UTs for TC functions (#25)

* UTs for tc functions

* Fix vet

* Add mocks

* Feedback

* PR feedbacl

* UTs for recovery and progs (#27)

* UTs for recovery and progs

* PR feedbacks

* UTs for cache and kprobes (#28)

* Xdp and Events UT (#29)

* XDP and events update

* cleanup

* Third party attribution doc

* readme-v1 (#30)

* Update README.md (#33)

* Update README.md

* chore: spelling in README (#36)

* Add github action for functional tests

* Merge issue with func tests (#38)

* test-data: Fix to use __builtin_memset() instead of memset() (#40)

In BPF programs, when using functions like `memset()` and `memcpy()`,
you should use LLVM built-in functions like `__builtin_memset()`.

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

* Bump golang.org/x/sys from 0.6.0 to 0.12.0 (#41)

Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.6.0 to 0.12.0.
- [Commits](golang/sys@v0.6.0...v0.12.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fixup poller for events race condition (#43)

* Fixup poller for events race condition

* Testing package go tidy

* makefile: fix to remove unused option from build-bpf target (#42)

* makefile: fix to remove unused option from build-bpf target

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

* makefile: refactor using pattern rule

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

---------

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

* test-data: fix to solve compile warning for test-data (#45)

* test-data: fix to solve compile warning for test-data

use `void`instead of the `struct sched_process_fork_t` to solve
compile warnings for resolvedata and tc.ingress

```shellsesson
$ doas make test-data/recoverydata.bpf.elf
clang -I../../.. -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -D__TARGET_ARCH_x86  -c test-data/recoverydata.bpf.c -o test-data/recoverydata.bpf.elf
test-data/recoverydata.bpf.c:101:31: warning: declaration of 'struct sched_process_fork_t' will not be visible outside of this function [-Wvisibility]
int sched_process_fork(struct sched_process_fork_t *ctx) {
                              ^
1 warning generated.
```

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

* makefile: Refactor the vmlinux and unit-test targets

1. Check the existence of the /sys/kernel/btf/vmlinux file before generating the header file using bpftool.

2. Improve the idempotency of the vmlinux target.

3. Add the `LOGFILE_PATH` variable to allow specifying a different path for the `AWS_EBPF_SDK_LOG_FILE`.

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

---------

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

* kprobe: Add defer statements for resource cleanup in KprobeAttach()/KretprobeAttach (#46)

Ensure that file handle is properly closed using `defer` statements.

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>

---------

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Apurup Chevuru <60630804+achevuru@users.noreply.github.com>
Co-authored-by: Alex Jones <alex@k8sgpt.ai>
Co-authored-by: Davanum Srinivas <davanum@gmail.com>
Co-authored-by: Eishun Kondoh <dreamdiagnosis@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
6 people authored Sep 26, 2023
1 parent 42605e0 commit 6ecc2a6
Show file tree
Hide file tree
Showing 34 changed files with 6,658 additions and 187 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/pr-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ jobs:
- name: Build
run: make build-linux
- name: Unit test
run: make unit-test
run: sudo make unit-test
- name: Upload code coverage
uses: codecov/codecov-action@v3
functional-test:
name: Functional test
runs-on: ubuntu-latest
steps:
- name: Checkout latest commit in the PR
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"
- name: Set up BPF
run: |
sudo apt-get install libbpf-dev
- name: Build
run: make build-linux
- name: Functional test
run: cd test && sudo make run-test
61 changes: 38 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

export GOPROXY = direct

CURDIR := $(abspath .)
TESTDATADIR := $(CURDIR)/test-data
BPFTOOL := bpftool
CLANG := clang
LOGFILE_PATH ?= stdout

UNAME_ARCH = $(shell uname -m)
ARCH = $(lastword $(subst :, ,$(filter $(UNAME_ARCH):%,x86_64:x86 aarch64:arm64)))

Expand Down Expand Up @@ -29,33 +35,42 @@ check-format: format
vet: ## Run go vet on source code.
go vet $(ALLPKGS)


# Build BPF
CLANG := clang
CLANG_INCLUDE := -I../../..
EBPF_SOURCE := test-data/tc.ingress.bpf.c
EBPF_BINARY := test-data/tc.ingress.bpf.elf
EBPF_TEST_SOURCE := test-data/tc.bpf.c
EBPF_TEST_BINARY := test-data/tc.bpf.elf
EBPF_TEST_MAP_SOURCE := test-data/test.map.bpf.c
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
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)

vmlinuxh:
bpftool btf dump file /sys/kernel/btf/vmlinux format c > $(abspath ./test-data/vmlinux.h)
BPF_CFLAGS := -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -D__TARGET_ARCH_$(ARCH)
TARGETS := \
$(TESTDATADIR)/tc.ingress \
$(TESTDATADIR)/tc \
$(TESTDATADIR)/test.map \
$(TESTDATADIR)/test_license \
$(TESTDATADIR)/invalid_map \
$(TESTDATADIR)/recoverydata \
$(TESTDATADIR)/test-kprobe \
$(TESTDATADIR)/xdp \
$(TESTDATADIR)/ring_buffer

%.bpf.elf: %.bpf.c
$(CLANG) $(CLANG_INCLUDE) $(BPF_CFLAGS) -c $< -o $@

## check if the vmlinux exists in /sys/kernel/btf directory
VMLINUX_BTF ?= $(wildcard /sys/kernel/btf/vmlinux)
ifeq ($(VMLINUX_BTF),)
$(error Cannot find a vmlinux)
endif

$(TESTDATADIR)/vmlinux.h:
$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@

##@ Run Unit Tests
# Run unit tests
unit-test: vmlinuxh
unit-test: build-bpf
unit-test: export AWS_EBPF_SDK_LOG_FILE=stdout
unit-test: $(TESTDATADIR)/vmlinux.h
unit-test: $(addsuffix .bpf.elf,$(TARGETS))
unit-test: export AWS_EBPF_SDK_LOG_FILE=$(LOGFILE_PATH)
unit-test: ## Run unit tests
go test -v -coverprofile=coverage.txt -covermode=atomic ./pkg/...

.PHONY: clean
clean:
-@rm -f $(TESTDATADIR)/vmlinux.h
-@rm -f $(TESTDATADIR)/*.elf
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Go to -

```
cd test/
make run-test
sudo make run-test
```

## Security
Expand Down
Loading

0 comments on commit 6ecc2a6

Please sign in to comment.