Commit 6ae4ba6c authored by Jakob Unterwurzacher's avatar Jakob Unterwurzacher

tests: add OpenAt test

Tests that openat(2) works as expected when the parent
directory is renamed (it does).

Originally written to get a FUSE log about what happens
when userspace calls openat, but it might make sense to
just keep it as a test.

Change-Id: I3fac815a7c0f713b4f859f6876d60380df9bc953
parent da5ff9a7
...@@ -37,6 +37,7 @@ var All = map[string]func(*testing.T, string){ ...@@ -37,6 +37,7 @@ var All = map[string]func(*testing.T, string){
"ReadDir": ReadDir, "ReadDir": ReadDir,
"ReadDirPicksUpCreate": ReadDirPicksUpCreate, "ReadDirPicksUpCreate": ReadDirPicksUpCreate,
"DirectIO": DirectIO, "DirectIO": DirectIO,
"OpenAt": OpenAt,
} }
func DirectIO(t *testing.T, mnt string) { func DirectIO(t *testing.T, mnt string) {
...@@ -505,3 +506,34 @@ func AppendWrite(t *testing.T, mnt string) { ...@@ -505,3 +506,34 @@ func AppendWrite(t *testing.T, mnt string) {
t.Errorf("got %q want %q", got, want) t.Errorf("got %q want %q", got, want)
} }
} }
// OpenAt tests syscall.Openat().
//
// Hint:
// $ go test ./fs -run TestPosix/OpenAt -v
func OpenAt(t *testing.T, mnt string) {
dir1 := mnt + "/dir1"
err := os.Mkdir(dir1, 0777)
if err != nil {
t.Fatal(err)
}
dirfd, err := syscall.Open(dir1, syscall.O_RDONLY, 0)
if err != nil {
t.Fatal(err)
}
defer syscall.Close(dirfd)
dir2 := mnt + "/dir2"
err = os.Rename(dir1, dir2)
if err != nil {
t.Fatal(err)
}
fd, err := syscall.Openat(dirfd, "file1", syscall.O_CREAT, 0700)
if err != nil {
t.Fatal(err)
}
defer syscall.Close(fd)
_, err = os.Stat(dir2 + "/file1")
if err != nil {
t.Error(err)
}
}
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