Skip to content

Commit

Permalink
Add tests for qemu-tcg backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ereslibre committed Jan 4, 2024
1 parent d5553b1 commit 207781f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
21 changes: 21 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ let
modules = [ {
microvm.hypervisor = "qemu";
} ];
} {
id = "qemu-tcg";
modules = let
# Emulate a different guest system than the host one
guestSystem = if "${system}" == "x86_64-linux" then "aarch64-unknown-linux-gnu"
else "x86_64-linux";
in [
{
microvm = {
hypervisor = "qemu";
# Force the CPU to be something else than the current
# system, and thus, emulated with qemu's Tiny Code Generator
# (TCG)
cpu = if "${system}" == "x86_64-linux" then "cortex-a53"
else "Westmere";
};
# This hypervisor requires a crossSystem nixpkgs for the
# guest system
nixpkgs.crossSystem.config = guestSystem;
}
];
} {
id = "cloud-hypervisor";
modules = [ {
Expand Down
20 changes: 15 additions & 5 deletions checks/startup-shutdown.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ let
let
exit = {
qemu = "reboot";
qemu-tcg = "reboot";
firecracker = "reboot";
cloud-hypervisor = "poweroff";
crosvm = "reboot";
kvmtool = "reboot";
}.${config.microvm.hypervisor};
in ''
${pkgs.coreutils}/bin/uname > /var/OK
${pkgs.coreutils}/bin/uname > /var/kernel-name
${pkgs.coreutils}/bin/uname -m > /var/machine-name
${exit}
'';
};
Expand All @@ -55,11 +58,18 @@ builtins.mapAttrs (_: nixos:
} ''
microvm-run
7z e var.img OK
if [ "$(cat OK)" != "Linux" ] ; then
echo Output does not match
7z e var.img kernel-name machine-name
if [ "$(cat machine-name)-linux" != "${nixos.config.nixpkgs.system}" ] ; then
echo "Machine does not match (got: $(cat machine-name)-linux; expected: ${nixos.config.nixpkgs.system})"
exit 1
fi
if [ "$(cat kernel-name)" != "Linux" ] ; then
echo "Kernel does not match (got: $(cat kernel-name); expected: Linux"
exit 1
fi
cp OK $out
touch $out
''
) configs
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rec {
, autoCreate ? true
, ...
}: nixpkgs-lib.optionalString autoCreate ''
PATH=$PATH:${with pkgs; lib.makeBinPath [ coreutils util-linux e2fsprogs ]}
PATH=$PATH:${with pkgs.buildPackages; lib.makeBinPath [ coreutils util-linux e2fsprogs ]}
if [ ! -e '${image}' ]; then
touch '${image}'
Expand Down
12 changes: 6 additions & 6 deletions lib/runner.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ let
preStart = hypervisorConfig.preStart or microvmConfig.preStart;
tapMultiQueue = hypervisorConfig.tapMultiQueue or false;

runScriptBin = pkgs.writeScriptBin "microvm-run" ''
#! ${pkgs.runtimeShell} -e
runScriptBin = pkgs.buildPackages.writeScriptBin "microvm-run" ''
#! ${pkgs.buildPackages.runtimeShell} -e
${preStart}
${createVolumesScript pkgs microvmConfig.volumes}
${createVolumesScript pkgs.buildPackages microvmConfig.volumes}
${lib.optionalString (hypervisorConfig.requiresMacvtapAsFds or false) openMacvtapFds}
exec ${command}
'';

shutdownScriptBin = pkgs.writeScriptBin "microvm-shutdown" ''
shutdownScriptBin = pkgs.buildPackages.writeScriptBin "microvm-shutdown" ''
#! ${pkgs.runtimeShell} -e
${shutdownCommand}
'';

balloonScriptBin = pkgs.writeScriptBin "microvm-balloon" ''
balloonScriptBin = pkgs.buildPackages.writeScriptBin "microvm-balloon" ''
#! ${pkgs.runtimeShell} -e
if [ -z "$1" ]; then
Expand All @@ -48,7 +48,7 @@ let
'';
in

pkgs.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConfig.hostName}"
pkgs.buildPackages.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConfig.hostName}"
{
# for `nix run`
meta.mainProgram = "microvm-run";
Expand Down

0 comments on commit 207781f

Please sign in to comment.