Skip to content

Commit 088ba56

Browse files
ereslibreastro
authored andcommitted
Add tests for qemu-tcg backend
1 parent f554d2f commit 088ba56

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

checks/default.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ let
88
modules = [ {
99
microvm.hypervisor = "qemu";
1010
} ];
11+
} {
12+
id = "qemu-tcg";
13+
modules = let
14+
# Emulate a different guest system than the host one
15+
guestSystem = if "${system}" == "x86_64-linux" then "aarch64-unknown-linux-gnu"
16+
else "x86_64-linux";
17+
in [
18+
{
19+
microvm = {
20+
hypervisor = "qemu";
21+
# Force the CPU to be something else than the current
22+
# system, and thus, emulated with qemu's Tiny Code Generator
23+
# (TCG)
24+
cpu = if "${system}" == "x86_64-linux" then "cortex-a53"
25+
else "Westmere";
26+
};
27+
nixpkgs.crossSystem.config = guestSystem;
28+
}
29+
];
1130
} {
1231
id = "cloud-hypervisor";
1332
modules = [ {

checks/startup-shutdown.nix

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ let
1515
};
1616
microvm = {
1717
volumes = [ {
18-
label = "var";
19-
mountPoint = "/var";
20-
image = "var.img";
18+
image = "output.img";
19+
label = "output";
20+
mountPoint = "/output";
2121
size = 32;
2222
} ];
2323
crosvm.pivotRoot = "/build/empty";
@@ -35,7 +35,9 @@ let
3535
kvmtool = "reboot";
3636
}.${config.microvm.hypervisor};
3737
in ''
38-
${pkgs.coreutils}/bin/uname > /var/OK
38+
${pkgs.coreutils}/bin/uname > /output/kernel-name
39+
${pkgs.coreutils}/bin/uname -m > /output/machine-name
40+
3941
${exit}
4042
'';
4143
};
@@ -53,14 +55,34 @@ builtins.mapAttrs (_: nixos:
5355
];
5456
requiredSystemFeatures = [ "kvm" ];
5557
meta.timeout = 120;
56-
} ''
58+
} (let
59+
expectedMachineName = (crossSystem:
60+
if crossSystem == null then
61+
expectedMachineName { config = system; }
62+
else if crossSystem.config == "aarch64-unknown-linux-gnu" then
63+
"aarch64"
64+
else if crossSystem.config == "x86_64-linux" then
65+
"x86_64"
66+
else throw "unknown machine name (${crossSystem.config})"
67+
);
68+
in ''
5769
microvm-run
5870
59-
7z e var.img OK
60-
if [ "$(cat OK)" != "Linux" ] ; then
61-
echo Output does not match
71+
7z e output.img kernel-name machine-name
72+
73+
EXPECTED_KERNEL_NAME="Linux"
74+
if [ "$(cat kernel-name)" != "$EXPECTED_KERNEL_NAME" ] ; then
75+
echo "Kernel does not match (got: $(cat kernel-name); expected: $EXPECTED_KERNEL_NAME)"
76+
exit 1
77+
fi
78+
79+
EXPECTED_MACHINE_NAME="${expectedMachineName nixos.config.nixpkgs.crossSystem}"
80+
if [ "$(cat machine-name)" != "$EXPECTED_MACHINE_NAME" ] ; then
81+
echo "Machine does not match (got: $(cat machine-name); expected: $EXPECTED_MACHINE_NAME)"
6282
exit 1
6383
fi
64-
cp OK $out
65-
''
84+
85+
mkdir $out
86+
cp {kernel-name,machine-name} $out
87+
'')
6688
) configs

lib/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ rec {
5656
# Mark NOCOW
5757
chattr +C '${image}' || true
5858
fallocate -l${toString size}MiB '${image}'
59-
mkfs.${fsType} ${pkgs.lib.optionalString (label != null) "-L '${label}'"} '${image}'
59+
mkfs.${fsType} ${labelArgument} '${image}'
6060
fi
61-
''));
61+
'')));
6262

6363
buildRunner = import ./runner.nix;
6464

lib/runner.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ let
1919
preStart = hypervisorConfig.preStart or microvmConfig.preStart;
2020
tapMultiQueue = hypervisorConfig.tapMultiQueue or false;
2121

22-
runScriptBin = pkgs.writeScriptBin "microvm-run" ''
23-
#! ${pkgs.runtimeShell} -e
22+
runScriptBin = pkgs.buildPackages.writeScriptBin "microvm-run" ''
23+
#! ${pkgs.buildPackages.runtimeShell} -e
2424
2525
${preStart}
26-
${createVolumesScript pkgs microvmConfig.volumes}
26+
${createVolumesScript pkgs.buildPackages microvmConfig.volumes}
2727
${lib.optionalString (hypervisorConfig.requiresMacvtapAsFds or false) openMacvtapFds}
2828
2929
exec ${command}
3030
'';
3131

32-
shutdownScriptBin = pkgs.writeScriptBin "microvm-shutdown" ''
32+
shutdownScriptBin = pkgs.buildPackages.writeScriptBin "microvm-shutdown" ''
3333
#! ${pkgs.runtimeShell} -e
3434
3535
${shutdownCommand}
3636
'';
3737

38-
balloonScriptBin = pkgs.writeScriptBin "microvm-balloon" ''
38+
balloonScriptBin = pkgs.buildPackages.writeScriptBin "microvm-balloon" ''
3939
#! ${pkgs.runtimeShell} -e
4040
4141
if [ -z "$1" ]; then
@@ -48,7 +48,7 @@ let
4848
'';
4949
in
5050

51-
pkgs.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConfig.hostName}"
51+
pkgs.buildPackages.runCommand "microvm-${microvmConfig.hypervisor}-${microvmConfig.hostName}"
5252
{
5353
# for `nix run`
5454
meta.mainProgram = "microvm-run";

0 commit comments

Comments
 (0)