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/syscall_aggregate_consumer_test.go | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/syscall_aggregate_consumer_test.go (limited to 'internal/syscall_aggregate_consumer_test.go') diff --git a/internal/syscall_aggregate_consumer_test.go b/internal/syscall_aggregate_consumer_test.go new file mode 100644 index 0000000..1f6e856 --- /dev/null +++ b/internal/syscall_aggregate_consumer_test.go @@ -0,0 +1,53 @@ +package internal + +import ( + "bytes" + "encoding/binary" + "testing" + + "ior/internal/flags" + "ior/internal/types" +) + +func TestBuildSyscallSamplingRatesFamilyAndSyscallOverride(t *testing.T) { + cfg := flags.NewFlags() + cfg.SyscallFamilySamplingRates[types.FamilyTime] = 100 + cfg.SyscallSamplingRates["clock_gettime"] = 3 + + rates := buildSyscallSamplingRates(cfg) + if got := rates[types.SYS_ENTER_NANOSLEEP]; got != 100 { + t.Fatalf("nanosleep rate = %d, want 100", got) + } + if got := rates[types.SYS_ENTER_CLOCK_GETTIME]; got != 3 { + t.Fatalf("clock_gettime rate = %d, want 3", got) + } +} + +func TestDecodeRawSyscallAggregate(t *testing.T) { + want := rawSyscallAggregate{ + Count: 7, + Errors: 2, + TotalDuration: 1234, + MinDuration: 12, + MaxDuration: 456, + Histogram: [8]uint64{1, 2, 3, 4, 5, 6, 7, 8}, + } + var buf bytes.Buffer + if err := binary.Write(&buf, binary.LittleEndian, want); err != nil { + t.Fatalf("binary write: %v", err) + } + + got, err := decodeRawSyscallAggregate(buf.Bytes()) + if err != nil { + t.Fatalf("decodeRawSyscallAggregate error: %v", err) + } + if got != want { + t.Fatalf("decoded aggregate = %+v, want %+v", got, want) + } +} + +func TestDecodeRawSyscallAggregateRejectsBadSize(t *testing.T) { + if _, err := decodeRawSyscallAggregate([]byte{1, 2, 3}); err == nil { + t.Fatal("expected error for short value") + } +} -- cgit v1.2.3