diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-20 11:38:19 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-20 11:38:19 +0300 |
| commit | 9310b54d439d4a1a8d4d337987aa63884df0af76 (patch) | |
| tree | c6fb38085891a04ce81672f977af316a2e96b2fd /internal/flags/sampling_test.go | |
| parent | 5fd613562e2aa2ab3aac3349f44db88330046c1c (diff) | |
feat: add syscall aggregate sampling infrastructure (task 17)
Diffstat (limited to 'internal/flags/sampling_test.go')
| -rw-r--r-- | internal/flags/sampling_test.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/internal/flags/sampling_test.go b/internal/flags/sampling_test.go new file mode 100644 index 0000000..0966c0f --- /dev/null +++ b/internal/flags/sampling_test.go @@ -0,0 +1,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) + } +} |
