Add shallow_find_files helper function to run-make-support
This commit is contained in:
parent
b15e72a9ed
commit
c9be69fd0a
@ -272,6 +272,7 @@ pub fn shallow_find_files<P: AsRef<Path>, F: Fn(&PathBuf) -> bool>(
|
|||||||
for entry in fs_wrapper::read_dir(path) {
|
for entry in fs_wrapper::read_dir(path) {
|
||||||
let entry = entry.expect("failed to read directory entry.");
|
let entry = entry.expect("failed to read directory entry.");
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
if path.is_file() && closure(&path) {
|
if path.is_file() && closure(&path) {
|
||||||
matching_files.push(path);
|
matching_files.push(path);
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
//@ needs-profiler-support
|
//@ needs-profiler-support
|
||||||
//@ ignore-cross-compile
|
//@ ignore-cross-compile
|
||||||
|
|
||||||
use run_make_support::{cwd, find_files_by_prefix_and_extension, run, rustc};
|
use run_make_support::{cwd, has_extension, has_prefix, run, rustc, shallow_find_files};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rustc().arg("-g").profile_generate(cwd()).run();
|
rustc().arg("-g").profile_generate(cwd()).input("test.rs").run();
|
||||||
run("test");
|
run("test");
|
||||||
assert!(
|
let profraw_files = shallow_find_files(cwd(), |path| {
|
||||||
find_files_by_prefix_and_extension(cwd(), "default", "profraw").len() > 0,
|
has_prefix(path, "default") && has_extension(path, "profraw")
|
||||||
"no .profraw file generated"
|
});
|
||||||
);
|
assert!(!profraw_files.is_empty(), "no .profraw file generated");
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
//@ ignore-cross-compile
|
//@ ignore-cross-compile
|
||||||
|
|
||||||
use run_make_support::{
|
use run_make_support::{
|
||||||
cwd, find_files_by_prefix_and_extension, fs_wrapper, llvm_filecheck, llvm_profdata,
|
cwd, fs_wrapper, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args,
|
||||||
run_with_args, rustc,
|
rustc, shallow_find_files,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -28,11 +28,11 @@ fn main() {
|
|||||||
// Run it in order to generate some profiling data
|
// Run it in order to generate some profiling data
|
||||||
run_with_args("main", &["some-argument"]);
|
run_with_args("main", &["some-argument"]);
|
||||||
// Postprocess the profiling data so it can be used by the compiler
|
// Postprocess the profiling data so it can be used by the compiler
|
||||||
llvm_profdata()
|
let profraw_files = shallow_find_files(cwd(), |path| {
|
||||||
.merge()
|
has_prefix(path, "default") && has_extension(path, "profraw")
|
||||||
.output("merged.profdata")
|
});
|
||||||
.input(find_files_by_prefix_and_extension(cwd(), "default", "profraw").get(0).unwrap())
|
let profraw_file = profraw_files.get(0).unwrap();
|
||||||
.run();
|
llvm_profdata().merge().output("merged.profdata").input(profraw_file).run();
|
||||||
// Compile the test program again, making use of the profiling data
|
// Compile the test program again, making use of the profiling data
|
||||||
rustc()
|
rustc()
|
||||||
.opt_level("2")
|
.opt_level("2")
|
||||||
@ -42,13 +42,14 @@ fn main() {
|
|||||||
.emit("llvm-ir")
|
.emit("llvm-ir")
|
||||||
.input("main.rs")
|
.input("main.rs")
|
||||||
.run();
|
.run();
|
||||||
// Check that the generate IR contains some things that we expect
|
// Check that the generate IR contains some things that we expect.
|
||||||
//
|
// We feed the file into LLVM FileCheck tool *with its lines reversed* so that we see the
|
||||||
// We feed the file into LLVM FileCheck tool *in reverse* so that we see the
|
|
||||||
// line with the function name before the line with the function attributes.
|
// line with the function name before the line with the function attributes.
|
||||||
// FileCheck only supports checking that something matches on the next line,
|
// FileCheck only supports checking that something matches on the next line,
|
||||||
// but not if something matches on the previous line.
|
// but not if something matches on the previous line.
|
||||||
let mut bytes = fs_wrapper::read("interesting.ll");
|
let ir = fs_wrapper::read_to_string("main.ll");
|
||||||
bytes.reverse();
|
let lines: Vec<_> = ir.lines().rev().collect();
|
||||||
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(bytes).run();
|
let mut reversed_ir = lines.join("\n");
|
||||||
|
reversed_ir.push('\n');
|
||||||
|
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(reversed_ir.as_bytes()).run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user