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

Use sudo for make benchmark if current user is not root #199

Merged
merged 3 commits into from
Jan 31, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- { name: ubuntu, version: "24.10" }
- { name: ubuntu, version: "24.04" }
runs-on: [ "${{ matrix.host.name }}" ]
name: "Build container: ${{ matrix.distribution.name }} ${{ matrix.distribution.version }} (${{ matrix.host.arch}})"
name: "Image: ${{ matrix.distribution.name }} ${{ matrix.distribution.version }} (${{ matrix.host.arch}})"
steps:
- name: Checkout bpfilter
uses: actions/checkout@v2
Expand All @@ -53,7 +53,7 @@ jobs:
uses: docker/build-push-action@v4
with:
file: .github/${{ matrix.distribution.name }}-${{ matrix.distribution.version }}.Dockerfile
push: true
push: ${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}
tags: ghcr.io/facebook/bpfilter:${{ matrix.distribution.name }}-${{ matrix.distribution.version }}-${{ matrix.host.arch}}
cache-from: type=gha,scope=${{ matrix.distribution.name }}-${{ matrix.distribution.version }}-${{ matrix.host.arch}}
cache-to: type=gha,mode=max,scope=${{ matrix.distribution.name }}-${{ matrix.distribution.version }}-${{ matrix.host.arch}}
Expand Down
11 changes: 6 additions & 5 deletions tests/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ add_custom_target(benchmark
-E make_directory
${CMAKE_BINARY_DIR}/output/benchmarks
COMMAND
$<TARGET_FILE:benchmark_bin>
--cli $<TARGET_FILE:bfcli>
--daemon $<TARGET_FILE:bpfilter>
--srcdir ${CMAKE_SOURCE_DIR}
--outfile ${CMAKE_BINARY_DIR}/output/benchmarks/{gitrev}.json
${CMAKE_CURRENT_SOURCE_DIR}/asroot
$<TARGET_FILE:benchmark_bin>
--cli $<TARGET_FILE:bfcli>
--daemon $<TARGET_FILE:bpfilter>
--srcdir ${CMAKE_SOURCE_DIR}
--outfile ${CMAKE_BINARY_DIR}/output/benchmarks/{gitrev}.json
DEPENDS benchmark_bin bfcli bpfilter
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL
Expand Down
12 changes: 12 additions & 0 deletions tests/benchmark/asroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

# Run a command as root: if the current user is root, run the command directly,
# otherwise prefix it with sudo.

SUDO=''
if [ "$(id -u)" -ne 0 ]
then
SUDO='sudo'
fi

$SUDO "$@"