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

Add build-scx-selftests action #146

Merged
merged 2 commits into from
Oct 18, 2024
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
12 changes: 8 additions & 4 deletions .github/scripts/tar-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fi

arch="${1}"
toolchain="${2}"
archive_make_helpers="${3:-0}"

# Convert a platform (as returned by uname -m) to the kernel
# arch (as expected by ARCH= env).
Expand All @@ -40,7 +39,7 @@ platform_to_kernel_arch() {
# Remove intermediate object files that we have no use for. Ideally
# we'd just exclude them from tar below, but it does not provide
# options to express the precise constraints.
find selftests/ -name "*.o" -a ! -name "*.bpf.o" -print0 | \
find tools/testing/selftests/ -name "*.o" -a ! -name "*.bpf.o" -print0 | \
xargs --null --max-args=10000 rm

# Strip debug information, which is excessively large (consuming
Expand Down Expand Up @@ -74,7 +73,7 @@ for file in "${kbuild_output_file_list[@]}"; do
done

additional_file_list=()
if [ $archive_make_helpers -ne 0 ]; then
if [[ -n "${ARCHIVE_MAKE_HELPERS}" ]]; then
# Package up a bunch of additional infrastructure to support running
# 'make kernelrelease' and bpf tool checks later on.
mapfile -t additional_file_list < <(find . -iname Makefile)
Expand All @@ -86,6 +85,11 @@ if [ $archive_make_helpers -ne 0 ]; then
)
fi

mkdir -p selftests
cp -r tools/testing/selftests/bpf selftests
if [[ -n "${BUILD_SCHED_EXT_SELFTESTS}" ]]; then
cp -r tools/testing/selftests/sched_ext selftests
fi

tar -cf - \
kbuild-output \
Expand All @@ -94,7 +98,7 @@ tar -cf - \
--exclude '*.d' \
--exclude '*.h' \
--exclude '*.output' \
selftests/bpf/ \
selftests/ \
| zstd -T0 -19 -o "vmlinux-${arch}-${toolchain}.tar.zst"

# Cleanup and restore the original KBUILD_OUTPUT
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/kernel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: 100
env:
ARCHIVE_MAKE_HELPERS: ${{ github.repository != 'kernel-patches/bpf' && '1' || '0' }}
ARCHIVE_MAKE_HELPERS: ${{ github.repository != 'kernel-patches/bpf' && 'true' || '' }}
KERNEL: ${{ inputs.kernel }}
REPO_ROOT: ${{ github.workspace }}
REPO_PATH: ""
Expand All @@ -55,6 +55,7 @@ jobs:
|| github.base_ref
|| 'bpf-next'
}}
BUILD_SCHED_EXT_SELFTESTS: ${{ inputs.arch == 'x86_64' || inputs.arch == 'aarch64' && 'true' || '' }}
steps:
- uses: actions/checkout@v4
# We fetch an actual bit of history here to facilitate incremental
Expand Down Expand Up @@ -82,7 +83,8 @@ jobs:
kbuild-output: ${{ env.KBUILD_OUTPUT }}
- uses: ./patch-kernel
with:
repo-root: '${{ github.workspace }}'
patches-root: '${{ github.workspace }}/ci/diffs'
repo-root: ${{ env.REPO_ROOT }}
- name: Setup build environment
uses: ./setup-build-env
with:
Expand All @@ -105,7 +107,7 @@ jobs:
kbuild-output: ${{ env.KBUILD_OUTPUT }}
max-make-jobs: 32
llvm-version: ${{ inputs.llvm-version }}
- name: Build selftests
- name: Build selftests/bpf
uses: ./build-selftests
with:
arch: ${{ inputs.arch }}
Expand All @@ -118,6 +120,16 @@ jobs:
# RELEASE=0 adds -O0 make flag
# RELEASE=1 adds -O2 make flag
RELEASE: ${{ inputs.release && '1' || '' }}
- if: ${{ env.BUILD_SCHED_EXT_SELFTESTS }}
name: Build selftests/sched_ext
uses: ./build-scx-selftests
with:
kbuild-output: ${{ env.KBUILD_OUTPUT }}
repo-root: ${{ env.REPO_ROOT }}
arch: ${{ inputs.arch }}
toolchain: ${{ inputs.toolchain }}
llvm-version: ${{ inputs.llvm-version }}
max-make-jobs: 32
- if: ${{ github.event_name != 'push' }}
name: Build samples
uses: ./build-samples
Expand All @@ -130,7 +142,7 @@ jobs:
- name: Tar artifacts
working-directory: ${{ env.REPO_ROOT }}
run: |
bash .github/scripts/tar-artifact.sh ${{ inputs.arch }} ${{ inputs.toolchain_full }} ${{ env.ARCHIVE_MAKE_HELPERS }}
bash .github/scripts/tar-artifact.sh ${{ inputs.arch }} ${{ inputs.toolchain_full }}
- if: ${{ github.event_name != 'push' }}
name: Remove KBUILD_OUTPUT content
shell: bash
Expand Down
1 change: 1 addition & 0 deletions build-linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cat_kernel_config() {
cat ${GITHUB_WORKSPACE}/tools/testing/selftests/bpf/config \
${GITHUB_WORKSPACE}/tools/testing/selftests/bpf/config.vm \
${GITHUB_WORKSPACE}/tools/testing/selftests/bpf/config.${TARGET_ARCH} \
${GITHUB_WORKSPACE}/tools/testing/selftests/sched_ext/config \
${GITHUB_WORKSPACE}/ci/vmtest/configs/config \
${GITHUB_WORKSPACE}/ci/vmtest/configs/config.${TARGET_ARCH} 2> /dev/null > "${1}"
}
Expand Down
20 changes: 20 additions & 0 deletions build-scx-selftests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Build selftests/sched_ext

This action builds selftests/sched_ext given a kernel build
output. Kernel build configuration is supposed to include necessary
flags (i.e. `tools/testing/selftests/sched_ext/config`).

The action is expected to be executed by a workflow with access to the
Linux kernel repository.

## Required inputs

* `kbuild-output` - Path to the kernel build output.
* `repo-root` - Path to the root of the Linux kernel repository.
* `arch` - Kernel build architecture.
* `toolchain` - Toolchain name: `gcc` (default) or `llvm`.

## Optional inputs
* `llvm-version` - LLVM version, used when `toolchain` is `llvm`. Default: `16`.
* `max-make-jobs` - Maximum number of jobs to use when running make (e.g argument to -j). Default: 4*nproc.

34 changes: 34 additions & 0 deletions build-scx-selftests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Build selftests/sched_ext'
inputs:
kbuild-output:
description: 'Path to the kernel build output'
required: true
repo-root:
description: "Path to the root of the kernel repository"
required: true
arch:
description: 'arch'
required: true
toolchain:
description: 'gcc or llvm'
default: 'gcc'
required: true
llvm-version:
description: 'llvm version'
required: false
default: '16'
max-make-jobs:
description: 'Maximum number of jobs to use when running make (e.g argument to -j). Default: 4*nproc'
default: ''

runs:
using: "composite"
steps:
- name: Build selftests/sched_ext
env:
KBUILD_OUTPUT: ${{ inputs.kbuild-output }}
MAX_MAKE_JOBS: ${{ inputs.max-make-jobs }}
REPO_ROOT: ${{ inputs.repo-root || github.workspace }}
shell: bash
run:
${GITHUB_ACTION_PATH}/build.sh "${{ inputs.arch }}" "${{ inputs.toolchain }}" "${{ inputs.llvm-version }}"
45 changes: 45 additions & 0 deletions build-scx-selftests/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -euo pipefail

source "${GITHUB_ACTION_PATH}/../helpers.sh"

TARGET_ARCH=$1
TOOLCHAIN=$2
LLVM_VERSION=$3

ARCH="$(platform_to_kernel_arch ${TARGET_ARCH})"
CROSS_COMPILE=""

if [[ "${TARGET_ARCH}" != "$(uname -m)" ]]
then
CROSS_COMPILE="${TARGET_ARCH}-linux-gnu-"
fi

if [[ $TOOLCHAIN = "llvm" ]]; then
export LLVM="-$LLVM_VERSION"
TOOLCHAIN="llvm-$LLVM_VERSION"
fi

foldable start build_selftests "Building selftests/sched_ext with $TOOLCHAIN"

MAKE_OPTS=$(cat <<EOF
ARCH=${ARCH}
CROSS_COMPILE=${CROSS_COMPILE}
CLANG=clang-${LLVM_VERSION}
LLC=llc-${LLVM_VERSION}
LLVM_STRIP=llvm-strip-${LLVM_VERSION}
VMLINUX_BTF=${KBUILD_OUTPUT}/vmlinux
EOF
)
SELF_OPTS=$(cat <<EOF
-C ${REPO_ROOT}/tools/testing/selftests/sched_ext
EOF
)

cd ${REPO_ROOT}
make ${MAKE_OPTS} ${SELF_OPTS} clean
make ${MAKE_OPTS} ${SELF_OPTS} -j $(kernel_build_make_jobs)

foldable end build_selftests

8 changes: 0 additions & 8 deletions build-selftests/build_selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ fi

foldable start build_selftests "Building selftests with $TOOLCHAIN"

LIBBPF_PATH="${REPO_ROOT}"

PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh
if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then
(cd "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT})
Expand Down Expand Up @@ -59,10 +57,4 @@ make ${MAKE_OPTS} headers
make ${MAKE_OPTS} ${SELF_OPTS} clean
make ${MAKE_OPTS} ${SELF_OPTS} -j $(kernel_build_make_jobs)

cd -
mkdir "${LIBBPF_PATH}"/selftests
cp -R "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \
"${LIBBPF_PATH}"/selftests
cd "${LIBBPF_PATH}"

foldable end build_selftests
Loading