Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 22.05 79 lines 2.3 kB view raw
1# to run these tests: 2# nix-instantiate --eval --strict . -A tests.kernel-config 3# 4# make sure to use NON EXISTING kernel settings else they may conflict with 5# common-config.nix 6{ lib, pkgs }: 7 8with lib; 9with kernel; 10 11let 12 lts_kernel = pkgs.linuxPackages.kernel; 13 14 # to see the result once the module transformed the lose structured config 15 getConfig = structuredConfig: 16 (lts_kernel.override { 17 structuredExtraConfig = structuredConfig; 18 }).configfile.structuredConfig; 19 20 mandatoryVsOptionalConfig = mkMerge [ 21 { NIXOS_FAKE_USB_DEBUG = yes;} 22 { NIXOS_FAKE_USB_DEBUG = option yes; } 23 ]; 24 25 freeformConfig = mkMerge [ 26 { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "32"; } # same as default, won't trigger any error 27 { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "64"; } # will trigger an error but the message is not great: 28 ]; 29 30 yesWinsOverNoConfig = mkMerge [ 31 # default for "NIXOS_TEST_BOOLEAN" is no 32 { "NIXOS_TEST_BOOLEAN" = yes; } # yes wins over no by default 33 { "NIXOS_TEST_BOOLEAN" = no; } 34 ]; 35 36 optionalNoWins = mkMerge [ 37 { NIXOS_FAKE_USB_DEBUG = option yes;} 38 { NIXOS_FAKE_USB_DEBUG = yes;} 39 ]; 40 41 allOptionalRemainOptional = mkMerge [ 42 { NIXOS_FAKE_USB_DEBUG = option yes;} 43 { NIXOS_FAKE_USB_DEBUG = option yes;} 44 ]; 45 46in 47runTests { 48 testEasy = { 49 expr = (getConfig { NIXOS_FAKE_USB_DEBUG = yes;}).NIXOS_FAKE_USB_DEBUG; 50 expected = { tristate = "y"; optional = false; freeform = null; }; 51 }; 52 53 # mandatory flag should win over optional 54 testMandatoryCheck = { 55 expr = (getConfig mandatoryVsOptionalConfig).NIXOS_FAKE_USB_DEBUG.optional; 56 expected = false; 57 }; 58 59 testYesWinsOverNo = { 60 expr = (getConfig yesWinsOverNoConfig)."NIXOS_TEST_BOOLEAN".tristate; 61 expected = "y"; 62 }; 63 64 testAllOptionalRemainOptional = { 65 expr = (getConfig allOptionalRemainOptional)."NIXOS_FAKE_USB_DEBUG".optional; 66 expected = true; 67 }; 68 69 # check that freeform options are unique 70 # Should trigger 71 # > The option `settings.NIXOS_FAKE_MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `<unknown-file>' and `<unknown-file>' 72 testTreeform = let 73 res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform); 74 in { 75 expr = res.success; 76 expected = false; 77 }; 78 79}