@@ -27,7 +27,7 @@ import (
2727// buildEventBytes constructs a raw eBPF byte payload for GoTLSDataEvent.
2828// Offsets match the C struct go_tls_event exactly.
2929func buildEventBytes (t * testing.T ,
30- timestamp uint64 , pid , tid uint32 , dataLen int32 , eventType uint8 ,
30+ timestamp uint64 , seq uint64 , emitCPU uint32 , pid , tid uint32 , dataLen int32 , eventType uint8 ,
3131 fd uint32 , srcIP [16 ]byte , srcPort uint16 , dstIP [16 ]byte , dstPort uint16 ,
3232 ipVersion uint8 , comm [16 ]byte , payload []byte ,
3333) []byte {
@@ -38,23 +38,25 @@ func buildEventBytes(t *testing.T,
3838 t .Fatalf ("binary.Write failed: %v" , err )
3939 }
4040 }
41- write (timestamp ) // offset 0, u64
42- write (pid ) // offset 8, u32
43- write (tid ) // offset 12, u32
44- write (dataLen ) // offset 16, s32
45- write (eventType ) // offset 20, u8
46- write ([3 ]byte {}) // offset 21, pad[3]
47- write (fd ) // offset 24, u32
48- write (srcIP ) // offset 28, u8[16]
49- write (srcPort ) // offset 44, u16
50- write ([2 ]byte {}) // offset 46, pad2
51- write (dstIP ) // offset 48, u8[16]
52- write (dstPort ) // offset 64, u16
53- write (ipVersion ) // offset 66, u8
54- write (uint8 (0 )) // offset 67, pad3
55- write (comm ) // offset 68, char[16]
41+ write (timestamp ) // offset 0, u64 ts_ns
42+ write (seq ) // offset 8, u64 seq
43+ write (emitCPU ) // offset 16, u32 emit_cpu
44+ write (pid ) // offset 20, u32
45+ write (tid ) // offset 24, u32
46+ write (dataLen ) // offset 28, s32
47+ write (eventType ) // offset 32, u8
48+ write ([3 ]byte {}) // offset 33, pad[3]
49+ write (fd ) // offset 36, u32
50+ write (srcIP ) // offset 40, u8[16]
51+ write (srcPort ) // offset 56, u16
52+ write ([2 ]byte {}) // offset 58, pad2
53+ write (dstIP ) // offset 60, u8[16]
54+ write (dstPort ) // offset 76, u16
55+ write (ipVersion ) // offset 78, u8
56+ write (uint8 (0 )) // offset 79, pad3
57+ write (comm ) // offset 80, char[16]
5658 if len (payload ) > 0 {
57- buf .Write (payload ) // offset 84 , variable data
59+ buf .Write (payload ) // offset 96 , variable data
5860 }
5961 return buf .Bytes ()
6062}
@@ -84,7 +86,7 @@ func TestGoTLSDataEvent_DecodeFromBytes_IPv4_Write(t *testing.T) {
8486 payload := []byte ("GET / HTTP/1.1\r \n " )
8587
8688 raw := buildEventBytes (t ,
87- 1000000 , 42 , 99 , int32 (len (payload )), 0 , // eventType=WRITE
89+ 1000000 , 1 , 0 , 42 , 99 , int32 (len (payload )), 0 , // eventType=WRITE
8890 7 , srcIP , 12345 , dstIP , 443 , 4 , // ipVersion=4
8991 commBytes ("curl" ), payload ,
9092 )
@@ -97,6 +99,15 @@ func TestGoTLSDataEvent_DecodeFromBytes_IPv4_Write(t *testing.T) {
9799 if e .Timestamp != 1000000 {
98100 t .Errorf ("Timestamp = %d, want 1000000" , e .Timestamp )
99101 }
102+ if e .BpfMonoNs != 1000000 {
103+ t .Errorf ("BpfMonoNs = %d, want 1000000" , e .BpfMonoNs )
104+ }
105+ if e .Seq != 1 {
106+ t .Errorf ("Seq = %d, want 1" , e .Seq )
107+ }
108+ if e .EmitCPU != 0 {
109+ t .Errorf ("EmitCPU = %d, want 0" , e .EmitCPU )
110+ }
100111 if e .Pid != 42 {
101112 t .Errorf ("Pid = %d, want 42" , e .Pid )
102113 }
@@ -141,7 +152,7 @@ func TestGoTLSDataEvent_DecodeFromBytes_IPv4_Read(t *testing.T) {
141152 payload := []byte ("HTTP/1.1 200 OK\r \n " )
142153
143154 raw := buildEventBytes (t ,
144- 2000000 , 100 , 200 , int32 (len (payload )), 1 , // eventType=READ
155+ 2000000 , 2 , 0 , 100 , 200 , int32 (len (payload )), 1 , // eventType=READ
145156 5 , srcIP , 443 , dstIP , 54321 , 4 ,
146157 commBytes ("myapp" ), payload ,
147158 )
@@ -174,7 +185,7 @@ func TestGoTLSDataEvent_DecodeFromBytes_IPv6(t *testing.T) {
174185
175186 payload := []byte ("hello" )
176187 raw := buildEventBytes (t ,
177- 3000000 , 7 , 8 , int32 (len (payload )), 0 ,
188+ 3000000 , 3 , 0 , 7 , 8 , int32 (len (payload )), 0 ,
178189 3 , ipv6Bytes (src6 ), 8080 , ipv6Bytes (dst6 ), 9090 , 6 , // ipVersion=6
179190 commBytes ("server" ), payload ,
180191 )
@@ -196,7 +207,7 @@ func TestGoTLSDataEvent_DecodeFromBytes_IPv6(t *testing.T) {
196207
197208func TestGoTLSDataEvent_DecodeFromBytes_ZeroDataLen (t * testing.T ) {
198209 raw := buildEventBytes (t ,
199- 1000 , 1 , 2 , 0 , 0 , // dataLen=0
210+ 1000 , 4 , 0 , 1 , 2 , 0 , 0 , // dataLen=0
200211 1 , ipv4Bytes (1 , 2 , 3 , 4 ), 100 , ipv4Bytes (5 , 6 , 7 , 8 ), 200 , 4 ,
201212 commBytes ("app" ), nil ,
202213 )
@@ -212,9 +223,27 @@ func TestGoTLSDataEvent_DecodeFromBytes_ZeroDataLen(t *testing.T) {
212223 }
213224}
214225
226+ func TestLessGoTLSDataEventByPerfOrder (t * testing.T ) {
227+ a := & GoTLSDataEvent {BpfMonoNs : 100 , EmitCPU : 1 , Seq : 5 }
228+ b := & GoTLSDataEvent {BpfMonoNs : 200 , EmitCPU : 0 , Seq : 1 }
229+ if ! LessGoTLSDataEventByPerfOrder (a , b ) {
230+ t .Fatal ("expected a before b (mono time)" )
231+ }
232+ sameT := & GoTLSDataEvent {BpfMonoNs : 100 , EmitCPU : 2 , Seq : 1 }
233+ otherCPU := & GoTLSDataEvent {BpfMonoNs : 100 , EmitCPU : 1 , Seq : 99 }
234+ if ! LessGoTLSDataEventByPerfOrder (otherCPU , sameT ) {
235+ t .Fatal ("expected CPU tie-break" )
236+ }
237+ sameTS := & GoTLSDataEvent {BpfMonoNs : 100 , EmitCPU : 1 , Seq : 1 }
238+ sameTS2 := & GoTLSDataEvent {BpfMonoNs : 100 , EmitCPU : 1 , Seq : 2 }
239+ if ! LessGoTLSDataEventByPerfOrder (sameTS , sameTS2 ) {
240+ t .Fatal ("expected seq tie-break" )
241+ }
242+ }
243+
215244func TestGoTLSDataEvent_DecodeFromBytes_TimestampZeroFallback (t * testing.T ) {
216245 raw := buildEventBytes (t ,
217- 0 , 1 , 2 , 0 , 0 , // timestamp=0 → should be filled by time.Now()
246+ 0 , 5 , 0 , 1 , 2 , 0 , 0 , // timestamp=0 → should be filled by time.Now()
218247 1 , ipv4Bytes (1 , 2 , 3 , 4 ), 80 , ipv4Bytes (5 , 6 , 7 , 8 ), 8080 , 4 ,
219248 commBytes ("app" ), nil ,
220249 )
@@ -241,7 +270,7 @@ func TestGoTLSDataEvent_DecodeFromBytes_TruncatedInput(t *testing.T) {
241270func TestGoTLSDataEvent_DecodeFromBytes_DataLenExceedsBuffer (t * testing.T ) {
242271 // claim dataLen=100 but provide no payload bytes
243272 raw := buildEventBytes (t ,
244- 1000 , 1 , 2 , 100 , 0 , // dataLen=100
273+ 1000 , 6 , 0 , 1 , 2 , 100 , 0 , // dataLen=100
245274 1 , ipv4Bytes (1 , 2 , 3 , 4 ), 80 , ipv4Bytes (5 , 6 , 7 , 8 ), 8080 , 4 ,
246275 commBytes ("app" ), nil , // no payload
247276 )
@@ -584,7 +613,7 @@ func TestGoTLSDataEvent_DecodeFromBytes_RoundTrip(t *testing.T) {
584613 copy (comm [:], "myservice" )
585614
586615 raw := buildEventBytes (t ,
587- 999888777 , 12345 , 67890 , int32 (len (wantPayload )), 0 ,
616+ 999888777 , 7 , 0 , 12345 , 67890 , int32 (len (wantPayload )), 0 ,
588617 8 , ipv4Bytes (172 , 16 , 0 , 1 ), 54321 , ipv4Bytes (172 , 16 , 0 , 2 ), 443 , 4 ,
589618 comm , wantPayload ,
590619 )
@@ -594,6 +623,12 @@ func TestGoTLSDataEvent_DecodeFromBytes_RoundTrip(t *testing.T) {
594623 t .Fatalf ("DecodeFromBytes error: %v" , err )
595624 }
596625
626+ if e .Seq != 7 {
627+ t .Errorf ("Seq = %d, want 7" , e .Seq )
628+ }
629+ if e .EmitCPU != 0 {
630+ t .Errorf ("EmitCPU = %d, want 0" , e .EmitCPU )
631+ }
597632 if e .Pid != 12345 {
598633 t .Errorf ("Pid = %d, want 12345" , e .Pid )
599634 }
0 commit comments