1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

factor::benches: Add check against ASLR

This commit is contained in:
nicoo 2021-05-03 16:14:38 +02:00
parent ddfcd2eb14
commit 7c649bc74e
2 changed files with 27 additions and 1 deletions

View file

@ -25,7 +25,6 @@ as possible:
to it, so it won't be preempted in the middle of a measurement ; to it, so it won't be preempted in the middle of a measurement ;
- disable ASLR by running `setarch -R cargo bench`, so we can compare results - disable ASLR by running `setarch -R cargo bench`, so we can compare results
across multiple executions. across multiple executions.
**TODO**: check this propagates to the benchmark process
[`criterion`]: https://bheisler.github.io/criterion.rs/book/index.html [`criterion`]: https://bheisler.github.io/criterion.rs/book/index.html

View file

@ -4,6 +4,9 @@ use std::convert::TryInto;
use uu_factor::{table::*, Factors}; use uu_factor::{table::*, Factors};
fn table(c: &mut Criterion) { fn table(c: &mut Criterion) {
#[cfg(target_os = "linux")]
check_personality();
const INPUT_SIZE: usize = 128; const INPUT_SIZE: usize = 128;
assert!( assert!(
INPUT_SIZE % CHUNK_SIZE == 0, INPUT_SIZE % CHUNK_SIZE == 0,
@ -55,5 +58,29 @@ fn table(c: &mut Criterion) {
group.finish() group.finish()
} }
#[cfg(target_os = "linux")]
fn check_personality() {
use std::fs;
const ADDR_NO_RANDOMIZE: u64 = 0x0040000;
const PERSONALITY_PATH: &'static str = "/proc/self/personality";
let p_string = fs::read_to_string(PERSONALITY_PATH)
.expect(&format!("Couldn't read '{}'", PERSONALITY_PATH))
.strip_suffix("\n")
.unwrap()
.to_owned();
let personality = u64::from_str_radix(&p_string, 16).expect(&format!(
"Expected a hex value for personality, got '{:?}'",
p_string
));
if personality & ADDR_NO_RANDOMIZE == 0 {
eprintln!(
"WARNING: Benchmarking with ASLR enabled (personality is {:x}), results might not be reproducible.",
personality
);
}
}
criterion_group!(benches, table); criterion_group!(benches, table);
criterion_main!(benches); criterion_main!(benches);