1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
package integrationtests
import (
"strings"
"testing"
)
func TestOpenBasic(t *testing.T) {
runScenario(t, "open-basic", []ExpectedEvent{
{
PathContains: "testfile.txt",
Tracepoint: "enter_openat",
Comm: "ioworkload",
MinCount: 1,
},
})
}
func TestOpenCreat(t *testing.T) {
runScenario(t, "open-creat", []ExpectedEvent{
{
PathContains: "creatfile.txt",
Tracepoint: "enter_creat",
Comm: "ioworkload",
MinCount: 1,
},
})
}
func TestOpenByHandleAt(t *testing.T) {
runScenario(t, "open-by-handle-at", []ExpectedEvent{
{
PathContains: "handlefile.txt",
Tracepoint: "enter_open_by_handle_at",
Comm: "ioworkload",
MinCount: 1,
},
})
}
func TestOpenEnoent(t *testing.T) {
runScenario(t, "open-enoent", []ExpectedEvent{
{
PathContains: "enoentfile.txt",
Tracepoint: "enter_openat",
Comm: "ioworkload",
MinCount: 1,
},
})
}
func TestOpenRdonlyWrite(t *testing.T) {
runScenario(t, "open-rdonly-write", []ExpectedEvent{
{
PathContains: "rdonlyfile.txt",
Tracepoint: "enter_openat",
Comm: "ioworkload",
MinCount: 1,
},
{
PathContains: "rdonlyfile.txt",
Tracepoint: "enter_write",
Comm: "ioworkload",
MinCount: 1,
},
})
}
func TestOpenPidFilter(t *testing.T) {
h := newTestHarness(t)
result, pid, err := h.Run("open-pid-filter", defaultDuration)
if err != nil {
t.Fatalf("run scenario open-pid-filter: %v", err)
}
AssertNoUnexpectedPID(t, result, pid)
AssertNoUnexpectedComm(t, result, "ioworkload")
// Parent's file should be captured.
AssertEventsPresent(t, result, []ExpectedEvent{
{
PathContains: "parentfile.txt",
Tracepoint: "enter_openat",
Comm: "ioworkload",
MinCount: 1,
},
})
// Child's file should NOT be captured (different PID).
// Scope to openat so parent cleanup unlink/rmdir operations on childfile
// do not create false positives.
AssertEventsAbsent(t, result, []ExpectedEvent{
{
PathContains: "childfile.txt",
Tracepoint: "enter_openat",
},
})
}
func TestOpenDurationGap(t *testing.T) {
h := newTestHarness(t)
result, pid, err := h.Run("open-duration-gap", defaultDuration)
if err != nil {
t.Fatalf("run scenario open-duration-gap: %v", err)
}
AssertNoUnexpectedPID(t, result, pid)
AssertNoUnexpectedComm(t, result, "ioworkload")
// We intentionally sleep 800ms between first and second openat.
const minGapNs = uint64(500 * 1_000_000)
for _, rec := range result.Records {
if !strings.Contains(rec.TraceID.String(), "enter_openat") {
continue
}
if !strings.Contains(rec.Path, "gap-second.txt") {
continue
}
if rec.Cnt.DurationToPrev < minGapNs {
t.Fatalf("durationToPrev for second openat = %d ns, want >= %d ns", rec.Cnt.DurationToPrev, minGapNs)
}
return
}
t.Fatalf("did not find second openat record for gap-second.txt")
}
|