From c207db05fe24520e1415e5b965f1bca3f74df442 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Thu, 1 Feb 2024 17:13:43 +0000 Subject: [PATCH 1/3] Remove the `debug_` prefix for tests. We can now use -- with a suitably set environment variable -- lang_tester's `ignore_if` to avoid having to encode which tests we want to run in filenames. --- tests/c/{debug_debuginfo.c => debuginfo.c} | 3 +- ...e_interp_loop2.c => simple_interp_loop2.c} | 0 tests/langtest_c.rs | 31 ++++++------------- 3 files changed, 12 insertions(+), 22 deletions(-) rename tests/c/{debug_debuginfo.c => debuginfo.c} (88%) rename tests/c/{debug_simple_interp_loop2.c => simple_interp_loop2.c} (100%) diff --git a/tests/c/debug_debuginfo.c b/tests/c/debuginfo.c similarity index 88% rename from tests/c/debug_debuginfo.c rename to tests/c/debuginfo.c index 8456e7d56..894adec49 100644 --- a/tests/c/debug_debuginfo.c +++ b/tests/c/debuginfo.c @@ -1,3 +1,4 @@ +// ignore-if: test $YK_CARGO_PROFILE != "debug" // Run-time: // env-var: YKD_PRINT_IR=jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 @@ -5,7 +6,7 @@ // ... // define ptr @__yk_compiled_trace_0(... // entry: -// ; main() c/debug_debuginfo.c:27:5 +// ; main() c/debuginfo.c:28:5 // ... // Check that debug information is included in module prints. diff --git a/tests/c/debug_simple_interp_loop2.c b/tests/c/simple_interp_loop2.c similarity index 100% rename from tests/c/debug_simple_interp_loop2.c rename to tests/c/simple_interp_loop2.c diff --git a/tests/langtest_c.rs b/tests/langtest_c.rs index 95f1b3443..f3bb03145 100644 --- a/tests/langtest_c.rs +++ b/tests/langtest_c.rs @@ -63,26 +63,6 @@ fn correct_cpu_arch(p: &Path) -> bool { fn run_suite(opt: &'static str) { println!("Running C tests with opt level {}...", opt); - fn is_c(p: &Path) -> bool { - p.extension().as_ref().and_then(|p| p.to_str()) == Some("c") - } - - // Tests with the filename prefix `debug_` are only run in debug builds. - #[cfg(cargo_profile = "release")] - let filter = |p: &Path| { - is_c(p) - && correct_cpu_arch(p) - && correct_codegen_for_test(p) - && !p - .file_name() - .unwrap() - .to_str() - .unwrap() - .starts_with("debug_") - }; - #[cfg(cargo_profile = "debug")] - let filter = |p: &Path| is_c(p) && correct_cpu_arch(p) && correct_codegen_for_test(p); - let tempdir = TempDir::new().unwrap(); // Generate a `compile_commands.json` database for clangd. @@ -92,10 +72,19 @@ fn run_suite(opt: &'static str) { } let wrapper_path = ccg.wrapper_path(); + #[cfg(cargo_profile = "debug")] + env::set_var("YK_CARGO_PROFILE", "debug"); + #[cfg(cargo_profile = "release")] + env::set_var("YK_CARGO_PROFILE", "release"); + LangTester::new() .comment_prefix("#") .test_dir("c") - .test_path_filter(filter) + .test_path_filter(|p: &Path| { + p.extension().as_ref().and_then(|p| p.to_str()) == Some("c") + && correct_cpu_arch(p) + && correct_codegen_for_test(p) + }) .test_extract(move |p| { let altp = p.with_extension(format!("c.{}", opt.strip_prefix('-').unwrap())); let p = if altp.exists() { altp.as_path() } else { p }; From d8937ad737ef3796239bbd52937e4301f7313f9d Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Thu, 1 Feb 2024 17:30:18 +0000 Subject: [PATCH 2/3] Remove the need to encode the architecture in test names. --- ..._64_zero_len_call.c => pt_zero_len_call.c} | 1 + ..._64_zero_len_call.s => pt_zero_len_call.s} | 0 tests/langtest_c.rs | 31 ++++--------------- tests/src/lib.rs | 8 ++--- 4 files changed, 11 insertions(+), 29 deletions(-) rename tests/c/{x86_64_zero_len_call.c => pt_zero_len_call.c} (95%) rename tests/extra_linkage/{x86_64_zero_len_call.s => pt_zero_len_call.s} (100%) diff --git a/tests/c/x86_64_zero_len_call.c b/tests/c/pt_zero_len_call.c similarity index 95% rename from tests/c/x86_64_zero_len_call.c rename to tests/c/pt_zero_len_call.c index 77c9042e4..15fce58a6 100644 --- a/tests/c/x86_64_zero_len_call.c +++ b/tests/c/pt_zero_len_call.c @@ -1,3 +1,4 @@ +// ignore-if: test ${YK_ARCH} != "x86_64" // Run-time: // env-var: YKD_SERIALISE_COMPILATION=1 // env-var: YKD_PRINT_JITSTATE=1 diff --git a/tests/extra_linkage/x86_64_zero_len_call.s b/tests/extra_linkage/pt_zero_len_call.s similarity index 100% rename from tests/extra_linkage/x86_64_zero_len_call.s rename to tests/extra_linkage/pt_zero_len_call.s diff --git a/tests/langtest_c.rs b/tests/langtest_c.rs index f3bb03145..79fad1af0 100644 --- a/tests/langtest_c.rs +++ b/tests/langtest_c.rs @@ -24,8 +24,6 @@ static NEW_CODEGEN: LazyLock = LazyLock::new(|| { false }); -static SUPPORTED_CPU_ARCHES: [&str; 1] = ["x86_64"]; - /// Transitionary hack to allow the LLVM and new codegen to co-exist. /// /// Once the new codegen is complete we can kill this. @@ -38,28 +36,6 @@ fn correct_codegen_for_test(p: &Path) -> bool { } } -/// Get string name for the current CPU architecture. -fn arch() -> &'static str { - if cfg!(target_arch = "x86_64") { - "x86_64" - } else { - panic!("unknown CPU architecture"); - } -} - -/// Check if we are on the right CPU for a test. -fn correct_cpu_arch(p: &Path) -> bool { - let my_arch = arch(); - let other_arches = SUPPORTED_CPU_ARCHES.iter().filter(|a| *a != &my_arch); - let p = p.to_str().unwrap(); - for oa in other_arches { - if p.contains(oa) { - return false; - } - } - return true; -} - fn run_suite(opt: &'static str) { println!("Running C tests with opt level {}...", opt); @@ -72,17 +48,22 @@ fn run_suite(opt: &'static str) { } let wrapper_path = ccg.wrapper_path(); + // Set variables for tests `ignore-if`s. #[cfg(cargo_profile = "debug")] env::set_var("YK_CARGO_PROFILE", "debug"); #[cfg(cargo_profile = "release")] env::set_var("YK_CARGO_PROFILE", "release"); + #[cfg(target_arch = "x86_64")] + env::set_var("YK_ARCH", "x86_64"); + #[cfg(not(target_arch = "x86_64"))] + panic!("Unknown target_arch"); + LangTester::new() .comment_prefix("#") .test_dir("c") .test_path_filter(|p: &Path| { p.extension().as_ref().and_then(|p| p.to_str()) == Some("c") - && correct_cpu_arch(p) && correct_codegen_for_test(p) }) .test_extract(move |p| { diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 7cf9a5dcd..1cf11b79c 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -46,15 +46,15 @@ pub static EXTRA_LINK: LazyLock>> = Lazy ); } map.insert( - "x86_64_zero_len_call.c", + "pt_zero_len_call.c", vec![ExtraLinkage::new( - "%%TEMPDIR%%/x86_64_zero_len_call.o", + "%%TEMPDIR%%/pt_zero_len_call.o", ykllvm_bin("clang").to_owned(), &[ "-c", - "extra_linkage/x86_64_zero_len_call.s", + "extra_linkage/pt_zero_len_call.s", "-o", - "%%TEMPDIR%%/x86_64_zero_len_call.o", + "%%TEMPDIR%%/pt_zero_len_call.o", ], )], ); From 7abb8a69ad0c5eb15091090165b60122fcc85d5c Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Thu, 1 Feb 2024 17:35:32 +0000 Subject: [PATCH 3/3] Remove the need to encode the code generator in test names. --- tests/c/simple.newcg.c | 1 + tests/langtest_c.rs | 43 +++++++++++++++++------------------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/tests/c/simple.newcg.c b/tests/c/simple.newcg.c index 68a7581eb..838ccc297 100644 --- a/tests/c/simple.newcg.c +++ b/tests/c/simple.newcg.c @@ -1,3 +1,4 @@ +// ignore-if: test YK_JIT_COMPILER != "yk" // Run-time: // env-var: YKD_PRINT_IR=aot // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/langtest_c.rs b/tests/langtest_c.rs index 79fad1af0..bb5e74563 100644 --- a/tests/langtest_c.rs +++ b/tests/langtest_c.rs @@ -7,7 +7,6 @@ use std::{ fs::read_to_string, path::{Path, PathBuf}, process::Command, - sync::LazyLock, }; use tempfile::TempDir; use tests::{mk_compiler, EXTRA_LINK}; @@ -15,27 +14,6 @@ use ykbuild::{completion_wrapper::CompletionWrapper, ykllvm_bin}; const COMMENT: &str = "//"; -static NEW_CODEGEN: LazyLock = LazyLock::new(|| { - if let Ok(val) = env::var("YKD_NEW_CODEGEN") { - if val == "1" { - return true; - } - } - false -}); - -/// Transitionary hack to allow the LLVM and new codegen to co-exist. -/// -/// Once the new codegen is complete we can kill this. -fn correct_codegen_for_test(p: &Path) -> bool { - let fname = p.file_name().unwrap().to_str().unwrap(); - if *NEW_CODEGEN { - fname.contains(".newcg.") - } else { - !fname.contains(".newcg.") - } -} - fn run_suite(opt: &'static str) { println!("Running C tests with opt level {}...", opt); @@ -59,13 +37,26 @@ fn run_suite(opt: &'static str) { #[cfg(not(target_arch = "x86_64"))] panic!("Unknown target_arch"); + let filter = match env::var("YKD_NEW_CODEGEN") { + Ok(x) if x == "1" => { + env::set_var("YK_JIT_COMPILER", "yk"); + |p: &Path| { + // A temporary hack because at the moment virtually no tests run on the new JIT + // compiler. + p.extension().as_ref().and_then(|p| p.to_str()) == Some("c") + && p.file_name().unwrap().to_str().unwrap().contains(".newcg") + } + } + _ => { + env::set_var("YK_JIT_COMPILER", "llvm"); + |p: &Path| p.extension().as_ref().and_then(|p| p.to_str()) == Some("c") + } + }; + LangTester::new() .comment_prefix("#") .test_dir("c") - .test_path_filter(|p: &Path| { - p.extension().as_ref().and_then(|p| p.to_str()) == Some("c") - && correct_codegen_for_test(p) - }) + .test_path_filter(filter) .test_extract(move |p| { let altp = p.with_extension(format!("c.{}", opt.strip_prefix('-').unwrap())); let p = if altp.exists() { altp.as_path() } else { p };