Fail 80% of the time on weak cmpxchg, not 50%

This commit is contained in:
Thom Chiovoloni 2021-01-25 02:59:12 -08:00
parent efd2d55e00
commit d4b592ed17
2 changed files with 3 additions and 3 deletions

View File

@ -567,10 +567,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
let old = this.allow_data_races_mut(|this| this.read_immediate(place.into()))?; let old = this.allow_data_races_mut(|this| this.read_immediate(place.into()))?;
// `binary_op` will bail if either of them is not a scalar. // `binary_op` will bail if either of them is not a scalar.
let eq = this.overflowing_binary_op(mir::BinOp::Eq, old, expect_old)?.0; let eq = this.overflowing_binary_op(mir::BinOp::Eq, old, expect_old)?.0;
// If the operation would succeed, but is "weak", fail 50% of the time. // If the operation would succeed, but is "weak", fail 80% of the time.
// FIXME: this is quite arbitrary. // FIXME: this is quite arbitrary.
let cmpxchg_success = eq.to_bool()? let cmpxchg_success = eq.to_bool()?
&& (!can_fail_spuriously || this.memory.extra.rng.borrow_mut().gen_range(0, 2) == 0); && (!can_fail_spuriously || this.memory.extra.rng.borrow_mut().gen_range(0, 10) < 8);
let res = Immediate::ScalarPair( let res = Immediate::ScalarPair(
old.to_scalar_or_uninit(), old.to_scalar_or_uninit(),
Scalar::from_bool(cmpxchg_success).into(), Scalar::from_bool(cmpxchg_success).into(),

View File

@ -89,7 +89,7 @@ fn atomic_fences() {
fn weak_sometimes_fails() { fn weak_sometimes_fails() {
let atomic = AtomicBool::new(false); let atomic = AtomicBool::new(false);
let tries = 20; let tries = 100;
for _ in 0..tries { for _ in 0..tries {
let cur = atomic.load(Relaxed); let cur = atomic.load(Relaxed);
// Try (weakly) to flip the flag. // Try (weakly) to flip the flag.