summaryrefslogtreecommitdiff
path: root/integrationtests/mmap_test.go
blob: 74eb14e6446320728e8924d53d06e0f7f3201031 (plain)
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
package integrationtests

import "testing"

const (
	mmapParquetDuration           = 6
	mmapWorkloadStartupEnv        = "IOR_WORKLOAD_STARTUP_DELAY_MS=1000"
	mmapScenarioAddressSpaceBytes = 8192
	mmapMinAddressSpaceBytesTotal = mmapScenarioAddressSpaceBytes * 2
)

var mmapTraceArgs = []string{"-trace-syscalls", "openat,write,close,mmap,msync,mremap,munmap"}

func TestMmapBasic(t *testing.T) {
	runScenarioResultWithIorArgs(t, "mmap-basic", []ExpectedEvent{
		{
			PathContains: "mmapfile.txt",
			Tracepoint:   "enter_mmap",
			Comm:         "ioworkload",
			MinCount:     1,
		},
	}, mmapTraceArgs)
}

func TestMmapMsyncSync(t *testing.T) {
	runScenarioResultWithIorArgs(t, "mmap-msync-sync", []ExpectedEvent{
		{
			PathContains: "msyncfile.txt",
			Tracepoint:   "enter_mmap",
			Comm:         "ioworkload",
			MinCount:     1,
		},
		{
			Tracepoint: "enter_msync",
			Comm:       "ioworkload",
			MinCount:   1,
		},
	}, mmapTraceArgs)
}

func TestMmapMsyncInvalidFlags(t *testing.T) {
	runScenarioResultWithIorArgs(t, "mmap-msync-invalid-flags", []ExpectedEvent{
		{
			PathContains: "msyncinvalidfile.txt",
			Tracepoint:   "enter_mmap",
			Comm:         "ioworkload",
			MinCount:     1,
		},
		{
			Tracepoint: "enter_msync",
			Comm:       "ioworkload",
			MinCount:   1,
		},
	}, mmapTraceArgs)
}

func TestMmapMremapMunmap(t *testing.T) {
	result, _ := runScenarioResultWithIorArgs(t, "mmap-mremap-munmap", []ExpectedEvent{
		{
			Tracepoint: "enter_mremap",
			Comm:       "ioworkload",
			MinCount:   1,
		},
		{
			Tracepoint: "enter_munmap",
			Comm:       "ioworkload",
			MinCount:   1,
		},
	}, mmapTraceArgs)

	assertEventBytesEqual(t, result, ExpectedEvent{
		Tracepoint: "enter_mremap",
		Comm:       "ioworkload",
	}, 0)
	assertEventBytesEqual(t, result, ExpectedEvent{
		Tracepoint: "enter_munmap",
		Comm:       "ioworkload",
	}, 0)
}

func TestMmapMremapMunmapAddressSpaceBytesInParquet(t *testing.T) {
	h := newTestHarness(t)
	h.WorkloadEnv = []string{mmapWorkloadStartupEnv}
	path, pid, err := h.RunParquetWithIorArgs("mmap-mremap-munmap", mmapParquetDuration, mmapTraceArgs)
	if err != nil {
		t.Fatalf("run mmap-mremap-munmap parquet scenario: %v", err)
	}

	rows := filterRecordsByPID(readParquetRecords(t, path), uint32(pid))
	if len(rows) == 0 {
		t.Fatalf("expected parquet rows for workload PID %d", pid)
	}

	var foundMremap, foundMunmap bool
	var addressSpaceTotal uint64
	for _, row := range rows {
		switch row.Syscall {
		case "mremap":
			if row.Bytes != 0 {
				t.Fatalf("mremap bytes = %d, want 0 (I/O bytes must stay separate)", row.Bytes)
			}
			if row.AddressSpaceBytes == mmapScenarioAddressSpaceBytes {
				foundMremap = true
			}
			addressSpaceTotal += row.AddressSpaceBytes
		case "munmap":
			if row.Bytes != 0 {
				t.Fatalf("munmap bytes = %d, want 0 (I/O bytes must stay separate)", row.Bytes)
			}
			if row.AddressSpaceBytes == mmapScenarioAddressSpaceBytes {
				foundMunmap = true
			}
			addressSpaceTotal += row.AddressSpaceBytes
		}
	}

	if !foundMremap {
		t.Fatalf("expected mremap row with AddressSpaceBytes=%d", mmapScenarioAddressSpaceBytes)
	}
	if !foundMunmap {
		t.Fatalf("expected munmap row with AddressSpaceBytes=%d", mmapScenarioAddressSpaceBytes)
	}
	if addressSpaceTotal < mmapMinAddressSpaceBytesTotal {
		t.Fatalf("mremap+munmap AddressSpaceBytes total = %d, want >= %d", addressSpaceTotal, mmapMinAddressSpaceBytesTotal)
	}
}