#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[path = "cargo_ktstr/cli.rs"]
mod cli;
#[path = "cargo_ktstr/kernel/mod.rs"]
mod kernel;
#[path = "cargo_ktstr/misc/mod.rs"]
mod misc;
#[path = "cargo_ktstr/run_cargo.rs"]
mod run_cargo;
#[path = "cargo_ktstr/stats.rs"]
mod stats;
#[path = "cargo_ktstr/verifier.rs"]
mod verifier;
#[cfg(test)]
#[path = "cargo_ktstr/parse_tests.rs"]
mod parse_tests;
use clap::Parser;
use ktstr::cli::KernelCommand;
use crate::cli::{Cargo, CargoSub, KtstrCommand, ModelCommand};
fn main() {
ktstr::cli::restore_sigpipe_default();
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn")),
)
.with_writer(std::io::stderr)
.init();
let Cargo {
command: CargoSub::Ktstr(ktstr),
} = Cargo::parse();
let result = match ktstr.command {
KtstrCommand::Test {
kernel,
no_perf_mode,
release,
args,
} => run_cargo::run_test(kernel, no_perf_mode, release, args),
KtstrCommand::Coverage {
kernel,
no_perf_mode,
release,
args,
} => run_cargo::run_coverage(kernel, no_perf_mode, release, args),
KtstrCommand::LlvmCov {
kernel,
no_perf_mode,
args,
} => run_cargo::run_llvm_cov(kernel, no_perf_mode, args),
KtstrCommand::Stats { ref command } => stats::run_stats(command),
KtstrCommand::Kernel { command } => match command {
KernelCommand::List { json, range } => match range {
Some(r) => {
ktstr::cli::kernel_list_range_preview(json, &r).map_err(|e| format!("{e:#}"))
}
None => ktstr::cli::kernel_list(json).map_err(|e| format!("{e:#}")),
},
KernelCommand::Build {
version,
source,
git,
git_ref,
force,
clean,
cpu_cap,
extra_kconfig,
skip_sha256,
} => kernel::kernel_build(
version,
source,
git,
git_ref,
force,
clean,
cpu_cap,
extra_kconfig,
skip_sha256,
),
KernelCommand::Clean {
keep,
force,
corrupt_only,
} => ktstr::cli::kernel_clean(keep, force, corrupt_only).map_err(|e| format!("{e:#}")),
},
KtstrCommand::Model { command } => match command {
ModelCommand::Fetch => misc::run_model_fetch(),
ModelCommand::Status => misc::run_model_status(),
ModelCommand::Clean => misc::run_model_clean(),
},
KtstrCommand::Verifier {
scheduler,
scheduler_bin,
kernel,
raw,
all_profiles,
profiles,
} => verifier::run_verifier(
scheduler,
scheduler_bin,
kernel,
raw,
all_profiles,
profiles,
),
KtstrCommand::Funify {
input,
seed,
pretty,
} => misc::run_funify(input, seed, pretty),
KtstrCommand::Completions { shell, binary } => {
misc::run_completions(shell, &binary);
Ok(())
}
KtstrCommand::ShowHost => {
print!("{}", ktstr::cli::show_host());
Ok(())
}
KtstrCommand::ShowThresholds { test } => match ktstr::cli::show_thresholds(&test) {
Ok(s) => {
print!("{s}");
Ok(())
}
Err(e) => Err(format!("{e:#}")),
},
KtstrCommand::Export {
test,
output,
package,
release,
} => misc::run_export(test, output, package, release),
KtstrCommand::Locks { json, watch } => {
ktstr::cli::list_locks(json, watch).map_err(|e| format!("{e:#}"))
}
KtstrCommand::Shell {
kernel,
topology,
include_files,
memory_mb,
dmesg,
exec,
no_perf_mode,
cpu_cap,
disk,
} => misc::run_shell(
kernel,
topology,
include_files,
memory_mb,
dmesg,
exec,
no_perf_mode,
cpu_cap,
disk,
),
};
if let Err(e) = result {
eprintln!("error: {e:#}");
std::process::exit(1);
}
}