Skip to content

Commit

Permalink
Initial vmtests
Browse files Browse the repository at this point in the history
TODO:
- separate vmtests infra in a different file
- add more kernels
  • Loading branch information
javierhonduco committed Apr 2, 2024
1 parent 85c6d31 commit f8a61af
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/vmtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: release

on:
pull_request:
push:

jobs:
release:
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: 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
90 changes: 90 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,95 @@
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 this 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=";
nativeBuildInputs = [ pkgs.qemu ];
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
'';
};

runvmtests = pkgs.stdenv.mkDerivation {
name = "run-vmtests";
dontUnpack = true;

src = pkgs.writeText "run-vmtests" ''
vmtest --config ${vmtest-create-config}/vmtest.toml
'';
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 +127,7 @@
llvmPackages_16.libcxx
llvmPackages_16.libclang
llvmPackages_16.lld
runvmtests
# Debugging
strace
gdb
Expand Down
68 changes: 68 additions & 0 deletions vmtests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{ lib, inputs, nixpkgs, home-manager, user, location, ... }:

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
'';
};
vmtest = pkgs.rustPlatform.buildRustPackage {
name = "vmtest";
src = pkgs.fetchFromGitHub {
owner = "danobi";
repo = "vmtest";
rev = "51f11bf301fea054342996802a16ed21fb5054f4";
sha256 = "sha256-qtTq0dnDHi1ITfQzKrXz+1dRMymAFBivWpjXntD09+A=";
};
cargoHash = "sha256-SHjjCWz4FVVk1cczkMltRVEB3GK8jz2tVABNSlSZiUc=";
nativeBuildInputs = [ pkgs.qemu ];
doCheck = false;

meta = with pkgs.lib; {
description = "";
homepage = "";
license = licenses.agpl3Only;
mainProgram = "";
maintainers = with maintainers; [ ];
platforms = platforms.linux;
};
};


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

src = pkgs.writeText "vmtest.toml" ''
[[target]]
name = "6.6"
kernel = "${kernel_6_6.out}/bzImage"
command = "/home/javierhonduco/code/lightswitch/target/x86_64-unknown-linux-gnu/debug/lightswitch --duration 2"
'';
nativeBuildInputs = [ vmtest kernel_6_6 ];
installPhase = ''
mkdir -p $out
cp -r $src $out/
'';
};

runvmtests = pkgs.stdenv.mkDerivation {
name = "run-vm-tests";
dontUnpack = true;

src = pkgs.writeText "run-vmtests" ''
vmtest --config ${vmtest-run}
'';
nativeBuildInputs = [ vmtest-run ];
installPhase = ''
mkdir -p $out
cp -r $src $out/
'';
};

0 comments on commit f8a61af

Please sign in to comment.