summary refs log tree commit diff
path: root/pkgs/test/kernel.nix
blob: 86f1b8d8e9acc043fef5897c4c45e52b7e9a8ec8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{ lib, pkgs }:

with lib.kernel;
with lib.asserts;
with lib.modules;

# To test nixos/modules/system/boot/kernel_config.nix;
let
  # copied from release-lib.nix
  assertTrue = bool:
    if bool
    then pkgs.runCommand "evaluated-to-true" {} "touch $out"
    else pkgs.runCommand "evaluated-to-false" {} "false";

  lts_kernel = pkgs.linuxPackages.kernel;

  kernelTestConfig = structuredConfig: (lts_kernel.override {
    structuredExtraConfig = structuredConfig;
  }).configfile.structuredConfig;

  mandatoryVsOptionalConfig = mkMerge [
    { USB_DEBUG = option yes;}
    { USB_DEBUG = yes;}
  ];

  freeformConfig = mkMerge [
    { MMC_BLOCK_MINORS = freeform "32"; } # same as default, won't trigger any error
    { MMC_BLOCK_MINORS = freeform "64"; } # will trigger an error but the message is not great:
  ];

  yesWinsOverNoConfig = mkMerge [
    # default for "8139TOO_PIO" is no
    { "8139TOO_PIO"  = yes; } # yes wins over no by default
    { "8139TOO_PIO"  = no; }
  ];
in
{
  # mandatory flag should win over optional
  mandatoryCheck = (kernelTestConfig mandatoryVsOptionalConfig);

  # check that freeform options are unique
  # Should trigger
  # > The option `settings.MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `<unknown-file>' and `<unknown-file>'
  freeformCheck = let
    res = builtins.tryEval ( (kernelTestConfig freeformConfig).MMC_BLOCK_MINORS.freeform);
  in
    assertTrue (res.success == false);

  yesVsNoCheck = let
    res = kernelTestConfig yesWinsOverNoConfig;
  in
    assertTrue (res."8139TOO_PIO".tristate == "y");
}