Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions library/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ cc_test(
],
)

# Standalone calc_par API test
# Standalone calc_par API test.
# medium: MSAN can spend ~80s on the remaining suite alone (small = 120s under
# --config=msan), so keep headroom against runner load variance.
cc_test(
name = "calc_par_test",
srcs = ["calc_par_test.cpp"],
size = "small",
size = "medium",
copts = DDS_CPPOPTS,
linkopts = DDS_LINKOPTS,
local_defines = DDS_LOCAL_DEFINES,
Expand Down
69 changes: 1 addition & 68 deletions library/tests/TestTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/


#include <algorithm>
#include <ctime>
#include <iostream>
#include <iomanip>
Expand Down Expand Up @@ -45,11 +44,6 @@ void TestTimer::reset()
user_cum_ = 0;
user_cum_old_ = 0;
sys_cum_ = 0;
user_min_ = 0;
user_max_ = 0;
sys_min_ = 0;
sys_max_ = 0;
batch_count_ = 0;
pending_hands_ = 0;
sys_time_known_ = true;
}
Expand Down Expand Up @@ -120,52 +114,6 @@ void TestTimer::record(const int hands, const long user_ms, const long sys_ms)
count_ += hands;
user_cum_ += user_ms;
sys_cum_ += sys_ms;

const double user_per_hand = user_ms / static_cast<double>(hands);
const double sys_per_hand = sys_ms / static_cast<double>(hands);
if (batch_count_ == 0)
{
user_min_ = user_max_ = user_per_hand;
sys_min_ = sys_max_ = sys_per_hand;
}
else
{
user_min_ = std::min(user_min_, user_per_hand);
user_max_ = std::max(user_max_, user_per_hand);
sys_min_ = std::min(sys_min_, sys_per_hand);
sys_max_ = std::max(sys_max_, sys_per_hand);
}
batch_count_++;
}


bool TestTimer::has_batch_times() const
{
return batch_count_ > 0;
}


double TestTimer::user_min_ms() const
{
return user_min_;
}


double TestTimer::user_max_ms() const
{
return user_max_;
}


double TestTimer::sys_min_ms() const
{
return sys_min_;
}


double TestTimer::sys_max_ms() const
{
return sys_max_;
}


Expand Down Expand Up @@ -226,10 +174,7 @@ void TestTimer::print_basic() const
}


void TestTimer::print_hands(
ostream& out,
const bool show_min,
const bool show_max) const
void TestTimer::print_hands(ostream& out) const
{
struct StreamFormatGuard
{
Expand Down Expand Up @@ -277,12 +222,6 @@ void TestTimer::print_hands(
out << setw(21) << left << "Avg user time (ms)" <<
setw(12) << right << fixed << setprecision(2) << user_cum_ /
static_cast<float>(count_) << "\n";
if (show_min && has_batch_times())
out << setw(21) << left << "Min user time (ms)" <<
setw(12) << right << fixed << setprecision(2) << user_min_ << "\n";
if (show_max && has_batch_times())
out << setw(21) << left << "Max user time (ms)" <<
setw(12) << right << fixed << setprecision(2) << user_max_ << "\n";
}

if (!sys_time_known_)
Expand All @@ -298,12 +237,6 @@ void TestTimer::print_hands(
out << setw(21) << left << "Avg sys time (ms)" <<
setw(12) << right << fixed << setprecision(2) << sys_cum_ /
static_cast<float>(count_) << "\n";
if (show_min && has_batch_times())
out << setw(21) << left << "Min sys time (ms)" <<
setw(12) << right << fixed << setprecision(2) << sys_min_ << "\n";
if (show_max && has_batch_times())
out << setw(21) << left << "Max sys time (ms)" <<
setw(12) << right << fixed << setprecision(2) << sys_max_ << "\n";
if (user_cum_ > 0) {
out << setw(21) << left << "Ratio" <<
setw(12) << right << fixed << setprecision(2) <<
Expand Down
33 changes: 4 additions & 29 deletions library/tests/TestTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
See LICENSE and README.
*/


#pragma once

#include <ostream>
Expand Down Expand Up @@ -40,11 +41,6 @@ class TestTimer
long user_cum_; ///< Cumulative user time (milliseconds)
long user_cum_old_; ///< Previous cumulative user time (milliseconds)
long sys_cum_; ///< Cumulative system time (milliseconds)
double user_min_; ///< Min per-hand user time across batches (ms)
double user_max_; ///< Max per-hand user time across batches (ms)
double sys_min_; ///< Min per-hand system time across batches (ms)
double sys_max_; ///< Max per-hand system time across batches (ms)
long batch_count_; ///< Number of completed batches
int pending_hands_; ///< Hands counted into the open start()/end() batch
bool sys_time_known_; ///< False when clock() is unusable (e.g. wasm32)

Expand Down Expand Up @@ -80,29 +76,13 @@ class TestTimer
void end();

/// Record one completed batch without wall-clock measurement.
/// Updates cumulative totals and per-hand min/max extremes.
/// Used by end() and by unit tests for deterministic extremes.
/// Non-positive hands is ignored (no cumulative or extreme updates).
/// Updates cumulative totals. Used by end() and by unit tests.
/// Non-positive hands is ignored (no cumulative updates).
/// @param hands Number of hands in the batch
/// @param user_ms Batch user (wall) time in milliseconds
/// @param sys_ms Batch system (CPU) time in milliseconds
void record(const int hands, const long user_ms, const long sys_ms);

/// Whether at least one batch has been recorded.
bool has_batch_times() const;

/// Minimum per-hand user time across batches (milliseconds).
double user_min_ms() const;

/// Maximum per-hand user time across batches (milliseconds).
double user_max_ms() const;

/// Minimum per-hand system time across batches (milliseconds).
double sys_min_ms() const;

/// Maximum per-hand system time across batches (milliseconds).
double sys_max_ms() const;

/// Print timer status while running.
/// @param reached Number of iterations completed so far
/// @param number Total number of iterations
Expand All @@ -115,10 +95,5 @@ class TestTimer

/// Print detailed per-hand timer results.
/// @param out Output stream
/// @param show_min Include min per-hand times across batches
/// @param show_max Include max per-hand times across batches
void print_hands(
std::ostream& out = std::cout,
bool show_min = false,
bool show_max = false) const;
void print_hands(std::ostream& out = std::cout) const;
};
27 changes: 4 additions & 23 deletions library/tests/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ struct optEntry
unsigned numArgs;
};

#define DTEST_NUM_OPTIONS 7
#define DTEST_NUM_OPTIONS 5

enum DtestOpt
{
OPT_FILE = 0,
OPT_SOLVER = 1,
OPT_NUMTHR = 2,
OPT_MEMORY = 3,
OPT_REPORT = 4,
OPT_MAX = 5,
OPT_MIN = 6
OPT_REPORT = 4
};

const optEntry optList[DTEST_NUM_OPTIONS] =
Expand All @@ -61,9 +59,7 @@ const optEntry optList[DTEST_NUM_OPTIONS] =
{"s", "solver", 1},
{"n", "numthr", 1},
{"m", "memory", 1},
{"r", "report", 0},
{"", "max", 0},
{"", "min", 0}
{"r", "report", 0}
};

const vector<string> solverList =
Expand Down Expand Up @@ -115,10 +111,6 @@ void usage(
"\n" <<
"-r, --report Print per-board timings sorted by longest first.\n" <<
"\n" <<
" --max Also print max per-hand user/sys time across batches.\n" <<
"\n" <<
" --min Also print min per-hand user/sys time across batches.\n" <<
"\n" <<
endl;
}

Expand Down Expand Up @@ -167,8 +159,7 @@ int GetNextArgToken(
else
nextToken++;

// Return 1-based option index so --max/--min do not collide with
// --memory on the shared leading 'm'.
// Return 1-based option index so 0 can mean "done".
return static_cast<int>(i) + 1;
}
}
Expand All @@ -184,8 +175,6 @@ void SetDefaults()
options.num_threads_ = 0;
options.memory_mb_ = 0;
options.report_slow_boards_ = false;
options.show_min_ = false;
options.show_max_ = false;
}


Expand Down Expand Up @@ -503,14 +492,6 @@ void read_args(
options.report_slow_boards_ = true;
break;

case OPT_MAX:
options.show_max_ = true;
break;

case OPT_MIN:
options.show_min_ = true;
break;

default:
cout << "Unknown option\n";
errFlag = true;
Expand Down
1 change: 0 additions & 1 deletion library/tests/args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
/// - Number of threads
/// - Memory allocation
/// - Slow board reporting
/// - Optional min/max per-hand timing summary across batches

/// Print usage information.
/// @param base Command name for usage message
Expand Down
48 changes: 7 additions & 41 deletions library/tests/args_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,6 @@ class HandsLayoutFixture : public ::testing::Test

} // namespace

TEST(Args, MaxAndMinFlagsDefaultOff)
{
const std::string path = make_temp_input_file();
char arg0[] = "dtest";
char arg_f[] = "-f";
char* argv[] = {arg0, arg_f, const_cast<char*>(path.c_str())};
read_args(3, argv);
EXPECT_FALSE(options.show_min_);
EXPECT_FALSE(options.show_max_);
}

TEST(Args, MakeDirSucceedsWhenDirectoryAlreadyExists)
{
const std::string dir =
Expand All @@ -222,42 +211,19 @@ TEST(Args, MakeDirFailsWhenPathIsExistingFile)
EXPECT_FALSE(make_dir(path));
}

TEST(Args, MaxFlagEnablesShowMax)
{
const std::string path = make_temp_input_file();
char arg0[] = "dtest";
char arg_f[] = "-f";
char arg_max[] = "--max";
char* argv[] = {arg0, arg_f, const_cast<char*>(path.c_str()), arg_max};
read_args(4, argv);
EXPECT_TRUE(options.show_max_);
EXPECT_FALSE(options.show_min_);
}

TEST(Args, MinFlagEnablesShowMin)
TEST(Args, UnknownMinMaxFlagsAreRejected)
{
// Former --min/--max batch-extreme flags must not be accepted.
// read_args prints to cout and exits(0); death tests only match stderr.
const std::string path = make_temp_input_file();
char arg0[] = "dtest";
char arg_f[] = "-f";
char arg_min[] = "--min";
char* argv[] = {arg0, arg_f, const_cast<char*>(path.c_str()), arg_min};
read_args(4, argv);
EXPECT_TRUE(options.show_min_);
EXPECT_FALSE(options.show_max_);
}

TEST(Args, MaxAndMinFlagsCanCombine)
{
const std::string path = make_temp_input_file();
char arg0[] = "dtest";
char arg_f[] = "-f";
char arg_max[] = "--max";
char arg_min[] = "--min";
char* argv[] = {
arg0, arg_f, const_cast<char*>(path.c_str()), arg_max, arg_min};
read_args(5, argv);
EXPECT_TRUE(options.show_min_);
EXPECT_TRUE(options.show_max_);
char* argv_min[] = {arg0, arg_f, const_cast<char*>(path.c_str()), arg_min};
char* argv_max[] = {arg0, arg_f, const_cast<char*>(path.c_str()), arg_max};
EXPECT_EXIT(read_args(4, argv_min), ::testing::ExitedWithCode(0), ".*");
EXPECT_EXIT(read_args(4, argv_max), ::testing::ExitedWithCode(0), ".*");
}

TEST(Args, ResolvePrefersLiteralExistingPath)
Expand Down
23 changes: 0 additions & 23 deletions library/tests/calc_par_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,26 +379,3 @@ TEST_F(CalcParTest, CalcParContextOverloadMatchesNonContext)
<< "Hand " << hand_idx << " EW contracts differ";
}
}

// Performance test: context reuse should work efficiently
TEST_F(CalcParTest, ContextReusePerformance)
{
SolverContext ctx;

// Run multiple calculations with same context
const int num_iterations = 10;
for (int i = 0; i < num_iterations; i++) {
DdTableResults table;
ParResults par;

// Alternate between different deals
DdTableDeal* deal = (i % 2 == 0) ? &deal0_ : &deal1_;
int vuln = vulnerability_[i % 2];

int result = calc_par(ctx, *deal, vuln, &table, &par);
ASSERT_EQ(result, RETURN_NO_FAULT) << "Iteration " << i << " should succeed";
}

// If we got here, context reuse is working
SUCCEED();
}
2 changes: 0 additions & 2 deletions library/tests/cst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@ struct OptionsType
int num_threads_; ///< Number of threads to use
int memory_mb_; ///< Memory allocation in MB
bool report_slow_boards_; ///< Report slow-executing hands
bool show_min_; ///< Report min per-hand time across batches
bool show_max_; ///< Report max per-hand time across batches
};

4 changes: 3 additions & 1 deletion library/tests/solve_board/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ cc_test(
copts = DDS_CPPOPTS,
)

# medium: MSAN can exceed the small-test limit (120s under --config=msan) on the
# random-playout consistency suite, so keep headroom against runner load variance.
cc_test(
name = "analyse_play_consistency_test",
size = "small",
size = "medium",
srcs = [
"analyse_play_consistency.cpp",
],
Expand Down
Loading