aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-11-28 10:26:40 +0100
committerDmitry Vyukov <dvyukov@google.com>2019-11-28 10:30:27 +0100
commit46869e3ee2274fbf353cb2c7d6cf36ed19e52b45 (patch)
tree5851b8634916ba051573abd3007b9623d11ec442 /pkg
parent97264cb1f32b60bfce5a79a8c06d2b1b20875490 (diff)
pkg/csource: detect common mistakes in the common executor header
Diffstat (limited to 'pkg')
-rw-r--r--pkg/csource/csource_test.go35
-rw-r--r--pkg/csource/generated.go6
2 files changed, 39 insertions, 2 deletions
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go
index 914ecaa71..162fcf788 100644
--- a/pkg/csource/csource_test.go
+++ b/pkg/csource/csource_test.go
@@ -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])
+ }
+ }
+}
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index d51f321ea..778a9f4d3 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -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;
}