Path: blob/main/cranelift/filetests/src/lib.rs
1691 views
//! File tests.1//!2//! This crate contains the main test driver as well as implementations of the3//! available filetest commands.45#![deny(missing_docs)]67pub use crate::function_runner::TestFileCompiler;8use crate::runner::TestRunner;9use cranelift_reader::TestCommand;10use std::path::Path;1112mod concurrent;13pub mod function_runner;14mod match_directive;15mod runner;16mod runone;17mod subtest;1819mod test_alias_analysis;20mod test_cat;21mod test_compile;22mod test_domtree;23mod test_inline;24mod test_interpret;25mod test_legalizer;26mod test_optimize;27mod test_print_cfg;28mod test_run;29mod test_safepoint;30mod test_unwind;31mod test_verifier;3233/// Main entry point for `clif-util test`.34///35/// Take a list of filenames which can be either `.clif` files or directories.36///37/// Files are interpreted as test cases and executed immediately.38///39/// Directories are scanned recursively for test cases ending in `.clif`. These test cases are40/// executed on background threads.41///42pub fn run(verbose: bool, report_times: bool, files: &[String]) -> anyhow::Result<()> {43let mut runner = TestRunner::new(verbose, report_times);4445for path in files.iter().map(Path::new) {46if path.is_file() {47runner.push_test(path);48} else {49runner.push_dir(path);50}51}5253runner.start_threads();54runner.run()55}5657/// Used for 'pass' subcommand.58/// Commands are interpreted as test and executed.59///60/// Directories are scanned recursively for test cases ending in `.clif`.61///62pub fn run_passes(63verbose: bool,64report_times: bool,65passes: &[String],66target: &str,67file: &str,68) -> anyhow::Result<()> {69let mut runner = TestRunner::new(verbose, report_times);7071let path = Path::new(file);72if path == Path::new("-") || path.is_file() {73runner.push_test(path);74} else {75runner.push_dir(path);76}7778runner.start_threads();79runner.run_passes(passes, target)80}8182/// Create a new subcommand trait object to match `parsed.command`.83///84/// This function knows how to create all of the possible `test <foo>` commands that can appear in85/// a `.clif` test file.86fn new_subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn subtest::SubTest>> {87match parsed.command {88"alias-analysis" => test_alias_analysis::subtest(parsed),89"cat" => test_cat::subtest(parsed),90"compile" => test_compile::subtest(parsed),91"domtree" => test_domtree::subtest(parsed),92"inline" => test_inline::subtest(parsed),93"interpret" => test_interpret::subtest(parsed),94"legalizer" => test_legalizer::subtest(parsed),95"optimize" => test_optimize::subtest(parsed),96"print-cfg" => test_print_cfg::subtest(parsed),97"run" => test_run::subtest(parsed),98"safepoint" => test_safepoint::subtest(parsed),99"unwind" => test_unwind::subtest(parsed),100"verifier" => test_verifier::subtest(parsed),101_ => anyhow::bail!("unknown test command '{}'", parsed.command),102}103}104105fn pretty_anyhow_error(106func: &cranelift_codegen::ir::Function,107err: cranelift_codegen::CodegenError,108) -> anyhow::Error {109let s = cranelift_codegen::print_errors::pretty_error(func, err);110anyhow::anyhow!("{}", s)111}112113114