mirror of
https://github.com/reactos/syzkaller.git
synced 2024-10-07 00:53:27 +00:00
executor: add some code style checks
Move the test from pkg/csource to executor/ in order to be able to (1) run it on *.cc files, (2) run on unprocessed *.h files, (3) produce line numbers. Add a check for missed space after //.
This commit is contained in:
parent
56fe566546
commit
cb436c69d9
@ -9,7 +9,7 @@
|
||||
// - NORETURN/PRINTF/debug are removed
|
||||
// - exitf/fail are replaced with exit
|
||||
// - uintN types are replaced with uintN_t
|
||||
// - /*FOO*/ placeholders are replaced by actual values
|
||||
// - /*{{{FOO}}}*/ placeholders are replaced by actual values
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
|
@ -362,7 +362,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
if (argc >= 2 && strcmp(argv[1], "setup_kcsan_filterlist") == 0) {
|
||||
#if SYZ_HAVE_KCSAN
|
||||
setup_kcsan_filterlist(argv + 2, argc - 2, /*suppress=*/true);
|
||||
setup_kcsan_filterlist(argv + 2, argc - 2, true);
|
||||
#else
|
||||
fail("KCSAN is not implemented");
|
||||
#endif
|
||||
|
107
executor/style_test.go
Normal file
107
executor/style_test.go
Normal file
@ -0,0 +1,107 @@
|
||||
// Copyright 2020 syzkaller project authors. All rights reserved.
|
||||
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
||||
|
||||
package executor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExecutorMistakes(t *testing.T) {
|
||||
checks := []*struct {
|
||||
pattern string
|
||||
suppression string
|
||||
message string
|
||||
tests []string
|
||||
commonOnly bool
|
||||
}{
|
||||
{
|
||||
pattern: `\)\n\t*(debug|debug_dump_data)\(`,
|
||||
message: "debug() calls are stripped from C reproducers, this code will break. Use {} around debug() to fix",
|
||||
commonOnly: true,
|
||||
tests: []string{
|
||||
`
|
||||
if (foo)
|
||||
debug("foo failed");
|
||||
`, `
|
||||
if (x + y)
|
||||
debug_dump_data(data, len);
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
// These are also not properly stripped by pkg/csource.
|
||||
pattern: `/\*[^{]`,
|
||||
message: "Don't use /* */ block comments. Use // line comments instead",
|
||||
tests: []string{
|
||||
`/* C++ comment */`,
|
||||
},
|
||||
},
|
||||
{
|
||||
pattern: `//[^\s]`,
|
||||
suppression: `https?://`,
|
||||
message: "Add a space after //",
|
||||
tests: []string{
|
||||
`//foo`,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, check := range checks {
|
||||
re := regexp.MustCompile(check.pattern)
|
||||
for _, test := range check.tests {
|
||||
if !re.MatchString(test) {
|
||||
t.Fatalf("patter %q does not match test %q", check.pattern, test)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, file := range executorFiles(t) {
|
||||
data, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, check := range checks {
|
||||
if check.commonOnly && !strings.Contains(file, "common") {
|
||||
continue
|
||||
}
|
||||
re := regexp.MustCompile(check.pattern)
|
||||
supp := regexp.MustCompile(check.suppression)
|
||||
for _, match := range re.FindAllIndex(data, -1) {
|
||||
start, end := match[0], match[1]
|
||||
for start != 0 && data[start-1] != '\n' {
|
||||
start--
|
||||
}
|
||||
for end != len(data) && data[end] != '\n' {
|
||||
end++
|
||||
}
|
||||
if supp.Match(data[start:end]) {
|
||||
continue
|
||||
}
|
||||
line := bytes.Count(data[:start], []byte{'\n'}) + 1
|
||||
t.Errorf("\nexecutor/%v:%v: %v\n%s\n", file, line, check.message, data[start:end])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func executorFiles(t *testing.T) []string {
|
||||
cc, err := filepath.Glob("*.cc")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h, err := filepath.Glob("*.h")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(cc) == 0 || len(h) == 0 {
|
||||
t.Fatal("found no executor files")
|
||||
}
|
||||
res := append(cc, h...)
|
||||
sort.Strings(res)
|
||||
return res
|
||||
}
|
@ -100,7 +100,7 @@ static int test_kvm()
|
||||
// if (res = test_one(64, text16_vm, sizeof(text16_vm) - 1, KVM_SETUP_VM, KVM_EXIT_HLT, true))
|
||||
// return res;
|
||||
|
||||
/// TODO: test code executed in interrupt handlers.
|
||||
// TODO: test code executed in interrupt handlers.
|
||||
// const char text32_div0[] = "\x31\xc0\xf7\xf0";
|
||||
// if (res = test_one(32, text32_div0, sizeof(text32_div0)-1, 0, KVM_EXIT_HLT, true))
|
||||
// return res;
|
||||
|
@ -184,51 +184,3 @@ func TestExecutorMacros(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecutorMistakes(t *testing.T) {
|
||||
mistakes := []struct {
|
||||
pattern string
|
||||
message string
|
||||
tests []string
|
||||
}{
|
||||
{
|
||||
pattern: `\)\n\t*(debug|debug_dump_data)\(`,
|
||||
message: "debug() calls are stripped from C reproducers, this code will break. Use {} around debug() to fix",
|
||||
tests: []string{
|
||||
`
|
||||
if (foo)
|
||||
debug("foo failed");
|
||||
`, `
|
||||
if (x + y)
|
||||
debug_dump_data(data, len);
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
// These are also not properly stripped by pkg/csource.
|
||||
pattern: `/\*[^{]`,
|
||||
message: "Don't use /* */ block comments. Use // line comments instead",
|
||||
tests: []string{
|
||||
`/* C++ comment */`,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, mistake := range mistakes {
|
||||
re := regexp.MustCompile(mistake.pattern)
|
||||
for _, test := range mistake.tests {
|
||||
if !re.MatchString(test) {
|
||||
t.Errorf("patter %q does not match test %q", mistake.pattern, test)
|
||||
}
|
||||
}
|
||||
for _, match := range re.FindAllStringIndex(commonHeader, -1) {
|
||||
start, end := match[0], match[1]
|
||||
for start != 0 && commonHeader[start] != '\n' {
|
||||
start--
|
||||
}
|
||||
for end != len(commonHeader) && commonHeader[end] != '\n' {
|
||||
end++
|
||||
}
|
||||
t.Errorf("%v:%v", mistake.message, commonHeader[start:end])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user