diff options
| author | Mason Reed <mason@vector35.com> | 2025-01-27 16:56:15 -0500 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-01-27 17:52:29 -0500 |
| commit | 01a224425d2a90e660bbfffe8d1cbc6b93da24bd (patch) | |
| tree | 4be2aa6c3154b4fb34e61815956dcd357c754e2c /rust/tests | |
| parent | 9c9f5085e010059c813d2285ddff79b542c76834 (diff) | |
Fix some rust race conditions and comment some likely suspects
FYI The binary view saving stuff can deadlock right now, so we document that now :/
Diffstat (limited to 'rust/tests')
| -rw-r--r-- | rust/tests/binary_view.rs | 5 | ||||
| -rw-r--r-- | rust/tests/collaboration.rs | 22 | ||||
| -rw-r--r-- | rust/tests/platform.rs | 1 |
3 files changed, 23 insertions, 5 deletions
diff --git a/rust/tests/binary_view.rs b/rust/tests/binary_view.rs index 65f6b45b..0ee10d87 100644 --- a/rust/tests/binary_view.rs +++ b/rust/tests/binary_view.rs @@ -3,6 +3,7 @@ use binaryninja::headless::Session; use binaryninja::symbol::{SymbolBuilder, SymbolType}; use rstest::*; use std::path::PathBuf; +use binaryninja::main_thread::execute_on_main_thread_and_wait; #[fixture] #[once] @@ -31,6 +32,10 @@ fn test_binary_saving(_session: &Session) { // Verify that we modified the binary let modified_contents = view.read_vec(0x1560, 4); assert_eq!(modified_contents, [0xff, 0xff, 0xff, 0xff]); + + // HACK: To prevent us from deadlocking in save_to_path we wait for all main thread actions to finish. + execute_on_main_thread_and_wait(|| {}); + // Save the modified file assert!(view.save_to_path(out_dir.join("atox.obj.new"))); // Verify that the file exists and is modified. diff --git a/rust/tests/collaboration.rs b/rust/tests/collaboration.rs index 56b357e9..a8c0d52c 100644 --- a/rust/tests/collaboration.rs +++ b/rust/tests/collaboration.rs @@ -6,6 +6,7 @@ use binaryninja::headless::Session; use binaryninja::symbol::{SymbolBuilder, SymbolType}; use rstest::*; use std::path::PathBuf; +use serial_test::serial; #[fixture] #[once] @@ -14,13 +15,21 @@ fn session() -> Session { } // TODO: This cannot run in CI, as headless does not have collaboration, we should gate this. +// TODO: Why cant we create_project for the same project name? why does that fail. -fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, cb: T) { +// TODO: Remote connection / disconnection is NOT thread safe, the core needs to lock on each. +// TODO: Because of this we run these tests serially, this isnt _really_ an issue for real code, as +// TODO: Real code shouldnt be trying to connect to the same remote on multiple threads. + +fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, project_name: &str, cb: T) { if !remote.is_connected() { - remote.connect().expect("Failed to connect to remote"); + // TODO: Because connecting is not thread safe we wont check the error here, this is because we might already + // TODO: be connecting in some other thread and will error out on this thread. But we _probably_ will + // TODO: have connected by the time this errors out. Maybe? + let _ = remote.connect(); } let project = remote - .create_project("Test Project", "Test project for test purposes") + .create_project(project_name, "Test project for test purposes") .expect("Failed to create project"); project.open().expect("Failed to open project"); assert!(project.is_open(), "Project was not opened"); @@ -48,6 +57,7 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, cb: T) { } #[rstest] +#[serial] fn test_connection(_session: &Session) { if !has_collaboration_support() { eprintln!("No collaboration support, skipping test..."); @@ -63,6 +73,7 @@ fn test_connection(_session: &Session) { } #[rstest] +#[serial] fn test_project_creation(_session: &Session) { if !has_collaboration_support() { eprintln!("No collaboration support, skipping test..."); @@ -70,7 +81,7 @@ fn test_project_creation(_session: &Session) { } let remotes = binaryninja::collaboration::known_remotes(); let remote = remotes.iter().next().expect("No known remotes!"); - temp_project_scope(&remote, |project| { + temp_project_scope(&remote, "test_creation", |project| { // Create the file than verify it by opening and checking contents. let created_file = project .create_file( @@ -143,6 +154,7 @@ fn test_project_creation(_session: &Session) { } #[rstest] +#[serial] fn test_project_sync(_session: &Session) { if !has_collaboration_support() { eprintln!("No collaboration support, skipping test..."); @@ -150,7 +162,7 @@ fn test_project_sync(_session: &Session) { } let remotes = binaryninja::collaboration::known_remotes(); let remote = remotes.iter().next().expect("No known remotes!"); - temp_project_scope(&remote, |project| { + temp_project_scope(&remote, "test_sync", |project| { // Open a view so that we can upload it. let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); diff --git a/rust/tests/platform.rs b/rust/tests/platform.rs index c6c861fb..530f97b0 100644 --- a/rust/tests/platform.rs +++ b/rust/tests/platform.rs @@ -15,6 +15,7 @@ fn test_platform_lifetime(_session: &Session) { let platform_1 = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let platform_types_1 = platform_1.types(); assert_eq!(platform_types_0.len(), platform_types_1.len()); + assert_ne!(platform_types_1.len(), 0); } #[rstest] |
