feat(gasm): audit a .s corpus with audit-instructions --corpus
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -293,3 +293,58 @@ func TestSweepCheckLines(t *testing.T) {
|
||||
t.Errorf("sweepCheckLines = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunCorpusAudit drives the corpus audit over a small fixture tree: one
|
||||
// suffixed amd64 file, one suffixed arm64 file whose body is not arm64, one
|
||||
// generic file, and one file that does not parse.
|
||||
func TestRunCorpusAudit(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(name, src string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte(src), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write("good_amd64.s", "#include \"textflag.h\"\nTEXT ·add(SB), NOSPLIT, $0-0\n\tMOVQ AX, BX\n\tRET\n")
|
||||
write("bad_arm64.s", "#include \"textflag.h\"\nTEXT ·f(SB), NOSPLIT, $0-0\n\tMOVQ AX, BX\n\tRET\n")
|
||||
write("generic.s", "#include \"textflag.h\"\nTEXT ·g(SB), NOSPLIT, $0-0\n\tRET\n")
|
||||
write("broken.s", "#include \"textflag.h\"\nTEXT ·b(SB), NOSPLIT, $0-0\n\tJMP nowhere\n\tRET\n")
|
||||
|
||||
stats, err := runCorpusAudit(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("runCorpusAudit: %v", err)
|
||||
}
|
||||
if stats.files != 4 {
|
||||
t.Errorf("files = %d, want 4", stats.files)
|
||||
}
|
||||
if stats.generic != 2 {
|
||||
t.Errorf("generic = %d, want 2 (generic.s and broken.s)", stats.generic)
|
||||
}
|
||||
// good_amd64 and generic.s assemble everywhere they are attempted.
|
||||
if stats.full != 2 {
|
||||
t.Errorf("full = %d, want 2", stats.full)
|
||||
}
|
||||
get := func(name string) *corpusTally {
|
||||
for i, tg := range stats.targets {
|
||||
if tg.name == name {
|
||||
return stats.tallies[i]
|
||||
}
|
||||
}
|
||||
t.Fatalf("no tally for %s", name)
|
||||
return nil
|
||||
}
|
||||
// amd64: good_amd64 + generic.s + broken.s; the broken file fails to parse.
|
||||
if a := get("amd64"); a.attempted != 3 || a.assembled != 2 {
|
||||
t.Errorf("amd64 = %d/%d, want 2/3", a.assembled, a.attempted)
|
||||
}
|
||||
// arm64: bad_arm64 (MOVQ is not arm64) + generic.s + broken.s.
|
||||
if a := get("arm64"); a.attempted != 3 || a.assembled != 1 {
|
||||
t.Errorf("arm64 = %d/%d, want 1/3", a.assembled, a.attempted)
|
||||
}
|
||||
if r := get("amd64").reasons["instruction not encodable"]; r != 0 {
|
||||
t.Errorf("amd64 unexpected unencodable reason: %d", r)
|
||||
}
|
||||
if r := get("arm64").reasons["instruction not encodable"]; r != 1 {
|
||||
t.Errorf("arm64 unencodable reasons = %d, want 1", r)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user