Skip to content

Commit b7c2bb8

Browse files
lmbti-mo
authored andcommitted
internal/linux: skip some tests on non-Linux platforms
Skip most tests in the package, with the exception of the vdso tests that use testdata. For those we need to make the string manipulation functions in package unix work on Windows. Signed-off-by: Lorenz Bauer <[email protected]>
1 parent db50d22 commit b7c2bb8

File tree

9 files changed

+65
-8
lines changed

9 files changed

+65
-8
lines changed

internal/linux/auxv.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package linux
22

33
import (
44
"errors"
5+
"fmt"
56
"io"
7+
"runtime"
68
_ "unsafe"
9+
10+
"github.com/cilium/ebpf/internal"
711
)
812

913
type auxvPairReader interface {
@@ -47,6 +51,10 @@ func (r *auxvRuntimeReader) ReadAuxvPair() (uint64, uint64, error) {
4751
}
4852

4953
func newAuxvRuntimeReader() (auxvPairReader, error) {
54+
if runtime.GOOS != "linux" {
55+
return nil, fmt.Errorf("read auxv from runtime: %w", internal.ErrNotSupportedOnOS)
56+
}
57+
5058
data := runtime_getAuxv()
5159

5260
if len(data)%2 != 0 {

internal/linux/auxv_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func newDefaultAuxvFileReader() (auxvPairReader, error) {
7272

7373
func TestAuxvBothSourcesEqual(t *testing.T) {
7474
runtimeBased, err := newAuxvRuntimeReader()
75+
skipIfNotSupportedOnOS(t, err)
7576
if err != nil {
7677
t.Fatal(err)
7778
}

internal/linux/helper_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package linux
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/cilium/ebpf/internal"
8+
)
9+
10+
// skipIfNotSupportedOnOS is a copy of testutils.SkipIfNotSupported to avoid
11+
// a circular dependency.
12+
func skipIfNotSupportedOnOS(tb testing.TB, err error) {
13+
tb.Helper()
14+
15+
if err == internal.ErrNotSupportedOnOS {
16+
tb.Fatal("Unwrapped ErrNotSupportedOnOS")
17+
}
18+
19+
if errors.Is(err, internal.ErrNotSupportedOnOS) {
20+
tb.Skip(err.Error())
21+
}
22+
}

internal/linux/statfs_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestFSType(t *testing.T) {
1717
{"/sys/fs/bpf", unix.BPF_FS_MAGIC},
1818
} {
1919
fst, err := FSType(fs.path)
20+
skipIfNotSupportedOnOS(t, err)
2021
qt.Assert(t, qt.IsNil(err))
2122
qt.Assert(t, qt.Equals(fst, fs.magic))
2223
}

internal/linux/vdso_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func TestAuxvNoVDSO(t *testing.T) {
5353

5454
func TestVDSOVersion(t *testing.T) {
5555
_, err := vdsoVersion()
56+
skipIfNotSupportedOnOS(t, err)
5657
qt.Assert(t, qt.IsNil(err))
5758
}
5859

internal/linux/version_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88

99
func TestCurrentKernelVersion(t *testing.T) {
1010
_, err := KernelVersion()
11+
skipIfNotSupportedOnOS(t, err)
1112
qt.Assert(t, qt.IsNil(err))
1213
}
1314

1415
func TestKernelRelease(t *testing.T) {
1516
r, err := KernelRelease()
17+
skipIfNotSupportedOnOS(t, err)
1618
if err != nil {
1719
t.Fatal(err)
1820
}

internal/unix/strings_other.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !linux && !windows
2+
3+
package unix
4+
5+
func BytePtrFromString(s string) (*byte, error) {
6+
return nil, errNonLinux()
7+
}
8+
9+
func ByteSliceToString(s []byte) string {
10+
return ""
11+
}

internal/unix/strings_windows.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package unix
2+
3+
import (
4+
"syscall"
5+
6+
"golang.org/x/sys/windows"
7+
)
8+
9+
func BytePtrFromString(s string) (*byte, error) {
10+
p, err := windows.BytePtrFromString(s)
11+
if err == syscall.EINVAL {
12+
err = EINVAL
13+
}
14+
return p, err
15+
}
16+
17+
func ByteSliceToString(s []byte) string {
18+
return windows.ByteSliceToString(s)
19+
}

internal/unix/types_other.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,6 @@ func Tgkill(tgid int, tid int, sig syscall.Signal) (err error) {
267267
return errNonLinux()
268268
}
269269

270-
func BytePtrFromString(s string) (*byte, error) {
271-
return nil, errNonLinux()
272-
}
273-
274-
func ByteSliceToString(s []byte) string {
275-
return ""
276-
}
277-
278270
func Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) error {
279271
return errNonLinux()
280272
}

0 commit comments

Comments
 (0)