fix unit test that was timing dependent (#217)
This commit is contained in:
parent
a8ac09f364
commit
be8c731890
2 changed files with 12 additions and 18 deletions
|
|
@ -116,7 +116,7 @@ B3_API b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3S
|
|||
b3QueryFilter filter, b3CastResultFcn* fcn, void* context );
|
||||
|
||||
/// Overlap test for all shapes that *potentially* overlap the provided AABB. This only considers static bodies,
|
||||
/// so it may be invoked concurrently with b3World_Step. This is not thread-safe with creationg and destruction
|
||||
/// so it may be invoked concurrently with b3World_Step. This is not thread-safe with creation and destruction
|
||||
/// operations. This is a workaround for The Legend of California and may be removed later if the workaround is no
|
||||
/// longer needed. This is not part of a strategy to make concurrent queries thread-safe.
|
||||
B3_API b3TreeStats b3World_OverlapAABB_Static( b3WorldId worldId, b3AABB aabb, b3QueryFilter filter,
|
||||
|
|
|
|||
|
|
@ -1807,6 +1807,7 @@ typedef struct StaticQueryShared
|
|||
b3AtomicInt stepping;
|
||||
b3AtomicInt quit;
|
||||
b3AtomicInt idle;
|
||||
b3AtomicInt started;
|
||||
b3AtomicInt expectedCount;
|
||||
b3AtomicInt queryCount;
|
||||
b3AtomicInt failCount;
|
||||
|
|
@ -1913,6 +1914,7 @@ static void StaticQueryThread( void* context )
|
|||
}
|
||||
|
||||
b3AtomicStoreInt( &shared->idle, 0 );
|
||||
b3AtomicStoreInt( &shared->started, 1 );
|
||||
int expected = b3AtomicLoadInt( &shared->expectedCount );
|
||||
|
||||
StaticQueryHits hits = { shared->worldId, 0, false };
|
||||
|
|
@ -1959,13 +1961,6 @@ static int TestOverlapStaticDuringStep( void )
|
|||
b3CreateHullShape( bodyId, &shapeDef, &cube.base );
|
||||
}
|
||||
|
||||
b3World* world = b3GetWorldFromId( worldId );
|
||||
|
||||
// Islands falling asleep during the step grow the solver set array under the reader. Count the
|
||||
// steps where that happened while at least two full query rounds, which read static transforms,
|
||||
// ran inside the step.
|
||||
int overlappedGrowthCount = 0;
|
||||
|
||||
StaticQueryShared shared = { 0 };
|
||||
shared.worldId = worldId;
|
||||
b3Thread* thread = b3CreateThread( StaticQueryThread, &shared, "static query" );
|
||||
|
|
@ -1982,12 +1977,16 @@ static int TestOverlapStaticDuringStep( void )
|
|||
|
||||
ENSURE( b3HasTreeMoved( b3GetWorldFromId( worldId )->broadPhase.trees + b3_staticBody ) );
|
||||
|
||||
int setCapacity = world->sleepingSets.capacity;
|
||||
int queryCount = b3AtomicLoadInt( &shared.queryCount );
|
||||
|
||||
b3AtomicStoreInt( &shared.expectedCount, staticCount );
|
||||
b3AtomicStoreInt( &shared.started, 0 );
|
||||
b3AtomicStoreInt( &shared.stepping, 1 );
|
||||
|
||||
// Scheduling decides how many rounds land inside the step, so only wait for one to begin
|
||||
while ( b3AtomicLoadInt( &shared.started ) == 0 )
|
||||
{
|
||||
b3Yield();
|
||||
}
|
||||
|
||||
b3World_Step( worldId, 1.0f / 60.0f, 4 );
|
||||
|
||||
b3AtomicStoreInt( &shared.stepping, 0 );
|
||||
|
|
@ -1997,20 +1996,15 @@ static int TestOverlapStaticDuringStep( void )
|
|||
b3Yield();
|
||||
}
|
||||
|
||||
if ( world->sleepingSets.capacity > setCapacity && b3AtomicLoadInt( &shared.queryCount ) - queryCount >= 2 )
|
||||
{
|
||||
overlappedGrowthCount += 1;
|
||||
}
|
||||
|
||||
ENSURE( b3HasTreeMoved( b3GetWorldFromId( worldId )->broadPhase.trees + b3_staticBody ) == false );
|
||||
}
|
||||
|
||||
b3AtomicStoreInt( &shared.quit, 1 );
|
||||
b3JoinThread( thread );
|
||||
|
||||
ENSURE( b3AtomicLoadInt( &shared.queryCount ) > 0 );
|
||||
// Each step started a round, and the thread cannot report idle until that round finishes
|
||||
ENSURE( b3AtomicLoadInt( &shared.queryCount ) >= 120 );
|
||||
ENSURE( b3AtomicLoadInt( &shared.failCount ) == 0 );
|
||||
ENSURE( overlappedGrowthCount > 0 );
|
||||
|
||||
// The serial path agrees with the regular overlap filtered to static bodies.
|
||||
StaticQueryHits hits = { worldId, 0, false };
|
||||
|
|
|
|||
Loading…
Reference in a new issue