aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/clangtool/tooltest
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-02-05 13:59:08 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-02-06 09:29:18 +0000
commitfd36daf55d7f9e8ab412fcbf0441658a8d8be727 (patch)
tree6d0a982741820007d1a15212e0227df85eb1b501 /pkg/clangtool/tooltest
parentf03c419189ef8ed823e306a342ee4d330fb2c394 (diff)
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
Diffstat (limited to 'pkg/clangtool/tooltest')
-rw-r--r--pkg/clangtool/tooltest/tooltest.go16
1 files changed, 5 insertions, 11 deletions
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"),