-
Notifications
You must be signed in to change notification settings - Fork 402
Make debug_sync
regex more robust
#1944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TheBlueMatt
merged 4 commits into
lightningdevkit:main
from
TheBlueMatt:2022-01-lockorder-windows-robust
Jan 10, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f66f720
Move `no-std` sync implementations to a folder to clean up
TheBlueMatt 558bfa3
Move `debug_sync` to the new `sync` folder
TheBlueMatt 230331f
Move tests from debug_sync to a new submodule
TheBlueMatt ab46f6b
Make `debug_sync` regex more robust
TheBlueMatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))] | ||
mod debug_sync; | ||
#[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))] | ||
pub use debug_sync::*; | ||
#[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))] | ||
// Note that to make debug_sync's regex work this must not contain `debug_string` in the module name | ||
mod test_lockorder_checks; | ||
|
||
#[cfg(all(feature = "std", any(feature = "_bench_unstable", not(test))))] | ||
pub use ::std::sync::{Arc, Mutex, Condvar, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; | ||
#[cfg(all(feature = "std", any(feature = "_bench_unstable", not(test))))] | ||
pub use crate::util::fairrwlock::FairRwLock; | ||
|
||
#[cfg(not(feature = "std"))] | ||
mod nostd_sync; | ||
#[cfg(not(feature = "std"))] | ||
pub use nostd_sync::*; |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use crate::sync::debug_sync::{RwLock, Mutex}; | ||
|
||
#[test] | ||
#[should_panic] | ||
#[cfg(not(feature = "backtrace"))] | ||
fn recursive_lock_fail() { | ||
let mutex = Mutex::new(()); | ||
let _a = mutex.lock().unwrap(); | ||
let _b = mutex.lock().unwrap(); | ||
} | ||
|
||
#[test] | ||
fn recursive_read() { | ||
let lock = RwLock::new(()); | ||
let _a = lock.read().unwrap(); | ||
let _b = lock.read().unwrap(); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn lockorder_fail() { | ||
let a = Mutex::new(()); | ||
let b = Mutex::new(()); | ||
{ | ||
let _a = a.lock().unwrap(); | ||
let _b = b.lock().unwrap(); | ||
} | ||
{ | ||
let _b = b.lock().unwrap(); | ||
let _a = a.lock().unwrap(); | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn write_lockorder_fail() { | ||
let a = RwLock::new(()); | ||
let b = RwLock::new(()); | ||
{ | ||
let _a = a.write().unwrap(); | ||
let _b = b.write().unwrap(); | ||
} | ||
{ | ||
let _b = b.write().unwrap(); | ||
let _a = a.write().unwrap(); | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn read_lockorder_fail() { | ||
let a = RwLock::new(()); | ||
let b = RwLock::new(()); | ||
{ | ||
let _a = a.read().unwrap(); | ||
let _b = b.read().unwrap(); | ||
} | ||
{ | ||
let _b = b.read().unwrap(); | ||
let _a = a.read().unwrap(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn read_recursive_no_lockorder() { | ||
// Like the above, but note that no lockorder is implied when we recursively read-lock a | ||
// RwLock, causing this to pass just fine. | ||
let a = RwLock::new(()); | ||
let b = RwLock::new(()); | ||
let _outer = a.read().unwrap(); | ||
{ | ||
let _a = a.read().unwrap(); | ||
let _b = b.read().unwrap(); | ||
} | ||
{ | ||
let _b = b.read().unwrap(); | ||
let _a = a.read().unwrap(); | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn read_write_lockorder_fail() { | ||
let a = RwLock::new(()); | ||
let b = RwLock::new(()); | ||
{ | ||
let _a = a.write().unwrap(); | ||
let _b = b.read().unwrap(); | ||
} | ||
{ | ||
let _b = b.read().unwrap(); | ||
let _a = a.write().unwrap(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a trailing
.*
to match the locks type (andnew
when it is not truncated)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so,
is_match
"Returns true if and only if there is a match for the regex in the string given." ie not if the match is the string but if there is a match in the string.