diff --git a/tests/flake.nix b/tests/flake.nix index ef87d69d1..4527cb980 100644 --- a/tests/flake.nix +++ b/tests/flake.nix @@ -26,109 +26,113 @@ "x86_64-linux" ]; - ciTestChunks = + testChunks = system: let pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs) lib; # Create chunked test packages for better CI parallelization - testChunks = + tests = import ./. { + inherit pkgs; + # Disable big tests since this is only used for CI + enableBig = false; + }; + allTests = lib.attrNames tests.build; + # Remove 'all' from the test list as it's a meta-package + filteredTests = lib.filter (name: name != "all") allTests; + # NOTE: Just a starting value, we can tweak this to find a good value. + targetTestsPerChunk = 50; + numChunks = lib.max 1 ( + builtins.ceil ((builtins.length filteredTests) / (targetTestsPerChunk * 1.0)) + ); + chunkSize = builtins.ceil ((builtins.length filteredTests) / (numChunks * 1.0)); + + makeChunk = + chunkNum: testList: let - tests = import ./. { - inherit pkgs; - # Disable big tests since this is only used for CI - enableBig = false; - }; - allTests = lib.attrNames tests.build; - # Remove 'all' from the test list as it's a meta-package - filteredTests = lib.filter (name: name != "all") allTests; - # NOTE: Just a starting value, we can tweak this to find a good value. - targetTestsPerChunk = 50; - numChunks = lib.max 1 ( - builtins.ceil ((builtins.length filteredTests) / (targetTestsPerChunk * 1.0)) - ); - chunkSize = builtins.ceil ((builtins.length filteredTests) / (numChunks * 1.0)); - - makeChunk = - chunkNum: testList: - let - start = (chunkNum - 1) * chunkSize; - end = lib.min (start + chunkSize) (builtins.length testList); - chunkTests = lib.sublist start (end - start) testList; - chunkAttrs = lib.genAttrs chunkTests (name: tests.build.${name}); - in - pkgs.symlinkJoin { - name = "test-chunk-${toString chunkNum}"; - paths = lib.attrValues chunkAttrs; - passthru.tests = chunkTests; - }; + start = (chunkNum - 1) * chunkSize; + end = lib.min (start + chunkSize) (builtins.length testList); + chunkTests = lib.sublist start (end - start) testList; + chunkAttrs = lib.genAttrs chunkTests (name: tests.build.${name}); in - lib.listToAttrs ( - lib.genList ( - i: lib.nameValuePair "test-chunk-${toString (i + 1)}" (makeChunk (i + 1) filteredTests) - ) numChunks - ); + pkgs.symlinkJoin { + name = "test-chunk-${toString chunkNum}"; + paths = lib.attrValues chunkAttrs; + passthru.tests = chunkTests; + }; in - testChunks; + lib.listToAttrs ( + lib.genList ( + i: lib.nameValuePair "test-chunk-${toString (i + 1)}" (makeChunk (i + 1) filteredTests) + ) numChunks + ); - allPackagesAndTests = + integrationTests = system: let pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs) lib; - - renamedBuildTests = - let - tests = import ./. { inherit pkgs; }; - renameTestPkg = n: lib.nameValuePair "test-${n}"; - in - lib.mapAttrs' renameTestPkg tests.build; - - integrationTestPackages = - let - tests = import ./integration { - inherit pkgs; - inherit (pkgs) lib; - }; - renameTestPkg = n: lib.nameValuePair "integration-test-${n}"; - in - lib.mapAttrs' renameTestPkg tests; - - # Aggregate test set without big tests - testAllNoBig = - let - tests = import ./. { - inherit pkgs; - enableBig = false; - }; - in - lib.nameValuePair "test-all-no-big" tests.build.all; - - # Aggregate test set without big tests, with legacy IFD - testAllNoBigIfd = - let - tests = import ./. { - inherit pkgs; - enableBig = false; - enableLegacyIfd = true; - }; - in - lib.nameValuePair "test-all-no-big-ifd" tests.build.all; in - # Merge all the packages and tests meant for the 'packages' output - renamedBuildTests - // integrationTestPackages - // (lib.listToAttrs [ - testAllNoBig - testAllNoBigIfd - ]) - // (ciTestChunks system); + lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux ( + let + tests = import ./integration { inherit pkgs lib; }; + renameTestPkg = n: v: lib.nameValuePair "integration-${n}" v; + in + lib.mapAttrs' renameTestPkg (lib.removeAttrs tests [ "all" ]) + ); + + # Test group definitions + buildTests = + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + tests = import ./. { inherit pkgs; }; + renameTestPkg = n: nixpkgs.lib.nameValuePair "test-${n}"; + in + nixpkgs.lib.mapAttrs' renameTestPkg tests.build; + + buildTestsNoBig = + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + tests = import ./. { + inherit pkgs; + enableBig = false; + }; + in + { + test-all-no-big = tests.build.all; + }; + + buildTestsNoBigIfd = + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + tests = import ./. { + inherit pkgs; + enableBig = false; + enableLegacyIfd = true; + }; + in + { + test-all-no-big-ifd = tests.build.all; + }; + + integrationTestPackages = + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; + tests = import ./integration { inherit pkgs lib; }; + renameTestPkg = n: lib.nameValuePair "integration-test-${n}"; + in + lib.mapAttrs' renameTestPkg tests; in { # TODO: increase buildbot testing scope - buildbot = forCI ciTestChunks; + buildbot = forCI (system: (testChunks system)); devShells = forAllSystems ( system: @@ -139,6 +143,14 @@ tests.run ); - packages = forAllSystems allPackagesAndTests; + packages = forAllSystems ( + system: + (buildTests system) + // (integrationTestPackages system) + // (buildTestsNoBig system) + // (buildTestsNoBigIfd system) + // (testChunks system) + // (integrationTests system) + ); }; }