Skip to content

Commit

Permalink
feat: add libbpfgo selftests to github actions
Browse files Browse the repository at this point in the history
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
  • Loading branch information
grantseltzer committed Mar 13, 2021
1 parent ec34648 commit cb4589f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/pr-libbpfgo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: pr-libbpfgo
on:
pull_request:
paths:
- "libbpfgo/**"
jobs:
build-test:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: libbpfgo
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.15
- name: Checkout Code
uses: actions/checkout@v2
- name: selftest
run: |
sudo ./selftest/run.sh
18 changes: 9 additions & 9 deletions libbpfgo/libbpfgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ type PerfBuffer struct {
}

type RingBuffer struct {
rb *C.struct_ring_buffer
bpfMap *BPFMap
stop chan struct{}
closed bool
wg sync.WaitGroup
rb *C.struct_ring_buffer
bpfMap *BPFMap
stop chan struct{}
closed bool
wg sync.WaitGroup
}

// BPF is using locked memory for BPF maps and various other things.
Expand Down Expand Up @@ -693,10 +693,10 @@ func (rb *RingBuffer) Close() {

func (rb *RingBuffer) isStopped() bool {
select {
case _, _ = <-rb.stop:
return true
default:
return false
case _, _ = <-rb.stop:
return true
default:
return false
}
}

Expand Down
2 changes: 1 addition & 1 deletion libbpfgo/selftest/ringbuffers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ $(TARGET_BPF): $(BPF_SRC)

.PHONY: clean
clean:
rm $(TARGET) $(TARGET_BPF) vmlinux.h
rm $(TARGET) $(TARGET_BPF) vmlinux.h
8 changes: 5 additions & 3 deletions libbpfgo/selftest/ringbuffers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import "C"

import (
bpf "github.com/aquasecurity/tracee/libbpfgo"
"os"
"fmt"

"encoding/binary"
"fmt"

bpf "github.com/aquasecurity/tracee/libbpfgo"
)

func main() {
Expand Down Expand Up @@ -39,7 +41,7 @@ func main() {
numberOfEventsReceived := 0

recvLoop:
for {
for {
b := <-eventsChannel
if binary.LittleEndian.Uint32(b) != 2021 {
fmt.Fprintf(os.Stderr, "invalid data retrieved\n")
Expand Down
6 changes: 3 additions & 3 deletions libbpfgo/selftest/ringbuffers/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

GREEN='\033[0;32m'
RED='\033[0;31m'
GREEN=' \033[0;32m'
RED=' \033[0;31m'
NC='\033[0m'

VERSION_LIMIT=5.8
Expand All @@ -20,7 +20,7 @@ MINOR_VERSION_LIMIT=$(echo $VERSION_LIMIT | cut -d '.' -f2)
MINOR_CURRENT_VERSION=$(echo $CURRENT_VERSION | cut -d '.' -f2)
if (( $(echo "$MINOR_CURRENT_VERSION < $MINOR_VERSION_LIMIT") |bc -l)); then
echo -e "${RED}[*] OUTDATED MINOR KERNEL VERSION${NC}"
exit 1
exit 0
else
echo -e "${GREEN}[*] SUFFICIENT KERNEL VERSION${NC}"
fi
Expand Down
12 changes: 12 additions & 0 deletions libbpfgo/selftest/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'

for d in */
do
echo -e "${GREEN}[*] RUNNING $d ${NC}"
( cd $d && bash "run.sh" )
done

0 comments on commit cb4589f

Please sign in to comment.