From 0bbeb68b5ff6c42353cf660607b86c797067f997 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Tue, 18 Jul 2023 19:04:31 +0200 Subject: [PATCH] test Signed-off-by: Edoardo Vacchi --- internal/platform/fdset_windows_test.go | 109 ++++++++++++++++++++++++ internal/sysfs/select_windows.go | 1 - 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 internal/platform/fdset_windows_test.go diff --git a/internal/platform/fdset_windows_test.go b/internal/platform/fdset_windows_test.go new file mode 100644 index 0000000000..3e56b21b8e --- /dev/null +++ b/internal/platform/fdset_windows_test.go @@ -0,0 +1,109 @@ +package platform + +import ( + "syscall" + "testing" + + "github.com/tetratelabs/wazero/internal/testing/require" +) + +func TestWinSockFdSet(t *testing.T) { + allSet := WinSockFdSet{ + count: _FD_SETSIZE, + } + for i := 0; i < _FD_SETSIZE; i++ { + allSet.handles[i] = syscall.Handle(i) + } + + tests := []struct { + name string + init WinSockFdSet + exec func(fdSet *WinSockFdSet) + expected WinSockFdSet + }{ + { + name: "all fields set", + exec: func(fdSet *WinSockFdSet) { + for fd := 0; fd < _FD_SETSIZE; fd++ { + fdSet.Set(fd) + } + }, + expected: allSet, + }, + { + name: "all bits cleared", + init: allSet, + exec: func(fdSet *WinSockFdSet) { + for fd := 0; fd < _FD_SETSIZE; fd++ { + fdSet.Clear(fd) + } + }, + expected: WinSockFdSet{}, + }, + { + name: "zero should clear all bits", + init: allSet, + exec: func(fdSet *WinSockFdSet) { + fdSet.Zero() + }, + expected: WinSockFdSet{}, + }, + { + name: "is-set should return true for all bits", + init: allSet, + exec: func(fdSet *WinSockFdSet) { + for i := 0; i < fdSet.Count(); i++ { + require.True(t, fdSet.IsSet(i)) + } + }, + expected: allSet, + }, + { + name: "is-set should return true for all odd bits", + init: WinSockFdSet{}, + exec: func(fdSet *WinSockFdSet) { + for fd := 1; fd < _FD_SETSIZE; fd += 2 { + fdSet.Set(fd) + } + for fd := 0; fd < _FD_SETSIZE; fd++ { + isSet := fdSet.IsSet(fd) + if fd&0x1 == 0x1 { + require.True(t, isSet) + } else { + require.False(t, isSet) + } + } + fdSet.Zero() + }, + expected: WinSockFdSet{}, + }, + { + name: "should clear all even bits", + init: allSet, + exec: func(fdSet *WinSockFdSet) { + for fd := 0; fd < _FD_SETSIZE; fd += 2 { + fdSet.Clear(fd) + } + for fd := 0; fd < _FD_SETSIZE; fd++ { + isSet := fdSet.IsSet(fd) + if fd&0x1 == 0x1 { + require.True(t, isSet) + } else { + require.False(t, isSet) + } + } + fdSet.Zero() + }, + expected: WinSockFdSet{}, + }, + } + + for _, tt := range tests { + tc := tt + t.Run(tc.name, func(t *testing.T) { + x := tc.init + tc.exec(&x) + require.Equal(t, tc.expected, x) + }) + } +} diff --git a/internal/sysfs/select_windows.go b/internal/sysfs/select_windows.go index af104d4d77..a0f58c3c14 100644 --- a/internal/sysfs/select_windows.go +++ b/internal/sysfs/select_windows.go @@ -109,7 +109,6 @@ func selectAllHandles(ctx context.Context, r, w, e *platform.FdSet, duration *ti } } } - } func peekAllHandles(r, w, e *platform.FdSet) (int, sys.Errno) {