Commit 037efc7d authored by Jakob Unterwurzacher's avatar Jakob Unterwurzacher Committed by Han-Wen Nienhuys

tests: posixtest: add FstatDeleted

Excercises the fd-finding logic in rawBridge.GetAttr.
No issues found, tests pass, logic works fine.

Change-Id: I49731b8ec5b41344d58409c8ca615f466bd95f29
parent f28fbbf1
...@@ -28,6 +28,7 @@ var All = map[string]func(*testing.T, string){ ...@@ -28,6 +28,7 @@ var All = map[string]func(*testing.T, string){
"FdLeak": FdLeak, "FdLeak": FdLeak,
"MkdirRmdir": MkdirRmdir, "MkdirRmdir": MkdirRmdir,
"NlinkZero": NlinkZero, "NlinkZero": NlinkZero,
"FstatDeleted": FstatDeleted,
"ParallelFileOpen": ParallelFileOpen, "ParallelFileOpen": ParallelFileOpen,
"Link": Link, "Link": Link,
"LinkUnlinkRename": LinkUnlinkRename, "LinkUnlinkRename": LinkUnlinkRename,
...@@ -255,6 +256,62 @@ func NlinkZero(t *testing.T, mnt string) { ...@@ -255,6 +256,62 @@ func NlinkZero(t *testing.T, mnt string) {
} }
// FstatDeleted is similar to NlinkZero, but Fstat()s multiple deleted files
// in random order and checks that the results match an earlier Stat().
//
// Excercises the fd-finding logic in rawBridge.GetAttr.
func FstatDeleted(t *testing.T, mnt string) {
const iMax = 9
type file struct {
fd int
st syscall.Stat_t
}
files := make(map[int]file)
for i := 0; i <= iMax; i++ {
// Create files with different sizes
path := fmt.Sprintf("%s/%d", mnt, i)
content := make([]byte, i)
err := ioutil.WriteFile(path, content, 0644)
if err != nil {
t.Fatalf("WriteFile: %v", err)
}
var st syscall.Stat_t
err = syscall.Stat(path, &st)
if err != nil {
t.Fatal(err)
}
// Open
fd, err := syscall.Open(path, syscall.O_RDONLY, 0)
if err != nil {
t.Fatal(err)
}
files[i] = file{fd, st}
defer syscall.Close(fd)
// Delete
err = syscall.Unlink(path)
if err != nil {
t.Fatal(err)
}
}
// Fstat in random order
for _, v := range files {
var st syscall.Stat_t
err := syscall.Fstat(v.fd, &st)
if err != nil {
t.Fatal(err)
}
// Ignore ctime, changes on unlink
v.st.Ctim = syscall.Timespec{}
st.Ctim = syscall.Timespec{}
// Nlink value should have dropped to zero
v.st.Nlink = 0
// Rest should stay the same
if v.st != st {
t.Errorf("stat mismatch: want=%v\n have=%v", v.st, st)
}
}
}
func ParallelFileOpen(t *testing.T, mnt string) { func ParallelFileOpen(t *testing.T, mnt string) {
fn := mnt + "/file" fn := mnt + "/file"
if err := ioutil.WriteFile(fn, []byte("content"), 0644); err != nil { if err := ioutil.WriteFile(fn, []byte("content"), 0644); err != nil {
......
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