Skip to content

test(world): set a sleep threshold on a sleeping body - #348

Merged
siracozmen01 merged 1 commit into
mainfrom
sleeping-threshold-test
Nov 5, 2026
Merged

siracozmen01 merged 1 commit into
mainfrom
sleeping-threshold-test

Conversation

@siracozmen01

Copy link
Copy Markdown
Collaborator

Problem

m2Body_SetSleepThreshold's header says the change applies from the next step and a sleeping body stays asleep. No test sets a threshold on a sleeping body, so a wake on the call, or a threshold lost while asleep, would pass every suite (#347).

Change

test/test_islands.c gains TestThresholdOnASleepingBody:

  • A box glides at 0.03 m/s with no gravity, and falls asleep at the default 0.05 m/s.
  • It is given a threshold of 0.02 m/s while asleep. It is still asleep on the call and 30 steps later.
  • It is then woken at 0.03 m/s with m2Body_SetLinearVelocity, and stays awake for a second: the threshold set while asleep governs.
  • As the near miss, the same run with the default set again also stays asleep, and once woken sleeps again.

A test-only change.

Verification

  • test_islands passes.
  • Mutants, each built into a scratch library and run against test_islands:
Mutant Fails
the threshold change wakes the body both checks: the body is awake after the call
the threshold change keeps the old value the existing readbacks, and the 0.02 m/s check: the woken body sleeps again
  • tools/check.sh changed passes. The changed file compiles clean with gcc-14 and clang-20 under the strict flags.
  • test_golden prints the 13 lines of test/hashes.txt unchanged in the scalar (linux-clang-20-asan) and AVX2 (linux-clang-20) presets.

Closes #347

@siracozmen01 siracozmen01 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 997ad36: ready. Read, not run.

The keep-old-value mutant fails on the threshold's effect, not only on the awake flag.

  • After the call, the body is woken at 0.03 m/s and run for a second, and the check needs it still awake: !GlideAfterThreshold(0.02f, ...).
  • 0.03 is above the new 0.02 and below the old 0.05. So if the old value is kept, the body sleeps again within that second (the run before the call shows it does at 0.05), and the first check fails. That is the right reason.
  • The near miss (0.05 set again, the same run) has to sleep again. This shows the only thing separating the two runs is the threshold, not the wake by m2Body_SetLinearVelocity or the time allowed.

The wake mutant. asleep is read straight after the call and again 30 steps later. Both checks need stillAsleep, so a wake on the call fails both.

Each assertion can fail, nothing is weakened or removed, and the body has Problem, Change and Verification.

@siracozmen01
siracozmen01 merged commit 244d342 into main Nov 5, 2026
30 checks passed
@siracozmen01
siracozmen01 deleted the sleeping-threshold-test branch November 5, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No test sets a sleep threshold on a sleeping body

1 participant