Skip to content

Commit

Permalink
Initial vmtests
Browse files Browse the repository at this point in the history
This is broken due to the init script spawning qemu-ga which fails under
the nix flake environment

TODO:
- separate vmtests infra in a different file
- add more kernels
  • Loading branch information
javierhonduco committed Apr 3, 2024
1 parent f8da16a commit 79e20c8
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/vmtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: vmtests

on:
pull_request:
push:

jobs:
vmtests:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@main
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

- name: Install system deps
run: |
sudo apt-get update
sudo apt-get install -y qemu-system-x86-64 qemu-guest-agent qemu-utils ovmf
- name: Set up nix dev env
run: nix develop --command echo 0

- name: Build `lightswitch` statically linked using glibc
run: nix develop --command bash -c 'RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-gnu'

- name: Run vmtests
run: nix develop --command run-vmtests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
flame.svg
src/bpf/*_skel.rs
.vmtest.log
95 changes: 95 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,100 @@
elfutils-without-zstd = pkgs.elfutils.overrideAttrs (attrs: {
configureFlags = attrs.configureFlags ++ [ "--without-zstd" ];
});
# Separate in other nix files.
kernel_5_15 = pkgs.stdenv.mkDerivation {
name = "download-kernel-5.15";
src = pkgs.fetchurl {
url = "https://github.com/danobi/vmtest/releases/download/test_assets/bzImage-v5.15-fedora38";
hash = "sha256-nq8W72vuNKCgO1OS6aJtAfg7AjHavRZ7WAkP7X6V610=";
};
dontUnpack = true;
installPhase = ''
mkdir -p $out
cp -r $src $out/bzImage
'';
};

kernel_6_6 = pkgs.stdenv.mkDerivation {
name = "download-kernel-6.6";
src = pkgs.fetchurl {
url = "https://github.com/danobi/vmtest/releases/download/test_assets/bzImage-v6.6-fedora38";
hash = "sha256-6Fu16SPBITP0sI3lapkckZna6GKBn2hID038itt82jA=";
};
dontUnpack = true;
installPhase = ''
mkdir -p $out
cp -r $src $out/bzImage
'';
};

# Using the rust derivation to make nix aware of this package and use the cache.
vmtest = pkgs.rustPlatform.buildRustPackage {
name = "vmtest";
src = pkgs.fetchFromGitHub {
owner = "danobi";
repo = "vmtest";
rev = "51f11bf301fea054342996802a16ed21fb5054f4";
sha256 = "sha256-qtTq0dnDHi1ITfQzKrXz+1dRMymAFBivWpjXntD09+A=";
};
cargoHash = "sha256-SHjjCWz4FVVk1cczkMltRVEB3GK8jz2tVABNSlSZiUc=";
nativeCheckInputs = [ pkgs.qemu ];

# There are various errors trying to access `/build/source/tests/*`.
doCheck = false;

meta = with pkgs.lib; {
description = "Helps run tests in virtual machines";
homepage = "https://github.com/danobi/vmtest/";
license = licenses.asl20;
mainProgram = "";
maintainers = with maintainers; [ ];
platforms = platforms.linux;
};
};


vmtest-create-config = pkgs.stdenv.mkDerivation {
name = "vmtest-dump-config";
dontUnpack = true;

# The flamegraph is written to the current directory, run lightswitch from /tmp to write it there.
src = pkgs.writeText "vmtest.toml" ''
[[target]]
name = "Fedora 5.15"
kernel = "${kernel_5_15.out}/bzImage"
command = "pushd /tmp && /home/javierhonduco/code/lightswitch/target/x86_64-unknown-linux-gnu/debug/lightswitch --duration 2"
[[target]]
name = "Fedora 6.6"
kernel = "${kernel_6_6.out}/bzImage"
command = "pushd /tmp && /home/javierhonduco/code/lightswitch/target/x86_64-unknown-linux-gnu/debug/lightswitch --duration 2"
'';
nativeBuildInputs = [ vmtest kernel_5_15 kernel_6_6 ];
installPhase = ''
mkdir -p $out
cp -r $src $out/vmtest.toml
'';
};

# Requires lightswitch to be statically built using the x86_64-unknown-linux-gnu target. Definitely
# should be done automatically.
runvmtests = pkgs.stdenv.mkDerivation {
name = "run-vmtests";
dontUnpack = true;

src = pkgs.writeText "run-vmtests" ''
${vmtest}/bin/vmtest --config ${vmtest-create-config}/vmtest.toml
'';
# propagatedBuildInputs = [ pkgs.qemu ];
nativeBuildInputs = [ vmtest-create-config ];
installPhase = ''
mkdir -p $out/bin
cp -r $src $out/bin/run-vmtests
chmod +x $out/bin/run-vmtests
'';
};

in
with pkgs;
{
Expand All @@ -38,6 +132,7 @@
llvmPackages_16.libcxx
llvmPackages_16.libclang
llvmPackages_16.lld
runvmtests
# Debugging
strace
gdb
Expand Down

0 comments on commit 79e20c8

Please sign in to comment.