MCPcopy Create free account
hub / github.com/dds-bridge/dds / TEST

Function TEST

library/tests/system/concurrency_validation_test.cpp:55–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55TEST(ConcurrencyValidation, ParallelInstancesMatchSequentialBaseline)
56{
57 // A small set of distinct boards in PBN text form.
58 // Source: examples/hands.cpp (representative random deals)
59 const std::vector<std::string> pbns = {
60 "N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3",
61 "E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63",
62 "N:73.QJT.AQ54.T752 QT6.876.KJ9.AQ84 5.A95432.7632.K6 AKJ9842.K.T8.J93"
63 };
64
65 const size_t N = pbns.size();
66 ensure_threads(N);
67
68 // Prepare deals and sequential baselines (single thread / thr 0)
69 std::vector<Deal> deals;
70 deals.reserve(N);
71 for (const auto& s : pbns) {
72 deals.emplace_back(make_deal_from_pbn(s.c_str(), /*trump=*/0, /*first=*/0));
73 }
74
75 std::vector<FutureTricks> baseline_ft(N);
76 std::vector<int> baseline_rc(N, 0);
77
78 {
79 SolverContext ctx;
80 for (size_t i = 0; i < N; ++i) {
81 FutureTricks ft{};
82 const int rc = solve_board(ctx, deals[i], /*target=*/0, /*solutions=*/1, /*mode=*/0, &ft);
83 baseline_rc[i] = rc;
84 baseline_ft[i] = ft; // copy
85 }
86 }
87
88 // Run in parallel: one thread per board with its own ThreadData/Context
89 std::vector<FutureTricks> out_ft(N);
90 std::vector<int> out_rc(N, 0);
91
92 std::vector<std::thread> threads;
93 threads.reserve(N);
94 for (size_t i = 0; i < N; ++i) {
95 threads.emplace_back([i, &deals, &out_ft, &out_rc]() {
96 SolverContext ctx;
97 FutureTricks ft{};
98 const int rc = solve_board(ctx, deals[i], /*target=*/0, /*solutions=*/1, /*mode=*/0, &ft);
99 out_rc[i] = rc;
100 out_ft[i] = ft;
101 });
102 }
103 for (auto& t : threads) t.join();
104
105 for (size_t i = 0; i < N; ++i) {
106 EXPECT_EQ(out_rc[i], baseline_rc[i]) << "Return code mismatch for case " << i;
107 EXPECT_TRUE(equal_future_tricks(out_ft[i], baseline_ft[i])) << "FutureTricks mismatch for case " << i;
108 }
109}

Callers

nothing calls this directly

Calls 4

ensure_threadsFunction · 0.85
make_deal_from_pbnFunction · 0.85
solve_boardFunction · 0.85
equal_future_tricksFunction · 0.85

Tested by

no test coverage detected