Commit 135f7059 authored by lch's avatar lch Committed by lchopn

fs: fix building of tests

Change-Id: Iffa5314fbe171d182a4bdef42e0ab4781cc1d221
parent 8d89f3cd
...@@ -45,7 +45,7 @@ func (ds *errDirStream) Next() (fuse.DirEntry, syscall.Errno) { ...@@ -45,7 +45,7 @@ func (ds *errDirStream) Next() (fuse.DirEntry, syscall.Errno) {
Mode: fuse.S_IFREG, Mode: fuse.S_IFREG,
Name: "last", Name: "last",
Ino: 3, Ino: 3,
}, syscall.EKEYEXPIRED }, syscall.EBADMSG
} }
panic("boom") panic("boom")
...@@ -76,9 +76,14 @@ func TestDirStreamError(t *testing.T) { ...@@ -76,9 +76,14 @@ func TestDirStreamError(t *testing.T) {
} else if e.Name != "first" { } else if e.Name != "first" {
t.Errorf("got %q want 'first'", e.Name) t.Errorf("got %q want 'first'", e.Name)
} }
// Here we need choose a errno to test if errno could be passed and handled
if _, errno := ds.Next(); errno != syscall.EKEYEXPIRED { // correctly by the fuse library. To build the test on different platform,
t.Errorf("got errno %v, want EKEYEXPIRED", errno) // an errno which defined on each platform should be chosen. And if the
// chosen integer number is not a valid errno, the fuse in kernel would refuse
// and throw an error, which is observed on Linux.
// Here we choose to use EBADMSG, which is defined on multiple Unix-like OSes.
if _, errno := ds.Next(); errno != syscall.EBADMSG {
t.Errorf("got errno %v, want EBADMSG", errno)
} }
}) })
} }
......
...@@ -244,7 +244,7 @@ func bdiReadahead(mnt string) int { ...@@ -244,7 +244,7 @@ func bdiReadahead(mnt string) int {
if err != nil { if err != nil {
panic(err) panic(err)
} }
path := fmt.Sprintf("/sys/class/bdi/%d:%d/read_ahead_kb", unix.Major(st.Dev), unix.Minor(st.Dev)) path := fmt.Sprintf("/sys/class/bdi/%d:%d/read_ahead_kb", unix.Major(uint64(st.Dev)), unix.Minor(uint64(st.Dev)))
buf, err := ioutil.ReadFile(path) buf, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
panic(err) panic(err)
......
...@@ -137,8 +137,7 @@ func TestDataFile(t *testing.T) { ...@@ -137,8 +137,7 @@ func TestDataFile(t *testing.T) {
if err := syscall.Lstat(mntDir+"/file", &st); err != nil { if err := syscall.Lstat(mntDir+"/file", &st); err != nil {
t.Fatalf("Lstat: %v", err) t.Fatalf("Lstat: %v", err)
} }
if want := uint(syscall.S_IFREG | 0464); uint(st.Mode) != want {
if want := uint32(syscall.S_IFREG | 0464); st.Mode != want {
t.Errorf("got mode %o, want %o", st.Mode, want) t.Errorf("got mode %o, want %o", st.Mode, want)
} }
......
...@@ -11,14 +11,14 @@ import ( ...@@ -11,14 +11,14 @@ import (
"testing" "testing"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"golang.org/x/sys/unix"
) )
func TestReadonlyCreate(t *testing.T) { func TestReadonlyCreate(t *testing.T) {
root := &Inode{} root := &Inode{}
mntDir, _ := testMount(t, root, nil) mntDir, _ := testMount(t, root, nil)
_, err := unix.Open(mntDir+"/test", unix.O_CREAT, 0644)
_, err := syscall.Creat(mntDir+"/test", 0644)
if want := syscall.EROFS; want != err { if want := syscall.EROFS; want != err {
t.Fatalf("got err %v, want %v", err, want) t.Fatalf("got err %v, want %v", err, want)
} }
...@@ -44,7 +44,7 @@ func TestDefaultPermissions(t *testing.T) { ...@@ -44,7 +44,7 @@ func TestDefaultPermissions(t *testing.T) {
var st syscall.Stat_t var st syscall.Stat_t
if err := syscall.Lstat(filepath.Join(mntDir, k), &st); err != nil { if err := syscall.Lstat(filepath.Join(mntDir, k), &st); err != nil {
t.Error("Lstat", err) t.Error("Lstat", err)
} else if st.Mode != v { } else if uint(st.Mode) != uint(v) {
t.Errorf("got %o want %o", st.Mode, v) t.Errorf("got %o want %o", st.Mode, v)
} }
} }
......
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/internal/testutil" "github.com/hanwen/go-fuse/v2/internal/testutil"
"github.com/hanwen/go-fuse/v2/posixtest" "github.com/hanwen/go-fuse/v2/posixtest"
"golang.org/x/sys/unix"
) )
type testCase struct { type testCase struct {
...@@ -339,7 +340,7 @@ func TestMknod(t *testing.T) { ...@@ -339,7 +340,7 @@ func TestMknod(t *testing.T) {
var st syscall.Stat_t var st syscall.Stat_t
if err := syscall.Stat(p, &st); err != nil { if err := syscall.Stat(p, &st); err != nil {
got := st.Mode &^ 07777 got := st.Mode &^ 07777
if want := mode; got != want { if want := uint(mode); want != uint(got) {
t.Fatalf("stat(%s): got %o want %o", nm, got, want) t.Fatalf("stat(%s): got %o want %o", nm, got, want)
} }
} }
...@@ -648,7 +649,7 @@ func TestStaleHardlinks(t *testing.T) { ...@@ -648,7 +649,7 @@ func TestStaleHardlinks(t *testing.T) {
// "link0" is original file // "link0" is original file
link0 := tc.mntDir + "/link0" link0 := tc.mntDir + "/link0"
if fd, err := syscall.Creat(link0, 0600); err != nil { if fd, err := unix.Open(link0, unix.O_CREAT, 0600); err != nil {
t.Fatal(err) t.Fatal(err)
} else { } else {
syscall.Close(fd) syscall.Close(fd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment