| 
 | 1 | +name: bpf-ci  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  pull_request:  | 
 | 5 | + | 
 | 6 | +concurrency:  | 
 | 7 | +  group: ci-test-${{ github.head_ref }}  | 
 | 8 | +  cancel-in-progress: true  | 
 | 9 | + | 
 | 10 | +jobs:  | 
 | 11 | +  llvm-toolchain:  | 
 | 12 | +    runs-on: ubuntu-latest  | 
 | 13 | +    outputs:  | 
 | 14 | +      llvm: ${{ steps.llvm-toolchain-impl.outputs.version }}  | 
 | 15 | +    steps:  | 
 | 16 | +      - id: llvm-version  | 
 | 17 | +        uses: libbpf/ci/get-llvm-version@master  | 
 | 18 | +      - id: llvm-toolchain-impl  | 
 | 19 | +        shell: bash  | 
 | 20 | +        run: echo "version=llvm-${{ steps.llvm-version.outputs.version }}" >> $GITHUB_OUTPUT  | 
 | 21 | +  set-matrix:  | 
 | 22 | +    needs: llvm-toolchain  | 
 | 23 | +    runs-on: ubuntu-latest  | 
 | 24 | +    outputs:  | 
 | 25 | +      build-matrix: ${{ steps.set-matrix-impl.outputs.build_matrix }}  | 
 | 26 | +      test-matrix: ${{ steps.set-matrix-impl.outputs.test_matrix }}  | 
 | 27 | +    steps:  | 
 | 28 | +      - id: set-matrix-impl  | 
 | 29 | +        shell: python3 -I {0}  | 
 | 30 | +        run: |  | 
 | 31 | +          from json import dumps  | 
 | 32 | +          import os  | 
 | 33 | +
  | 
 | 34 | +          def set_output(name, value):  | 
 | 35 | +            """Write an output variable to the GitHub output file."""  | 
 | 36 | +            with open(os.getenv("GITHUB_OUTPUT"), "a") as f:  | 
 | 37 | +              f.write(f"{name}={value}\n")  | 
 | 38 | +
  | 
 | 39 | +          matrix = [  | 
 | 40 | +            {"kernel": "LATEST", "runs_on": ["ubuntu-latest", "self-hosted"], "arch": "x86_64", "toolchain": "gcc"},  | 
 | 41 | +            {"kernel": "LATEST", "runs_on": ["ubuntu-latest", "self-hosted"], "arch": "x86_64", "toolchain": "${{ needs.llvm-toolchain.outputs.llvm }}"},  | 
 | 42 | +            {"kernel": "LATEST", "runs_on": ["z15", "self-hosted"], "arch": "s390x", "toolchain": "gcc"},  | 
 | 43 | +          ]  | 
 | 44 | +          self_hosted_repos = [  | 
 | 45 | +            "kernel-patches/bpf",  | 
 | 46 | +            "kernel-patches/vmtest",  | 
 | 47 | +          ]  | 
 | 48 | +
  | 
 | 49 | +          # Only a few repository within "kernel-patches" use self-hosted runners.  | 
 | 50 | +          if "${{ github.repository_owner }}" != "kernel-patches" or "${{ github.repository }}" not in self_hosted_repos:  | 
 | 51 | +            # Outside of those repositories, remove the self-hosted label and skip  | 
 | 52 | +            # any testing on s390x, as no suitable runners will be available.  | 
 | 53 | +            for idx in range(len(matrix) - 1, -1, -1):  | 
 | 54 | +              if "z15" in matrix[idx]["runs_on"]:  | 
 | 55 | +                del matrix[idx]  | 
 | 56 | +              else:  | 
 | 57 | +                matrix[idx]["runs_on"].remove("self-hosted")  | 
 | 58 | +
  | 
 | 59 | +          build_matrix = {"include": matrix}  | 
 | 60 | +          set_output("build_matrix", dumps(build_matrix))  | 
 | 61 | +
  | 
 | 62 | +          tests = ["test_progs", "test_progs_no_alu32", "test_maps", "test_verifier"]  | 
 | 63 | +          test_matrix = {"include": [{**config, **{"test": test}}  | 
 | 64 | +                                      for config in matrix  | 
 | 65 | +                                        for test in tests]}  | 
 | 66 | +          set_output("test_matrix", dumps(test_matrix))  | 
 | 67 | +  build:  | 
 | 68 | +    name: build for ${{ matrix.arch }} with ${{ matrix.toolchain }}  | 
 | 69 | +    needs: set-matrix  | 
 | 70 | +    runs-on: ${{ matrix.runs_on }}  | 
 | 71 | +    timeout-minutes: 100  | 
 | 72 | +    strategy:  | 
 | 73 | +      fail-fast: false  | 
 | 74 | +      matrix: ${{ fromJSON(needs.set-matrix.outputs.build-matrix) }}  | 
 | 75 | +    env:  | 
 | 76 | +      KERNEL: ${{ matrix.kernel }}  | 
 | 77 | +      REPO_ROOT: ${{ github.workspace }}  | 
 | 78 | +      REPO_PATH: ""  | 
 | 79 | +    steps:  | 
 | 80 | +      - uses: actions/checkout@v3  | 
 | 81 | +      - if: ${{ github.repository == 'kernel-patches/vmtest' }}  | 
 | 82 | +        name: Download bpf-next tree  | 
 | 83 | +        uses: libbpf/ci/get-linux-source@master  | 
 | 84 | +        with:  | 
 | 85 | +          dest: '.kernel'  | 
 | 86 | +      - if: ${{ github.repository == 'kernel-patches/vmtest' }}  | 
 | 87 | +        name: Move linux source in place  | 
 | 88 | +        shell: bash  | 
 | 89 | +        run: |  | 
 | 90 | +          rm -rf .kernel/.git  | 
 | 91 | +          cp -rf .kernel/. .  | 
 | 92 | +          rm -rf .kernel  | 
 | 93 | +      - uses: libbpf/ci/patch-kernel@master  | 
 | 94 | +        with:  | 
 | 95 | +          patches-root: '${{ github.workspace }}/ci/diffs'  | 
 | 96 | +          repo-root: '${{ github.workspace }}'  | 
 | 97 | +      - name: Setup build environment  | 
 | 98 | +        uses: libbpf/ci/setup-build-env@master  | 
 | 99 | +      - name: Build kernel image  | 
 | 100 | +        uses: libbpf/ci/build-linux@master  | 
 | 101 | +        with:  | 
 | 102 | +          arch: ${{ matrix.arch }}  | 
 | 103 | +          toolchain: ${{ matrix.toolchain }}  | 
 | 104 | +      - name: Build selftests  | 
 | 105 | +        uses: libbpf/ci/build-selftests@master  | 
 | 106 | +        with:  | 
 | 107 | +          vmlinux_btf: ${{ github.workspace }}/vmlinux  | 
 | 108 | +          toolchain: ${{ matrix.toolchain }}  | 
 | 109 | +      - name: Build samples  | 
 | 110 | +        uses: libbpf/ci/build-samples@master  | 
 | 111 | +        with:  | 
 | 112 | +          vmlinux_btf: ${{ github.workspace }}/vmlinux  | 
 | 113 | +          toolchain: ${{ matrix.toolchain }}  | 
 | 114 | +      - name: Tar artifacts  | 
 | 115 | +        run: |  | 
 | 116 | +          file_list=""  | 
 | 117 | +          if [ "${{ github.repository }}" == "kernel-patches/vmtest" ]; then  | 
 | 118 | +            # Package up a bunch of additional infrastructure to support running  | 
 | 119 | +            # 'make kernelrelease' and bpf tool checks later on.  | 
 | 120 | +            file_list="$(find . -iname Makefile | xargs) \  | 
 | 121 | +              scripts/ \  | 
 | 122 | +              tools/testing/selftests/bpf/ \  | 
 | 123 | +              tools/include/ \  | 
 | 124 | +              tools/bpf/bpftool/";  | 
 | 125 | +          fi  | 
 | 126 | +          # zstd is installed by default in the runner images.  | 
 | 127 | +          tar -cf - \  | 
 | 128 | +            .config \  | 
 | 129 | +            arch/*/boot/bzImage \  | 
 | 130 | +            include/config/auto.conf \  | 
 | 131 | +            include/generated/autoconf.h \  | 
 | 132 | +            ${file_list} \  | 
 | 133 | +            --exclude '*.h' \  | 
 | 134 | +            selftests/bpf/ \  | 
 | 135 | +            vmlinux | zstd -T0 -19 -o vmlinux-${{ matrix.arch }}-${{ matrix.toolchain }}.tar.zst  | 
 | 136 | +      - uses: actions/upload-artifact@v3  | 
 | 137 | +        with:  | 
 | 138 | +          name: vmlinux-${{ matrix.arch }}-${{ matrix.toolchain }}  | 
 | 139 | +          if-no-files-found: error  | 
 | 140 | +          path: vmlinux-${{ matrix.arch }}-${{ matrix.toolchain }}.tar.zst  | 
 | 141 | +  test:  | 
 | 142 | +    name: ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain }}  | 
 | 143 | +    needs: [set-matrix, build]  | 
 | 144 | +    strategy:  | 
 | 145 | +      fail-fast: false  | 
 | 146 | +      matrix: ${{ fromJSON(needs.set-matrix.outputs.test-matrix) }}  | 
 | 147 | +    runs-on: ${{ matrix.runs_on }}  | 
 | 148 | +    timeout-minutes: 100  | 
 | 149 | +    env:  | 
 | 150 | +      KERNEL: ${{ matrix.kernel }}  | 
 | 151 | +      REPO_ROOT: ${{ github.workspace }}  | 
 | 152 | +      REPO_PATH: ""  | 
 | 153 | +    steps:  | 
 | 154 | +      - uses: actions/checkout@v3  | 
 | 155 | +      - uses: actions/download-artifact@v3  | 
 | 156 | +        with:  | 
 | 157 | +          name: vmlinux-${{ matrix.arch }}-${{ matrix.toolchain }}  | 
 | 158 | +          path: .  | 
 | 159 | +      - name: Untar artifacts  | 
 | 160 | +        # zstd is installed by default in the runner images.  | 
 | 161 | +        run: zstd -d -T0  vmlinux-${{ matrix.arch }}-${{ matrix.toolchain }}.tar.zst --stdout | tar -xf -  | 
 | 162 | +      - name: Prepare rootfs  | 
 | 163 | +        uses: libbpf/ci/prepare-rootfs@master  | 
 | 164 | +        with:  | 
 | 165 | +          project-name: 'libbpf'  | 
 | 166 | +          arch: ${{ matrix.arch }}  | 
 | 167 | +          kernel: ${{ matrix.kernel }}  | 
 | 168 | +          kernel-root: '.'  | 
 | 169 | +          image-output: '/tmp/root.img'  | 
 | 170 | +          test: ${{ matrix.test }}  | 
 | 171 | +      - name: Run selftests  | 
 | 172 | +        uses: libbpf/ci/run-qemu@master  | 
 | 173 | +        with:  | 
 | 174 | +          arch: ${{ matrix.arch}}  | 
 | 175 | +          img: '/tmp/root.img'  | 
 | 176 | +          vmlinuz: '${{ github.workspace }}/vmlinuz'  | 
 | 177 | +          kernel-root: '.'  | 
0 commit comments