Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Tests: shard by a hash of the test name, not the registration index
islandmeddb9a82eb3f51
diff --git a/tests/TestHarness.h b/tests/TestHarness.hindex 2ca14f9c..4044c45f 100644--- a/tests/TestHarness.h+++ b/tests/TestHarness.h@@ -9,6 +9,7 @@#include "core/Document.h"#include <cstddef>+#include <cstdint>#include <cstdio>#include <cstdlib>#include <filesystem>@@ -39,10 +40,17 @@ inline Document makeDoc(Mesh m) {return d;}-// `sculptforge_tests --shard K/N` (tests/test_main.cpp) runs the tests whose registration index is K modulo N: every-// test is in exactly one of the N shards.-inline bool inShard(std::size_t index, int shard, int shards) {- return shards <= 1 || index % static_cast<std::size_t>(shards) == static_cast<std::size_t>(shard);+// `sculptforge_tests --shard K/N` (tests/test_main.cpp) runs the tests whose name hashes (FNV-1a) to K modulo N: every+// test is in exactly one of the N shards, a test stays in its shard when others are added, and the slow tests of one+// file (registered next to each other) don't all land in the same shards, as they did by registration index: CI+// runs every other shard on one machine (ctest -I K,,N), and that machine got all the slow ones.+inline std::uint32_t shardHash(const char* name) {+ std::uint32_t h = 2166136261u;+ for (const char* c = name; *c; ++c) h = (h ^ std::uint8_t(*c)) * 16777619u;+ return h ^ (h >> 16); // the low bits of FNV-1a alone follow the last character too closely+}+inline bool inShard(const char* name, int shard, int shards) {+ return shards <= 1 || shardHash(name) % std::uint32_t(shards) == std::uint32_t(shard);}// A wall-clock limit for a speed check: the value given on a developer machine, four times that on a CI runnerdiff --git a/tests/test_harness.cpp b/tests/test_harness.cppindex fa7b0484..f54ce918 100644--- a/tests/test_harness.cpp+++ b/tests/test_harness.cpp@@ -9,21 +9,24 @@TEST(test_shards_cover_every_test_once) {using sf::test::inShard;- const std::size_t count = sf::test::registry().size();- CHECK(count > 100); // the whole suite is registered- for (int shards = 1; shards <= 9; ++shards) {- std::vector<int> runs(count + 17, 0); // a few more than registered: the rule must not depend on the count- for (int k = 0; k < shards; ++k)- for (std::size_t i = 0; i < runs.size(); ++i)- if (inShard(i, k, shards)) ++runs[i];+ const auto& tests = sf::test::registry();+ CHECK(tests.size() > 100); // the whole suite is registered+ for (int shards = 1; shards <= 17; ++shards) {bool once = true;- for (int r : runs) once = once && r == 1;+ for (const auto& t : tests) {+ int runs = 0;+ for (int k = 0; k < shards; ++k) runs += inShard(t.name, k, shards) ? 1 : 0;+ once = once && runs == 1;+ }CHECK(once);}- // Shards stay balanced: with 4 shards none gets more than a quarter (rounded up) of the tests.- for (int k = 0; k < 4; ++k) {- std::size_t n = 0;- for (std::size_t i = 0; i < count; ++i) n += inShard(i, k, 4) ? 1 : 0;- CHECK(n <= (count + 3) / 4);+ // Shards stay balanced by count: with 16 shards (CMakeLists.txt) none gets more than twice its share, and with+ // CI's 2 and 4 machines (every other / every fourth shard) none more than 1.3 times.+ for (int shards : {2, 4, 16}) {+ std::vector<std::size_t> n(std::size_t(shards), 0);+ for (const auto& t : tests)+ for (int k = 0; k < shards; ++k) n[std::size_t(k)] += inShard(t.name, k, shards) ? 1 : 0;+ const double share = double(tests.size()) / shards;+ for (std::size_t c : n) CHECK(double(c) <= share * (shards == 16 ? 2.0 : 1.3));}}diff --git a/tests/test_main.cpp b/tests/test_main.cppindex c0b1ddf8..2e1b39e8 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -30,7 +30,7 @@ int main(int argc, char** argv) {int ran = 0;for (std::size_t index = 0; index < registry().size(); ++index) {const auto& t = registry()[index];- if (!inShard(index, shard, shards)) continue;+ if (!inShard(t.name, shard, shards)) continue;bool wanted = filters.empty();for (const char* f : filters) wanted = wanted || std::strstr(t.name, f) != nullptr;if (!wanted) continue;