|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from json import dumps |
| 4 | +from enum import Enum |
| 5 | +import os |
| 6 | + |
| 7 | + |
| 8 | +class Arch(Enum): |
| 9 | + """ |
| 10 | + CPU architecture supported by CI. |
| 11 | + """ |
| 12 | + |
| 13 | + AARCH64 = "aarch64" |
| 14 | + S390X = "s390x" |
| 15 | + X86_64 = "x86_64" |
| 16 | + |
| 17 | + |
| 18 | +def set_output(name, value): |
| 19 | + """Write an output variable to the GitHub output file.""" |
| 20 | + with open(os.getenv("GITHUB_OUTPUT"), "a", encoding="utf-8") as file: |
| 21 | + file.write(f"{name}={value}\n") |
| 22 | + |
| 23 | + |
| 24 | +def generate_test_config(test): |
| 25 | + """Create the configuration for the provided test.""" |
| 26 | + experimental = test.endswith("_parallel") |
| 27 | + config = { |
| 28 | + "test": test, |
| 29 | + "continue_on_error": experimental, |
| 30 | + # While in experimental mode, parallel jobs may get stuck |
| 31 | + # anywhere, including in user space where the kernel won't detect |
| 32 | + # a problem and panic. We add a second layer of (smaller) timeouts |
| 33 | + # here such that if we get stuck in a parallel run, we hit this |
| 34 | + # timeout and fail without affecting the overall job success (as |
| 35 | + # would be the case if we hit the job-wide timeout). For |
| 36 | + # non-experimental jobs, 360 is the default which will be |
| 37 | + # superseded by the overall workflow timeout (but we need to |
| 38 | + # specify something). |
| 39 | + "timeout_minutes": 30 if experimental else 360, |
| 40 | + } |
| 41 | + return config |
| 42 | + |
| 43 | + |
| 44 | +def get_tests(config): |
| 45 | + tests = [ |
| 46 | + "test_progs", |
| 47 | + "test_progs_parallel", |
| 48 | + "test_progs_no_alu32", |
| 49 | + "test_progs_no_alu32_parallel", |
| 50 | + "test_maps", |
| 51 | + "test_verifier", |
| 52 | + ] |
| 53 | + if config.get("parallel_tests", True): |
| 54 | + return tests |
| 55 | + return [test for test in tests if not test.endswith("parallel")] |
| 56 | + |
| 57 | + |
| 58 | +matrix = [ |
| 59 | + { |
| 60 | + "kernel": "LATEST", |
| 61 | + "runs_on": [], |
| 62 | + "arch": Arch.X86_64.value, |
| 63 | + "toolchain": "gcc", |
| 64 | + "llvm-version": "16", |
| 65 | + }, |
| 66 | + { |
| 67 | + "kernel": "LATEST", |
| 68 | + "runs_on": [], |
| 69 | + "arch": Arch.X86_64.value, |
| 70 | + "toolchain": "llvm", |
| 71 | + "llvm-version": "16", |
| 72 | + }, |
| 73 | + { |
| 74 | + "kernel": "LATEST", |
| 75 | + "runs_on": [], |
| 76 | + "arch": Arch.AARCH64.value, |
| 77 | + "toolchain": "gcc", |
| 78 | + "llvm-version": "16", |
| 79 | + }, |
| 80 | + # { |
| 81 | + # "kernel": "LATEST", |
| 82 | + # "runs_on": [], |
| 83 | + # "arch": Arch.AARCH64.value, |
| 84 | + # "toolchain": "llvm", |
| 85 | + # "llvm-version": "16", |
| 86 | + # }, |
| 87 | + { |
| 88 | + "kernel": "LATEST", |
| 89 | + "runs_on": [], |
| 90 | + "arch": Arch.S390X.value, |
| 91 | + "toolchain": "gcc", |
| 92 | + "llvm-version": "16", |
| 93 | + "parallel_tests": False, |
| 94 | + }, |
| 95 | +] |
| 96 | +self_hosted_repos = [ |
| 97 | + "kernel-patches/bpf", |
| 98 | + "kernel-patches/vmtest", |
| 99 | +] |
| 100 | + |
| 101 | +for idx in range(len(matrix) - 1, -1, -1): |
| 102 | + if matrix[idx]["toolchain"] == "gcc": |
| 103 | + matrix[idx]["toolchain_full"] = "gcc" |
| 104 | + else: |
| 105 | + matrix[idx]["toolchain_full"] = "llvm-" + matrix[idx]["llvm-version"] |
| 106 | + |
| 107 | +# Only a few repository within "kernel-patches" use self-hosted runners. |
| 108 | +if ( |
| 109 | + os.environ["GITHUB_REPOSITORY_OWNER"] != "kernel-patches" |
| 110 | + or os.environ["GITHUB_REPOSITORY"] not in self_hosted_repos |
| 111 | +): |
| 112 | + # Outside of those repositories, we only run on x86_64 GH hosted runners (ubuntu-latest) |
| 113 | + for idx in range(len(matrix) - 1, -1, -1): |
| 114 | + if matrix[idx]["arch"] != Arch.X86_64.value: |
| 115 | + del matrix[idx] |
| 116 | + else: |
| 117 | + matrix[idx]["runs_on"] = ["ubuntu-latest"] |
| 118 | +else: |
| 119 | + # Otherwise, run on (self-hosted, arch) runners |
| 120 | + for idx in range(len(matrix) - 1, -1, -1): |
| 121 | + matrix[idx]["runs_on"].extend(["self-hosted", matrix[idx]["arch"]]) |
| 122 | + |
| 123 | +build_matrix = {"include": matrix} |
| 124 | +set_output("build_matrix", dumps(build_matrix)) |
| 125 | + |
| 126 | +test_matrix = { |
| 127 | + "include": [ |
| 128 | + {**config, **generate_test_config(test)} |
| 129 | + for config in matrix |
| 130 | + for test in get_tests(config) |
| 131 | + ] |
| 132 | +} |
| 133 | +set_output("test_matrix", dumps(test_matrix)) |
| 134 | + |
| 135 | +veristat_runs_on = next( |
| 136 | + x["runs_on"] |
| 137 | + for x in matrix |
| 138 | + if x["arch"] == os.environ["veristat_arch"] |
| 139 | + and x["toolchain"] == os.environ["veristat_toolchain"] |
| 140 | +) |
| 141 | +set_output("veristat_runs_on", veristat_runs_on) |
0 commit comments