Skip to content

Commit

Permalink
tests: use modern boost.test macros
Browse files Browse the repository at this point in the history
  • Loading branch information
timblechmann committed Nov 2, 2023
1 parent d919f9b commit 08c5434
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 201 deletions.
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ foreach(Test ${Tests})
Boost::foreach
)

target_compile_definitions(boost_lockfree_${Test} PRIVATE BOOST_TEST_NO_OLD_TOOLS )

# CTest Target
add_test(NAME boost_lockfree_${Test} COMMAND boost_lockfree_${Test})
add_dependencies(boost_lockfree_all_tests boost_lockfree_${Test} )
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rule test_all
<library>../../thread/build//boost_thread/
<threading>multi
<link>static
<define>BOOST_TEST_NO_OLD_TOOLS
] ;
}

Expand Down
12 changes: 6 additions & 6 deletions test/destructor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE( stack_instance_deleter_test )
}

assert( g_instance_counter == 0 );
BOOST_REQUIRE( g_instance_counter == 0 );
BOOST_TEST_REQUIRE( g_instance_counter == 0 );
}


Expand All @@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE( spsc_queue_instance_deleter_test )
}

assert( g_instance_counter == 0 );
BOOST_REQUIRE( g_instance_counter == 0 );
BOOST_TEST_REQUIRE( g_instance_counter == 0 );
}

BOOST_AUTO_TEST_CASE( spsc_queue_fixed_sized_instance_deleter_test )
Expand All @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE( spsc_queue_fixed_sized_instance_deleter_test )
}

assert( g_instance_counter == 0 );
BOOST_REQUIRE( g_instance_counter == 0 );
BOOST_TEST_REQUIRE( g_instance_counter == 0 );
}

struct no_default_init_tester
Expand Down Expand Up @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE( stack_instance_deleter_no_default_init_test )
}

assert( g_instance_counter == 0 );
BOOST_REQUIRE( g_instance_counter == 0 );
BOOST_TEST_REQUIRE( g_instance_counter == 0 );
}


Expand All @@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE( spsc_queue_instance_deleter_no_default_init_test )
}

assert( g_instance_counter == 0 );
BOOST_REQUIRE( g_instance_counter == 0 );
BOOST_TEST_REQUIRE( g_instance_counter == 0 );
}

BOOST_AUTO_TEST_CASE( spsc_queue_fixed_sized_instance_deleter_no_default_init_test )
Expand All @@ -147,5 +147,5 @@ BOOST_AUTO_TEST_CASE( spsc_queue_fixed_sized_instance_deleter_no_default_init_te
}

assert( g_instance_counter == 0 );
BOOST_REQUIRE( g_instance_counter == 0 );
BOOST_TEST_REQUIRE( g_instance_counter == 0 );
}
4 changes: 2 additions & 2 deletions test/freelist_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void run_test( void )

for ( int i = 0; i != 4; ++i ) {
dummy* allocated = fl.template construct< threadsafe, bounded >();
BOOST_REQUIRE( nodes.find( allocated ) == nodes.end() );
BOOST_TEST_REQUIRE( ( nodes.find( allocated ) == nodes.end() ) );
nodes.insert( allocated );
}

Expand Down Expand Up @@ -107,7 +107,7 @@ void oom_test( void )
fl.template construct< threadsafe, bounded >();

dummy* allocated = fl.template construct< threadsafe, bounded >();
BOOST_REQUIRE( allocated == NULL );
BOOST_TEST_REQUIRE( allocated == (dummy*)NULL );
}

BOOST_AUTO_TEST_CASE( oom_tests )
Expand Down
84 changes: 42 additions & 42 deletions test/queue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,70 @@ BOOST_AUTO_TEST_CASE( simple_queue_test )
{
queue< int > f( 64 );

BOOST_WARN( f.is_lock_free() );
BOOST_TEST_WARN( f.is_lock_free() );

BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.empty() );
f.push( 1 );
f.push( 2 );

int i1( 0 ), i2( 0 );

BOOST_REQUIRE( f.pop( i1 ) );
BOOST_REQUIRE_EQUAL( i1, 1 );
BOOST_TEST_REQUIRE( f.pop( i1 ) );
BOOST_TEST_REQUIRE( i1 == 1 );

BOOST_REQUIRE( f.pop( i2 ) );
BOOST_REQUIRE_EQUAL( i2, 2 );
BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.pop( i2 ) );
BOOST_TEST_REQUIRE( i2 == 2 );
BOOST_TEST_REQUIRE( f.empty() );
}

BOOST_AUTO_TEST_CASE( simple_queue_test_capacity )
{
queue< int, capacity< 64 > > f;

BOOST_WARN( f.is_lock_free() );
BOOST_TEST_WARN( f.is_lock_free() );

BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.empty() );
f.push( 1 );
f.push( 2 );

int i1( 0 ), i2( 0 );

BOOST_REQUIRE( f.pop( i1 ) );
BOOST_REQUIRE_EQUAL( i1, 1 );
BOOST_TEST_REQUIRE( f.pop( i1 ) );
BOOST_TEST_REQUIRE( i1 == 1 );

BOOST_REQUIRE( f.pop( i2 ) );
BOOST_REQUIRE_EQUAL( i2, 2 );
BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.pop( i2 ) );
BOOST_TEST_REQUIRE( i2 == 2 );
BOOST_TEST_REQUIRE( f.empty() );
}


BOOST_AUTO_TEST_CASE( unsafe_queue_test )
{
queue< int > f( 64 );

BOOST_WARN( f.is_lock_free() );
BOOST_REQUIRE( f.empty() );
BOOST_TEST_WARN( f.is_lock_free() );
BOOST_TEST_REQUIRE( f.empty() );

int i1( 0 ), i2( 0 );

f.unsynchronized_push( 1 );
f.unsynchronized_push( 2 );

BOOST_REQUIRE( f.unsynchronized_pop( i1 ) );
BOOST_REQUIRE_EQUAL( i1, 1 );
BOOST_TEST_REQUIRE( f.unsynchronized_pop( i1 ) );
BOOST_TEST_REQUIRE( i1 == 1 );

BOOST_REQUIRE( f.unsynchronized_pop( i2 ) );
BOOST_REQUIRE_EQUAL( i2, 2 );
BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.unsynchronized_pop( i2 ) );
BOOST_TEST_REQUIRE( i2 == 2 );
BOOST_TEST_REQUIRE( f.empty() );
}


BOOST_AUTO_TEST_CASE( queue_consume_one_test )
{
queue< int > f( 64 );

BOOST_WARN( f.is_lock_free() );
BOOST_REQUIRE( f.empty() );
BOOST_TEST_WARN( f.is_lock_free() );
BOOST_TEST_REQUIRE( f.empty() );

f.push( 1 );
f.push( 2 );
Expand All @@ -101,26 +101,26 @@ BOOST_AUTO_TEST_CASE( queue_consume_one_test )
bool success2 = f.consume_one( test_equal( 2 ) );
#else
bool success1 = f.consume_one( []( int i ) {
BOOST_REQUIRE_EQUAL( i, 1 );
BOOST_TEST_REQUIRE( i == 1 );
} );

bool success2 = f.consume_one( []( int i ) {
BOOST_REQUIRE_EQUAL( i, 2 );
BOOST_TEST_REQUIRE( i == 2 );
} );
#endif

BOOST_REQUIRE( success1 );
BOOST_REQUIRE( success2 );
BOOST_TEST_REQUIRE( success1 );
BOOST_TEST_REQUIRE( success2 );

BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.empty() );
}

BOOST_AUTO_TEST_CASE( queue_consume_all_test )
{
queue< int > f( 64 );

BOOST_WARN( f.is_lock_free() );
BOOST_REQUIRE( f.empty() );
BOOST_TEST_WARN( f.is_lock_free() );
BOOST_TEST_REQUIRE( f.empty() );

f.push( 1 );
f.push( 2 );
Expand All @@ -131,16 +131,16 @@ BOOST_AUTO_TEST_CASE( queue_consume_all_test )
size_t consumed = f.consume_all( []( int i ) {} );
#endif

BOOST_REQUIRE_EQUAL( consumed, 2u );
BOOST_TEST_REQUIRE( consumed == 2u );

BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.empty() );
}


BOOST_AUTO_TEST_CASE( queue_convert_pop_test )
{
queue< int* > f( 128 );
BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.empty() );
f.push( new int( 1 ) );
f.push( new int( 2 ) );
f.push( new int( 3 ) );
Expand All @@ -149,16 +149,16 @@ BOOST_AUTO_TEST_CASE( queue_convert_pop_test )
{
int* i1;

BOOST_REQUIRE( f.pop( i1 ) );
BOOST_REQUIRE_EQUAL( *i1, 1 );
BOOST_TEST_REQUIRE( f.pop( i1 ) );
BOOST_TEST_REQUIRE( *i1 == 1 );
delete i1;
}


{
boost::shared_ptr< int > i2;
BOOST_REQUIRE( f.pop( i2 ) );
BOOST_REQUIRE_EQUAL( *i2, 2 );
BOOST_TEST_REQUIRE( f.pop( i2 ) );
BOOST_TEST_REQUIRE( *i2 == 2 );
}

{
Expand All @@ -167,20 +167,20 @@ BOOST_AUTO_TEST_CASE( queue_convert_pop_test )
#else
auto_ptr< int > i3;
#endif
BOOST_REQUIRE( f.pop( i3 ) );
BOOST_TEST_REQUIRE( f.pop( i3 ) );

BOOST_REQUIRE_EQUAL( *i3, 3 );
BOOST_TEST_REQUIRE( *i3 == 3 );
}

{
boost::shared_ptr< int > i4;
BOOST_REQUIRE( f.pop( i4 ) );
BOOST_TEST_REQUIRE( f.pop( i4 ) );

BOOST_REQUIRE_EQUAL( *i4, 4 );
BOOST_TEST_REQUIRE( *i4 == 4 );
}


BOOST_REQUIRE( f.empty() );
BOOST_TEST_REQUIRE( f.empty() );
}

BOOST_AUTO_TEST_CASE( reserve_test )
Expand Down
18 changes: 9 additions & 9 deletions test/spsc_queue_stress_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct spsc_queue_tester
{
running = true;

BOOST_REQUIRE( sf.empty() );
BOOST_TEST_REQUIRE( sf.empty() );

boost::thread reader( boost::bind( &spsc_queue_tester::get, this ) );
boost::thread writer( boost::bind( &spsc_queue_tester::add, this ) );
Expand All @@ -106,10 +106,10 @@ struct spsc_queue_tester

reader.join();

BOOST_REQUIRE_EQUAL( received_nodes, nodes_per_thread );
BOOST_REQUIRE_EQUAL( spsc_queue_cnt, 0 );
BOOST_REQUIRE( sf.empty() );
BOOST_REQUIRE( working_set.count_nodes() == 0 );
BOOST_TEST_REQUIRE( received_nodes == nodes_per_thread );
BOOST_TEST_REQUIRE( spsc_queue_cnt == 0 );
BOOST_TEST_REQUIRE( sf.empty() );
BOOST_TEST_REQUIRE( working_set.count_nodes() == 0 );
}
};

Expand Down Expand Up @@ -210,10 +210,10 @@ struct spsc_queue_tester_buffering

reader.join();

BOOST_REQUIRE_EQUAL( received_nodes, nodes_per_thread );
BOOST_REQUIRE_EQUAL( spsc_queue_cnt, 0 );
BOOST_REQUIRE( sf.empty() );
BOOST_REQUIRE( working_set.count_nodes() == 0 );
BOOST_TEST_REQUIRE( received_nodes == nodes_per_thread );
BOOST_TEST_REQUIRE( spsc_queue_cnt == 0 );
BOOST_TEST_REQUIRE( sf.empty() );
BOOST_TEST_REQUIRE( working_set.count_nodes() == 0 );
}
};

Expand Down
Loading

0 comments on commit 08c5434

Please sign in to comment.