Skip to content

Commit

Permalink
fix(test): update tests to align with the helper
Browse files Browse the repository at this point in the history
- align the err msg return;
- remove one test case - the func helper is enabled for the type for
new kernels.
  • Loading branch information
rscampos committed Jan 17, 2025
1 parent eb576c7 commit c0ac603
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package libbpfgo

import (
"errors"
"fmt"
"strings"
"syscall"
"testing"

Expand Down Expand Up @@ -69,10 +69,12 @@ func TestFuncSupportbyType(t *testing.T) {
errMsg error
}{
// func available but not enough permission (permission denied)
// May return success (`true`) even if the BPF program load would fail due to permission issues (EPERM).
// Check BPFHelperIsSupported for more info.
{
progType: BPFProgTypeKprobe,
funcId: BPFFuncGetCurrentUidGid,
supported: false,
supported: true,
capability: []string{},
errMsg: syscall.EPERM,
},
Expand All @@ -87,17 +89,12 @@ func TestFuncSupportbyType(t *testing.T) {
// func unavailable and enough permission
// When the function is unavailable, BPF returns "Invalid Argument".
// Therefore, ignore the error and proceed with validation.
// May return success (`true`) even if the BPF program load would fail due to permission issues (EPERM).
// Check BPFHelperIsSupported for more info.
{
progType: BPFProgTypeSkLookup,
funcId: BPFFuncGetCurrentCgroupId,
supported: false,
capability: []string{"cap_sys_admin"},
errMsg: syscall.EINVAL,
},
{
progType: BPFProgTypeSkLookup,
funcId: BPFFuncGetCurrentCgroupId,
supported: false,
supported: true,
capability: []string{},
errMsg: syscall.EPERM,
},
Expand Down Expand Up @@ -153,7 +150,6 @@ func TestFuncSupportbyType(t *testing.T) {
errMsg: syscall.EINVAL,
},
}

for _, tc := range tt {
// reset all current effective capabilities
resetEffectiveCapabilities()
Expand All @@ -169,8 +165,8 @@ func TestFuncSupportbyType(t *testing.T) {
t.Errorf("expected no error, got %v", err)
}
} else {
if !errors.Is(err, tc.errMsg) {
t.Errorf("expected error %v, got %v", tc.errMsg, err)
if err == nil || !strings.Contains(err.Error(), tc.errMsg.Error()) {
t.Errorf("expected error containing %q, got %v", tc.errMsg.Error(), err)
}
}

Expand Down

0 comments on commit c0ac603

Please sign in to comment.