at master 7.4 kB view raw
1# Run: 2# [nixpkgs]$ nix-instantiate --eval --strict lib/tests/systems.nix 3# Expected output: [], or the failed cases 4# 5# OfBorg runs (approximately) nix-build lib/tests/release.nix 6let 7 lib = import ../default.nix; 8 mseteq = x: y: { 9 expr = lib.sort lib.lessThan x; 10 expected = lib.sort lib.lessThan y; 11 }; 12 13 /* 14 Try to convert an elaborated system back to a simple string. If not possible, 15 return null. So we have the property: 16 17 sys: _valid_ sys -> 18 sys == elaborate (toLosslessStringMaybe sys) 19 20 NOTE: This property is not guaranteed when `sys` was elaborated by a different 21 version of Nixpkgs. 22 */ 23 toLosslessStringMaybe = 24 sys: 25 if lib.isString sys then 26 sys 27 else if lib.systems.equals sys (lib.systems.elaborate sys.system) then 28 sys.system 29 else 30 null; 31 32in 33lib.runTests ( 34 # We assert that the new algorithmic way of generating these lists matches the 35 # way they were hard-coded before. 36 # 37 # One might think "if we exhaustively test, what's the point of procedurally 38 # calculating the lists anyway?". The answer is one can mindlessly update these 39 # tests as new platforms become supported, and then just give the diff a quick 40 # sanity check before committing :). 41 42 (with lib.systems.doubles; { 43 testall = mseteq all ( 44 linux 45 ++ darwin 46 ++ freebsd 47 ++ openbsd 48 ++ netbsd 49 ++ illumos 50 ++ wasi 51 ++ windows 52 ++ cygwin 53 ++ embedded 54 ++ mmix 55 ++ js 56 ++ genode 57 ++ redox 58 ); 59 60 testarm = mseteq arm [ 61 "armv5tel-linux" 62 "armv6l-linux" 63 "armv6l-netbsd" 64 "armv6l-none" 65 "armv7a-linux" 66 "armv7a-netbsd" 67 "armv7l-linux" 68 "armv7l-netbsd" 69 "arm-none" 70 ]; 71 testarmv7 = mseteq armv7 [ 72 "armv7a-linux" 73 "armv7l-linux" 74 "armv7a-netbsd" 75 "armv7l-netbsd" 76 ]; 77 testi686 = mseteq i686 [ 78 "i686-linux" 79 "i686-freebsd" 80 "i686-genode" 81 "i686-netbsd" 82 "i686-openbsd" 83 "i686-cygwin" 84 "i686-windows" 85 "i686-none" 86 ]; 87 testmips = mseteq mips [ 88 "mips-none" 89 "mips64-none" 90 "mips-linux" 91 "mips64-linux" 92 "mips64el-linux" 93 "mipsel-linux" 94 "mipsel-netbsd" 95 ]; 96 testmmix = mseteq mmix [ "mmix-mmixware" ]; 97 testpower = mseteq power [ 98 "powerpc-linux" 99 "powerpc-netbsd" 100 "powerpc-none" 101 "powerpc64-linux" 102 "powerpc64le-linux" 103 "powerpcle-none" 104 ]; 105 testriscv = mseteq riscv [ 106 "riscv32-linux" 107 "riscv64-linux" 108 "riscv32-netbsd" 109 "riscv64-netbsd" 110 "riscv32-none" 111 "riscv64-none" 112 ]; 113 testriscv32 = mseteq riscv32 [ 114 "riscv32-linux" 115 "riscv32-netbsd" 116 "riscv32-none" 117 ]; 118 testriscv64 = mseteq riscv64 [ 119 "riscv64-linux" 120 "riscv64-netbsd" 121 "riscv64-none" 122 ]; 123 tests390x = mseteq s390x [ 124 "s390x-linux" 125 "s390x-none" 126 ]; 127 testx86_64 = mseteq x86_64 [ 128 "x86_64-linux" 129 "x86_64-darwin" 130 "x86_64-freebsd" 131 "x86_64-genode" 132 "x86_64-redox" 133 "x86_64-openbsd" 134 "x86_64-netbsd" 135 "x86_64-cygwin" 136 "x86_64-solaris" 137 "x86_64-windows" 138 "x86_64-none" 139 ]; 140 141 testcygwin = mseteq cygwin [ 142 "i686-cygwin" 143 "x86_64-cygwin" 144 ]; 145 testdarwin = mseteq darwin [ 146 "x86_64-darwin" 147 "aarch64-darwin" 148 ]; 149 testfreebsd = mseteq freebsd [ 150 "aarch64-freebsd" 151 "i686-freebsd" 152 "x86_64-freebsd" 153 ]; 154 testgenode = mseteq genode [ 155 "aarch64-genode" 156 "i686-genode" 157 "x86_64-genode" 158 ]; 159 testredox = mseteq redox [ "x86_64-redox" ]; 160 testgnu = mseteq gnu ( 161 linux # ++ kfreebsd ++ ... 162 ); 163 testillumos = mseteq illumos [ "x86_64-solaris" ]; 164 testlinux = mseteq linux [ 165 "aarch64-linux" 166 "armv5tel-linux" 167 "armv6l-linux" 168 "armv7a-linux" 169 "armv7l-linux" 170 "i686-linux" 171 "loongarch64-linux" 172 "m68k-linux" 173 "microblaze-linux" 174 "microblazeel-linux" 175 "mips-linux" 176 "mips64-linux" 177 "mips64el-linux" 178 "mipsel-linux" 179 "powerpc-linux" 180 "powerpc64-linux" 181 "powerpc64le-linux" 182 "riscv32-linux" 183 "riscv64-linux" 184 "s390-linux" 185 "s390x-linux" 186 "x86_64-linux" 187 ]; 188 testnetbsd = mseteq netbsd [ 189 "aarch64-netbsd" 190 "armv6l-netbsd" 191 "armv7a-netbsd" 192 "armv7l-netbsd" 193 "i686-netbsd" 194 "m68k-netbsd" 195 "mipsel-netbsd" 196 "powerpc-netbsd" 197 "riscv32-netbsd" 198 "riscv64-netbsd" 199 "x86_64-netbsd" 200 ]; 201 testopenbsd = mseteq openbsd [ 202 "i686-openbsd" 203 "x86_64-openbsd" 204 ]; 205 testwindows = mseteq windows [ 206 "aarch64-windows" 207 "i686-windows" 208 "x86_64-windows" 209 ]; 210 testunix = mseteq unix ( 211 linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ cygwin ++ redox 212 ); 213 }) 214 215 // { 216 test_equals_example_x86_64-linux = { 217 expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") ( 218 lib.systems.elaborate "x86_64-linux" 219 ); 220 expected = true; 221 }; 222 223 test_toLosslessStringMaybe_example_x86_64-linux = { 224 expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux"); 225 expected = "x86_64-linux"; 226 }; 227 test_toLosslessStringMaybe_fail = { 228 expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux" // { something = "extra"; }); 229 expected = null; 230 }; 231 test_elaborate_config_over_system = { 232 expr = 233 (lib.systems.elaborate { 234 config = "i686-unknown-linux-gnu"; 235 system = "x86_64-linux"; 236 }).system; 237 expected = "i686-linux"; 238 }; 239 test_elaborate_config_over_parsed = { 240 expr = 241 (lib.systems.elaborate { 242 config = "i686-unknown-linux-gnu"; 243 parsed = (lib.systems.elaborate "x86_64-linux").parsed; 244 }).parsed.cpu.arch; 245 expected = "i686"; 246 }; 247 test_elaborate_system_over_parsed = { 248 expr = 249 (lib.systems.elaborate { 250 system = "i686-linux"; 251 parsed = (lib.systems.elaborate "x86_64-linux").parsed; 252 }).parsed.cpu.arch; 253 expected = "i686"; 254 }; 255 } 256 257 # Generate test cases to assert that a change in any non-function attribute makes a platform unequal 258 // 259 lib.concatMapAttrs 260 (platformAttrName: origValue: { 261 262 ${"test_equals_unequal_${platformAttrName}"} = 263 let 264 modified = 265 assert origValue != arbitraryValue; 266 lib.systems.elaborate "x86_64-linux" // { ${platformAttrName} = arbitraryValue; }; 267 arbitraryValue = x: "<<modified>>"; 268 in 269 { 270 expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") modified; 271 expected = 272 { 273 # Changes in these attrs are not detectable because they're function. 274 # The functions should be derived from the data, so this is not a problem. 275 canExecute = null; 276 emulator = null; 277 emulatorAvailable = null; 278 staticEmulatorAvailable = null; 279 isCompatible = null; 280 } ? ${platformAttrName}; 281 }; 282 283 }) 284 ( 285 lib.systems.elaborate "x86_64-linux" # arbitrary choice, just to get all the elaborated attrNames 286 ) 287 288)