Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Testing Namespace Reference

Namespaces

namespace  detail
 

Classes

class  BipartiteNetworkGenerator
 Complete bipartite network generator. More...
 
class  Deterministic_Start_Gate
 Single-use deterministic start gate for concurrent tests. More...
 
class  ErdosRenyiGenerator
 Erdős–Rényi random network generator. More...
 
class  GridNetworkGenerator
 Grid network generator. More...
 
struct  has_cost_support
 
struct  has_cost_support< Net, std::void_t< decltype(std::declval< typename Net::Arc >().cost)> >
 
class  LayeredNetworkGenerator
 Layered (staged) network generator. More...
 
struct  NetworkGeneratorConfig
 Random network generator configuration. More...
 
struct  Producer_Consumer_Stress_Config
 Configuration for producer/consumer stress helpers. More...
 
struct  Producer_Consumer_Stress_Result
 Result returned by producer/consumer stress helpers. More...
 
class  RandomNetworkGenerator
 Base class for random network generators. More...
 
struct  Trace_Operation
 One randomized operation trace entry. More...
 

Enumerations

enum class  Trace_Operation_Kind {
  push , pop , insert , erase ,
  contains
}
 Operation kind for randomized reference traces. More...
 

Functions

template<typename Worker >
void run_workers (const size_t thread_count, Worker worker)
 Launch thread_count workers with a deterministic simultaneous start, join every one of them, and rethrow the first worker exception (if any) only after all have joined.
 
template<typename Push , typename TryPop >
Producer_Consumer_Stress_Result run_producer_consumer_stress (const Producer_Consumer_Stress_Config &config, Push push, TryPop try_pop)
 Run a deterministic producer/consumer stress scenario.
 
std::vector< Trace_Operation > make_random_operation_trace (const size_t count, const uint32_t seed, const size_t key_range, const std::initializer_list< Trace_Operation_Kind > kinds={ Trace_Operation_Kind::insert, Trace_Operation_Kind::erase, Trace_Operation_Kind::contains })
 Build a deterministic pseudo-random operation trace.
 
template<typename SubjectStep , typename ReferenceStep >
std::vector< size_t > replay_trace_and_collect_mismatches (const std::vector< Trace_Operation > &trace, SubjectStep subject_step, ReferenceStep reference_step)
 Replay a trace against a subject and a reference implementation.
 
template<class Net >
std::unique_ptr< RandomNetworkGenerator< Net > > create_generator (const std::string &type, const NetworkGeneratorConfig &config)
 Factory function to create generators.
 

Enumeration Type Documentation

◆ Trace_Operation_Kind

Operation kind for randomized reference traces.

Enumerator
push 
pop 
insert 
erase 
contains 

Definition at line 430 of file concurrency_test_utils.H.

Function Documentation

◆ create_generator()

template<class Net >
std::unique_ptr< RandomNetworkGenerator< Net > > Aleph::Testing::create_generator ( const std::string &  type,
const NetworkGeneratorConfig &  config 
)

Factory function to create generators.

Definition at line 462 of file random_network_generator.H.

◆ make_random_operation_trace()

std::vector< Trace_Operation > Aleph::Testing::make_random_operation_trace ( const size_t  count,
const uint32_t  seed,
const size_t  key_range,
const std::initializer_list< Trace_Operation_Kind >  kinds = { Trace_Operation_Kind::insert, Trace_Operation_Kind::erase, Trace_Operation_Kind::contains } 
)
inline

Build a deterministic pseudo-random operation trace.

Parameters
[in]countNumber of operations to generate.
[in]seedRandom seed.
[in]key_rangeExclusive upper bound for generated keys.
[in]kindsAllowed operation kinds.
Returns
Generated operation trace.
Precondition
key_range > 0.
kinds.size() > 0.

Definition at line 468 of file concurrency_test_utils.H.

References make_random_operation_trace().

Referenced by make_random_operation_trace(), TEST(), TEST(), TEST(), and TEST().

◆ replay_trace_and_collect_mismatches()

std::vector< size_t > Aleph::Testing::replay_trace_and_collect_mismatches ( const std::vector< Trace_Operation > &  trace,
SubjectStep  subject_step,
ReferenceStep  reference_step 
)

Replay a trace against a subject and a reference implementation.

Template Parameters
SubjectStepCallable invoked as subject_step(operation).
ReferenceStepCallable invoked as reference_step(operation).
Parameters
[in]traceOperation trace to replay.
[in,out]subject_stepSubject implementation step.
[in,out]reference_stepReference implementation step.
Returns
Operation indexes where returned results differ.

Definition at line 511 of file concurrency_test_utils.H.

References replay_trace_and_collect_mismatches().

Referenced by replay_trace_and_collect_mismatches(), TEST(), and TEST().

◆ run_producer_consumer_stress()

template<typename Push , typename TryPop >
Producer_Consumer_Stress_Result Aleph::Testing::run_producer_consumer_stress ( const Producer_Consumer_Stress_Config &  config,
Push  push,
TryPop  try_pop 
)

Run a deterministic producer/consumer stress scenario.

Template Parameters
PushCallable invoked as push(size_t value). It may return void for always-successful pushes or bool for retryable pushes. Must be safe to copy into one closure per producer thread; each thread runs its own copy (so Push itself need not be thread-safe unless it captures shared state).
TryPopCallable invoked as try_pop(size_t &out) returning true when a value was consumed. Same per-thread-copy contract as Push.
Parameters
[in]configStress dimensions and timeout.
[in,out]pushProducer operation.
[in,out]try_popConsumer operation.
Returns
Consumed values and timeout flag.

The helper assigns unique values in [0, producers * items_per_producer). It does not assume FIFO ordering; callers should verify conservation, ordering, or topology-specific properties separately.

Exceptions
std::system_errorpropagated as-is if the underlying std::thread constructor fails to create a thread; threads already launched are unblocked and joined (never left parked on the gate or abandoned joinable) before this propagates.
Whateverthe first producer/consumer worker throws (e.g. from push/try_pop itself), once every thread has been joined – see run_workers(), which this delegates to.

Definition at line 360 of file concurrency_test_utils.H.

References Aleph::Testing::Producer_Consumer_Stress_Result::consumed, Aleph::Testing::Producer_Consumer_Stress_Config::consumers, Aleph::Testing::Producer_Consumer_Stress_Config::items_per_producer, Aleph::Testing::Producer_Consumer_Stress_Config::producers, push, run_producer_consumer_stress(), run_workers(), and Aleph::Testing::Producer_Consumer_Stress_Config::timeout.

Referenced by run_producer_consumer_stress(), TEST(), TEST(), and TEST().

◆ run_workers()

template<typename Worker >
void Aleph::Testing::run_workers ( const size_t  thread_count,
Worker  worker 
)

Launch thread_count workers with a deterministic simultaneous start, join every one of them, and rethrow the first worker exception (if any) only after all have joined.

Template Parameters
WorkerCallable invoked as worker(size_t index) from its own thread, index in [0, thread_count). Must be safe to copy into one closure per thread; each thread runs its own copy (so Worker itself need not be thread-safe unless it captures shared state).
Parameters
[in]thread_countNumber of worker threads to launch.
[in,out]workerPer-worker callable.
Exceptions
std::invalid_argumentif thread_count == 0 (see Deterministic_Start_Gate's constructor).
std::system_errorpropagated as-is if the underlying std::thread constructor fails to create a thread; threads already launched are unblocked and joined (never left parked on the gate or abandoned joinable) before this propagates.
Whateverthe first worker to throw at runtime propagates with (whichever worker's catch block first acquires the internal exception mutex – not necessarily the one with the smallest index), rethrown only once every thread has been launched, released, and joined. If more than one worker throws, only the first one recorded is rethrown; the others are discarded.

Definition at line 255 of file concurrency_test_utils.H.

References Aleph::blossom_maximum_cardinality_matching().

Referenced by run_producer_consumer_stress(), TEST(), and TEST().