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
|
package flags
import (
"strings"
"testing"
"ior/internal/types"
)
func TestParseSamplingRates(t *testing.T) {
cfg, err := parseForTest(t,
"-syscall-sampling-families", "Time=100,misc=0",
"-syscall-sampling-syscalls", "futex=0,clock_gettime=7",
)
if err != nil {
t.Fatalf("parse returned error: %v", err)
}
if got := cfg.SyscallFamilySamplingRates[types.FamilyTime]; got != 100 {
t.Fatalf("Time family rate = %d, want 100", got)
}
if got := cfg.SyscallFamilySamplingRates[types.FamilyMisc]; got != 0 {
t.Fatalf("Misc family rate = %d, want 0", got)
}
if got := cfg.SyscallSamplingRates["futex"]; got != 0 {
t.Fatalf("futex rate = %d, want 0", got)
}
if got := cfg.SyscallSamplingRates["clock_gettime"]; got != 7 {
t.Fatalf("clock_gettime rate = %d, want 7", got)
}
}
func TestParseSamplingFamilyRejectsUnknown(t *testing.T) {
_, err := parseForTest(t, "-syscall-sampling-families", "Nope=4")
if err == nil {
t.Fatal("expected parse error")
}
if !strings.Contains(err.Error(), "invalid syscall family") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestParseSamplingSyscallRejectsMalformedEntry(t *testing.T) {
_, err := parseForTest(t, "-syscall-sampling-syscalls", "futex")
if err == nil {
t.Fatal("expected parse error")
}
if !strings.Contains(err.Error(), "expected name=rate") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestParseSamplingSyscallRejectsUnknownName(t *testing.T) {
_, err := parseForTest(t, "-syscall-sampling-syscalls", "not_a_syscall=2")
if err == nil {
t.Fatal("expected parse error")
}
if !strings.Contains(err.Error(), "invalid syscall in sampling map") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestCloneDeepCopiesSamplingMaps(t *testing.T) {
cfg := NewFlags()
cfg.SyscallFamilySamplingRates[types.FamilyTime] = 5
cfg.SyscallSamplingRates["futex"] = 9
cloned := cfg.Clone()
cloned.SyscallFamilySamplingRates[types.FamilyTime] = 100
cloned.SyscallSamplingRates["futex"] = 1
if got := cfg.SyscallFamilySamplingRates[types.FamilyTime]; got != 5 {
t.Fatalf("original family rate mutated: got %d, want 5", got)
}
if got := cfg.SyscallSamplingRates["futex"]; got != 9 {
t.Fatalf("original syscall rate mutated: got %d, want 9", got)
}
}
|