mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-10-29 03:34:44 +08:00
* Modernize workflow actions and permissions * Test the fentry tutorial in CI * Support Rust 1.97 symbol mangling * Limit documentation writes to main * Harden Rust symbol resolution --------- Co-authored-by: LinuxDev9002 <i@littlefisher.me>
61 lines
2.7 KiB
YAML
61 lines
2.7 KiB
YAML
name: Test bpftrace examples
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
pull_request:
|
|
branches: [ "main" ]
|
|
schedule:
|
|
- cron: '0 0 * * 0'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
submodules: 'recursive'
|
|
|
|
- name: Install Rust toolchain
|
|
uses: dtolnay/rust-toolchain@1.97.0
|
|
|
|
- name: test 37 uprobe-rust helloworld
|
|
run: |
|
|
cd src/37-uprobe-rust/helloworld
|
|
cargo build
|
|
# Verify the hello function symbol exists in debug build
|
|
nm -C target/debug/helloworld | grep -F "helloworld::hello" || (echo "Error: hello function symbol not found in debug build" && exit 1)
|
|
echo "✓ helloworld debug build has correct hello symbol"
|
|
|
|
- name: test 37 uprobe-rust args
|
|
run: |
|
|
cd src/37-uprobe-rust/args
|
|
cargo build
|
|
# Verify the hello function symbol exists in debug build
|
|
nm -C target/debug/helloworld | grep -F "helloworld::hello" || (echo "Error: hello function symbol not found in debug build" && exit 1)
|
|
echo "✓ args debug build has correct hello symbol"
|
|
# Run the binary to ensure it works
|
|
./target/debug/helloworld 1 2 3 | grep -q "Hello, world!" || (echo "Error: binary execution failed" && exit 1)
|
|
echo "✓ args binary runs successfully"
|
|
|
|
- name: test 37 uprobe-rust bpftrace attach
|
|
run: |
|
|
cd src/37-uprobe-rust/args
|
|
# Rust 1.97 uses v0 mangling by default, so resolve the raw symbol dynamically.
|
|
hello_address=$(nm -C target/debug/helloworld | awk '$2 ~ /^[tT]$/ && $3 ~ /^helloworld::hello(::h[[:xdigit:]]+)?$/ && !matched { found = $1; matched = 1 } END { if (matched) print found }')
|
|
test -n "$hello_address" || (echo "Error: demangled hello function symbol not found" && exit 1)
|
|
hello_symbol=$(nm target/debug/helloworld | awk -v address="$hello_address" '$1 == address && $2 ~ /^[tT]$/ && !matched { found = $3; matched = 1 } END { if (matched) print found }')
|
|
test -n "$hello_symbol" || (echo "Error: raw hello function symbol not found" && exit 1)
|
|
sudo timeout 3 bpftrace -e "uprobe:target/debug/helloworld:${hello_symbol} { printf(\"traced\\n\"); exit(); }" -c "./target/debug/helloworld 1" > /tmp/bpftrace_output.txt 2>&1 || true
|
|
# Check if bpftrace successfully attached and traced the function
|
|
if grep -q "traced" /tmp/bpftrace_output.txt && grep -q "Attaching 1 probe" /tmp/bpftrace_output.txt; then
|
|
echo "✓ bpftrace successfully attached to hello function"
|
|
else
|
|
echo "Error: bpftrace failed to attach or trace the hello function"
|
|
cat /tmp/bpftrace_output.txt
|
|
exit 1
|
|
fi
|