diff options
Diffstat (limited to 'tests/nixos')
-rw-r--r-- | tests/nixos/coredumps/default.nix | 15 | ||||
-rw-r--r-- | tests/nixos/coredumps/package.nix | 16 | ||||
-rw-r--r-- | tests/nixos/default.nix | 2 | ||||
-rw-r--r-- | tests/nixos/util.nix | 7 |
4 files changed, 39 insertions, 1 deletions
diff --git a/tests/nixos/coredumps/default.nix b/tests/nixos/coredumps/default.nix new file mode 100644 index 000000000..3d0d62945 --- /dev/null +++ b/tests/nixos/coredumps/default.nix @@ -0,0 +1,15 @@ +let + inherit (import ../util.nix) mkNixBuildTest; +in mkNixBuildTest rec { + name = "coredumps"; + extraMachineConfig = { pkgs, ... }: { + boot.kernel.sysctl."kernel.core_pattern" = "core"; + }; + + expressionFile = ./package.nix; + + testScriptPost = '' + # do a test, but this time with coredumps enabled. + machine.succeed('nix-build --option enable-core-dumps true --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} { shouldBePresent = true; }"') + ''; +} diff --git a/tests/nixos/coredumps/package.nix b/tests/nixos/coredumps/package.nix new file mode 100644 index 000000000..a7f6434ed --- /dev/null +++ b/tests/nixos/coredumps/package.nix @@ -0,0 +1,16 @@ +{ lib, runCommand, shouldBePresent ? false }: + +runCommand "core-dump-now" { } '' + set -m + sleep infinity & + + # make a coredump + kill -SIGSEGV %1 + + if ${lib.optionalString (shouldBePresent) "!"} test -n "$(find . -maxdepth 1 -name 'core*' -print -quit)"; then + echo "core file was in wrong presence state, expected: ${if shouldBePresent then "present" else "missing"}" + exit 1 + fi + + touch $out +'' diff --git a/tests/nixos/default.nix b/tests/nixos/default.nix index 987463b07..9dd888916 100644 --- a/tests/nixos/default.nix +++ b/tests/nixos/default.nix @@ -166,4 +166,6 @@ in rootInSandbox = runNixOSTestFor "x86_64-linux" ./root-in-sandbox; broken-userns = runNixOSTestFor "x86_64-linux" ./broken-userns.nix; + + coredumps = runNixOSTestFor "x86_64-linux" ./coredumps; } diff --git a/tests/nixos/util.nix b/tests/nixos/util.nix index 0c51cc075..1b8b4223c 100644 --- a/tests/nixos/util.nix +++ b/tests/nixos/util.nix @@ -1,5 +1,6 @@ { - mkNixBuildTest = { name, expressionFile, extraMachineConfig ? {} }: + mkNixBuildTest = + { name, expressionFile, extraMachineConfig ? {}, testScriptPre ? "", testScriptPost ? "" }: { lib, pkgs, ... }: { inherit name; @@ -17,7 +18,11 @@ testScript = { nodes }: '' start_all() + ${testScriptPre} + machine.succeed('nix-build --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} {}"') + + ${testScriptPost} ''; }; } |