Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run some unit tests in CI #145

Merged
merged 6 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ in
, rustEnvironment ? defaultRustEnvironment
, targetTriple ? defaultRustTargetTriple

, rootCrate

, name ? if rootCrate != null then rootCrate.name else "build-crates"

, rootCrate ? null
, rootCrates ? if rootCrate != null then [ rootCrate ] else throw "must supply 'rootCrates' argument"

, layers ? [ crateUtils.defaultIntermediateLayer ] # default to two building in two steps (external then local)
, commonModifications ? {}
Expand All @@ -45,6 +49,7 @@ in
, noDefaultFeatures ? false

, test ? false
, justBuildTests ? false

, verifyWithVerus ? false
, extraVerusArgs ? []
Expand Down Expand Up @@ -74,7 +79,7 @@ let

prunedLockfile = pruneLockfile {
inherit (rustEnvironment) rustToolchain vendoredSuperLockfile;
rootCrates = [ rootCrate ];
inherit rootCrates;
extraManifest = elaboratedCommonModifications.modifyManifest {}; # TODO
};

Expand All @@ -87,7 +92,7 @@ let

elaboratedCommonModifications = elaborateModifications commonModifications;

closure = crateUtils.getClosureOfCrate rootCrate;
closure = crateUtils.getClosureOfCrates rootCrates;

accumulatedLayers =
let
Expand Down Expand Up @@ -116,7 +121,7 @@ let

baseManifest = {
workspace.resolver = "2";
workspace.members = [ "src/${rootCrate.name}" ];
workspace.members = lib.forEach rootCrates (crate: "src/${crate.name}");
};

baseConfig = denyWarnings: crateUtils.clobber [
Expand All @@ -137,8 +142,8 @@ let
baseFlags = [
"--offline"
"--frozen"
"-p" rootCrate.name
] ++ lib.optionals (lib.length features > 0) [
] ++ lib.concatMap (crate: [ "-p" crate.name ]) rootCrates
++ lib.optionals (lib.length features > 0) [
"--features" (lib.concatStringsSep "," features)
] ++ lib.optionals noDefaultFeatures [
"--no-default-features"
Expand All @@ -158,12 +163,12 @@ let
else "build"
);

mkCargoInvocation = runClippy: commonArgs: subcommandArgs:
mkCargoInvocation = isLastLayer: runClippy: commonArgs: subcommandArgs:
let
joinedCommonArgs = lib.concatStringsSep " " commonArgs;
joinedSubcommandArgs = lib.concatStringsSep " " (
subcommandArgs
++ lib.optionals test [ "--no-run" ]
++ lib.optionals (test && (!isLastLayer || justBuildTests)) [ "--no-run" ]
++ lib.optionals verifyWithVerus ([ "--" ] ++ extraVerusArgs)
);
in ''
Expand Down Expand Up @@ -211,7 +216,7 @@ let
runClippyThisLayer = runClippy && layer.reals != {};
in
modifications.modifyDerivation (stdenv.mkDerivation (baseArgs // {
name = "${rootCrate.name}-intermediate";
name = "${name}-intermediate";

phases = [ "buildPhase" ];

Expand All @@ -221,7 +226,7 @@ let
cp -r --preserve=timestamps ${prev} $out
chmod -R +w $out

${mkCargoInvocation runClippyThisLayer (flags ++ [
${mkCargoInvocation false runClippyThisLayer (flags ++ [
"--config" "${config}"
"--manifest-path" "${workspace}/Cargo.toml"
"--target-dir" "$out"
Expand Down Expand Up @@ -256,7 +261,7 @@ in let
];

final = modifications.modifyDerivation (stdenv.mkDerivation (baseArgs // {
name = rootCrate.name;
name = name;

phases = [ "buildPhase" ];

Expand All @@ -267,23 +272,29 @@ in let
cp -r --preserve=timestamps ${lastIntermediateLayer} $target_dir
chmod -R +w $target_dir

${mkCargoInvocation runClippy (flags ++ [
${mkCargoInvocation true runClippy (flags ++ [
"--config" "${config}"
"--manifest-path" "${workspace}/Cargo.toml"
"--target-dir" "$target_dir"
]) (lib.optionals (!test) [
"--out-dir" "$out/bin"
])}

${lib.optionalString test (lib.concatStringsSep " " (findTestsCommandPrefix "$target_dir" ++ [
"-exec" "install" "-D" "-t" "$out/bin" "'{}'" "';'"
]))}
${lib.optionalString test (
if justBuildTests
then (lib.concatStringsSep " " (findTestsCommandPrefix "$target_dir" ++ [
"-exec" "install" "-D" "-t" "$out/bin" "'{}'" "';'"
]))
else ''
touch $out
''
)}

runHook postBuild
'';

passthru = {
inherit rootCrate workspace lastIntermediateLayer;
inherit rootCrate rootCrates workspace lastIntermediateLayer;
};
}));

Expand Down
2 changes: 1 addition & 1 deletion hacking/nix/rust-utils/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let
in

{
buildCrateInLayers = callPackage ./build-crate-in-layers.nix {};
buildCratesInLayers = callPackage ./build-crates-in-layers.nix {};

buildSysroot = callPackage ./build-sysroot.nix {};

Expand Down
19 changes: 17 additions & 2 deletions hacking/nix/scope/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ superCallPackage ../rust-utils {} self //

mkMkCustomTargetPathForEnvironment = { rustEnvironment }:
let
tool = buildCrateInLayers rec {
tool = buildCratesInLayers rec {
inherit rustEnvironment;
rootCrate = crates.sel4-generate-target-specs;
lastLayerModifications = crateUtils.elaborateModifications {
Expand Down Expand Up @@ -182,7 +182,7 @@ superCallPackage ../rust-utils {} self //

### local tools

mkTool = rootCrate: buildCrateInLayers {
mkTool = rootCrate: buildCratesInLayers {
inherit rootCrate;
};

Expand All @@ -197,6 +197,21 @@ superCallPackage ../rust-utils {} self //
shellForMakefile = callPackage ./shell-for-makefile.nix {};
shellForHacking = callPackage ./shell-for-hacking.nix {};

### unit tests

someUnitTests = buildCratesInLayers {
name = "some-unit-tests";
test = true;
rootCrates = with crates; [
sel4-bitfield-ops
sel4-kernel-loader-embed-page-tables
sel4-backtrace-types
];
features = [
"sel4-backtrace-types/full"
];
};

### kernel

mkSeL4 = callPackage ./sel4 {};
Expand Down
2 changes: 2 additions & 0 deletions hacking/nix/scope/world/instances/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ in rec {
rootTask = mkTask {
rootCrate = crates.tests-root-task-default-test-harness;
test = true;
justBuildTests = true;
};
extraPlatformArgs = lib.optionalAttrs canSimulate {
canAutomateSimply = true;
Expand All @@ -231,6 +232,7 @@ in rec {
rootTask = lib.makeOverridable mkTask {
rootCrate = crates.ring;
test = true;
justBuildTests = true;
features = [
"less-safe-getrandom-custom-or-rdrand"
# "slow_tests"
Expand Down
4 changes: 2 additions & 2 deletions hacking/nix/scope/world/mk-task.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{ lib, buildPackages
, runCommand, runCommandCC
, buildCrateInLayers, buildSysroot, crateUtils
, buildCratesInLayers, buildSysroot, crateUtils
, crates
, defaultRustEnvironment
, defaultRustTargetTriple
Expand Down Expand Up @@ -107,7 +107,7 @@ let

in

buildCrateInLayers (prunedArgs // {
buildCratesInLayers (prunedArgs // {
commonModifications = crateUtils.composeModifications
(crateUtils.elaborateModifications commonModifications)
theseCommonModifications
Expand Down
4 changes: 2 additions & 2 deletions hacking/nix/scope/world/sel4-kernel-loader.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

{ lib, buildPackages, writeText
, buildCrateInLayers, buildSysroot, crateUtils
, buildCratesInLayers, buildSysroot, crateUtils
, crates, bareMetalRustTargetTriple
, libclangPath
, seL4RustEnvVars, seL4ForBoot, seL4ForUserspace
Expand Down Expand Up @@ -44,7 +44,7 @@ let
};

in
buildCrateInLayers {
buildCratesInLayers {

inherit rootCrate;
inherit targetTriple;
Expand Down
2 changes: 2 additions & 0 deletions hacking/nix/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ in {
map (instance: instance.links) world.instances.all
))

pkgs.build.this.someUnitTests

someConfigurationBuildTests

sel4testInstancesList
Expand Down
Loading