diff options
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/tests/background_task.rs | 22 | ||||
| -rw-r--r-- | rust/tests/base_detection.rs | 12 | ||||
| -rw-r--r-- | rust/tests/binary_reader.rs | 17 | ||||
| -rw-r--r-- | rust/tests/binary_view.rs | 22 | ||||
| -rw-r--r-- | rust/tests/binary_writer.rs | 17 | ||||
| -rw-r--r-- | rust/tests/collaboration.rs | 66 | ||||
| -rw-r--r-- | rust/tests/component.rs | 12 | ||||
| -rw-r--r-- | rust/tests/demangler.rs | 17 | ||||
| -rw-r--r-- | rust/tests/high_level_il.rs | 12 | ||||
| -rw-r--r-- | rust/tests/initialization.rs | 3 | ||||
| -rw-r--r-- | rust/tests/low_level_il.rs | 17 | ||||
| -rw-r--r-- | rust/tests/main_thread.rs | 16 | ||||
| -rw-r--r-- | rust/tests/medium_level_il.rs | 12 | ||||
| -rw-r--r-- | rust/tests/platform.rs | 22 | ||||
| -rw-r--r-- | rust/tests/project.rs | 22 | ||||
| -rw-r--r-- | rust/tests/render_layer.rs | 17 | ||||
| -rw-r--r-- | rust/tests/repository.rs | 11 | ||||
| -rw-r--r-- | rust/tests/secrets_provider.rs | 17 | ||||
| -rw-r--r-- | rust/tests/type_archive.rs | 21 | ||||
| -rw-r--r-- | rust/tests/type_container.rs | 61 | ||||
| -rw-r--r-- | rust/tests/type_parser.rs | 22 | ||||
| -rw-r--r-- | rust/tests/types.rs | 31 | ||||
| -rw-r--r-- | rust/tests/websocket.rs | 17 | ||||
| -rw-r--r-- | rust/tests/worker_thread.rs | 17 | ||||
| -rw-r--r-- | rust/tests/workflow.rs | 17 |
25 files changed, 198 insertions, 322 deletions
diff --git a/rust/tests/background_task.rs b/rust/tests/background_task.rs index d0c329e3..6e0c354b 100644 --- a/rust/tests/background_task.rs +++ b/rust/tests/background_task.rs @@ -1,15 +1,9 @@ use binaryninja::background_task::*; use binaryninja::headless::Session; -use rstest::*; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_background_task_registered(_session: &Session) { +#[test] +fn test_background_task_registered() { + let _session = Session::new().expect("Failed to initialize session"); let task_progress = "test registered"; let task = BackgroundTask::new(task_progress, false); BackgroundTask::running_tasks() @@ -24,8 +18,9 @@ fn test_background_task_registered(_session: &Session) { assert!(!still_running, "Task still running"); } -#[rstest] -fn test_background_task_cancellable(_session: &Session) { +#[test] +fn test_background_task_cancellable() { + let _session = Session::new().expect("Failed to initialize session"); let task_progress = "test cancellable"; let task = BackgroundTask::new(task_progress, false); BackgroundTask::running_tasks() @@ -37,8 +32,9 @@ fn test_background_task_cancellable(_session: &Session) { task.finish(); } -#[rstest] -fn test_background_task_progress(_session: &Session) { +#[test] +fn test_background_task_progress() { + let _session = Session::new().expect("Failed to initialize session"); let task = BackgroundTask::new("test progress", false); let first_progress = task.progress_text().to_string(); assert_eq!(first_progress, "test progress"); diff --git a/rust/tests/base_detection.rs b/rust/tests/base_detection.rs index e4594b8e..e42c6071 100644 --- a/rust/tests/base_detection.rs +++ b/rust/tests/base_detection.rs @@ -1,17 +1,11 @@ use binaryninja::base_detection::{BaseAddressDetectionConfidence, BaseAddressDetectionSettings}; use binaryninja::binary_view::BinaryViewExt; use binaryninja::headless::Session; -use rstest::{fixture, rstest}; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_base_detection(_session: &Session) { +#[test] +fn test_base_detection() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("raw_base_detection_aarch64")) .expect("Failed to create view"); diff --git a/rust/tests/binary_reader.rs b/rust/tests/binary_reader.rs index 592025e0..12be9706 100644 --- a/rust/tests/binary_reader.rs +++ b/rust/tests/binary_reader.rs @@ -1,18 +1,12 @@ use binaryninja::binary_reader::BinaryReader; use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt}; use binaryninja::headless::Session; -use rstest::*; use std::io::{Read, Seek, SeekFrom}; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_binary_reader_seek(_session: &Session) { +#[test] +fn test_binary_reader_seek() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let mut reader = BinaryReader::new(&view); @@ -49,8 +43,9 @@ fn test_binary_reader_seek(_session: &Session) { ); } -#[rstest] -fn test_binary_reader_read(_session: &Session) { +#[test] +fn test_binary_reader_read() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let mut reader = BinaryReader::new(&view); diff --git a/rust/tests/binary_view.rs b/rust/tests/binary_view.rs index 08e530aa..e48d5f52 100644 --- a/rust/tests/binary_view.rs +++ b/rust/tests/binary_view.rs @@ -2,17 +2,11 @@ use binaryninja::binary_view::{AnalysisState, BinaryViewBase, BinaryViewExt}; use binaryninja::headless::Session; use binaryninja::main_thread::execute_on_main_thread_and_wait; use binaryninja::symbol::{SymbolBuilder, SymbolType}; -use rstest::*; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_binary_loading(_session: &Session) { +#[test] +fn test_binary_loading() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); assert!(view.has_initial_analysis(), "No initial analysis"); @@ -21,8 +15,9 @@ fn test_binary_loading(_session: &Session) { assert_eq!(view.file().is_database_backed(), false); } -#[rstest] -fn test_binary_saving(_session: &Session) { +#[test] +fn test_binary_saving() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); // Verify the contents before we modify. @@ -48,8 +43,9 @@ fn test_binary_saving(_session: &Session) { ); } -#[rstest] -fn test_binary_saving_database(_session: &Session) { +#[test] +fn test_binary_saving_database() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); // Update a symbol to verify modification diff --git a/rust/tests/binary_writer.rs b/rust/tests/binary_writer.rs index 632d0e64..1ec12dd3 100644 --- a/rust/tests/binary_writer.rs +++ b/rust/tests/binary_writer.rs @@ -2,18 +2,12 @@ use binaryninja::binary_reader::BinaryReader; use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt}; use binaryninja::binary_writer::BinaryWriter; use binaryninja::headless::Session; -use rstest::*; use std::io::{Read, Seek, SeekFrom, Write}; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_binary_writer_seek(_session: &Session) { +#[test] +fn test_binary_writer_seek() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let mut writer = BinaryWriter::new(&view); @@ -50,8 +44,9 @@ fn test_binary_writer_seek(_session: &Session) { ); } -#[rstest] -fn test_binary_writer_write(_session: &Session) { +#[test] +fn test_binary_writer_write() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let mut reader = BinaryReader::new(&view); diff --git a/rust/tests/collaboration.rs b/rust/tests/collaboration.rs index 19044a82..210492e4 100644 --- a/rust/tests/collaboration.rs +++ b/rust/tests/collaboration.rs @@ -1,22 +1,14 @@ use binaryninja::binary_view::BinaryViewExt; -use binaryninja::collaboration::{ - has_collaboration_support, NoNameChangeset, Remote, RemoteFileType, RemoteProject, -}; +use binaryninja::collaboration::{NoNameChangeset, Remote, RemoteFileType, RemoteProject}; use binaryninja::headless::Session; +use binaryninja::rc::Ref; use binaryninja::symbol::{SymbolBuilder, SymbolType}; use rstest::*; use serial_test::serial; +use std::env; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize 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. - // 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. @@ -28,6 +20,13 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, project_name: &str // TODO: have connected by the time this errors out. Maybe? let _ = remote.connect(); } + + if let Ok(home_dir) = env::var("HOME").or_else(|_| env::var("USERPROFILE")) { + eprintln!("Current user directory: {}", home_dir); + } else { + eprintln!("Unable to determine the current user directory."); + } + let project = remote .create_project(project_name, "Test project for test purposes") .expect("Failed to create project"); @@ -56,15 +55,26 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, project_name: &str .expect("Failed to delete project"); } +/// Get the selected remote to test with. +fn selected_remote() -> Option<Ref<Remote>> { + // If the user has initialized with a enterprise server we might already have an active remote. + match binaryninja::collaboration::active_remote() { + Some(remote) => Some(remote), + None => { + let remotes = binaryninja::collaboration::known_remotes(); + remotes.iter().next().map(|r| r.clone()) + } + } +} + #[rstest] #[serial] -fn test_connection(_session: &Session) { - if !has_collaboration_support() { - eprintln!("No collaboration support, skipping test..."); +fn test_connection() { + let _session = Session::new().expect("Failed to initialize session"); + let Some(remote) = selected_remote() else { + eprintln!("No known remotes, skipping test..."); return; - } - let remotes = binaryninja::collaboration::known_remotes(); - let remote = remotes.iter().next().expect("No known remotes!"); + }; assert!(remote.connect().is_ok(), "Failed to connect to remote"); remote .disconnect() @@ -74,13 +84,12 @@ fn test_connection(_session: &Session) { #[rstest] #[serial] -fn test_project_creation(_session: &Session) { - if !has_collaboration_support() { - eprintln!("No collaboration support, skipping test..."); +fn test_project_creation() { + let _session = Session::new().expect("Failed to initialize session"); + let Some(remote) = selected_remote() else { + eprintln!("No known remotes, skipping test..."); return; - } - let remotes = binaryninja::collaboration::known_remotes(); - let remote = remotes.iter().next().expect("No known remotes!"); + }; temp_project_scope(&remote, "test_creation", |project| { // Create the file than verify it by opening and checking contents. let created_file = project @@ -155,13 +164,12 @@ fn test_project_creation(_session: &Session) { #[rstest] #[serial] -fn test_project_sync(_session: &Session) { - if !has_collaboration_support() { - eprintln!("No collaboration support, skipping test..."); +fn test_project_sync() { + let _session = Session::new().expect("Failed to initialize session"); + let Some(remote) = selected_remote() else { + eprintln!("No known remotes, skipping test..."); return; - } - let remotes = binaryninja::collaboration::known_remotes(); - let remote = remotes.iter().next().expect("No known remotes!"); + }; 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(); diff --git a/rust/tests/component.rs b/rust/tests/component.rs index c57785ce..3341f0d7 100644 --- a/rust/tests/component.rs +++ b/rust/tests/component.rs @@ -1,17 +1,11 @@ use binaryninja::binary_view::BinaryViewExt; use binaryninja::component::ComponentBuilder; use binaryninja::headless::Session; -use rstest::*; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_component_creation(_session: &Session) { +#[test] +fn test_component_creation() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let component = ComponentBuilder::new(view.clone()).name("test").finalize(); diff --git a/rust/tests/demangler.rs b/rust/tests/demangler.rs index da57f67e..3c1d0216 100644 --- a/rust/tests/demangler.rs +++ b/rust/tests/demangler.rs @@ -6,16 +6,10 @@ use binaryninja::demangle::{ use binaryninja::headless::Session; use binaryninja::rc::Ref; use binaryninja::types::{QualifiedName, Type}; -use rstest::*; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_demangler_simple(_session: &Session) { +#[test] +fn test_demangler_simple() { + let _session = Session::new().expect("Failed to initialize session"); let placeholder_arch = CoreArchitecture::by_name("x86").expect("x86 exists"); // Example LLVM-style mangled name let llvm_mangled = "_Z3fooi"; // "foo(int)" in LLVM mangling @@ -45,8 +39,9 @@ fn test_demangler_simple(_session: &Session) { ); } -#[rstest] -fn test_custom_demangler(_session: &Session) { +#[test] +fn test_custom_demangler() { + let _session = Session::new().expect("Failed to initialize session"); struct TestDemangler; impl CustomDemangler for TestDemangler { diff --git a/rust/tests/high_level_il.rs b/rust/tests/high_level_il.rs index bec1d67c..4466678c 100644 --- a/rust/tests/high_level_il.rs +++ b/rust/tests/high_level_il.rs @@ -1,17 +1,11 @@ use binaryninja::binary_view::BinaryViewExt; use binaryninja::headless::Session; use binaryninja::high_level_il::{HighLevelILInstructionKind, HighLevelInstructionIndex}; -use rstest::*; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_hlil_info(_session: &Session) { +#[test] +fn test_hlil_info() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let image_base = view.original_image_base(); diff --git a/rust/tests/initialization.rs b/rust/tests/initialization.rs index cfbdbdc3..9847a734 100644 --- a/rust/tests/initialization.rs +++ b/rust/tests/initialization.rs @@ -5,12 +5,11 @@ use binaryninja::headless::{ init, init_with_opts, shutdown, InitializationError, InitializationOptions, }; use binaryninja::set_license; -use rstest::rstest; // NOTE: Do not add any tests here, behavior will change (i.e. a failure might pass) if we initialize // NOTE: The core in another test. The only test here should be `test_license_validation`. -#[rstest] +#[test] fn test_license_validation() { // Release floating license if we already have one, otherwise the failure will succeed. release_license(); diff --git a/rust/tests/low_level_il.rs b/rust/tests/low_level_il.rs index 6131de0b..b9d7d203 100644 --- a/rust/tests/low_level_il.rs +++ b/rust/tests/low_level_il.rs @@ -8,17 +8,11 @@ use binaryninja::low_level_il::instruction::{ InstructionHandler, LowLevelILInstructionKind, LowLevelInstructionIndex, }; use binaryninja::low_level_il::{LowLevelILRegister, VisitorAction}; -use rstest::*; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_llil_info(_session: &Session) { +#[test] +fn test_llil_info() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let image_base = view.original_image_base(); @@ -170,8 +164,9 @@ fn test_llil_info(_session: &Session) { } } -#[rstest] -fn test_llil_visitor(_session: &Session) { +#[test] +fn test_llil_visitor() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let image_base = view.original_image_base(); diff --git a/rust/tests/main_thread.rs b/rust/tests/main_thread.rs index f74414d5..a42157a9 100644 --- a/rust/tests/main_thread.rs +++ b/rust/tests/main_thread.rs @@ -1,22 +1,16 @@ use binaryninja::headless::Session; -use rstest::*; // TODO: Add a test for MainThreadHandler -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_not_main_thread(_session: &Session) { +#[test] +fn test_not_main_thread() { // We should never be the main thread. assert!(!binaryninja::is_main_thread()) } -#[rstest] -fn test_main_thread_different(_session: &Session) { +#[test] +fn test_main_thread_different() { + let _session = Session::new().expect("Failed to initialize session"); let calling_thread = std::thread::current(); binaryninja::main_thread::execute_on_main_thread_and_wait(move || { let main_thread = std::thread::current(); diff --git a/rust/tests/medium_level_il.rs b/rust/tests/medium_level_il.rs index 65746186..544076cc 100644 --- a/rust/tests/medium_level_il.rs +++ b/rust/tests/medium_level_il.rs @@ -1,17 +1,11 @@ use binaryninja::binary_view::BinaryViewExt; use binaryninja::headless::Session; use binaryninja::medium_level_il::{MediumLevelILInstructionKind, MediumLevelInstructionIndex}; -use rstest::*; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_mlil_info(_session: &Session) { +#[test] +fn test_mlil_info() { + let _session = Session::new().expect("Failed to initialize session"); let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); let image_base = view.original_image_base(); diff --git a/rust/tests/platform.rs b/rust/tests/platform.rs index 530f97b0..36a04d7f 100644 --- a/rust/tests/platform.rs +++ b/rust/tests/platform.rs @@ -1,15 +1,9 @@ use binaryninja::headless::Session; use binaryninja::platform::Platform; -use rstest::*; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_platform_lifetime(_session: &Session) { +#[test] +fn test_platform_lifetime() { + let _session = Session::new().expect("Failed to initialize session"); let platform_0 = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let platform_types_0 = platform_0.types(); let platform_1 = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); @@ -18,16 +12,18 @@ fn test_platform_lifetime(_session: &Session) { assert_ne!(platform_types_1.len(), 0); } -#[rstest] -fn test_platform_types(_session: &Session) { +#[test] +fn test_platform_types() { + let _session = Session::new().expect("Failed to initialize session"); let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let platform_types = platform.types(); // windows-x86_64 has a few thousand, not zero. assert_ne!(platform_types.len(), 0); } -#[rstest] -fn test_platform_calling_conventions(_session: &Session) { +#[test] +fn test_platform_calling_conventions() { + let _session = Session::new().expect("Failed to initialize session"); let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); assert_eq!(platform.calling_conventions().len(), 1); } diff --git a/rust/tests/project.rs b/rust/tests/project.rs index cc41c11e..f7d49bad 100644 --- a/rust/tests/project.rs +++ b/rust/tests/project.rs @@ -2,23 +2,17 @@ use binaryninja::headless::Session; use binaryninja::metadata::Metadata; use binaryninja::project::Project; use binaryninja::rc::Ref; -use rstest::*; use std::time::SystemTime; // TODO: We should use tempdir to manage the project directory. -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - fn unique_project(name: &str) -> String { format!("{}/{}", std::env::temp_dir().to_str().unwrap(), name) } -#[rstest] -fn create_delete_empty(_session: &Session) { +#[test] +fn create_delete_empty() { + let _session = Session::new().expect("Failed to initialize session"); use std::fs::canonicalize; let project_name = "create_delete_empty_project"; @@ -46,8 +40,9 @@ fn create_delete_empty(_session: &Session) { std::fs::remove_dir_all(project_path).unwrap(); } -#[rstest] -fn create_close_open_close(_session: &Session) { +#[test] +fn create_close_open_close() { + let _session = Session::new().expect("Failed to initialize session"); let project_name = "create_close_open_close"; let project_path = unique_project(project_name); // create the project @@ -74,8 +69,9 @@ fn create_close_open_close(_session: &Session) { std::fs::remove_dir_all(project_path).unwrap(); } -#[rstest] -fn modify_project(_session: &Session) { +#[test] +fn modify_project() { + let _session = Session::new().expect("Failed to initialize session"); let project_name = "modify_project_project"; let project_path = unique_project(project_name); // create the project diff --git a/rust/tests/render_layer.rs b/rust/tests/render_layer.rs index 184467b7..05ea17f6 100644 --- a/rust/tests/render_layer.rs +++ b/rust/tests/render_layer.rs @@ -5,25 +5,20 @@ use binaryninja::function::NativeBlock; use binaryninja::headless::Session; use binaryninja::linear_view::LinearViewObject; use binaryninja::render_layer::{register_render_layer, CoreRenderLayer, RenderLayer}; -use rstest::{fixture, rstest}; use std::path::PathBuf; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_render_layer_register(_session: &Session) { +#[test] +fn test_render_layer_register() { + let _session = Session::new().expect("Failed to initialize session"); struct EmptyRenderLayer; impl RenderLayer for EmptyRenderLayer {} register_render_layer("Test Render Layer", EmptyRenderLayer, Default::default()); CoreRenderLayer::render_layer_by_name("Test Render Layer").expect("Failed to get render layer"); } -#[rstest] -fn test_render_layer_linear_view(_session: &Session) { +#[test] +fn test_render_layer_linear_view() { + let _session = Session::new().expect("Failed to initialize session"); 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/repository.rs b/rust/tests/repository.rs index 6047bcae..b1efee11 100644 --- a/rust/tests/repository.rs +++ b/rust/tests/repository.rs @@ -1,14 +1,9 @@ use binaryninja::headless::Session; use binaryninja::repository::RepositoryManager; -use rstest::*; -#[fixture] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_list(_session: Session) { +#[test] +fn test_list() { + let _session = Session::new().expect("Failed to initialize session"); let manager = RepositoryManager::default(); let repositories = manager.repositories(); for repository in &repositories { diff --git a/rust/tests/secrets_provider.rs b/rust/tests/secrets_provider.rs index 46ee7d18..6ea59773 100644 --- a/rust/tests/secrets_provider.rs +++ b/rust/tests/secrets_provider.rs @@ -1,15 +1,9 @@ use binaryninja::headless::Session; use binaryninja::secrets_provider::{CoreSecretsProvider, SecretsProvider}; -use rstest::*; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn list_secrets_provider(_session: &Session) { +#[test] +fn list_secrets_provider() { + let _session = Session::new().expect("Failed to initialize session"); let providers = CoreSecretsProvider::all(); assert!(providers.len() > 0); let providers_again = CoreSecretsProvider::all(); @@ -36,8 +30,9 @@ impl SecretsProvider for MySecretsProvider { } } -#[rstest] -fn custom_secrets_provider(_session: &Session) { +#[test] +fn custom_secrets_provider() { + let _session = Session::new().expect("Failed to initialize session"); let my_provider = CoreSecretsProvider::new("MySecretsProvider", MySecretsProvider {}); assert!(my_provider.has_data("my_key")); assert!(!my_provider.has_data("not_my_key")); diff --git a/rust/tests/type_archive.rs b/rust/tests/type_archive.rs index dafb7178..38d0b758 100644 --- a/rust/tests/type_archive.rs +++ b/rust/tests/type_archive.rs @@ -1,25 +1,10 @@ -use binaryninja::binary_view::BinaryView; -use binaryninja::file_metadata::FileMetadata; use binaryninja::headless::Session; use binaryninja::platform::Platform; -use binaryninja::rc::Ref; use binaryninja::type_archive::TypeArchive; -use rstest::*; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[fixture] -#[once] -fn empty_view() -> Ref<BinaryView> { - BinaryView::from_data(&FileMetadata::new(), &[]).expect("Failed to create view") -} - -#[rstest] -fn test_create_archive(_session: &Session) { +#[test] +fn test_create_archive() { + let _session = Session::new().expect("Failed to initialize session"); let placeholder_platform = Platform::by_name("x86_64").expect("Failed to get platform"); let temp_dir = tempfile::tempdir().unwrap(); diff --git a/rust/tests/type_container.rs b/rust/tests/type_container.rs index d5a72031..4a017541 100644 --- a/rust/tests/type_container.rs +++ b/rust/tests/type_container.rs @@ -2,40 +2,22 @@ use binaryninja::binary_view::{BinaryView, BinaryViewExt}; use binaryninja::file_metadata::FileMetadata; use binaryninja::headless::Session; use binaryninja::platform::Platform; -use binaryninja::rc::Ref; use binaryninja::types::Type; -use rstest::*; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[fixture] -#[once] -fn platform() -> Ref<Platform> { - // TODO: Because some behavior might be platform specific we might need to move this back into each test. - // TODO: See test_parse_type - Platform::by_name("windows-x86_64").expect("windows-x86_64 exists") -} - -#[fixture] -#[once] -fn empty_view() -> Ref<BinaryView> { - BinaryView::from_data(&FileMetadata::new(), &[]).expect("Failed to create view") -} - -#[rstest] -fn test_types(_session: &Session, platform: &Platform) { +#[test] +fn test_types() { + let _session = Session::new().expect("Failed to initialize session"); + let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let type_container = platform.type_container(); let types = type_container.types().unwrap(); // windows-x86_64 has a few thousand, not zero. assert_eq!(types.len(), platform.types().len()); } -#[rstest] -fn test_type_id(_session: &Session, platform: &Platform) { +#[test] +fn test_type_id() { + let _session = Session::new().expect("Failed to initialize session"); + let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let type_container = platform.type_container(); let type_ids = type_container.type_ids().unwrap(); let first_type_id = type_ids.iter().next().unwrap(); @@ -52,8 +34,11 @@ fn test_type_id(_session: &Session, platform: &Platform) { assert_eq!(found_type, found_type_for_type_name); } -#[rstest] -fn test_add_delete_type(_session: &Session, empty_view: &BinaryView) { +#[test] +fn test_add_delete_type() { + let _session = Session::new().expect("Failed to initialize session"); + let empty_view = + BinaryView::from_data(&FileMetadata::new(), &[]).expect("Failed to create view"); let view_type_container = empty_view.type_container(); let test_type = Type::int(4, true); assert!( @@ -71,8 +56,10 @@ fn test_add_delete_type(_session: &Session, empty_view: &BinaryView) { assert_eq!(view_type_container.type_ids().unwrap().len(), 0) } -#[rstest] -fn test_immutable_container(_session: &Session, platform: &Platform) { +#[test] +fn test_immutable_container() { + let _session = Session::new().expect("Failed to initialize session"); + let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); // Platform type containers are immutable, so we shouldn't be able to delete/add/rename types. let plat_type_container = platform.type_container(); assert!( @@ -101,8 +88,10 @@ fn test_immutable_container(_session: &Session, platform: &Platform) { ); } -#[rstest] -fn test_parse_type(_session: &Session, platform: &Platform) { +#[test] +fn test_parse_type() { + let _session = Session::new().expect("Failed to initialize session"); + let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let type_container = platform.type_container(); // HANDLE will be pulled in from the platform, which is `windows-x86_64`. let parsed_type = type_container @@ -113,8 +102,12 @@ fn test_parse_type(_session: &Session, platform: &Platform) { assert_eq!(parsed_type.ty.to_string(), "HANDLE"); } -#[rstest] -fn test_container_lifetime(_session: &Session, platform: &Platform, empty_view: &BinaryView) { +#[test] +fn test_container_lifetime() { + let _session = Session::new().expect("Failed to initialize session"); + let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); + let empty_view = + BinaryView::from_data(&FileMetadata::new(), &[]).expect("Failed to create view"); let plat_type_container_dropped = platform.type_container(); let view_type_container_dropped = empty_view.type_container(); let _plat_types_dropped = plat_type_container_dropped.types(); diff --git a/rust/tests/type_parser.rs b/rust/tests/type_parser.rs index 5726fb0a..d08e7791 100644 --- a/rust/tests/type_parser.rs +++ b/rust/tests/type_parser.rs @@ -3,7 +3,6 @@ use binaryninja::platform::Platform; use binaryninja::type_parser::{CoreTypeParser, TypeParser, TypeParserError}; use binaryninja::types::Type; use binaryninjacore_sys::BNTypeParserErrorSeverity::ErrorSeverity; -use rstest::*; const TEST_TYPES: &str = r#" typedef int int32_t; @@ -27,14 +26,9 @@ typedef struct { } struct_type; "#; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[rstest] -fn test_string_to_type(_session: &Session) { +#[test] +fn test_string_to_type() { + let _session = Session::new().expect("Failed to initialize session"); let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let plat_type_container = platform.type_container(); let parser = CoreTypeParser::default(); @@ -45,8 +39,9 @@ fn test_string_to_type(_session: &Session) { assert_eq!(test_type, parsed_type.ty); } -#[rstest] -fn test_string_to_types(_session: &Session) { +#[test] +fn test_string_to_types() { + let _session = Session::new().expect("Failed to initialize session"); let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let plat_type_container = platform.type_container(); let parser = CoreTypeParser::default(); @@ -64,8 +59,9 @@ fn test_string_to_types(_session: &Session) { assert_eq!(14, parsed_type.types.len()); } -#[rstest] -fn test_parse_error(_session: &Session) { +#[test] +fn test_parse_error() { + let _session = Session::new().expect("Failed to initialize session"); let platform = Platform::by_name("windows-x86_64").expect("windows-x86_64 exists"); let plat_type_container = platform.type_container(); let parser = CoreTypeParser::default(); diff --git a/rust/tests/types.rs b/rust/tests/types.rs index 63e9542b..4ed4caf7 100644 --- a/rust/tests/types.rs +++ b/rust/tests/types.rs @@ -3,24 +3,11 @@ use binaryninja::confidence::Conf; use binaryninja::file_metadata::FileMetadata; use binaryninja::headless::Session; use binaryninja::platform::Platform; -use binaryninja::rc::Ref; use binaryninja::types::{MemberAccess, MemberScope, StructureBuilder, StructureMember, Type}; -use rstest::*; -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} - -#[fixture] -#[once] -fn empty_view() -> Ref<BinaryView> { - BinaryView::from_data(&FileMetadata::new(), &[]).expect("Failed to create view") -} - -#[rstest] -fn test_type_to_string(_session: &Session) { +#[test] +fn test_type_to_string() { + let _session = Session::new().expect("Failed to initialize session"); let test_type = Type::int(4, true); assert_eq!(test_type.to_string(), "int32_t".to_string()); @@ -33,8 +20,9 @@ fn test_type_to_string(_session: &Session) { assert_eq!(test_fn_type.to_string(), "int32_t()"); } -#[rstest] -fn test_structure_builder(_session: &Session) { +#[test] +fn test_structure_builder() { + let _session = Session::new().expect("Failed to initialize session"); let mut builder = StructureBuilder::new(); builder.insert( &Type::int(4, true), @@ -68,8 +56,11 @@ fn test_structure_builder(_session: &Session) { ); } -#[rstest] -fn add_type_to_view(_session: &Session, empty_view: &BinaryView) { +#[test] +fn add_type_to_view() { + let _session = Session::new().expect("Failed to initialize session"); + let empty_view = + BinaryView::from_data(&FileMetadata::new(), &[]).expect("Failed to create view"); let test_type = Type::int(4, true); empty_view.define_auto_type("test", "me", &test_type); assert!(empty_view.type_by_name("test").is_some()); diff --git a/rust/tests/websocket.rs b/rust/tests/websocket.rs index 9feb9381..97a4ae2b 100644 --- a/rust/tests/websocket.rs +++ b/rust/tests/websocket.rs @@ -5,13 +5,6 @@ use binaryninja::websocket::{ register_websocket_provider, CoreWebsocketClient, CoreWebsocketProvider, WebsocketClient, WebsocketClientCallback, WebsocketProvider, }; -use rstest::*; - -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} struct MyWebsocketProvider { core: CoreWebsocketProvider, @@ -90,8 +83,9 @@ impl WebsocketClientCallback for MyClientCallbacks { } } -#[rstest] -fn reg_websocket_provider(_session: &Session) { +#[test] +fn reg_websocket_provider() { + let _session = Session::new().expect("Failed to initialize session"); let provider = register_websocket_provider::<MyWebsocketProvider>("RustWebsocketProvider"); let client = provider.create_client().unwrap(); let mut callback = MyClientCallbacks::default(); @@ -99,8 +93,9 @@ fn reg_websocket_provider(_session: &Session) { assert!(success, "Failed to initialize connection!"); } -#[rstest] -fn listen_websocket_provider(_session: &Session) { +#[test] +fn listen_websocket_provider() { + let _session = Session::new().expect("Failed to initialize session"); let provider = register_websocket_provider::<MyWebsocketProvider>("RustWebsocketProvider2"); let client = provider.create_client().unwrap(); diff --git a/rust/tests/worker_thread.rs b/rust/tests/worker_thread.rs index 666e85ba..1d30c13a 100644 --- a/rust/tests/worker_thread.rs +++ b/rust/tests/worker_thread.rs @@ -1,15 +1,9 @@ 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) { +#[test] +fn test_setting_worker_thread() { + let _session = Session::new().expect("Failed to initialize session"); let original_count = binaryninja::worker_thread::worker_thread_count(); binaryninja::worker_thread::set_worker_thread_count(original_count - 1); assert_eq!( @@ -23,8 +17,9 @@ fn test_setting_worker_thread(_session: &Session) { ); } -#[rstest] -fn test_worker_thread_different(_session: &Session) { +#[test] +fn test_worker_thread_different() { + let _session = Session::new().expect("Failed to initialize session"); let calling_thread = std::thread::current(); // We need both (2) threads to synchronize diff --git a/rust/tests/workflow.rs b/rust/tests/workflow.rs index fcede59c..148d66fd 100644 --- a/rust/tests/workflow.rs +++ b/rust/tests/workflow.rs @@ -1,19 +1,13 @@ use binaryninja::headless::Session; use binaryninja::settings::Settings; use binaryninja::workflow::Workflow; -use rstest::*; - -#[fixture] -#[once] -fn session() -> Session { - Session::new().expect("Failed to initialize session") -} // TODO: Test running a workflow activity // TODO: Test activity insertion and removal -#[rstest] -fn test_workflow_clone(_session: &Session) { +#[test] +fn test_workflow_clone() { + let _session = Session::new().expect("Failed to initialize session"); let original_workflow = Workflow::new("core.function.baseAnalysis"); let mut cloned_workflow = original_workflow.clone("clone_workflow"); @@ -30,8 +24,9 @@ fn test_workflow_clone(_session: &Session) { ); } -#[rstest] -fn test_workflow_registration(_session: &Session) { +#[test] +fn test_workflow_registration() { + let _session = Session::new().expect("Failed to initialize session"); // Validate NULL workflows cannot be registered let workflow = Workflow::new("null"); assert_eq!(workflow.name().as_str(), "null"); |
