Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
Adrian Cole committed Jul 19, 2023
1 parent 2d5cc36 commit baa3948
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/fsapi/oflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package fsapi
// flags can coexist bitwise.
// - This is like `flag` in os.OpenFile and `oflag` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
type Oflag uint16
type Oflag uint32

// This is a subset of oflags to reduce implementation burden. `wasip` splits
// these across `oflags` and `fdflags`. We can't rely on the Go `os` package,
Expand Down
20 changes: 11 additions & 9 deletions internal/sysfs/oflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/tetratelabs/wazero/internal/testing/require"
)

// Test_toOsOpenFlag doesn't use subtests to reduce volume of verbose output,
// and in recognition we have tens of thousands of tests, which can hit IDE
// limits.
func Test_toOsOpenFlag(t *testing.T) {
tests := []struct {
name string
Expand All @@ -27,11 +30,8 @@ func Test_toOsOpenFlag(t *testing.T) {
{name: "undefined", flag: 1 << 15, expected: os.O_RDONLY},
}

for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.expected, toOsOpenFlag(tc.flag))
})
for _, tc := range tests {
require.Equal(t, tc.expected, toOsOpenFlag(tc.flag), tc.name)
}

// Tests any supported syscall flags
Expand All @@ -45,9 +45,11 @@ func Test_toOsOpenFlag(t *testing.T) {
if supportedSyscallOflag&f == 0 {
continue
}
f := f
t.Run(n, func(t *testing.T) {
require.NotEqual(t, 0, toOsOpenFlag(f))
})
require.NotEqual(t, 0, toOsOpenFlag(f), n)
}

// Example of a flag that can be or'd into O_RDONLY even if not
// currently supported in WASI or GOOS=js
const O_NOATIME = fsapi.Oflag(0x40000)
require.Zero(t, 0, toOsOpenFlag(O_NOATIME))
}
24 changes: 24 additions & 0 deletions internal/sysfs/open_file_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sysfs

import (
"syscall"

"github.com/tetratelabs/wazero/internal/fsapi"
)

const supportedSyscallOflag = fsapi.O_DIRECTORY | fsapi.O_NOFOLLOW | fsapi.O_NONBLOCK

func withSyscallOflag(oflag fsapi.Oflag, flag int) int {
if oflag&fsapi.O_DIRECTORY != 0 {
flag |= syscall.O_DIRECTORY
}
// syscall.O_DSYNC not defined on darwin
if oflag&fsapi.O_NOFOLLOW != 0 {
flag |= syscall.O_NOFOLLOW
}
if oflag&fsapi.O_NONBLOCK != 0 {
flag |= syscall.O_NONBLOCK
}
// syscall.O_RSYNC not defined on darwin
return flag
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build linux || freebsd

package sysfs

import (
Expand Down
2 changes: 1 addition & 1 deletion internal/sysfs/open_file_notwindows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !windows && !js && !illumos && !solaris
//go:build !windows

package sysfs

Expand Down
2 changes: 1 addition & 1 deletion internal/sysfs/open_file_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !darwin && !linux && !windows && !illumos && !solaris
//go:build !darwin && !linux && !windows && !illumos && !solaris && !freebsd

package sysfs

Expand Down
2 changes: 1 addition & 1 deletion internal/sysfs/sysfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ human
t.Run("or'd flag", func(t *testing.T) {
// Example of a flag that can be or'd into O_RDONLY even if not
// currently supported in WASI or GOOS=js
const O_NOATIME = fsapi.Oflag(0xF000)
const O_NOATIME = fsapi.Oflag(0x40000)

f, errno := testFS.OpenFile("animals.txt", fsapi.O_RDONLY|O_NOATIME, 0)
require.EqualErrno(t, 0, errno)
Expand Down

0 comments on commit baa3948

Please sign in to comment.