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