Skip to content

Commit

Permalink
Fix concurrency in libcasr tests (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
anfedotoff authored Dec 9, 2023
1 parent 47adf77 commit d7a82a3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions libcasr/src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl ParseStacktrace for JsStacktrace {
#[cfg(test)]
mod tests {
use super::*;
use crate::{init_ignored_frames, stacktrace::CrashLineExt, stacktrace::Filter};
use crate::stacktrace::{tests::safe_init_ignore_stack_frames, CrashLineExt, Filter};

#[test]
fn test_js_stacktrace() {
Expand Down Expand Up @@ -310,7 +310,7 @@ Uncaught ReferenceError: var is not defined
}
let mut stacktrace = sttr.unwrap();

init_ignored_frames!("js");
safe_init_ignore_stack_frames();
stacktrace.filter();

// Check crashline
Expand Down
9 changes: 3 additions & 6 deletions libcasr/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,7 @@ pub fn cluster_reports(casreps: &[CrashReport]) -> Result<Vec<usize>> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
init_ignored_frames,
stacktrace::{Filter, Stacktrace},
};
use crate::stacktrace::tests::safe_init_ignore_stack_frames;

#[test]
fn test_report_display() {
Expand Down Expand Up @@ -962,7 +959,7 @@ mod tests {
];

// Init ignored frames for correct filtering
init_ignored_frames!("cpp");
safe_init_ignore_stack_frames();

let res = dedup_reports(&[report.clone(), report.clone()]);
let Ok(res) = res else {
Expand All @@ -986,7 +983,7 @@ mod tests {
];

// Init ignored frames for correct filtering
init_ignored_frames!("cpp");
safe_init_ignore_stack_frames();

let res = cluster_reports(&[report.clone(), report.clone()]);
let Ok(res) = res else {
Expand Down
7 changes: 2 additions & 5 deletions libcasr/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ impl ParseStacktrace for RustStacktrace {
mod tests {

use super::*;
use crate::{
init_ignored_frames,
stacktrace::{Filter, Stacktrace},
};
use crate::stacktrace::{tests::safe_init_ignore_stack_frames, Filter};

#[test]
fn test_rust_parse_stacktrace() {
Expand Down Expand Up @@ -267,7 +264,7 @@ SUMMARY: libFuzzer: deadly signal"#;
assert_eq!(bt, trace);

let mut stacktrace = RustStacktrace::parse_stacktrace(&bt).unwrap();
init_ignored_frames!("rust");
safe_init_ignore_stack_frames();
stacktrace.filter();

assert_eq!(stacktrace[0].address, 0x557e259648d8);
Expand Down
17 changes: 16 additions & 1 deletion libcasr/src/stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,24 @@ fn get_interval_repetitions<T: PartialEq>(arr: &[T]) -> Vec<bool> {
}

#[cfg(test)]
mod tests {
pub mod tests {
use std::sync::RwLock;

use crate::stacktrace::*;

lazy_static::lazy_static! {
static ref INITED_STACKFRAMES_FILTER: RwLock<bool> = RwLock::new(false);
}

/// Thread-safe initialization of all stackframe filters
pub fn safe_init_ignore_stack_frames() {
let mut is_inited = INITED_STACKFRAMES_FILTER.write().unwrap();
if !*is_inited {
*is_inited = true;
init_ignored_frames!("cpp", "rust", "python", "go", "java", "js");
}
}

#[test]
fn test_main_lorentz() {
let tests = [
Expand Down

0 comments on commit d7a82a3

Please sign in to comment.