Add syndicate test

trunk
Emery Hemingway 3 months ago
parent 23ccb0a30c
commit ce08351d4d

@ -165,23 +165,23 @@ in nullPkgs // {
# Stay clear of upstream on this one.
addPatchesHost [ ./ncurses/genode.patch ] prev.ncurses;
nim-unwrapped =
# programs are still linking to posix library
overrideAttrsTarget ({ patches, ... }: {
version = "1.6.8";
src = fetchurl {
url = "https://nim-lang.org/download/nim-1.6.8.tar.xz";
hash = "sha256-D1tlzbYPeK9BywdcI4mDaJoeH34lyBnxeYYsGKSEz1c=";
};
patches = patches ++ [ ./nim.patch ];
}) prev.nim-unwrapped;
nimNoLibs = nim.override { stdenv = stdenvNoLibs; };
nimPackages =
# Packages from the Nimble flake with adjustments.
prev.nimPackages.overrideScope' (_: prev': {
dhall = with prev';
buildNimPackage rec {
prev.nimPackages.overrideScope' (final': prev':
with final'; {
buildNimPackage = if hostPlatform.isGenode then
({ nimFlags ? [ ], ... }@args:
prev'.buildNimPackage (args // {
nimBackend = "cpp";
nimDefines.posix = { };
doCheck = false;
}))
else
prev'.buildNimPackage;
dhall = buildNimPackage rec {
pname = "dhall";
version = "20221007";
src = prev.fetchFromSourcehut {
@ -193,16 +193,34 @@ in nullPkgs // {
buildInputs = [ bigints cbor ];
};
genode = prev'.genode.overrideAttrs (attrs: rec {
version = "20.11.1";
src = fetchgit {
inherit (attrs.src) url;
rev = "v${version}";
sha256 = "0i78idsrgph0g2yir6niar7v827y6qnmd058s6mpvp091sllvlv8";
};
});
genode = prev'.genode.overrideAttrs ({ ... }: rec {
version = "20221020";
src = final.fetchFromSourcehut {
owner = "~ehmry";
repo = "nim_genode";
rev = version;
hash = "sha256-kUbhYKoN/H/fP7ekDYY5rZwZY8UDdcbFBEodthFkmYk=";
};
});
preserves = overrideAttrsTarget ({ ... }: rec {
pname = "preserves";
version = "20221020";
src = final.fetchFromGitea {
domain = "git.syndicate-lang.org";
owner = "ehmry";
repo = "${pname}-nim";
rev = version;
sha256 = "sha256-yUyt4hAKvEKTFV9KF8994k7RrirQQJ2Jv7ngjbnfXgw=";
};
dontFixup = true; # this is breaking input propagation?
}) prev'.preserves;
syndicate = overrideAttrsTarget ({ ... }: {
dontFixup = true; # this is breaking input propagation?
}) prev'.syndicate;
});
});
openssl =
overrideHost { static = true; } # shared library comes out stupid big

@ -16,6 +16,7 @@ let
./hello.nix
./log.nix
./nim.nix
./syndicate
./tor.nix
./usb.nix
./vmm_x86.nix

@ -1,11 +1,12 @@
{
name = "nim";
machine = { pkgs, ... }: {
genode.init.children.test_nim = let
testNim = with pkgs;
genode.init.children.test_nim = {
package = with pkgs;
nimPackages.buildNimPackage {
pname = "test_nim";
inherit (nim) version;
nimDefines.posix = {};
unpackPhase = ''
mkdir test
cd test
@ -16,8 +17,6 @@
EOF
'';
};
in {
package = testNim;
configFile = builtins.toFile "nim.dhall" ''
let Sigil = env:DHALL_SIGIL

@ -0,0 +1,53 @@
{
name = "syndicate";
machine = { pkgs, ... }: {
genode.init.verbose = true;
genode.init.children.syndicate_service = {
package = with pkgs.nimPackages;
buildNimPackage rec {
pname = "syndicate";
version = "unstable";
nimDefines.posix = { };
src = ./src;
propagatedBuildInputs = [ genode npeg preserves syndicate ];
nimBinOnly = true;
meta.mainProgram = "test";
};
extraInputs = with pkgs.genodePackages; [ libc stdcxx ];
configFile = builtins.toFile "nim.dhall" ''
let Sigil = env:DHALL_SIGIL
let Init = Sigil.Init
let Child = Init.Child
let Libc = Sigil.Libc
in λ(binary : Text)
Child.flat
Child.Attributes::{
, binary
, exitPropagate = True
, resources = Sigil.Init.Resources::{
, caps = 500
, ram = Sigil.units.MiB 10
}
, routes =
[ Sigil.Init.ServiceRoute.parentLabel
"ROM"
(Some "state")
(Some "state")
]
, config =
(Libc.toConfig Libc.default)
with attributes = toMap { ld_verbose = "true" }
}
'';
};
};
testScript = ''
start_all()
machine.wait_until_serial_output("<ROM \"config\"")
'';
}

@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: ☭ 2022 Emery Hemingway
# SPDX-License-Identifier: AGPL-3.0-or-later.txt
import std/[asyncdispatch, options, streams, strutils, xmltree]
import genode, genode/[reports, roms]
import preserves, preserves/xmlhooks, syndicate
type RomAssertion {.preservesRecord: "ROM".} = object
name: string
content: XmlNode
type RomCallback = proc (t: var Turn; rom: RomClient) {.closure, gcsafe.}
proc newRomHandler(env: GenodeEnv; label: string; turn: var Turn; cb: RomCallback): RomHandler =
## Create a `RomHandler` that dispatches a callback within a Syndicate `Turn`.
let facet = turn.facet
result = newRomHandler(env, label) do (rom: RomClient):
run(facet) do (turn: var Turn):
cb(turn, rom)
componentConstructHook = proc(env: GenodeEnv) =
bootDataspace("main") do (ds: Ref; turn: var Turn):
echo "bootDataspace…"
# Syndicate boot hook
onPublish(turn, ds, grab()) do (a: Assertion):
echo "seen in Syndicate dataspace ", ds, " - ", a
var configHandle, stateHandle: syndicate.Handle
let configRom = newRomHandler(env, "config", turn) do (turn: var Turn; rom: RomClient):
# config ROM hook
var ass = RomAssertion(name: "config", content: rom.xml)
echo "publish ", ass.name, " XML in dataspace: ", ass.content
replace(turn, ds, configHandle, ass)

@ -0,0 +1 @@
bin = @["test.nim"]
Loading…
Cancel
Save