~ehmry/sigil

350cfbc0b5d64f1e8feb850df917294efb693fb3 — Emery Hemingway 4 years ago 56bdd97 absolute-needed
WiP! store test
2 files changed, 140 insertions(+), 0 deletions(-)

A tests/nix-store.dhall
A tests/nix-store.nix
A tests/nix-store.dhall => tests/nix-store.dhall +119 -0
@@ 0,0 1,119 @@
-- SPDX-License-Identifier: CC0-1.0

let Test = ./test.dhall ? env:DHALL_GENODE_TEST

let Genode = Test.Genode

let Prelude = Genode.Prelude

let XML = Prelude.XML

let Init = Genode.Init

let Child = Init.Child

let Resources = Init.Resources

let ServiceRoute = Init.ServiceRoute

let init =
        λ(storeTarball : Text)
      → λ(testBinary : Text)
      → Init::{
        , verbose = True
        , routes =
          [ ServiceRoute.parent "Timer"
          , { service =
                { name = "ROM"
                , label =
                    Init.LabelSelector.Type.Partial
                      { prefix = Some "/nix/store/", suffix = None Text }
                }
            , route =
                Init.Route.Type.Child
                  { name = "nix/store-rom", label = None Text }
            }
          ]
        , children = toMap
            { nix/store-fs =
                Child.flat
                  Child.Attributes::{
                  , binary = "vfs"
                  , config = Init.Config::{
                    , content =
                      [ XML.element
                          { name = "vfs"
                          , attributes = XML.emptyAttributes
                          , content =
                            [ XML.leaf
                                { name = "tar"
                                , attributes = toMap
                                    { name = "${storeTarball}" }
                                }
                            ]
                          }
                      , XML.leaf
                          { name = "default-policy"
                          , attributes = toMap { root = "/", writeable = "no" }
                          }
                      ]
                    }
                  , provides = [ "File_system" ]
                  }
            , nix/store-rom =
                Child.flat
                  Child.Attributes::{
                  , binary = "cached_fs_rom"
                  , resources = Resources::{ ram = Genode.units.MiB 8 }
                  , provides = [ "ROM" ]
                  , routes = [ ServiceRoute.child "File_system" "nix/store-fs" ]
                  }
            , test-init =
                Init.toChild
                  Init::{
                  , children = toMap
                      { test =
                          Child.flat
                            Child.Attributes::{
                            , binary = "${testBinary}"
                            , exitPropagate = True
                            , resources = Genode.Init.Resources::{
                              , caps = 256
                              , ram = Genode.units.MiB 4
                              }
                            , config = Genode.Init.Config::{
                              , attributes = toMap { ld_verbose = "yes" }
                              , content =
                                [ Prelude.XML.text
                                    ''
                                    <libc stdin="/dev/null" stdout="/dev/log" stderr="/dev/log" />
                                    <vfs> <dir> <log/> <null/> </dir> </vfs>
                                    ''
                                ]
                              }
                            }
                      }
                  , verbose = True
                  }
                  Init.Attributes::{
                  , routes =
                    [ { service =
                          { name = "ROM"
                          , label =
                              Init.LabelSelector.Type.Partial
                                { prefix = Some "/nix/store/"
                                , suffix = None Text
                                }
                          }
                      , route =
                          Init.Route.Type.Child
                            { name = "nix/store-rom", label = None Text }
                      }
                    ]
                  }
            }
        }

in    λ(storeTarball : Text)
    → λ(testBinary : Text)
    → Test::{ children = Test.initToChildren (init storeTarball testBinary) }

A tests/nix-store.nix => tests/nix-store.nix +21 -0
@@ 0,0 1,21 @@
# SPDX-License-Identifier: CC0-1.0

{ testEnv, pkgs, buildPackages, legacyPackages, ... }:
with pkgs;

let
  storeTarball = buildPackages.runCommand "store" { } ''
    mkdir -p $out
    tar cf "$out/store.tar" --absolute-names "${legacyPackages.hello}"
  '';
in testEnv.mkTest {
  name = "nix-store";
  meta.maintainers = with pkgs.stdenv.lib.maintainers; [ ehmry ];

  testConfig = ''
    ${
      ./nix-store.dhall
    } \"${storeTarball}/store.tar\" \"${legacyPackages.hello}/bin/hello\"'';
  testInputs = [ storeTarball ]
    ++ map pkgs.genodeSources.depot [ "cached_fs_rom" "vfs" ];
}