...

Source file src/github.com/cilium/ebpf/internal/sys/syscall_test.go

Documentation: github.com/cilium/ebpf/internal/sys

     1  package sys
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/cilium/ebpf/internal/unix"
     8  )
     9  
    10  func TestObjName(t *testing.T) {
    11  	name := NewObjName("more_than_16_characters_long")
    12  	if name[len(name)-1] != 0 {
    13  		t.Error("NewBPFObjName doesn't null terminate")
    14  	}
    15  	if len(name) != unix.BPF_OBJ_NAME_LEN {
    16  		t.Errorf("Name is %d instead of %d bytes long", len(name), unix.BPF_OBJ_NAME_LEN)
    17  	}
    18  }
    19  
    20  func TestWrappedErrno(t *testing.T) {
    21  	a := error(wrappedErrno{unix.EINVAL})
    22  	b := error(unix.EINVAL)
    23  
    24  	if a == b {
    25  		t.Error("wrappedErrno is comparable to plain errno")
    26  	}
    27  
    28  	if !errors.Is(a, b) {
    29  		t.Error("errors.Is(wrappedErrno, errno) returns false")
    30  	}
    31  
    32  	if errors.Is(a, unix.EAGAIN) {
    33  		t.Error("errors.Is(wrappedErrno, EAGAIN) returns true")
    34  	}
    35  }
    36  
    37  func TestSyscallError(t *testing.T) {
    38  	err := errors.New("foo")
    39  	foo := Error(err, unix.EINVAL)
    40  
    41  	if !errors.Is(foo, unix.EINVAL) {
    42  		t.Error("SyscallError is not the wrapped errno")
    43  	}
    44  
    45  	if !errors.Is(foo, err) {
    46  		t.Error("SyscallError is not the wrapped error")
    47  	}
    48  
    49  	if errors.Is(unix.EINVAL, foo) {
    50  		t.Error("Errno is the SyscallError")
    51  	}
    52  
    53  	if errors.Is(err, foo) {
    54  		t.Error("Error is the SyscallError")
    55  	}
    56  }
    57  

View as plain text