Crates.io | libmemtester |
lib.rs | libmemtester |
version | 1.2.1 |
source | src |
created_at | 2022-09-13 14:21:34.356589 |
updated_at | 2022-11-18 11:54:15.765669 |
description | A Rust library for testing memory for faults |
homepage | |
repository | |
max_upload_size | |
id | 664605 |
size | 52,624 |
This project is a Rust library for testing memory. It is a Rust version of memtester.
The goal of this crate is to provide a cross-platform memory tester (it has been tested on Linux and Windows) that can be used in other projects.
It works by allocating a large chunk of memory and then writing a pattern to it. It then reads the memory and checks that the pattern is correct. It does this for a number of different patterns. If the memory is faulty, it will detect it and return a hashmap of the faulty addresses and the number of times they were faulty.
To prevent the operating system from swapping out the memory and moving pages, this crate locks the memory (using mlock
syscall on Linux and VirtualLock
on Windows).
In order to do this, the crate needs to be run as root.
use libmemtester::MemoryTests;
fn main() {
// The size to allocate in bytes (must be divisible by 16)
let size_to_allocate = 1024 * 1024 * 1024; // 1GB
let debug_prints = false; // If you want the debug prints
// Create a new MemTester instance
let mem_tests_res = MemoryTests::new(size_to_allocate, debug_prints);
// Checking if there were any errors when allocating the memory
if let Err(e) = mem_tests {
println!("Error: {}", e);
return;
}
let tests = mem_tests.unwrap();
// We run the tests by calling an iterator
// This way you can stop the tests when one fails
// or simply display information as the tests goes along
for let Some((test_name, error_count)) in tests.get_iterator() {
println!("Test: {} - Error count: {}", test_name, error_count);
}
// When the iterator is done, we can get the results
// This will return a hashmap of the faulty addresses and the number of times they were faulty
let errors = tests.get_errors();
println!("Errors: {:#?}", errors);
}
You can see an example of this crate being used in memtester-rs.
This project is licensed under the GPLv3 licence - see the LICENSE file for details