Skip to content

Commit

Permalink
build: refactor CI
Browse files Browse the repository at this point in the history
  • Loading branch information
qdeslandes committed Jan 25, 2025
1 parent 8ba13de commit 05690b6
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 198 deletions.
115 changes: 22 additions & 93 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,103 +1,32 @@
name: CI
name: Testing on CI

on:
push:
branches:
- main
pull_request:
branches:
- main
- "**"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

permissions:
checks: write
pull-requests: write
contents: read
packages: write

jobs:
full:
if: github.repository == 'facebook/bpfilter'
strategy:
fail-fast: false
matrix:
system: ["fedora:41"]
arch: ["X64", "ARM64"]
mode: ["release", "debug"]
container: "${{ matrix.system }}"
runs-on: [self-hosted, "${{ matrix.arch }}"]
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install dependencies (Fedora)
run: |
sudo dnf --disablerepo=* --enablerepo=fedora,updates --setopt=install_weak_deps=False -y install \
bison bpftool clang clang-tools-extra cmake doxygen flex g++ git gcc jq lcov libasan libbpf-devel \
libcmocka-devel libnl3-devel libubsan pkgconf python3-breathe python3-furo python3-linuxdoc \
python3-sphinx
- name: Configure build
run: cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build -DCMAKE_BUILD_TYPE=${{ matrix.mode }}
- name: Build
run: make -C $GITHUB_WORKSPACE/build
- name: Run unit tests
run: make -C $GITHUB_WORKSPACE/build test
- name: Coverage
run: make -C $GITHUB_WORKSPACE/build coverage
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v3
with:
files: build/doc/lcov.out
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Check style
run: make -C $GITHUB_WORKSPACE/build check
- name: Generate documentation
run: make -C $GITHUB_WORKSPACE/build doc

build:
if: github.repository == 'facebook/bpfilter'
strategy:
fail-fast: false
matrix:
image: ["fedora:39", "fedora:40", "ubuntu:24.04"]
arch: ["X64", "ARM64"]
container: ${{ matrix.image }}
runs-on: [self-hosted, "${{ matrix.arch }}"]
tests:
runs-on: ["4-core-ubuntu-arm"]
container:
image: ghcr.io/facebook/bpfilter:fedora-41-arm64
options: --privileged --pid=host -v /home/quentin/Projects/bpfilter:/bpfilter
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install dependencies (Fedora)
if: matrix.image == 'fedora:39' || matrix.image == 'fedora:40'
run: |
sudo dnf --disablerepo=* --enablerepo=fedora,updates --setopt=install_weak_deps=False -y install \
bison bpftool clang clang-tools-extra cmake doxygen flex g++ git gcc jq lcov libasan libbpf-devel \
libcmocka-devel libnl3-devel libubsan pkgconf python3-breathe python3-furo python3-linuxdoc \
python3-sphinx
- name: Install dependencies (Ubuntu)
if: matrix.image == 'ubuntu:24.04'
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install \
bison \
clang \
clang-format \
clang-tidy \
cmake \
doxygen \
flex \
furo \
git \
jq \
lcov \
libbpf-dev \
libcmocka-dev \
libnl-3-dev \
linux-tools-common \
python3-breathe \
python3-pip \
python3-sphinx \
pkgconf && \
pip3 install --break-system-packages linuxdoc
- name: Checkout repository
uses: actions/checkout@v2
- name: Mount bpffs
run: mount bpffs -t bpf /sys/fs/bpf
- name: Check
run: uname -a
- name: Configure build
run: cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build
- name: Build
run: make -C $GITHUB_WORKSPACE/build
- name: Run unit tests
run: make -C $GITHUB_WORKSPACE/build test
run: cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build -DCMAKE_BUILD_TYPE=debug
- name: Test
run: make -C $GITHUB_WORKSPACE/build -j `nproc` e2e
42 changes: 0 additions & 42 deletions .github/workflows/fork.yaml

This file was deleted.

51 changes: 0 additions & 51 deletions .github/workflows/pages.yaml

This file was deleted.

12 changes: 6 additions & 6 deletions src/bpfilter/cgen/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,24 @@ struct bf_program_context
{
/** Argument passed to the BPF program, its content depends on the BPF
* program type. */
void *arg;
void bf_aligned(8) *arg;

/** BPF dynamic pointer representing the packet data. Dynamic pointers are
* used with every program type. */
struct bpf_dynptr dynptr;
struct bpf_dynptr bf_aligned(8) dynptr;

/** Total size of the packet. */
uint64_t pkt_size;
uint64_t bf_aligned(8) pkt_size;

/** Offset of the layer 3 protocol. */
uint32_t l3_offset;
uint32_t bf_aligned(8) l3_offset;

/** Offset of the layer 4 protocol. */
uint32_t l4_offset;
uint32_t bf_aligned(8) l4_offset;

/** On ingress, index of the input interface. On egress, index of the
* output interface. */
uint32_t ifindex;
uint32_t bf_aligned(8) ifindex;

/** Layer 3 protocol, set when processing layer 2 protocol header. Required
* to process the layer 3 header. */
Expand Down
5 changes: 5 additions & 0 deletions src/bpfilter/cgen/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ int bf_stub_parse_l3_hdr(struct bf_program *program)
bf_swich_get(program, BF_ARG_4);

EMIT_SWICH_OPTION(&swich, htobe16(ETH_P_IP),
BPF_STX_MEM(BPF_H, BF_REG_CTX, BF_ARG_4,
BF_PROG_CTX_OFF(l3_proto)),
BPF_MOV64_IMM(BF_ARG_4, sizeof(struct iphdr)));
EMIT_SWICH_OPTION(&swich, htobe16(ETH_P_IPV6),
BPF_STX_MEM(BPF_H, BF_REG_CTX, BF_ARG_4,
BF_PROG_CTX_OFF(l3_proto)),
BPF_MOV64_IMM(BF_ARG_4, sizeof(struct ipv6hdr)));
EMIT_SWICH_DEFAULT(&swich, BPF_MOV64_IMM(BF_ARG_4, 0),
BPF_STX_MEM(BPF_H, BF_REG_CTX, BF_ARG_4,
Expand Down Expand Up @@ -264,6 +268,7 @@ int bf_stub_parse_l3_hdr(struct bf_program *program)
offsetof(struct ipv6hdr, nexthdr)),
BPF_STX_MEM(BPF_B, BF_REG_CTX, BF_REG_1,
BF_PROG_CTX_OFF(l4_proto)));
EMIT_SWICH_DEFAULT(&swich);

r = bf_swich_generate(&swich);
if (r)
Expand Down
1 change: 0 additions & 1 deletion tests/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ target_link_libraries(benchmark_bin

add_custom_target(benchmark
COMMAND
sudo
$<TARGET_FILE:benchmark_bin>
--cli $<TARGET_FILE:bfcli>
--daemon $<TARGET_FILE:bpfilter>
Expand Down
6 changes: 4 additions & 2 deletions tests/benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ int setup(std::span<char *> args)
err("failed to parse command line arguments: {}", errStr(r));
return r;
}
/*
const ::bf::Sources srcs(::bf::config.srcdir);
Expand All @@ -307,9 +308,10 @@ int setup(std::span<char *> args)
const auto pos = config.outfile.find(pattern);
if (pos != ::std::string::npos)
config.outfile.replace(pos, pattern.size(), config.gitrev);
*/

::benchmark::AddCustomContext("gitrev", config.gitrev);
::benchmark::AddCustomContext("gitdate", ::std::to_string(config.gitdate));
::benchmark::AddCustomContext("gitrev", "<none>");
::benchmark::AddCustomContext("gitdate", "<none>");
::benchmark::AddCustomContext("bfcli", config.bfcli);
::benchmark::AddCustomContext("bpfilter", config.bpfilter);
::benchmark::AddCustomContext("srcdir", config.srcdir);
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ set_property(TARGET e2e_bin PROPERTY POSITION_INDEPENDENT_CODE FALSE)

add_custom_target(e2e
COMMAND
sudo
$<TARGET_FILE:e2e_bin>
$<TARGET_FILE:e2e_bin>
--bpfilter $<TARGET_FILE:bpfilter>
DEPENDS
e2e_bin
Expand Down
9 changes: 8 additions & 1 deletion tests/harness/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
int bf_test_daemon_init(struct bf_test_daemon *daemon, const char *path,
uint32_t options)
{
char *args[__builtin_ctz(_BF_TEST_DAEMON_LAST) + 1] = {};
char *args[__builtin_ctz(_BF_TEST_DAEMON_LAST) + 1 + 6] = {};
size_t nargs = 0;

bf_assert(daemon);
Expand All @@ -40,6 +40,13 @@ int bf_test_daemon_init(struct bf_test_daemon *daemon, const char *path,
if (options & BF_TEST_DAEMON_NO_NFTABLES)
args[nargs++] = "--no-nftables";

args[nargs++] = "--verbose";
args[nargs++] = "debug";
args[nargs++] = "--verbose";
args[nargs++] = "bpf";
args[nargs++] = "--verbose";
args[nargs++] = "bytecode";

return bf_test_process_init(&daemon->process, path, args, nargs);
}

Expand Down
Loading

0 comments on commit 05690b6

Please sign in to comment.