Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "wild/tests/bins"]
path = wild/tests/bins
url = https://github.com/wild-linker/test-files
[submodule "external_test_suites/lld"]
path = external_test_suites/lld
url = https://github.com/wild-linker/lld-tests
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rela = "rela"
ot = "ot"
FRE = "FRE"
aranges = "aranges"
preemptable = "preemptable"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a typo that I've been known to make myself, so it'd be good if we could avoid adding it here. I just did some experimentation, and it looks like we can skip typo checking specifically for the excluded test lists with something like this:

[type.external-test-list]
extend-glob = ["*_skip_tests.toml"]
extend-ignore-re = ['(?m)^\s*tests\s*=\s*\[[^\]]*\]\s*$']


[files]
extend-exclude = ["external_test_suites", "wild/tests/bins"]
1 change: 1 addition & 0 deletions external_test_suites/lld
Submodule lld added at 3b0540
7 changes: 0 additions & 7 deletions external_test_suites/lld/test/ELF/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions external_test_suites/lld/update-lld-tests.sh

This file was deleted.

104 changes: 104 additions & 0 deletions wild/tests/external_tests/lld_skip_tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[skipped_groups.lld_specific]
reason = "Test exercises an lld-specific flag or behavior not applicable to Wild"
tests = ["x86-64-branch-to-branch.s"]

[skipped_groups.requires_newer_lld]
reason = "Test requires a newer lld/relocation type than our local llvm-mc supports"
tests = [
"x86-64-gotpc-no-relax-err.s",
"x86-64-gotpc-relax.s",
"x86-64-gotpc-relax-nopic.s",
"x86-64-plt-high-addr.s",
"x86-64-tlsdesc-gd.s",
"x86-64-tls-ie-err.s",
"x86-64-tls-ie-local.s",
]

[skipped_groups.design_differences]
reason = "Wild intentionally differs from lld's PLT/GOT layout and relocation binding strategy (immediate binding vs lazy binding)"
tests = [
"x86-64-tlsdesc-ld.s",
"x86-64-tlsdesc-gd-mixed.s",
"x86-64-reloc-gotoff64.s",
"x86-64-reloc-gotpc64.s",
"x86-64-reloc-pltoff64.s",
"x86-64-static-tls-model.s",
"x86-64-combined-dynrel.s",
"x86-64-got-plt-header.s",
"x86-64-plt.s",
"x86-64-rela.s",
"x86-64-tls-gd-local.s",
"x86-64-tls-ld-local.s",
"x86-64-zrel-zrela.s",
]

[skipped_groups.error_message_wording]
reason = "Wild correctly errors but with different message wording than lld"
tests = [
"x86-64-reloc-tpoff32-error.s",
"x86-64-pc32-overflow-large.s",
"x86-64-reloc-error2.s",
"x86-64-reloc-debug-overflow.s",
"x86-64-reloc-range-debug-loc.s",
"x86-64-tls-ie-opt-local.s",
]

[skipped_groups.gc_sections_behavior]
reason = "Test relies on lld's default --gc-sections behavior differing from Wild's"
tests = ["x86-64-reloc-error.s"]

[skipped_groups.noinhibit_exec_unsupported]
reason = "Test relies on --noinhibit-exec, which Wild does not support"
tests = ["x86-64-reloc-range.s", "x86-64-tls-le-undef.s"]

[skipped_groups.unsupported_features]
reason = "Feature not yet implemented in Wild"
tests = [
"x86-64-feature-cet.s",
"x86-64-dyn-rel-error.s",
"x86-64-dyn-rel-error3.s",
"x86-64-dyn-rel-error5.s",
"x86-64-relax-got-abs.s",
"x86-64-reloc-size.s",
"x86-64-retpoline.s",
"x86-64-retpoline-linkerscript.s",
"x86-64-retpoline-znow.s",
"x86-64-retpoline-znow-linkerscript.s",
"x86-64-retpoline-znow-static-iplt.s",
"x86-64-section-layout.s",
"x86-64-split-stack-prologue-adjust-fail.s",
"x86-64-split-stack-prologue-adjust-shared.s",
"x86-64-split-stack-prologue-adjust-silent.s",
"x86-64-tls-gd-got.s",
"x86-64-tls-opt-noplt.s",
"x86-64-tls-pie.s",
]

[skipped_groups.missing_flag_support]
reason = "Wild does not yet recognize the --image-base flag used by this test"
tests = ["x86-64-reloc-32.s"]

[skipped_groups.previously_believed_working]
reason = "Manual testing previously suggested Wild handles this correctly, but it fails under this harness's exact FileCheck comparison. Needs investigation to reconcile: possible regression, an imprecise manual check, or a local tooling gap (e.g. objdump missing x86_64 target support)."
tests = [
"x86-64-tls-le-align.s",
"x86-64-tls-ie.s",
"x86-64-tls-gdie.s",
"x86-64-reloc-8-16.s",
"x86-64-tls-ld-preemptable.s",
"x86-64-relax-offset.s",
"x86-64-gotpc-relax-too-far.s",
"x86-64-gotpc-relax-und-dso.s",
"x86-64-tls-dynamic.s",
"x86-64-reloc-pc32.s",
"x86-64-split-stack-prologue-adjust-success.s",
]

[skipped_groups.untriaged]
reason = "Not yet manually triaged against Wild"
tests = [
"x86-64-gotpc-offset.s",
"x86-64-gotpc-relax-too-far-relr.s",
"x86-64-relax-jump-tables.s",
"x86-64-reloc-size-shared.s",
]
101 changes: 96 additions & 5 deletions wild/tests/external_tests/lld_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,37 @@
use crate::Result;
use libtest_mimic::Failed;
use libtest_mimic::Trial;
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
use std::path::Path;
use std::process::Command;
use std::sync::OnceLock;

#[derive(Deserialize)]
struct Config {
skipped_groups: HashMap<String, SkippedGroup>,
}

#[derive(Deserialize)]
struct SkippedGroup {
tests: Vec<String>,
}

static SKIP_TESTS_NAME: OnceLock<Option<Vec<String>>> = OnceLock::new();

const PREFIX: &str = "external_test_suites/lld";

/// Architecture prefixes used by LLD's test file naming convention
/// (e.g. `x86-64-pcrel.s`, `aarch64-abs16.s`).
const SUPPORTED_ARCH_PREFIXES: &[&str] = &["x86-64-"];

fn is_supported_arch_test(file_name: &str) -> bool {
SUPPORTED_ARCH_PREFIXES
.iter()
.any(|prefix| file_name.starts_with(prefix))
}

pub(crate) fn collect_tests(tests: &mut Vec<Trial>, filter: &crate::Filter) -> Result {
if filter.excludes(PREFIX) {
return Ok(());
Expand All @@ -21,23 +47,48 @@ pub(crate) fn collect_tests(tests: &mut Vec<Trial>, filter: &crate::Filter) -> R
if !test_dir.exists() {
return Ok(());
}

let dir = std::fs::read_dir(&test_dir)?;
for ent in dir {
let ent = ent?;
let path = ent.path();
if path.extension().is_some_and(|ext| ext == "s") {
let file_name =
String::from_utf8_lossy(path.file_name().unwrap().as_encoded_bytes()).to_string();

// Other architectures (aarch64, riscv64, ...) are left for a
// TODO.
if !is_supported_arch_test(&file_name) {
continue;
}

let name = format!("{PREFIX}/test/ELF/{file_name}");
tests.push(Trial::test(name, move || {
run_lld_test(&path).map_err(|e| Failed::from(e.to_string()))
}));

if !should_skip_lld_test(&path) {
tests.push(Trial::test(name, move || {
run_lld_test(&path).map_err(|e| Failed::from(e.to_string()))
}));
} else {
tests.push(Trial::test(format!("{name}/expect_failure"), move || {
verify_skipped_lld_test_still_fails(&path)
.map_err(|e| Failed::from(e.to_string()))
}));
}
}
}
Ok(())
}

fn verify_skipped_lld_test_still_fails(test_file: &Path) -> Result {
if run_lld_test(test_file).is_ok() {
return Err(format!(
"Test `{}` is in the skip list but now passes. Should be removed from skip list.",
test_file.display()
)
.into());
}
Ok(())
}

fn run_lld_test(test_file: &Path) -> Result {
let llvm_mc = find_tool("llvm-mc")?;
let filecheck = find_tool("FileCheck")?;
Expand Down Expand Up @@ -97,9 +148,11 @@ fn extract_run_lines(content: &str) -> Vec<String> {
}

fn substitute_vars(cmd: &str, test_file: &Path, tmpdir: &Path) -> String {
let dir = test_file.parent().unwrap().display().to_string();
cmd.replace("%s", &test_file.display().to_string())
.replace("%t", &tmpdir.join("test").display().to_string())
.replace("%p", &test_file.parent().unwrap().display().to_string())
.replace("%S", &dir)
.replace("%p", &dir)
}

fn substitute_tools(cmd: &str, llvm_mc: &str, filecheck: &str) -> String {
Expand Down Expand Up @@ -128,3 +181,41 @@ fn execute_command(cmd: &str) -> Result {
}
Ok(())
}

fn load_skip_tests_config() -> &'static Option<Vec<String>> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, it's a code that is not actually run.

SKIP_TESTS_NAME.get_or_init(|| {
let skip_tests_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("external_tests")
.join("lld_skip_tests.toml");

fs::read_to_string(&skip_tests_path)
.map(|content| {
let config: Config =
toml::from_str(&content).expect("Failed to parse lld_skip_tests.toml");

config
.skipped_groups
.into_values()
.flat_map(|group| group.tests)
.collect()
})
.ok()
})
}

fn should_skip_lld_test(path: &Path) -> bool {
let file_name = path
.file_name()
.expect("Must be a valid filename")
.to_str()
.expect("Expected valid string name");

if crate::external_tests::should_not_ignore_tests("lld") {
return false;
}

load_skip_tests_config()
.as_ref()
.is_some_and(|skip_list| skip_list.contains(&file_name.to_string()))
}
Loading