Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 16 additions & 2 deletions nixos/lib/test-driver/test_driver/machine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from abc import ABCMeta, abstractmethod
from contextlib import _GeneratorContextManager, nullcontext
from pathlib import Path
from queue import Queue
Expand Down Expand Up @@ -132,7 +133,7 @@ def retry(fn: Callable, timeout: int = 900) -> None:
raise Exception(f"action timed out after {timeout} seconds")


class StartCommand:
class StartCommand(metaclass=ABCMeta):
"""The Base Start Command knows how to append the necessary
runtime qemu options as determined by a particular test driver
run. Any such start command is expected to happily receive and
Expand All @@ -141,6 +142,11 @@ class StartCommand:

_cmd: str

@property
@abstractmethod
def machine_name(self) -> str:
raise NotImplementedError("No machine_name property defined")

def cmd(
self,
monitor_socket_path: Path,
Expand All @@ -150,7 +156,9 @@ def cmd(
display_opts = ""
display_available = any(x in os.environ for x in ["DISPLAY", "WAYLAND_DISPLAY"])
if not display_available:
display_opts += " -nographic"
capture_file = Path(os.environ.get("out", Path.cwd()))
capture_file /= f"{self.machine_name}.video"
display_opts += f" -nixos-test {shlex.quote(str(capture_file))}"

# qemu options
qemu_opts = (
Expand Down Expand Up @@ -234,8 +242,11 @@ class LegacyStartCommand(StartCommand):
Legacy.
"""

machine_name: str

def __init__(
self,
machine_name: str,
netBackendArgs: Optional[str] = None,
netFrontendArgs: Optional[str] = None,
hda: Optional[Tuple[Path, str]] = None,
Expand All @@ -245,6 +256,8 @@ def __init__(
qemuBinary: Optional[str] = None,
qemuFlags: Optional[str] = None,
):
self.machine_name = machine_name

if qemuBinary is not None:
self._cmd = qemuBinary
else:
Expand Down Expand Up @@ -379,6 +392,7 @@ def create_startcommand(args: Dict[str, str]) -> StartCommand:
hda_arg_path: Path = Path(hda_arg)
hda = (hda_arg_path, args.get("hdaInterface", ""))
return LegacyStartCommand(
machine_name=args.get("name", "machine"),
netBackendArgs=args.get("netBackendArgs"),
netFrontendArgs=args.get("netFrontendArgs"),
hda=hda,
Expand Down
1 change: 1 addition & 0 deletions nixos/lib/testing/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let
./pkgs.nix
./run.nix
./testScript.nix
./video.nix
];

in
Expand Down
22 changes: 22 additions & 0 deletions nixos/lib/testing/video.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ config, pkgs, ... }:

{
passthru.videos = pkgs.runCommand "vm-test-run-${config.name}-videos" {
src = config.test;
nativeBuildInputs = [ pkgs.qemu_test.tools ];
} ''
mkdir -p "$out/nix-support"
if [ -e "$src/nix-support/hydra-build-products" ]; then
cp "$src/nix-support/hydra-build-products" \
> "$out/nix-support/hydra-build-products"
fi

for video in "$src/"*.video; do
vidbase="$(basename "$video")"
destfile="''${vidbase%.*}.webm"
nixos-test-encode-video "$video" "$out/$destfile"
echo "report video $out $destfile" \
>> "$out/nix-support/hydra-build-products"
done
'';
}
2 changes: 1 addition & 1 deletion nixos/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let
inherit system;
pkgs = import ./.. { inherit system; };
callTest = config: {
${system} = hydraJob config.test;
${system} = hydraJob (config.test.videos or config.test);
};
} // {
# for typechecking of the scripts and evaluation of
Expand Down
24 changes: 21 additions & 3 deletions pkgs/applications/virtualization/qemu/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib, stdenv, fetchurl, fetchpatch, python3Packages, zlib, pkg-config, glib, buildPackages
, pixman, vde2, alsa-lib, texinfo, flex
, pixman, vde2, alsa-lib, texinfo, flex, runCommandCC
, bison, lzo, snappy, libaio, libtasn1, gnutls, nettle, curl, ninja, meson, sigtool
, makeWrapper, removeReferencesTo
, makeWrapper, removeReferencesTo, ffmpeg_4
, attr, libcap, libcap_ng, socat, libslirp
, CoreServices, Cocoa, Hypervisor, rez, setfile, vmnet
, guestAgentSupport ? with stdenv.hostPlatform; isLinux || isNetBSD || isOpenBSD || isSunOS || isWindows
Expand Down Expand Up @@ -41,6 +41,7 @@

let
hexagonSupport = hostCpuTargets == null || lib.elem "hexagon" hostCpuTargets;

in

stdenv.mkDerivation (finalAttrs: {
Expand Down Expand Up @@ -128,12 +129,17 @@ stdenv.mkDerivation (finalAttrs: {
revert = true;
})
]
++ lib.optional nixosTestRunner ./force-uid0-on-9p.patch;
++ lib.optionals nixosTestRunner [
./force-uid0-on-9p.patch
./nixos-test-ui.patch
];

postPatch = ''
# Otherwise tries to ensure /var/run exists.
sed -i "/install_emptydir(get_option('localstatedir') \/ 'run')/d" \
qga/meson.build
'' + lib.optionalString nixosTestRunner ''
cat ${./nixos-test-ui.c} > ui/nixos-test.c
'';

preConfigure = ''
Expand Down Expand Up @@ -254,6 +260,18 @@ stdenv.mkDerivation (finalAttrs: {
rev-prefix = "v";
ignoredVersions = "(alpha|beta|rc).*";
};
} // lib.optionalAttrs nixosTestRunner {
tools = runCommandCC "nixos-test-tools" {
nativeBuildInputs = [ pkg-config ];
buildInputs = [ ffmpeg_4 zlib ];
pkgconfigLibs = [
"libavformat" "libavcodec" "libavutil" "libswscale" "zlib"
];
} ''
mkdir -p "$out/bin"
$CC -Wall $(pkg-config $pkgconfigLibs --libs --cflags) \
${./encode-video.c} -o "$out/bin/nixos-test-encode-video"
'';
};

# Builds in ~3h with 2 cores, and ~20m with a big-parallel builder.
Expand Down
Loading