Skip to main content

TestCtx

Struct TestCtx 

Source
pub struct TestCtx { /* private fields */ }

Implementations§

Source§

impl TestCtx

Source

pub fn thread_index(&self) -> usize

The index of your thread, in the range between 0 and the specified TestCfg::threads value.

Examples found in repository?
examples/stack.rs (line 73)
66fn main() {
67    cobb::run_test(cobb::TestCfg::<BuggyStack<usize>> {
68        threads: if cfg!(miri) { 8 } else { 16 },
69        iterations: if cfg!(miri) { 100 } else { 1000 },
70        sub_iterations: if cfg!(miri) { 10 } else { 20 },
71        setup: || BuggyStack::new(),
72        test: |stk, tctx| {
73            stk.push(tctx.thread_index());
74            let _ = stk.pop();
75        },
76        ..Default::default()
77    });
78}
More examples
Hide additional examples
examples/mutex.rs (line 51)
45fn main() {
46    cobb::run_test(cobb::TestCfg::<BuggyMutex<usize>> {
47        threads: 16,
48        iterations: 1000,
49        setup: || BuggyMutex::new(0),
50        test: |mutex, tctx| {
51            *mutex.lock() += tctx.thread_index();
52        },
53        before_each: |m| {
54            *m.lock() = 0;
55        },
56        after_each: |m| {
57            assert_eq!((0..16usize).sum::<usize>(), *m.lock());
58        },
59        ..Default::default()
60    });
61}
Source

pub fn sub_iteration(&self) -> usize

Which iteration you’re on between 0 and TestCfg::sub_iterations (which is usually 1).

Source

pub fn sp(&self)

Hint that if your thread got scheduled at this point, it may help expose bugs.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.