This adds a wazero adapter which passes wasi-testsuite 100pct on darwin, linux and windows. While the main change was adding inodes to the wasi `fd_readdir` dirents, there was a lot of incidental work needed. Most of the work was troubleshooting in nature, around windows specifically, but also wrapping of files. This backfills a lot of tests and reworked how wrapping works, particularly around windows. To accommodate this, we drop `os.File` special casing except for `sysfs.DirFS` Signed-off-by: Adrian Cole <adrian@tetrate.io>
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package platform
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"github.com/tetratelabs/wazero/internal/testing/require"
|
|
)
|
|
|
|
// Test_Fdatasync doesn't guarantee sync works because the operating system may
|
|
// sync anyway. There is no test in Go for syscall.Fdatasync, but closest is
|
|
// similar to below. Effectively, this only tests that things don't error.
|
|
func Test_Fdatasync(t *testing.T) {
|
|
f, err := os.CreateTemp("", t.Name())
|
|
require.NoError(t, err)
|
|
defer f.Close()
|
|
|
|
expected := "hello world!"
|
|
|
|
// Write the expected data
|
|
_, err = f.Write([]byte(expected))
|
|
require.NoError(t, err)
|
|
|
|
// Sync the data.
|
|
if err = Fdatasync(f); err == syscall.ENOSYS {
|
|
return // don't continue if it isn't supported.
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
// Rewind while the file is still open.
|
|
_, err = f.Seek(0, io.SeekStart)
|
|
require.NoError(t, err)
|
|
|
|
// Read data from the file
|
|
var buf bytes.Buffer
|
|
_, err = io.Copy(&buf, f)
|
|
require.NoError(t, err)
|
|
|
|
// It may be the case that sync worked.
|
|
require.Equal(t, expected, buf.String())
|
|
}
|