blob: 666e85ba73feae70c659c313082dc3078d896405 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
use binaryninja::headless::Session;
use rstest::*;
use std::sync::{Arc, Barrier};
#[fixture]
#[once]
fn session() -> Session {
Session::new().expect("Failed to initialize session")
}
#[rstest]
fn test_setting_worker_thread(_session: &Session) {
let original_count = binaryninja::worker_thread::worker_thread_count();
binaryninja::worker_thread::set_worker_thread_count(original_count - 1);
assert_eq!(
binaryninja::worker_thread::worker_thread_count(),
original_count - 1
);
binaryninja::worker_thread::set_worker_thread_count(original_count);
assert_eq!(
binaryninja::worker_thread::worker_thread_count(),
original_count
);
}
#[rstest]
fn test_worker_thread_different(_session: &Session) {
let calling_thread = std::thread::current();
// We need both (2) threads to synchronize
let barrier = Arc::new(Barrier::new(2));
let barrier_clone = Arc::clone(&barrier);
binaryninja::worker_thread::execute_on_worker_thread("test", move || {
let worker_thread = std::thread::current();
assert_ne!(
calling_thread.id(),
worker_thread.id(),
"Expected calling thread to be different from the worker thread"
);
barrier_clone.wait();
});
// Wait until worker thread has finished.
barrier.wait();
}
|