corevm_memory_test_common/
lib.rs

1#![no_std]
2
3extern crate alloc;
4
5// Re-export `rand` crate.
6pub use rand;
7
8use alloc::{vec, vec::Vec};
9
10use rand::{rngs::SmallRng, RngCore};
11
12pub fn generate_pages(rng: &mut SmallRng) -> Vec<(Vec<u8>, u64)> {
13	let mut pages = Vec::with_capacity(NUM_PAGES);
14	for _ in 0..NUM_PAGES {
15		let mut data = vec![0_u8; PAGE_SIZE];
16		rng.fill_bytes(&mut data[..]);
17		let checksum = page_checksum(&data);
18		pages.push((data, checksum));
19	}
20	pages
21}
22
23pub fn page_checksum(page: &[u8]) -> u64 {
24	page.iter().map(|x| u64::from(*x)).sum()
25}
26
27pub const PAGE_SIZE: usize = 4096;
28// Max. exports.
29pub const MAX_PAGES: usize = 100;
30// Pre-allocate one and half times more pages than can be exported from a work package.
31pub const NUM_PAGES: usize = MAX_PAGES * 3 / 2;