8000 xtask: Add action to generate a code coverage report by nicholasbishop · Pull Request #1423 · rust-osdev/uefi-rs · GitHub
[go: up one dir, main page]

Skip to content

xtask: Add action to generate a code coverage report #1423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
Next Next commit
xtask: Add action to generate a code coverage report
This uses llvm-cov (https://github.com/taiki-e/cargo-llvm-cov) to create a
simple HTML code coverage report.

For now this only includes coverage from host tests, but in the future we can
use https://github.com/Amanieu/minicov to include coverage from VM tests as
well.
  • Loading branch information
nicholasbishop committed Oct 8, 2024
commit 23b6d65febc728c2208e07269f588058f7fcef31
10 changes: 10 additions & 0 deletions xtask/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ impl TargetTypes {
pub enum CargoAction {
Build,
Clippy,
Coverage {
open: bool,
},
Doc {
open: bool,
document_private_items: bool,
Expand Down Expand Up @@ -251,6 +254,13 @@ impl Cargo {
tool_args.extend(["-D", "warnings"]);
}
}
CargoAction::Coverage { open } => {
action = "llvm-cov";
extra_args.push("--html");
if open {
extra_args.push("--open");
}
}
CargoAction::Doc {
open,
document_private_items,
Expand Down
26 changes: 24 additions & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ mod tpm;
mod util;

use crate::opt::{FmtOpt, TestOpt};
use anyhow::Result;
use anyhow::{bail, Result};
use arch::UefiArch;
use cargo::{Cargo, CargoAction, Feature, Package, TargetTypes};
use clap::Parser;
use itertools::Itertools;
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, Opt, QemuOpt, TpmVersion};
use opt::{Action, BuildOpt, ClippyOpt, CovOpt, DocOpt, Opt, QemuOpt, TpmVersion};
use std::process::Command;
use util::run_cmd;

Expand Down Expand Up @@ -85,6 +85,27 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
run_cmd(cargo.command()?)
}

/// Generate a code coverage report.
fn code_coverage(opt: &CovOpt) -> Result<()> {
if has_cmd("cargo-llvm-cov") {
let cargo = Cargo {
action: CargoAction::Coverage { open: opt.open },
features: Feature::more_code(*opt.unstable, false),
// Leave out uefi-macros; the compilation tests will just make
// things slower without contributing anything to the coverage
// report.
packages: vec![Package::UefiRaw, Package::Uefi],
release: false,
target: None,
warnings_as_errors: false,
target_types: TargetTypes::Default,
};
run_cmd(cargo.command()?)
} else {
bail!("cargo-llvm-cov not found, see https://github.com/taiki-e/cargo-llvm-cov");
}
}

/// Build docs.
fn doc(opt: &DocOpt) -> Result<()> {
let cargo = Cargo {
Expand Down Expand Up @@ -305,6 +326,7 @@ fn main() -> Result<()> {
Action::Build(build_opt) => build(build_opt),
Action::CheckRaw(_) => check_raw::check_raw(),
Action::Clippy(clippy_opt) => clippy(clippy_opt),
Action::Cov(cov_opt) => code_coverage(cov_opt),
Action::Doc(doc_opt) => doc(doc_opt),
Action::GenCode(gen_opt) => device_path::gen_code(gen_opt),
Action::Miri(_) => run_miri(),
Expand Down
12 changes: 12 additions & 0 deletions xtask/src/opt.rs