Skip to content

Commit

Permalink
common NewTimeoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Nov 15, 2024
1 parent 6abc341 commit 4b93078
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
23 changes: 23 additions & 0 deletions pkg/security/tests/module_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,29 @@ func (tm *testModule) Create(filename string) (string, unsafe.Pointer, error) {
return testFile, testPtr, err
}

// NewTimeoutError returns a new timeout error with the metrics collected during the test
func (tm *testModule) NewTimeoutError() ErrTimeout {
var msg strings.Builder

msg.WriteString("timeout, details: ")
tm.writePlatformSpecificTimeoutError(&msg)

events := tm.ruleEngine.StopEventCollector()
if len(events) != 0 {
msg.WriteString("\nevents evaluated:\n")

for _, event := range events {
msg.WriteString(fmt.Sprintf("%s (eval=%v) {\n", event.Type, event.EvalResult))
for field, value := range event.Fields {
msg.WriteString(fmt.Sprintf("\t%s=%v,\n", field, value))
}
msg.WriteString("}\n")
}
}

return ErrTimeout{msg.String()}
}

func (tm *testModule) WaitSignal(tb testing.TB, action func() error, cb onRuleHandler) {
tb.Helper()

Expand Down
25 changes: 3 additions & 22 deletions pkg/security/tests/module_tester_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,28 +1604,9 @@ func (tm *testModule) GetADSelector(dumpID *activityDumpIdentifier) (*cgroupMode
return &selector, err
}

// NewTimeoutError returns a new timeout error with the metrics collected during the test
func (tm *testModule) NewTimeoutError() ErrTimeout {
var msg strings.Builder

msg.WriteString("timeout, details: ")
msg.WriteString(GetEBPFStatusMetrics(tm.probe))
msg.WriteString(spew.Sdump(ebpftelemetry.GetProbeStats()))

events := tm.ruleEngine.StopEventCollector()
if len(events) != 0 {
msg.WriteString("\nevents evaluated:\n")

for _, event := range events {
msg.WriteString(fmt.Sprintf("%s (eval=%v) {\n", event.Type, event.EvalResult))
for field, value := range event.Fields {
msg.WriteString(fmt.Sprintf("\t%s=%v,\n", field, value))
}
msg.WriteString("}\n")
}
}

return ErrTimeout{msg.String()}
func (tm *testModule) writePlatformSpecificTimeoutError(b *strings.Builder) {
b.WriteString(GetEBPFStatusMetrics(tm.probe))
b.WriteString(spew.Sdump(ebpftelemetry.GetProbeStats()))
}

func (tm *testModule) WaitSignals(tb testing.TB, action func() error, cbs ...func(event *model.Event, rule *rules.Rule) error) {
Expand Down
21 changes: 1 addition & 20 deletions pkg/security/tests/module_tester_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,5 @@ func (tm *testModule) Close() {
tm.eventMonitor.Close()
}

// NewTimeoutError returns a new timeout error with the metrics collected during the test
func (tm *testModule) NewTimeoutError() ErrTimeout {
var msg strings.Builder

msg.WriteString("timeout, details: ")

events := tm.ruleEngine.StopEventCollector()
if len(events) != 0 {
msg.WriteString("\nevents evaluated:\n")

for _, event := range events {
msg.WriteString(fmt.Sprintf("%s (eval=%v) {\n", event.Type, event.EvalResult))
for field, value := range event.Fields {
msg.WriteString(fmt.Sprintf("\t%s=%v,\n", field, value))
}
msg.WriteString("}\n")
}
}

return ErrTimeout{msg.String()}
func (tm *testModule) writePlatformSpecificTimeoutError(b *strings.Builder) {
}

0 comments on commit 4b93078

Please sign in to comment.