setup.py: allow testing against local kernels

Move the logic for local kernels from vmtest.kmod and vmtest.vm to
vmtest.config and use it in setup.py.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
Omar Sandoval 2023-07-07 14:56:19 -07:00
parent c76f25b852
commit 4ea46bf283
4 changed files with 31 additions and 24 deletions

View File

@ -233,7 +233,7 @@ fi
def run(self):
import urllib.error
from vmtest.config import ARCHITECTURES, Kernel
from vmtest.config import ARCHITECTURES, Kernel, local_kernel
from vmtest.download import DownloadCompiler, DownloadKernel, download_in_thread
if os.getenv("GITHUB_ACTIONS") == "true":
@ -255,13 +255,18 @@ fi
# Start downloads ASAP so that they're hopefully done by the time we
# need them.
try:
to_downlad = []
to_download = []
if self.kernels:
to_downlad.append(DownloadCompiler(ARCHITECTURES["x86_64"]))
to_download.append(DownloadCompiler(ARCHITECTURES["x86_64"]))
for pattern in self.kernels:
to_downlad.append(DownloadKernel(ARCHITECTURES["x86_64"], pattern))
with download_in_thread(Path(self.vmtest_dir), to_downlad) as downloads:
if self.kernels:
if not pattern.startswith(".") and not pattern.startswith("/"):
to_download.append(
DownloadKernel(ARCHITECTURES["x86_64"], pattern)
)
with download_in_thread(Path(self.vmtest_dir), to_download) as downloads:
downloads_it = iter(downloads)
if to_download:
logger.info("downloading kernels in the background")
with github_workflow_group("Build extension"):
@ -280,9 +285,14 @@ fi
else:
failed.append("local")
for kernel in downloads:
if not isinstance(kernel, Kernel):
continue
for pattern in self.kernels:
if pattern.startswith(".") or pattern.startswith("/"):
kernel = local_kernel(ARCHITECTURES["x86_64"], Path(pattern))
else:
while True:
kernel = next(downloads_it)
if isinstance(kernel, Kernel):
break
with github_workflow_group(
f"Run integration tests on Linux {kernel.release}"
):

View File

@ -344,6 +344,14 @@ class Kernel(NamedTuple):
path: Path
def local_kernel(arch: Architecture, path: Path) -> Kernel:
return Kernel(
arch=arch,
release=(path / "build/include/config/kernel.release").read_text().strip(),
path=path,
)
class Compiler(NamedTuple):
target: Architecture
bin: Path

View File

@ -9,7 +9,7 @@ import subprocess
import tempfile
from util import nproc, out_of_date
from vmtest.config import Kernel
from vmtest.config import Kernel, local_kernel
from vmtest.download import downloaded_compiler
logger = logging.getLogger(__name__)
@ -115,14 +115,7 @@ def _main() -> None:
for kernel in args.kernels:
if kernel.pattern.startswith(".") or kernel.pattern.startswith("/"):
kernel_dir = Path(kernel.pattern)
downloaded = Kernel(
arch=kernel.arch,
release=(kernel_dir / "build/include/config/kernel.release")
.read_text()
.strip(),
path=kernel_dir,
)
downloaded = local_kernel(kernel.arch, Path(kernel.pattern))
else:
downloaded = next(download_it) # type: ignore[assignment]
print(build_kmod(args.directory, downloaded))

View File

@ -11,7 +11,7 @@ import sys
import tempfile
from util import nproc, out_of_date
from vmtest.config import HOST_ARCHITECTURE, Kernel
from vmtest.config import HOST_ARCHITECTURE, Kernel, local_kernel
from vmtest.download import (
DOWNLOAD_KERNEL_ARGPARSE_METAVAR,
DownloadKernel,
@ -368,11 +368,7 @@ if __name__ == "__main__":
assert HOST_ARCHITECTURE is not None
args.kernel = DownloadKernel(HOST_ARCHITECTURE, "*")
if args.kernel.pattern.startswith(".") or args.kernel.pattern.startswith("/"):
kernel = Kernel(
arch=args.kernel.arch,
release="", # run_in_vm() doesn't care about the release.
path=Path(args.kernel.pattern),
)
kernel = local_kernel(args.kernel.arch, Path(args.kernel.pattern))
else:
kernel = next(download(args.directory, [args.kernel])) # type: ignore[assignment]