From fd36daf55d7f9e8ab412fcbf0441658a8d8be727 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 5 Feb 2026 13:59:08 +0100 Subject: tools/clang: compile clang tools into the binary Compiled clang tools into Go binaries using cgo. This significantly simplifies building and deployment. This also enables unit testing of clang tools. Now raw go test for clang tools will build them, run, and verify output. Each clang tool is still started as a subprocess. I've experimented with running them in-process, but this makes stdout/stderr interception extremly complicated, and it seems that clang tools still use unsynchronized global state, which breaks when invoked multiple times. Subprocesses also make it safer in the face of potential memory leaks, or memory corruptions in clang tools. Fixes #6645 --- pkg/clangtool/tooltest/tooltest.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'pkg/clangtool/tooltest') diff --git a/pkg/clangtool/tooltest/tooltest.go b/pkg/clangtool/tooltest/tooltest.go index 4f0b3bced..e78a85b62 100644 --- a/pkg/clangtool/tooltest/tooltest.go +++ b/pkg/clangtool/tooltest/tooltest.go @@ -18,16 +18,10 @@ import ( "github.com/google/syzkaller/pkg/testutil" ) -var ( - FlagBin = flag.String("bin", "", "path to the clang tool binary to use") - FlagUpdate = flag.Bool("update", false, "update golden files") -) +var FlagUpdate = flag.Bool("update", false, "update golden files") -func TestClangTool[Output any, OutputPtr clangtool.OutputDataPtr[Output]](t *testing.T) { - if *FlagBin == "" { - t.Skipf("clang tool path is not specified, run with -bin=clangtool flag") - } - ForEachTestFile(t, func(t *testing.T, cfg *clangtool.Config, file string) { +func TestClangTool[Output any, OutputPtr clangtool.OutputDataPtr[Output]](t *testing.T, tool string) { + ForEachTestFile(t, tool, func(t *testing.T, cfg *clangtool.Config, file string) { out, err := clangtool.Run[Output, OutputPtr](cfg) if err != nil { t.Fatal(err) @@ -57,7 +51,7 @@ func LoadOutput[Output any, OutputPtr clangtool.OutputDataPtr[Output]](t *testin return out } -func ForEachTestFile(t *testing.T, fn func(t *testing.T, cfg *clangtool.Config, file string)) { +func ForEachTestFile(t *testing.T, tool string, fn func(t *testing.T, cfg *clangtool.Config, file string)) { forEachTestFile(t, func(t *testing.T, file string) { t.Run(filepath.Base(file), func(t *testing.T) { t.Parallel() @@ -73,7 +67,7 @@ func ForEachTestFile(t *testing.T, fn func(t *testing.T, cfg *clangtool.Config, t.Fatal(err) } cfg := &clangtool.Config{ - ToolBin: *FlagBin, + Tool: tool, KernelSrc: osutil.Abs("testdata"), KernelObj: buildDir, CacheFile: filepath.Join(buildDir, filepath.Base(file)+".json"), -- cgit mrf-deployment