Skip to content

Commit

Permalink
ci(xtask): add support for rftrace
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Mar 26, 2024
1 parent 639e109 commit 655d14c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
9 changes: 9 additions & 0 deletions xtask/src/ci/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ impl Build {

let sh = crate::sh()?;

let _push_env = if self.package.contains("rftrace") {
Some(sh.push_env(
"RUSTFLAGS",
"-Zinstrument-mcount -Cpasses=ee-instrument<post-inline>",
))
} else {
None
};

cmd!(sh, "cargo build --manifest-path ../Cargo.toml")
.args(self.cargo_build.artifact.arch.ci_cargo_args())
.cargo_build_args(&self.cargo_build)
Expand Down
37 changes: 36 additions & 1 deletion xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::io::{Read, Write};
use std::net::{TcpStream, UdpSocket};
use std::path::Path;
use std::process::{Child, Command, ExitStatus};
use std::str::from_utf8;
use std::time::Duration;
use std::{env, thread};
use std::{env, fs, thread};

use anyhow::{bail, ensure, Context, Result};
use clap::{Args, ValueEnum};
Expand Down Expand Up @@ -63,6 +64,10 @@ impl Qemu {
let virtiofsd = self.virtiofsd.then(spawn_virtiofsd).transpose()?;
thread::sleep(Duration::from_millis(100));

if self.build.package.contains("rftrace") {
sh.create_dir("shared/tracedir")?;
}

let arch = self.build.cargo_build.artifact.arch.name();
let qemu = env::var_os("QEMU").unwrap_or_else(|| format!("qemu-system-{arch}").into());

Expand Down Expand Up @@ -109,6 +114,10 @@ impl Qemu {
assert!(status.success());
}

if self.build.package.contains("rftrace") {
check_rftrace(&self.build.image())?;
}

Ok(())
}

Expand Down Expand Up @@ -332,6 +341,32 @@ fn test_mioudp() -> Result<()> {
Ok(())
}

fn check_rftrace(image: &Path) -> Result<()> {
let sh = crate::sh()?;
let image_name = image.file_name().unwrap().to_str().unwrap();

let nm = crate::binutil("nm")?;
let symbols = cmd!(sh, "{nm} --numeric-sort {image}").output()?.stdout;
sh.write_file(format!("shared/tracedir/{image_name}.sym"), symbols)?;

let replay = cmd!(
sh,
"uftrace replay --data=shared/tracedir --output-fields=tid"
)
.read()?;
eprintln!("[CI] replay: {replay}");

let expected = fs::read_to_string("xtask/src/ci/rftrace.snap")?;
if !replay.starts_with(&expected) {
eprintln!("[CI] expected: {expected}");
bail!("rftrace output does not match snapshot");
}

eprintln!("[CI] replay matches snapshot");

Ok(())
}

struct KillChildOnDrop(Child);

impl Drop for KillChildOnDrop {
Expand Down
6 changes: 6 additions & 0 deletions xtask/src/ci/rftrace.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# TID FUNCTION
[ 1] | rftrace_example::f1() {
[ 1] | rftrace_example::f2() {
[ 1] | rftrace_example::f3();
[ 1] | } /* rftrace_example::f2 */
[ 1] | } /* rftrace_example::f1 */

0 comments on commit 655d14c

Please sign in to comment.