Skip to content

Commit

Permalink
tools/syz-linter: check t.Logf/Errorf/Fatalf messages
Browse files Browse the repository at this point in the history
Fix checking of Logf, it has string in 0-th arg.
Add checking of t.Errorf/Fatalf.
  • Loading branch information
dvyukov committed Apr 17, 2024
1 parent 18f6e12 commit acc528c
Show file tree
Hide file tree
Showing 41 changed files with 100 additions and 89 deletions.
2 changes: 1 addition & 1 deletion dashboard/app/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func TestAccess(t *testing.T) {
continue
}
if bytes.Contains(reply, []byte(ent.ref)) {
t.Errorf("request %v at level %v contains ref %v at level %v:\n%s\n\n",
t.Errorf("request %v at level %v contains ref %v at level %v:\n%s",
url, requestLevel, ent.ref, ent.level, reply)
}
}
Expand Down
10 changes: 5 additions & 5 deletions dashboard/app/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestClientSecretOK(t *testing.T) {
},
}, "user", "secr1t", "")
if err != nil || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}

Expand All @@ -28,7 +28,7 @@ func TestClientOauthOK(t *testing.T) {
},
}, "user", "", "OauthSubject:public")
if err != nil || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}

Expand All @@ -39,7 +39,7 @@ func TestClientSecretFail(t *testing.T) {
},
}, "user", "wrong", "")
if err != ErrAccess || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}

Expand All @@ -48,7 +48,7 @@ func TestClientSecretMissing(t *testing.T) {
Clients: map[string]string{},
}, "user", "ignored", "")
if err != ErrAccess || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}

Expand All @@ -63,7 +63,7 @@ func TestClientNamespaceOK(t *testing.T) {
},
}, "user", "secr1t", "")
if err != nil || got != "ns1" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions dashboard/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ func TestPurgeOldCrashes(t *testing.T) {

// A sanity check for the test itself.
if !firstCrashExists() {
t.Fatalf("The first reported crash should be present")
t.Fatalf("the first reported crash should be present")
}

// Unreport the first crash.
Expand All @@ -970,7 +970,7 @@ func TestPurgeOldCrashes(t *testing.T) {
}
// Check that the unreported crash was purged.
if firstCrashExists() {
t.Fatalf("The unreported crash should have been purged.")
t.Fatalf("the unreported crash should have been purged")
}
}

Expand Down
4 changes: 2 additions & 2 deletions dashboard/app/reporting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,10 @@ func TestUpdateBugReporting(t *testing.T) {
setIDs(bug, test.After)
hasError := bug.updateReportings(c.ctx, cfg, now) != nil
if hasError != test.Error {
t.Errorf("Before: %#v, Expected error: %v, Got error: %v", test.Before, test.Error, hasError)
t.Errorf("before: %#v, expected error: %v, got error: %v", test.Before, test.Error, hasError)
}
if !test.Error && !reflect.DeepEqual(bug.Reporting, test.After) {
t.Errorf("Before: %#v, Expected After: %#v, Got After: %#v", test.Before, test.After, bug.Reporting)
t.Errorf("before: %#v, expected after: %#v, got after: %#v", test.Before, test.After, bug.Reporting)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/repro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func TestNeedReproIsolated(t *testing.T) {
}
funcResult := needReproForBug(c.ctx, bug)
if funcResult != test.needRepro {
t.Errorf("For %#v expected needRepro=%v, got needRepro=%v",
t.Errorf("for %#v expected needRepro=%v, got needRepro=%v",
bug, test.needRepro, funcResult)
}
}
Expand Down
2 changes: 1 addition & 1 deletion executor/style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ if (foo) {
}

line := bytes.Count(data[:start], []byte{'\n'}) + 1
t.Errorf("\nexecutor/%v:%v: %v\n%s\n", file, line, check.message, data[start:end])
t.Errorf("\nexecutor/%v:%v: %v\n%s", file, line, check.message, data[start:end])
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/asset/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,29 @@ func TestUploadBuildAsset(t *testing.T) {
be.objectRemove = func(string) error { return fmt.Errorf("not now") }
err = storage.DeprecateAssets()
if err == nil {
t.Fatalf("DeprecateAssets() should have failed")
t.Fatalf("DeprecateAssets should have failed")
}

// Let the deletion be successful.
be.objectRemove = nil
err = storage.DeprecateAssets()
if err != nil {
t.Fatalf("DeprecateAssets() was expected to be successful, got %s", err)
t.Fatalf("DeprecateAssets was expected to be successful, got %s", err)
}
path, err := be.getPath(allUrls[2])
if err != nil {
t.Fatalf("getPath failed: %s", err)
}
err = be.hasOnly([]string{path})
if err != nil {
t.Fatalf("after first DeprecateAssets(): %s", err)
t.Fatalf("after first DeprecateAssets: %s", err)
}

// Delete the rest.
dashMock.downloadURLs = map[string]bool{}
err = storage.DeprecateAssets()
if err != nil || len(be.objects) != 0 {
t.Fatalf("second DeprecateAssets() failed: %s, len %d",
t.Fatalf("second DeprecateAssets failed: %s, len %d",
err, len(be.objects))
}
}
Expand Down Expand Up @@ -365,7 +365,7 @@ func TestTwoBucketDeprecation(t *testing.T) {
url: true,
}
dummy.objectRemove = func(url string) error {
t.Fatalf("Unexpected removal")
t.Fatalf("unexpected removal")
return nil
}
err := storage.DeprecateAssets()
Expand All @@ -389,7 +389,7 @@ func TestInvalidAssetURLs(t *testing.T) {
url: true,
}
dummy.objectRemove = func(url string) error {
t.Fatalf("Unexpected removal")
t.Fatalf("unexpected removal")
return nil
}
err := storage.DeprecateAssets()
Expand Down
2 changes: 1 addition & 1 deletion pkg/ast/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestParseAll(t *testing.T) {
desc4 := desc.Filter(func(n Node) bool { return true })
desc5 := desc.Filter(func(n Node) bool { return false })
if len(desc4.Nodes) != len(desc.Nodes) || len(desc5.Nodes) != 0 {
t.Fatalf("Filter is broken: desc=%v desc4=%v desc5=%v",
t.Fatalf("filter is broken: desc=%v desc4=%v desc5=%v",
len(desc.Nodes), len(desc4.Nodes), len(desc5.Nodes))
}
})
Expand Down
16 changes: 8 additions & 8 deletions pkg/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func reponseFor(t *testing.T, claims jwtClaims) (*httptest.Server, Endpoint) {
Expiration: fmt.Sprint(claims.Expiration.Unix()),
})
if err != nil {
t.Fatalf("Marshal %v", err)
t.Fatalf("marshal %v", err)
}
w.Header()["Content-Type"] = []string{"application/json"}
w.Write(bytes)
Expand All @@ -41,10 +41,10 @@ func TestBearerValid(t *testing.T) {

got, err := dut.DetermineAuthSubj(tm, []string{"Bearer x"})
if err != nil {
t.Errorf("Unexpected error %v", err)
t.Errorf("inexpected error %v", err)
}
if !strings.HasSuffix(got, magic) {
t.Errorf("Wrong subj %v not suffix of %v", magic, got)
t.Errorf("wrong subj %v not suffix of %v", magic, got)
}
}

Expand All @@ -59,7 +59,7 @@ func TestBearerWrongAudience(t *testing.T) {

_, err := dut.DetermineAuthSubj(tm, []string{"Bearer x"})
if !strings.HasPrefix(err.Error(), "unexpected audience") {
t.Fatalf("Unexpected error %v", err)
t.Fatalf("unexpected error %v", err)
}
}

Expand All @@ -74,7 +74,7 @@ func TestBearerExpired(t *testing.T) {

_, err := dut.DetermineAuthSubj(tm, []string{"Bearer x"})
if !strings.HasPrefix(err.Error(), "token past expiration") {
t.Fatalf("Unexpected error %v", err)
t.Fatalf("unexpected error %v", err)
}
}

Expand All @@ -83,7 +83,7 @@ func TestMissingHeader(t *testing.T) {
defer ts.Close()
got, err := dut.DetermineAuthSubj(time.Now(), []string{})
if err != nil || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}

Expand All @@ -92,7 +92,7 @@ func TestBadHeader(t *testing.T) {
defer ts.Close()
got, err := dut.DetermineAuthSubj(time.Now(), []string{"bad"})
if err != nil || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}

Expand All @@ -104,6 +104,6 @@ func TestBadHttpStatus(t *testing.T) {
dut := MakeEndpoint(ts.URL)
got, err := dut.DetermineAuthSubj(time.Now(), []string{"Bearer x"})
if err == nil || !strings.HasSuffix(err.Error(), "400") || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
t.Errorf("unexpected error %v %v", got, err)
}
}
2 changes: 1 addition & 1 deletion pkg/build/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestQueryLinuxCompiler(t *testing.T) {
const badDir = "./testingData/non_existing_folder"
_, err = queryLinuxCompiler(badDir)
if err == nil {
t.Fatalf("Expected an error, got none")
t.Fatalf("expected an error, got none")
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,16 @@ func TestCollectUnused(t *testing.T) {
for i, input := range inputs {
desc := ast.Parse([]byte(input.text), "input", nil)
if desc == nil {
t.Fatalf("Test %d: failed to parse", i)
t.Fatalf("test %d: failed to parse", i)
}

nodes, err := CollectUnused(desc, targets.List[targets.TestOS][targets.TestArch64], nil)
if err != nil {
t.Fatalf("Test %d: CollectUnused failed: %v", i, err)
t.Fatalf("test %d: CollectUnused failed: %v", i, err)
}

if len(input.names) != len(nodes) {
t.Errorf("Test %d: want %d nodes, got %d", i, len(input.names), len(nodes))
t.Errorf("test %d: want %d nodes, got %d", i, len(input.names), len(nodes))
}

names := make([]string, len(nodes))
Expand All @@ -302,7 +302,7 @@ func TestCollectUnused(t *testing.T) {
sort.Strings(input.names)

if !reflect.DeepEqual(names, input.names) {
t.Errorf("Test %d: Unused nodes differ. Want %v, Got %v", i, input.names, names)
t.Errorf("test %d: Unused nodes differ. Want %v, Got %v", i, input.names, names)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cover/backend/dwarf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func TestIsKcovBrokenInCompiler(t *testing.T) {
}
for _, ver := range inputDataTrue {
if !isKcovBrokenInCompiler(ver) {
t.Fatalf("isKcovBrokenInCompiler(%q) unexpectedly returned false\n", ver)
t.Fatalf("isKcovBrokenInCompiler(%q) unexpectedly returned false", ver)
}
}
for _, ver := range inputDataFalse {
if isKcovBrokenInCompiler(ver) {
t.Fatalf("isKcovBrokenInCompiler(%q) unexpectedly returned true\n", ver)
t.Fatalf("isKcovBrokenInCompiler(%q) unexpectedly returned true", ver)
}
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestCleanPathAndroid(t *testing.T) {
path, epath, ename := files[0], files[1], files[2]
rpath, rname := cleanPathAndroid(path, test.SrcDir, test.Delimiters, test.FnExists)
if (rpath != epath) || (rname != ename) {
t.Fatalf("cleanPathAndroid(`%s`, `%s`, %v, ...) unexpectedly returned (`%s`, `%s`) instead of (`%s`, `%s`)\n",
t.Fatalf("cleanPathAndroid(`%s`, `%s`, %v, ...) unexpectedly returned (`%s`, `%s`) instead of (`%s`, `%s`)",
path, test.SrcDir, test.Delimiters, rpath, rname, epath, ename)
}
}
Expand All @@ -113,7 +113,7 @@ func runNextCallTarget(t *testing.T, arg NextCallTargetTest) {
i := 0
target, pc := nextCallTarget(arg.Arch, arg.Text, arg.Data, &i)
if target != arg.ExpTarget || pc != arg.ExpPC {
t.Fatalf("nextCallTarget(`%v`, %x, %v) unexpectedly returned (%x, %x) instead of (%x, %x)\n",
t.Fatalf("nextCallTarget(`%v`, %x, %v) unexpectedly returned (%x, %x) instead of (%x, %x)",
arg.Arch, arg.Text, arg.Data, target, pc, arg.ExpTarget, arg.ExpPC)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cover/cover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestMergeDiff(t *testing.T) {
cov.Merge(test.init)
diff := cov.MergeDiff(test.merge)
if res := cmp.Diff(test.diff, diff); res != "" {
t.Fatalf("MergeDiff result is wrong: %v", res)
t.Fatalf("result is wrong: %v", res)
}
result := cov.Serialize()
sort.Slice(result, func(i, j int) bool {
Expand Down
4 changes: 2 additions & 2 deletions pkg/csource/csource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ func testOne(t *testing.T, p *prog.Prog, opts Options) {
if atomic.AddUint32(&failedTests, 1) > maxFailures {
t.Fatal()
}
t.Logf("opts: %+v\nprogram:\n%s\n", opts, p.Serialize())
t.Logf("opts: %+v\nprogram:\n%s", opts, p.Serialize())
t.Fatalf("%v", err)
}
bin, err := Build(p.Target, src)
if err != nil {
if atomic.AddUint32(&failedTests, 1) > maxFailures {
t.Fatal()
}
t.Logf("opts: %+v\nprogram:\n%s\n", opts, p.Serialize())
t.Logf("opts: %+v\nprogram:\n%s", opts, p.Serialize())
t.Fatalf("%v", err)
}
defer os.Remove(bin)
Expand Down
2 changes: 1 addition & 1 deletion pkg/email/lore/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Bug report`,
}

if len(threads) > len(expected) {
t.Fatalf("Expected %d threads, got %d", len(expected), len(threads))
t.Fatalf("expected %d threads, got %d", len(expected), len(threads))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ipc/ipc_priv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func TestOutputDeadline(t *testing.T) {
c.wait()
out := <-c.readDone
if string(out) != "done\n" {
t.Errorf("Unexpected output: '%s'", out)
t.Errorf("unexpected output: '%s'", out)
}
}
2 changes: 1 addition & 1 deletion pkg/ipc/ipc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestExecute(t *testing.T) {

flags := []ExecFlags{0, FlagThreaded}
for _, flag := range flags {
t.Logf("testing flags 0x%x\n", flag)
t.Logf("testing flags 0x%x", flag)
cfg := &Config{
Executor: bin,
UseShmem: useShmem,
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/decompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ Disassembly of section .data:
},
}
if !reflect.DeepEqual(opcodes, expected) {
t.Errorf("Expected: %#v, got: %#v", expected, opcodes)
t.Errorf("expected: %#v, got: %#v", expected, opcodes)
}
}
10 changes: 5 additions & 5 deletions pkg/report/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func prepareLinuxReporter(t *testing.T, arch string) (*Reporter, *linux) {
}
reporter, err := NewReporter(cfg)
if err != nil {
t.Errorf("Failed to create a reporter instance for %#v: %v", arch, err)
t.Errorf("failed to create a reporter instance for %#v: %v", arch, err)
}
return reporter, reporter.impl.(*linux)
}
Expand Down Expand Up @@ -369,11 +369,11 @@ func TestParseLinuxOpcodes(t *testing.T) {
_, linuxReporter := prepareLinuxReporter(t, test.arch)
ret, err := linuxReporter.parseOpcodes(test.input)
if test.output == nil && err == nil {
t.Errorf("Expected an error on input %#v", test)
t.Errorf("expected an error on input %#v", test)
} else if test.output != nil && err != nil {
t.Errorf("Unexpected error %v on input %#v", err, test.input)
t.Errorf("unexpected error %v on input %#v", err, test.input)
} else if test.output != nil && !reflect.DeepEqual(ret, *test.output) {
t.Errorf("Expected: %#v, got: %#v", test.output, ret)
t.Errorf("expected: %#v, got: %#v", test.output, ret)
}
})
}
Expand Down Expand Up @@ -441,6 +441,6 @@ func testDisassembly(t *testing.T, reporter *Reporter, linuxReporter *linux, tes
}

if !bytes.Equal(output, result) {
t.Fatalf("Expected:\n%s\nGot:\n%s\n", output, result)
t.Fatalf("expected:\n%s\ngot:\n%s", output, result)
}
}
Loading

0 comments on commit acc528c

Please sign in to comment.