Skip to content

Commit

Permalink
move test fn into its own mod (solana-labs#24212)
Browse files Browse the repository at this point in the history
* move test fn into its own mod

* pub
  • Loading branch information
HaoranYi authored Apr 12, 2022
1 parent 4740806 commit 605036c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
5 changes: 4 additions & 1 deletion accounts-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use {
rayon::prelude::*,
solana_measure::measure::Measure,
solana_runtime::{
accounts::{create_test_accounts, update_accounts_bench, Accounts},
accounts::{
test_utils::{create_test_accounts, update_accounts_bench},
Accounts,
},
accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
Expand Down
2 changes: 1 addition & 1 deletion runtime/benches/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
rand::Rng,
rayon::iter::{IntoParallelRefIterator, ParallelIterator},
solana_runtime::{
accounts::{create_test_accounts, AccountAddressFilter, Accounts},
accounts::{test_utils::create_test_accounts, AccountAddressFilter, Accounts},
accounts_db::AccountShrinkThreshold,
accounts_index::{AccountSecondaryIndexes, ScanConfig},
ancestors::Ancestors,
Expand Down
45 changes: 25 additions & 20 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,28 +1311,33 @@ pub fn prepare_if_nonce_account<'a>(
}
}

pub fn create_test_accounts(
accounts: &Accounts,
pubkeys: &mut Vec<Pubkey>,
num: usize,
slot: Slot,
) {
for t in 0..num {
let pubkey = solana_sdk::pubkey::new_rand();
let account =
AccountSharedData::new((t + 1) as u64, 0, AccountSharedData::default().owner());
accounts.store_slow_uncached(slot, &pubkey, &account);
pubkeys.push(pubkey);
/// A set of utility functions used for testing and benchmarking
pub mod test_utils {
use super::*;

pub fn create_test_accounts(
accounts: &Accounts,
pubkeys: &mut Vec<Pubkey>,
num: usize,
slot: Slot,
) {
for t in 0..num {
let pubkey = solana_sdk::pubkey::new_rand();
let account =
AccountSharedData::new((t + 1) as u64, 0, AccountSharedData::default().owner());
accounts.store_slow_uncached(slot, &pubkey, &account);
pubkeys.push(pubkey);
}
}
}

// Only used by bench, not safe to call otherwise accounts can conflict with the
// accounts cache!
pub fn update_accounts_bench(accounts: &Accounts, pubkeys: &[Pubkey], slot: u64) {
for pubkey in pubkeys {
let amount = thread_rng().gen_range(0, 10);
let account = AccountSharedData::new(amount, 0, AccountSharedData::default().owner());
accounts.store_slow_uncached(slot, pubkey, &account);
// Only used by bench, not safe to call otherwise accounts can conflict with the
// accounts cache!
pub fn update_accounts_bench(accounts: &Accounts, pubkeys: &[Pubkey], slot: u64) {
for pubkey in pubkeys {
let amount = thread_rng().gen_range(0, 10);
let account = AccountSharedData::new(amount, 0, AccountSharedData::default().owner());
accounts.store_slow_uncached(slot, pubkey, &account);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use {
super::*,
crate::{
accounts::{create_test_accounts, Accounts},
accounts::{test_utils::create_test_accounts, Accounts},
accounts_db::{get_temp_accounts_paths, AccountShrinkThreshold},
bank::{Bank, StatusCacheRc},
hardened_unpack::UnpackedAppendVecMap,
Expand Down

0 comments on commit 605036c

Please sign in to comment.