From 979284c7f6be45c3c11f2d2b6184035cf0b5a7a5 Mon Sep 17 00:00:00 2001 From: Francisco Javier Honduvilla Coto Date: Tue, 2 Apr 2024 11:59:24 +0100 Subject: [PATCH] Initial vmtests TODO: - separate vmtests infra in a different file - add more kernels --- .github/workflows/vmtest.yml | 26 ++++++++++ .gitignore | 1 + flake.nix | 95 ++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 .github/workflows/vmtest.yml diff --git a/.github/workflows/vmtest.yml b/.github/workflows/vmtest.yml new file mode 100644 index 0000000..da39ad3 --- /dev/null +++ b/.github/workflows/vmtest.yml @@ -0,0 +1,26 @@ +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: 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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 142cfac..2ec4df3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target flame.svg src/bpf/*_skel.rs +.vmtest.log \ No newline at end of file diff --git a/flake.nix b/flake.nix index 0561136..4c66cd2 100644 --- a/flake.nix +++ b/flake.nix @@ -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="; + buildInputs = [ pkgs.qemu ]; + 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 + ''; + 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; { @@ -38,6 +132,7 @@ llvmPackages_16.libcxx llvmPackages_16.libclang llvmPackages_16.lld + runvmtests # Debugging strace gdb