Skip to content

Commit

Permalink
Add shallow_find_files helper function to run-make-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jul 5, 2024
1 parent b15e72a commit 85fbc51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
12 changes: 6 additions & 6 deletions tests/run-make/pgo-gen/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//@ needs-profiler-support
//@ 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() {
rustc().arg("-g").profile_generate(cwd()).run();
rustc().arg("-g").profile_generate(cwd()).input("test.rs").run();
run("test");
assert!(
find_files_by_prefix_and_extension(cwd(), "default", "profraw").len() > 0,
"no .profraw file generated"
);
let profraw_files = shallow_find_files(cwd(), |path| {
has_prefix(path, "default") && has_extension(path, "profraw")
});
assert!(!profraw_files.is_empty(), "no .profraw file generated");
}
27 changes: 14 additions & 13 deletions tests/run-make/pgo-use/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//@ ignore-cross-compile

use run_make_support::{
cwd, find_files_by_prefix_and_extension, fs_wrapper, llvm_filecheck, llvm_profdata,
run_with_args, rustc,
cwd, fs_wrapper, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args,
rustc, shallow_find_files,
};

fn main() {
Expand All @@ -28,11 +28,11 @@ fn main() {
// Run it in order to generate some profiling data
run_with_args("main", &["some-argument"]);
// Postprocess the profiling data so it can be used by the compiler
llvm_profdata()
.merge()
.output("merged.profdata")
.input(find_files_by_prefix_and_extension(cwd(), "default", "profraw").get(0).unwrap())
.run();
let profraw_files = shallow_find_files(cwd(), |path| {
has_prefix(path, "default") && has_extension(path, "profraw")
});
let profraw_file = profraw_files.get(0).unwrap();
llvm_profdata().merge().output("merged.profdata").input(profraw_file).run();
// Compile the test program again, making use of the profiling data
rustc()
.opt_level("2")
Expand All @@ -42,13 +42,14 @@ fn main() {
.emit("llvm-ir")
.input("main.rs")
.run();
// Check that the generate IR contains some things that we expect
//
// We feed the file into LLVM FileCheck tool *in reverse* so that we see the
// 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
// line with the function name before the line with the function attributes.
// FileCheck only supports checking that something matches on the next line,
// but not if something matches on the previous line.
let mut bytes = fs_wrapper::read("interesting.ll");
bytes.reverse();
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(bytes).run();
let ir = fs_wrapper::read_to_string("main.ll");
let lines: Vec<_> = ir.lines().rev().collect();
let mut reversed_ir = lines.join("\n");
reversed_ir.push('\n');
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(reversed_ir.as_bytes()).run();
}

0 comments on commit 85fbc51

Please sign in to comment.