The new bpf-vmtest.exp baseboard is used by GCC for runtime testing of BPF programs across different kernel versions. --- ChangeLog | 9 ++ Makefile.am | 1 + Makefile.in | 1 + baseboards/bpf-vmtest.exp | 179 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 baseboards/bpf-vmtest.exp
diff --git a/ChangeLog b/ChangeLog index 235125f..5e0dbab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2026-02-24 Piyush Raj <[email protected]> + + * baseboards/bpf-vmtest.exp: Add a new baseboard for runtime testing + of bpf programs in GCC testsuite. + + * Makefile.am (baseboard_DATA): Add bpf-vmtest.exp. + + * Makefile.in (baseboard_DATA): Likewise. + 2025-12-02 Jacob Bachmeyer <[email protected]> * baseboards/h8300.exp: Restore from Git history per a request diff --git a/Makefile.am b/Makefile.am index 9493cc6..c573616 100644 --- a/Makefile.am +++ b/Makefile.am @@ -98,6 +98,7 @@ baseboard_DATA = \ baseboards/arm-sim.exp \ baseboards/basic-sid.exp \ baseboards/basic-sim.exp \ + baseboards/bpf-vmtest.exp \ baseboards/cris-sim.exp \ baseboards/d30v-sim.exp \ baseboards/fr30-sim.exp \ diff --git a/Makefile.in b/Makefile.in index 1fb4120..d9b8fd8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -469,6 +469,7 @@ baseboard_DATA = \ baseboards/arm-sim.exp \ baseboards/basic-sid.exp \ baseboards/basic-sim.exp \ + baseboards/bpf-vmtest.exp \ baseboards/cris-sim.exp \ baseboards/d30v-sim.exp \ baseboards/fr30-sim.exp \ diff --git a/baseboards/bpf-vmtest.exp b/baseboards/bpf-vmtest.exp new file mode 100644 index 0000000..5340090 --- /dev/null +++ b/baseboards/bpf-vmtest.exp @@ -0,0 +1,179 @@ +# Copyright (C) 1997-2026, 2026 Free Software Foundation, Inc. +# +# This file is part of DejaGnu. +# +# DejaGnu is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# DejaGnu is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DejaGnu. If not, see <http://www.gnu.org/licenses/>. + +# Baseboard for runtime testing of BPF programs in the GCC testsuite. +# Uses bpf-vmtest-tool(https://gcc.gnu.org/wiki/BPFRunTimeTests) + +# Load procedures from common libraries. +load_lib "standard.exp" +# list of toolchains that are supported on this board. +set_board_info target_install {bpf-unknown-none} +# bpf does not need -lm +set_board_info mathlib "" +#timeout for bpf-vmtest-tool +set timeout 10 + +proc find_python3 {} { + global timeout + foreach candidate {python3 python} { + set path [which $candidate] + if {$path != 0 } { + set status [local_exec "$path -V" "" "" $timeout] + set exit_code [lindex $status 0] + set output [lindex $status 1] + + if { $exit_code == 0 } { + set version [lindex [split [string trim $output] " "] 1 ] + if { [package vcompare $version 3.9.0] >= 0 } { + verbose -log "Using Python interpreter at $path" 1 + return $path + } else { + verbose -log "Python 3.9 or newer is required; found $version for $path" 2 + continue + } + } else { + verbose -log "Failed to retrieve the Python version from $path (exit code: $exit_code)" 2 + continue + } + + } else { + verbose -log "\'$candidate\' not found in \$PATH" 2 + } + } + perror "No Python interpreter with version 3.9 or higher was found in \$PATH" + exit 1 + +} + +set PYTHON3 [find_python3] + +# Validate required environment variables upfront to fail fast rather +# than letting individual test cases fail +if {![info exists env(VMTEST_DIR)]} { + perror "VMTEST_DIR needs to be set for bpf-vmtest-tool" + exit 1 +} +# Process variables passed from arguments and apply defaults +if {![info exists KERNEL_VERSION]} { + set KERNEL_VERSION 6.15 + verbose -log "Using default kernel version: $KERNEL_VERSION" 1 +} + +if {![info exists LOG_LEVEL]} { + set LOG_LEVEL ERROR + verbose -log "Using default log level: $LOG_LEVEL" 1 +} + +if {![info exists BPF_VMTEST_PY]} { + global srcdir + set BPF_VMTEST_PY "$srcdir/../../contrib/bpf-vmtest-tool/main.py" + verbose -log "Using default bpf-vmtest-tool location: $BPF_VMTEST_PY" 1 +} + + +proc bpf-vmtest_compile {source destfile type options} { + + global KERNEL_VERSION + global LOG_LEVEL + global PYTHON3 + global BPF_VMTEST_PY + global timeout + + set opts "" + foreach i $options { + if {[regexp "^compiler=" $i]} { + regsub "^compiler=" $i "" tmp + if { $tmp eq "" } { + return "bpf-vmtest_compile: No compiler to compile with" + } + set compiler [ lindex [split $tmp " "] 0 ] + set compiler_flags [ lindex [split $tmp " "] 1 ] + append opts " $compiler_flags" + } + + if {[regexp "^additional_flags=" $i]} { + regsub "^additional_flags=" $i "" tmp + set tmp [string trim $tmp] + append opts " $tmp" + } + } + + if { $type eq "preprocess" } { + append opts " -E" + } elseif { $type eq "assembly" } { + append opts " -S" + } elseif { $type eq "object" } { + append opts " -c" + } elseif { $type eq "executable" } { + # For the executable case, we generate a BPF object. The final + # userland executable (which includes the loader) that is executed + # inside qemu VM is created in the bpf-vmtest_load proc + # by the bpf-vmtest-tool using the kernel-specific libbpf and bpftool. + append opts " -c" + } + #clean up spaces + set opts [string trim $opts] + # compile through the tool to use the kernel-specific vmlinux.h + set args [list "BPF_CFLAGS=$opts" "BPF_CC=$compiler" $PYTHON3 $BPF_VMTEST_PY --log-level $LOG_LEVEL bpf compile $source -k $KERNEL_VERSION -o $destfile ] + set status [local_exec "env $args" "" "" $timeout] + set exit_code [lindex $status 0] + set output [lindex $status 1] + + verbose -log "Executed 'env $args', exit_code $exit_code" 1 + + if { $exit_code > 0 } { + verbose -log "Couldn't compile $source" 1 + return $output + } + + if {$output ne ""} { + verbose -log -- $output 2 + } + + return $output +} + +proc bpf-vmtest_load {dest prog args} { + + global KERNEL_VERSION + global LOG_LEVEL + global PYTHON3 + global BPF_VMTEST_PY + global timeout + + set args [list $BPF_VMTEST_PY --log-level $LOG_LEVEL vmtest -k $KERNEL_VERSION --bpf-obj $prog ] + set status [local_exec "$PYTHON3 $args" "" "" $timeout] + set exit_code [lindex $status 0] + set output [lindex $status 1] + + verbose -log "Executed '$PYTHON3 $args', exit_code $exit_code" 1 + if { $exit_code > 0 } { + verbose -log "Couldn't execute $prog" 1 + return "unresolved" + } + + if {$output ne ""} { + verbose -log -- $output 2 + } + + if { $exit_code == 0 } { + return [list "pass" $output] + } else { + return [list "fail" $output] + } +} + -- 2.52.0
