iT邦幫忙

2025 iThome 鐵人賽

DAY 25
0

如果覺得文章對你有所啟發,可以考慮用 🌟 支持 Gthulhu 專案,短期目標是集齊 300 個 🌟 藉此被 CNCF Landscape 採納 [ref]

對於一個成熟的開源專案來說,測試覆蓋率也是相當重要的指標。在人力有限的情況下,至少需要確保新的更動至少不會影響 Gthulhu 的運作。最快速的方式就是將相關測試整合至 CI/CD pipeline 中,由於 Gthulhu 與相關的套件目前都託管在 GitHub 平台進行管理,而 GitHub Actions 提供的 Runner 目前也沒有 Linux Kernel 6.12+ 的版本可以使用(即使有,它也不一定允許我們使用 sched_ext 抽換預設的排程器)。

因此,我們會在 Actions 中使用到 virtme-ng 這套工具,它能夠利用 QEMU 建立一個輕量化的 Linux 測試環境,kernel 本身能夠與 Host 隔離,加上使用 Host 的系統充做 copy-on-write snapshot,所以它能夠在非常短的時間內啟動一個虛擬機器。

首先,我們將必要的 dependency 安裝步驟整合進 ./.github/actions/build-dependencies/action.yaml 之中:

name: Build Dependencies
description: |
  Install build dependencies to test and compile tracee artifacts
inputs:
  go-version:
    description: go version
    default: "1.21"
runs:
  using: composite
  steps:
    - name: Setup Go
      uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
      with:
        go-version: "${{ inputs.go-version }}"
    - name: Install Compilers & Formatters
      run: |
        sudo apt-get update
        sudo apt-get install --yes bsdutils
        sudo apt-get install --yes build-essential
        sudo apt-get install --yes pkgconf
        sudo apt-get install --yes llvm-17 clang-17 clang-format-17
        sudo apt-get install --yes libbpf-dev libelf-dev libzstd-dev zlib1g-dev
        sudo apt-get install --yes virtme-ng
        sudo apt-get install --yes gcc-multilib
        sudo apt-get install --yes systemtap-sdt-dev
        sudo apt-get install --yes python3 python3-pip ninja-build
        sudo apt-get install --yes libseccomp-dev protobuf-compiler
        pip3 install --user meson
        for tool in "clang" "clang-format" "llc" "llvm-strip"
        do
          sudo rm -f /usr/bin/$tool
          sudo ln -s /usr/bin/$tool-17 /usr/bin/$tool
        done
      shell: bash

這個 yaml 檔案會讓 Actions Runner 啟動時先將編譯 scx 所需要的工具鏈以及 virtme-ng 準備好,再進入測試環節:

name: Go
on:
  push:
    branches: [ main ]
  pull_request:
    branches:
      - main
  workflow_call:
jobs:
  analyze-code:
    name: Analyze Code
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout Code
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - name: Install Dependencies
        uses: ./.github/actions/build-dependencies
      - name: Lint
        run: |
          if test -z "$(gofmt -l .)"; then
            echo "Congrats! There is nothing to fix."
          else
            echo "The following lines should be fixed."
            gofmt -s -d .
            exit 1
          fi
        shell: bash
      - name: Lint (vet)
        run: |
          make dep
          git submodule init
          git submodule sync
          git submodule update
          cd scx
          meson setup build --prefix ~
          meson compile -C build
          cd ..
          cd libbpfgo
          make
          cd ..
          make lint
        shell: bash
  self-tests:
    name: Selftests
    runs-on: ubuntu-24.04
    strategy:
      matrix:
        go-version: [ 'stable' ]
    steps:
      - name: Checkout Code
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - name: Install Dependencies
        uses: ./.github/actions/build-dependencies
        with:
          go-version: ${{ matrix.go-version }}
      - name: Static Selftests
        run: |
          make dep
          git submodule init
          git submodule sync
          git submodule update
          cd scx
          meson setup build --prefix ~
          meson compile -C build
          cd ..
          cd libbpfgo
          make
          cd ..
          make build
          make test
        shell: bash

有了能夠執行 vng 以及 scx 的環境後,將 Gthulhu 的 submodule scx 以及 libbpfgo 進行編譯,完成後使用 make test 進入測試環節:

test: build
	vng -r v6.12.2 -- timeout 15 bash -c "./main" || true

如此一來,我們就能在 Actions Runner 上啟動 Gthulhu 了!

https://ithelp.ithome.com.tw/upload/images/20251004/201108500qkBC64mLb.png


上一篇
整合 free5GC 實作低延遲資料層處理(下)
系列文
30 篇文帶你用 eBPF 與 Golang 打造 Linux Scheduler25
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言