pkg/csource: detect common mistakes in the common executor header

This commit is contained in:
Dmitry Vyukov 2019-11-28 10:26:40 +01:00
parent 97264cb1f3
commit 46869e3ee2
3 changed files with 43 additions and 4 deletions

View File

@ -2637,8 +2637,9 @@ retry:
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
debug("reset FS_XFLAG_IMMUTABLE\n");
}
close(fd);
continue;
}
@ -2665,8 +2666,9 @@ retry:
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
debug("reset FS_XFLAG_IMMUTABLE\n");
}
close(fd);
continue;
}

View File

@ -181,3 +181,38 @@ func TestExecutorMacros(t *testing.T) {
}
}
}
func TestExecutorMistakes(t *testing.T) {
mistakes := map[string][]string{
// We strip debug() calls from the resulting C source,
// this breaks the following pattern. Use {} around debug() to fix.
"\\)\n\\t*(debug|debug_dump_data)\\(": {
`
if (foo)
debug("foo failed");
`, `
if (x + y)
debug_dump_data(data, len);
`,
},
}
for pattern, tests := range mistakes {
re := regexp.MustCompile(pattern)
for _, test := range tests {
if !re.MatchString(test) {
t.Errorf("patter %q does not match test %q", 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("pattern %q matches executor source:\n%v",
pattern, commonHeader[start:end])
}
}
}

View File

@ -5610,8 +5610,9 @@ retry:
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
debug("reset FS_XFLAG_IMMUTABLE\n");
}
close(fd);
continue;
}
@ -5637,8 +5638,9 @@ retry:
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
debug("reset FS_XFLAG_IMMUTABLE\n");
}
close(fd);
continue;
}