5 stable releases
1.2.1 | Nov 18, 2022 |
---|---|
1.2.0 | Oct 6, 2022 |
1.1.1 | Sep 15, 2022 |
1.1.0 | Sep 13, 2022 |
1.0.0 | Sep 13, 2022 |
#10 in #tester
29 downloads per month
Used in memtester
17KB
423 lines
libmemtester-rs
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.
⌨ Usage
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.
📃 License
This project is licensed under the GPLv3 licence - see the LICENSE file for details
Dependencies
~0.2–0.9MB
~14K SLoC