Skip to content

Commit e467111

Browse files
committed
fix Session init race condition
1 parent f6db8b0 commit e467111

20 files changed

+46
-67
lines changed

rust/tests/background_task.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ use binaryninja::headless::Session;
33
use rstest::*;
44

55
#[fixture]
6-
#[once]
76
fn session() -> Session {
87
Session::new().expect("Failed to initialize session")
98
}
109

1110
#[rstest]
12-
fn test_background_task_registered(_session: &Session) {
11+
fn test_background_task_registered(_session: Session) {
1312
let task_progress = "test registered";
1413
let task = BackgroundTask::new(task_progress, false);
1514
BackgroundTask::running_tasks()
@@ -25,7 +24,7 @@ fn test_background_task_registered(_session: &Session) {
2524
}
2625

2726
#[rstest]
28-
fn test_background_task_cancellable(_session: &Session) {
27+
fn test_background_task_cancellable(_session: Session) {
2928
let task_progress = "test cancellable";
3029
let task = BackgroundTask::new(task_progress, false);
3130
BackgroundTask::running_tasks()
@@ -38,7 +37,7 @@ fn test_background_task_cancellable(_session: &Session) {
3837
}
3938

4039
#[rstest]
41-
fn test_background_task_progress(_session: &Session) {
40+
fn test_background_task_progress(_session: Session) {
4241
let task = BackgroundTask::new("test progress", false);
4342
let first_progress = task.progress_text().to_string();
4443
assert_eq!(first_progress, "test progress");

rust/tests/binary_reader.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use std::io::{Read, Seek, SeekFrom};
66
use std::path::PathBuf;
77

88
#[fixture]
9-
#[once]
109
fn session() -> Session {
1110
Session::new().expect("Failed to initialize session")
1211
}
1312

1413
#[rstest]
15-
fn test_binary_reader_seek(_session: &Session) {
14+
fn test_binary_reader_seek(_session: Session) {
1615
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
1716
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
1817
let mut reader = BinaryReader::new(&view);
@@ -50,7 +49,7 @@ fn test_binary_reader_seek(_session: &Session) {
5049
}
5150

5251
#[rstest]
53-
fn test_binary_reader_read(_session: &Session) {
52+
fn test_binary_reader_read(_session: Session) {
5453
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
5554
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
5655
let mut reader = BinaryReader::new(&view);

rust/tests/binary_view.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use rstest::*;
66
use std::path::PathBuf;
77

88
#[fixture]
9-
#[once]
109
fn session() -> Session {
1110
Session::new().expect("Failed to initialize session")
1211
}
1312

1413
#[rstest]
15-
fn test_binary_loading(_session: &Session) {
14+
fn test_binary_loading(_session: Session) {
1615
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
1716
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
1817
assert!(view.has_initial_analysis(), "No initial analysis");
@@ -22,7 +21,7 @@ fn test_binary_loading(_session: &Session) {
2221
}
2322

2423
#[rstest]
25-
fn test_binary_saving(_session: &Session) {
24+
fn test_binary_saving(_session: Session) {
2625
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
2726
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
2827
// Verify the contents before we modify.
@@ -45,7 +44,7 @@ fn test_binary_saving(_session: &Session) {
4544
}
4645

4746
#[rstest]
48-
fn test_binary_saving_database(_session: &Session) {
47+
fn test_binary_saving_database(_session: Session) {
4948
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
5049
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
5150
// Update a symbol to verify modification

rust/tests/binary_writer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ use std::io::{Read, Seek, SeekFrom, Write};
77
use std::path::PathBuf;
88

99
#[fixture]
10-
#[once]
1110
fn session() -> Session {
1211
Session::new().expect("Failed to initialize session")
1312
}
1413

1514
#[rstest]
16-
fn test_binary_writer_seek(_session: &Session) {
15+
fn test_binary_writer_seek(_session: Session) {
1716
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
1817
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
1918
let mut writer = BinaryWriter::new(&view);
@@ -51,7 +50,7 @@ fn test_binary_writer_seek(_session: &Session) {
5150
}
5251

5352
#[rstest]
54-
fn test_binary_writer_write(_session: &Session) {
53+
fn test_binary_writer_write(_session: Session) {
5554
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
5655
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
5756
let mut reader = BinaryReader::new(&view);

rust/tests/collaboration.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use serial_test::serial;
99
use std::path::PathBuf;
1010

1111
#[fixture]
12-
#[once]
1312
fn session() -> Session {
1413
Session::new().expect("Failed to initialize session")
1514
}
@@ -58,7 +57,7 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, project_name: &str
5857

5958
#[rstest]
6059
#[serial]
61-
fn test_connection(_session: &Session) {
60+
fn test_connection(_session: Session) {
6261
if !has_collaboration_support() {
6362
eprintln!("No collaboration support, skipping test...");
6463
return;
@@ -74,7 +73,7 @@ fn test_connection(_session: &Session) {
7473

7574
#[rstest]
7675
#[serial]
77-
fn test_project_creation(_session: &Session) {
76+
fn test_project_creation(_session: Session) {
7877
if !has_collaboration_support() {
7978
eprintln!("No collaboration support, skipping test...");
8079
return;
@@ -155,7 +154,7 @@ fn test_project_creation(_session: &Session) {
155154

156155
#[rstest]
157156
#[serial]
158-
fn test_project_sync(_session: &Session) {
157+
fn test_project_sync(_session: Session) {
159158
if !has_collaboration_support() {
160159
eprintln!("No collaboration support, skipping test...");
161160
return;

rust/tests/component.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ use rstest::*;
55
use std::path::PathBuf;
66

77
#[fixture]
8-
#[once]
98
fn session() -> Session {
109
Session::new().expect("Failed to initialize session")
1110
}
1211

1312
#[rstest]
14-
fn test_component_creation(_session: &Session) {
13+
fn test_component_creation(_session: Session) {
1514
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
1615
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
1716
let component = ComponentBuilder::new(view.clone()).name("test").finalize();

rust/tests/demangler.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ use binaryninja::types::{QualifiedName, Type};
99
use rstest::*;
1010

1111
#[fixture]
12-
#[once]
1312
fn session() -> Session {
1413
Session::new().expect("Failed to initialize session")
1514
}
1615

1716
#[rstest]
18-
fn test_demangler_simple(_session: &Session) {
17+
fn test_demangler_simple(_session: Session) {
1918
let placeholder_arch = CoreArchitecture::by_name("x86").expect("x86 exists");
2019
// Example LLVM-style mangled name
2120
let llvm_mangled = "_Z3fooi"; // "foo(int)" in LLVM mangling
@@ -46,7 +45,7 @@ fn test_demangler_simple(_session: &Session) {
4645
}
4746

4847
#[rstest]
49-
fn test_custom_demangler(_session: &Session) {
48+
fn test_custom_demangler(_session: Session) {
5049
struct TestDemangler;
5150

5251
impl CustomDemangler for TestDemangler {

rust/tests/high_level_il.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ use rstest::*;
55
use std::path::PathBuf;
66

77
#[fixture]
8-
#[once]
98
fn session() -> Session {
109
Session::new().expect("Failed to initialize session")
1110
}
1211

1312
#[rstest]
14-
fn test_hlil_info(_session: &Session) {
13+
fn test_hlil_info(_session: Session) {
1514
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
1615
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
1716

rust/tests/low_level_il.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ use rstest::*;
1212
use std::path::PathBuf;
1313

1414
#[fixture]
15-
#[once]
1615
fn session() -> Session {
1716
Session::new().expect("Failed to initialize session")
1817
}
1918

2019
#[rstest]
21-
fn test_llil_info(_session: &Session) {
20+
fn test_llil_info(_session: Session) {
2221
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
2322
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
2423

@@ -170,7 +169,7 @@ fn test_llil_info(_session: &Session) {
170169
}
171170

172171
#[rstest]
173-
fn test_llil_visitor(_session: &Session) {
172+
fn test_llil_visitor(_session: Session) {
174173
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
175174
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
176175
let platform = view.default_platform().unwrap();

rust/tests/main_thread.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ use rstest::*;
44
// TODO: Add a test for MainThreadHandler
55

66
#[fixture]
7-
#[once]
87
fn session() -> Session {
98
Session::new().expect("Failed to initialize session")
109
}
1110

1211
#[rstest]
13-
fn test_not_main_thread(_session: &Session) {
12+
fn test_not_main_thread(_session: Session) {
1413
// We should never be the main thread.
1514
assert!(!binaryninja::is_main_thread())
1615
}
1716

1817
#[rstest]
19-
fn test_main_thread_different(_session: &Session) {
18+
fn test_main_thread_different(_session: Session) {
2019
let calling_thread = std::thread::current();
2120
binaryninja::main_thread::execute_on_main_thread_and_wait(move || {
2221
let main_thread = std::thread::current();

0 commit comments

Comments
 (0)