Skip to content

Use test_assert for debug_asserts that are used for failing tests #5318

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! Otherwise, an ancient append vec is the same as any other append vec
use {
crate::{
test_assert,
account_storage::ShrinkInProgress,
accounts_db::{
stats::{ShrinkAncientStats, ShrinkStatsSub},
Expand Down Expand Up @@ -1199,7 +1200,7 @@ pub fn is_ancient(storage: &AccountsFile) -> bool {
/// Debug builds check this invariant, and will panic if broken.
fn div_ceil(x: u64, y: NonZeroU64) -> u64 {
let y = y.get();
debug_assert!(
test_assert!(
x.checked_add(y).is_some(),
"x + y must not overflow! x: {x}, y: {y}",
);
Expand Down
13 changes: 8 additions & 5 deletions accounts-db/src/tiered_storage/index.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use {
crate::tiered_storage::{
crate::{
test_assert,
tiered_storage::{
file::TieredWritableFile, footer::TieredStorageFooter, mmap_utils::get_pod,
TieredStorageResult,
},
},
bytemuck::{Pod, Zeroable},
memmap2::Mmap,
Expand Down Expand Up @@ -85,13 +88,13 @@ impl IndexBlockFormat {
) -> TieredStorageResult<&'a Pubkey> {
let offset = match self {
Self::AddressesThenOffsets => {
debug_assert!(index_offset.0 < footer.account_entry_count);
test_assert!(index_offset.0 < footer.account_entry_count);
footer.index_block_offset as usize
+ std::mem::size_of::<Pubkey>() * (index_offset.0 as usize)
}
};

debug_assert!(
test_assert!(
offset.saturating_add(std::mem::size_of::<Pubkey>())
<= footer.owners_block_offset as usize,
"reading IndexOffset ({}) would exceed index block boundary ({}).",
Expand All @@ -112,14 +115,14 @@ impl IndexBlockFormat {
) -> TieredStorageResult<Offset> {
let offset = match self {
Self::AddressesThenOffsets => {
debug_assert!(index_offset.0 < footer.account_entry_count);
test_assert!(index_offset.0 < footer.account_entry_count);
footer.index_block_offset as usize
+ std::mem::size_of::<Pubkey>() * footer.account_entry_count as usize
+ std::mem::size_of::<Offset>() * index_offset.0 as usize
}
};

debug_assert!(
test_assert!(
offset.saturating_add(std::mem::size_of::<Offset>())
<= footer.owners_block_offset as usize,
"reading IndexOffset ({}) would exceed index block boundary ({}).",
Expand Down
8 changes: 8 additions & 0 deletions accounts-db/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ use {
pub const ACCOUNTS_RUN_DIR: &str = "run";
pub const ACCOUNTS_SNAPSHOT_DIR: &str = "snapshot";

#[macro_export]
macro_rules! test_assert {
($($tt: tt)*) => {
#[cfg(test)]
assert!($($tt)*)
}
}

/// For all account_paths, create the run/ and snapshot/ sub directories.
/// If an account_path directory does not exist, create it.
/// It returns (account_run_paths, account_snapshot_paths) or error
Expand Down
Loading