From 9310b54d439d4a1a8d4d337987aa63884df0af76 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 20 May 2026 11:38:19 +0300 Subject: feat: add syscall aggregate sampling infrastructure (task 17) --- internal/flags/sampling_test.go | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 internal/flags/sampling_test.go (limited to 'internal/flags/sampling_test.go') 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) + } +} -- cgit v1.2.3