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 27, 2024
1 parent 0fb3586 commit 8ac5fa5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ jobs:
profile: [dev, release]
include:
- arch: x86_64
packages: qemu-system-x86 libcap-ng-dev libseccomp-dev
flags: --features pci-ids
packages: qemu-system-x86 libcap-ng-dev libseccomp-dev uftrace
flags: --features hermit/pci-ids
- arch: aarch64
packages: qemu-system-aarch64
flags: --features pci-ids
flags: --features hermit/pci-ids
- arch: riscv64
packages: qemu-system-misc
flags: --no-default-features
Expand All @@ -157,6 +157,9 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install ${{ matrix.packages }}
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
- uses: mkroening/rust-toolchain-toml@main
- uses: mkroening/rust-toolchain-toml@main
with:
Expand Down Expand Up @@ -185,6 +188,8 @@ jobs:
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package rusty_demo --smp 4
# https://github.com/hermit-os/kernel/issues/737
if: ${{ matrix.arch != 'aarch64' }}
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package rftrace-example --virtiofsd
if: ${{ matrix.arch == 'x86_64' }}
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package httpd --features ci,dhcpv4 --netdev virtio-net-pci
if: ${{ matrix.arch != 'riscv64' }}
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package httpd --features ci,dhcpv4 --netdev rtl8139 --features rtl8139
Expand Down
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
4 changes: 4 additions & 0 deletions xtask/src/ci/rftrace.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TID FUNCTION
[ 1] | rftrace_example::f1() {
[ 1] | rftrace_example::f2() {
[ 1] | rftrace_example::f3()

0 comments on commit 8ac5fa5

Please sign in to comment.