Skip to content
Closed
Changes from 6 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
170 changes: 144 additions & 26 deletions .github/workflows/apple-build-kunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ name: Apple build and KUnit
# mt7932.kunitconfig (mt7932-kunit.yml), display.kunitconfig
# (apple-drm-kunit.yml) and .kunitconfig.pmgr-pwrstate
# (pmgr-pwrstate-kunit.yml).
#
# KUnit tiering (same-repo PRs): the plan job picks only the suites whose
# directories the PR changes; shared code (include/, rust/, mm/, configs,
# Kconfig/Makefile, iommu, soc/apple, lib/, kernel/, this workflow) or any
# doubt selects all of them. The full matrix runs on pushes, dispatches and
# fork PRs, on a push to an approved PR, and when the kunit-full label is
# added. The merge train adds kunit-full (with a maintainer token, so the
# label event starts this workflow) and waits for it to pass before merging.

on:
pull_request:
types: [opened, synchronize, reopened, labeled]
branches: [main, integration/aurora, aurora-wip]
paths:
- 'arch/arm64/configs/**'
Expand Down Expand Up @@ -39,6 +48,7 @@ on:
- '**/Makefile'
- '.github/workflows/apple-build-kunit.yml'
pull_request_target:
types: [opened, synchronize, reopened, labeled]
branches: [main, integration/aurora, aurora-wip]
paths:
- 'arch/arm64/configs/**'
Expand Down Expand Up @@ -101,7 +111,7 @@ permissions:
contents: read

concurrency:
group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}${{ github.event.action == 'labeled' && (github.event.label.name == 'kunit-full' && '-full' || format('-{0}', github.run_id)) || '' }}
cancel-in-progress: true

env:
Expand All @@ -110,7 +120,7 @@ env:

jobs:
apple-build:
if: ${{ (github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') }}
if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }}
runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }}
timeout-minutes: 120
steps:
Expand Down Expand Up @@ -177,37 +187,145 @@ jobs:
drivers/thunderbolt/ \
fs/splice.o kernel/sys.o mm/ksm.o mm/madvise.o mm/vma_exec.o

plan:
name: KUnit plan
if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }}
runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }}
timeout-minutes: 10
permissions:
contents: read
pull-requests: read
outputs:
matrix: ${{ steps.plan.outputs.matrix }}
count: ${{ steps.plan.outputs.count }}
steps:
# Reads the PR through the API only; no checkout, no PR code runs in this job.
- name: Pick the KUnit suites for this change
id: plan
env:
GITHUB_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
EVENT: ${{ github.event_name }}
PR: ${{ github.event.pull_request.number }}
HEAD: ${{ github.event.pull_request.head.sha }}
run: |
cat > "$RUNNER_TEMP/plan.py" <<'PLAN'
# KUnit tier planner for apple-build-kunit.yml (embedded in the workflow's plan job).
# Input (env): FILES = changed paths, one per line; FULL = "1" to force the full matrix.
# Output: the matrix JSON on stdout. Unknown or shared paths select the full matrix.
import fnmatch, json, os
SUITES = [
("ane-boot", "drivers/accel/ane/boot.kunitconfig", False, ["drivers/accel/ane/"]),
("ane-pm", "tools/testing/selftests/drivers/ane/pm.kunitconfig", False, ["drivers/accel/ane/", "tools/testing/selftests/drivers/ane/"]),
("dcp-fabric", "drivers/gpu/drm/apple/tests/.kunitconfig", False, ["drivers/gpu/drm/apple/"]),
("dcp-topology", "drivers/gpu/drm/apple/tests/topology.kunitconfig", False, ["drivers/gpu/drm/apple/"]),
("asahi", "drivers/gpu/drm/asahi/.kunitconfig", True, ["drivers/gpu/drm/asahi/"]),
("spi-hid-apple", "drivers/hid/spi-hid/.kunitconfig", False, ["drivers/hid/spi-hid/"]),
("avd", "drivers/media/platform/apple/avd/tests/.kunitconfig", False, ["drivers/media/platform/apple/avd/"]),
("ave", "drivers/media/platform/apple/ave/.kunitconfig", False, ["drivers/media/platform/apple/ave/"]),
("isp", "drivers/media/platform/apple/isp/.kunitconfig", False, ["drivers/media/platform/apple/isp/"]),
("jpeg", "drivers/media/platform/apple/jpeg/.kunitconfig", False, ["drivers/media/platform/apple/jpeg/"]),
("prores", "drivers/media/platform/apple/prores/.kunitconfig", False, ["drivers/media/platform/apple/prores/"]),
("scaler", "drivers/media/platform/apple/scaler/.kunitconfig", False, ["drivers/media/platform/apple/scaler/"]),
("macsmc", "drivers/mfd/macsmc.kunitconfig", False, ["drivers/mfd/"]),
("clpc", "drivers/soc/apple/clpc.kunitconfig", False, ["drivers/soc/apple/clpc"]),
("apple-spmi-nvmem", "drivers/nvmem/apple-spmi-nvmem.kunitconfig", False, ["drivers/nvmem/"]),
("trusted-keys", "security/keys/trusted-keys/tests/.kunitconfig", False, ["security/keys/"]),
]
MEDIA = "drivers/media/platform/apple/"
# The workflow's own trigger paths (on.pull_request.paths). Other files cannot change these suites
# (dt-checks, host-tests and the other workflows cover them), so they are ignored here.
TRIGGERS = ["arch/arm64/configs/", "drivers/accel/ane/", "drivers/gpu/drm/apple/", "drivers/gpu/drm/asahi/",
"drivers/hid/spi-hid/", "drivers/iommu/", "drivers/media/platform/apple/", "drivers/mfd/",
"drivers/net/wireless/apple/", "drivers/nvme/host/", "drivers/nvmem/", "drivers/pci/controller/",
"drivers/power/", "drivers/soc/apple/", "drivers/thunderbolt/", "fs/splice.c", "include/",
"kernel/sys.c", "mm/", "rust/", "security/keys/", "tools/testing/selftests/drivers/ane/",
".github/workflows/apple-build-kunit.yml"]
# Outside the trigger paths and unable to change these suites (DT, docs, other workflows' tests and tools).
UNRELATED = ["arch/arm64/boot/dts/", "Documentation/", "tools/testing/selftests/drivers/gpu/",
"tools/aurora-sep/", "tools/aurora-diag/", "scripts/dtc/", "MAINTAINERS", ".github/"]
# Compiled by the apple-build job; no KUnit suite lives there.
BUILD_ONLY = ["drivers/nvme/host/", "drivers/thunderbolt/", "drivers/net/wireless/apple/"]

def plan(files, full):
names = set()
for f in files:
base = f.rsplit("/", 1)[-1]
if fnmatch.fnmatch(base, "Kconfig*") or base == "Makefile":
full = True # build configuration: every suite
break
if not any(f.startswith(t) for t in TRIGGERS):
if any(f.startswith(u) for u in UNRELATED):
continue # checked by other workflows; cannot change these suites
full = True # shared code outside the trigger paths (lib/, kernel/, drivers/base, kunit tooling, ...)
break
hit = [s for s, _, _, pre in SUITES if any(f.startswith(p) for p in pre)]
if hit:
names.update(hit)
elif f.startswith(MEDIA):
names.update(s for s, k, _, _ in SUITES if k.startswith(MEDIA)) # shared media code
elif any(f.startswith(p) for p in BUILD_ONLY):
continue
else:
full = True # shared: include/, rust/, mm/, configs, iommu, pci, power, soc/apple (not clpc), this workflow
break
pick = [s for s in SUITES if full or s[0] in names]
return {"include": [dict(suite=s, kunitconfig=k, **({"rust": True} if r else {})) for s, k, r, _ in pick]}

if __name__ == "__main__":
files = [l.strip() for l in os.environ.get("FILES", "").splitlines() if l.strip()]
full = os.environ.get("FULL") == "1" or not files
print(json.dumps(plan(files, full), separators=(",", ":")))
PLAN
cat > "$RUNNER_TEMP/files.py" <<'FILES'
# Changed files and approval state of a same-repo PR, through the API. Any doubt selects the full matrix.
import json, os, urllib.request
api = os.environ.get("GITHUB_API_URL", "https://api.github.com")
def get(url, body=None):
req = urllib.request.Request(url, data=json.dumps(body).encode() if body else None, headers={
"Authorization": "Bearer " + os.environ["GITHUB_TOKEN"], "Accept": "application/vnd.github+json"})
with urllib.request.urlopen(req, timeout=60) as r:
return json.load(r)
ev, repo, t = os.environ["EVENT"], os.environ["REPO"], os.environ["RUNNER_TEMP"]
full, files = True, []
if ev == "pull_request_target": # forks (pull_request), pushes and dispatches always run everything
try:
owner, name = repo.split("/")
pr, head = os.environ["PR"], os.environ["HEAD"]
q = ("query($o:String!,$n:String!,$p:Int!){repository(owner:$o,name:$n){pullRequest(number:$p){"
"reviewDecision labels(first:100){nodes{name}} reviews(last:50){nodes{state commit{oid}}}}}}")
d = get(api + "/graphql", {"query": q, "variables": {"o": owner, "n": name, "p": int(pr)}})["data"]["repository"]["pullRequest"]
if not (d["reviewDecision"] == "APPROVED" or "kunit-full" in [l["name"] for l in d["labels"]["nodes"]]
or any(r["state"] == "APPROVED" and (r["commit"] or {}).get("oid") == head for r in d["reviews"]["nodes"])):
for page in range(1, 31):
got = get(f"{api}/repos/{repo}/pulls/{pr}/files?per_page=100&page={page}")
files += [f["filename"] for f in got] + [f["previous_filename"] for f in got if f.get("previous_filename")]
if len(got) < 100:
full = False
break
except Exception as e:
print(f"::warning::KUnit plan: {e}; running the full matrix")
full, files = True, []
open(t + "/full", "w").write("1" if full else "0")
open(t + "/files.txt", "w").write("\n".join(files))
FILES
python3 -I "$RUNNER_TEMP/files.py"
m=$(FULL=$(cat "$RUNNER_TEMP/full") FILES=$(cat "$RUNNER_TEMP/files.txt") python3 -I "$RUNNER_TEMP/plan.py")
n=$(printf '%s' "$m" | python3 -I -c 'import json,sys;print(len(json.load(sys.stdin)["include"]))')
{ echo "matrix=$m"; echo "count=$n"; } >> "$GITHUB_OUTPUT"
echo "### KUnit plan: $n of 16 suite(s)$( [ "$(cat "$RUNNER_TEMP/full")" = 1 ] && echo ' (full matrix)')" >> "$GITHUB_STEP_SUMMARY"
printf '%s\n' "$m" | python3 -I -c 'import json,sys;[print("- "+x["suite"]) for x in json.load(sys.stdin)["include"]]' >> "$GITHUB_STEP_SUMMARY"

kunit:
name: KUnit ${{ matrix.suite }}
if: ${{ (github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') }}
needs: plan
if: ${{ needs.plan.outputs.count != '0' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }}
runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }}
timeout-minutes: 60
strategy:
fail-fast: false
max-parallel: 4
matrix:
include:
# boot.kunitconfig runs the same ANE suites as transport.kunitconfig.
# It also sets UBSAN_SHIFT, and KASAN_INLINE is the default, so it
# covers both.
- { suite: ane-boot, kunitconfig: drivers/accel/ane/boot.kunitconfig }
- { suite: ane-pm, kunitconfig: tools/testing/selftests/drivers/ane/pm.kunitconfig }
- { suite: dcp-fabric, kunitconfig: drivers/gpu/drm/apple/tests/.kunitconfig }
- { suite: dcp-topology, kunitconfig: drivers/gpu/drm/apple/tests/topology.kunitconfig }
- { suite: asahi, kunitconfig: drivers/gpu/drm/asahi/.kunitconfig, rust: true }
- { suite: spi-hid-apple, kunitconfig: drivers/hid/spi-hid/.kunitconfig }
# avd-pm.kunitconfig runs the same AVD suites. PM_SLEEP, which it
# adds, is already on by default on arm64.
- { suite: avd, kunitconfig: drivers/media/platform/apple/avd/tests/.kunitconfig }
- { suite: ave, kunitconfig: drivers/media/platform/apple/ave/.kunitconfig }
- { suite: isp, kunitconfig: drivers/media/platform/apple/isp/.kunitconfig }
- { suite: jpeg, kunitconfig: drivers/media/platform/apple/jpeg/.kunitconfig }
- { suite: prores, kunitconfig: drivers/media/platform/apple/prores/.kunitconfig }
- { suite: scaler, kunitconfig: drivers/media/platform/apple/scaler/.kunitconfig }
- { suite: macsmc, kunitconfig: drivers/mfd/macsmc.kunitconfig }
- { suite: clpc, kunitconfig: drivers/soc/apple/clpc.kunitconfig }
- { suite: apple-spmi-nvmem, kunitconfig: drivers/nvmem/apple-spmi-nvmem.kunitconfig }
- { suite: trusted-keys, kunitconfig: security/keys/trusted-keys/tests/.kunitconfig }
matrix: ${{ fromJSON(needs.plan.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
Loading