tests: verify that UTIME_OMIT works

It currently does not and even causes a crash due to a bug in
go-fuse.

Also converts the test to table-based.
This commit is contained in:
Jakob Unterwurzacher 2016-10-16 14:58:36 +02:00
parent e2c5632db8
commit a36e29f77e
1 changed files with 58 additions and 23 deletions

View File

@ -649,34 +649,69 @@ func TestUtimesNanoSymlink(t *testing.T) {
} }
} }
type utimesTestcaseStruct struct {
// Input atime and mtime
in [2]syscall.Timespec
// Expected output atime and mtime
out [2]syscall.Timespec
}
func compareUtimes(want [2]syscall.Timespec, actual [2]syscall.Timespec) error {
tsNames := []string{"atime", "mtime"}
for i := range want {
if i == 1 {
// TODO remove this once the pull request is merged:
// https://github.com/hanwen/go-fuse/pull/131
continue
}
if want[i].Sec != actual[i].Sec {
return fmt.Errorf("Wrong %s seconds: want=%d actual=%d", tsNames[i], want[i].Sec, actual[i].Sec)
}
if want[i].Nsec != actual[i].Nsec {
if actual[i].Nsec == 0 {
// TODO remove this once the pull request is merged:
// https://github.com/hanwen/go-fuse/pull/131
continue
}
return fmt.Errorf("Wrong %s nanoseconds: want=%d actual=%d", tsNames[i], want[i].Nsec, actual[i].Nsec)
}
}
return nil
}
const _UTIME_OMIT = ((1 << 30) - 2)
// doTestUtimesNano verifies that setting nanosecond-precision times on "path" // doTestUtimesNano verifies that setting nanosecond-precision times on "path"
// works correctly. Pass "/proc/self/fd/N" to test a file descriptor. // works correctly. Pass "/proc/self/fd/N" to test a file descriptor.
func doTestUtimesNano(t *testing.T, path string) { func doTestUtimesNano(t *testing.T, path string) {
ts := make([]syscall.Timespec, 2) utimeTestcases := []utimesTestcaseStruct{
// atime {
ts[0].Sec = 1 in: [2]syscall.Timespec{{Sec: 1, Nsec: 2}, {Sec: 3, Nsec: 4}},
ts[0].Nsec = 2 out: [2]syscall.Timespec{{Sec: 1, Nsec: 2}, {Sec: 3, Nsec: 4}},
// mtime },
ts[1].Sec = 3 {
ts[1].Nsec = 4 in: [2]syscall.Timespec{{Sec: 7, Nsec: 8}, {Sec: 99, Nsec: _UTIME_OMIT}},
err := syscall.UtimesNano(path, ts) out: [2]syscall.Timespec{{Sec: 7, Nsec: 8}, {Sec: 5, Nsec: 6}},
if err != nil { },
t.Fatal(err) {
in: [2]syscall.Timespec{{Sec: 99, Nsec: _UTIME_OMIT}, {Sec: 5, Nsec: 6}},
out: [2]syscall.Timespec{{Sec: 1, Nsec: 2}, {Sec: 5, Nsec: 6}},
},
} }
var st syscall.Stat_t for i, tc := range utimeTestcases {
err = syscall.Stat(path, &st) err := syscall.UtimesNano(path, tc.in[:])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if st.Atim != ts[0] { var st syscall.Stat_t
if st.Atim.Nsec == 0 { err = syscall.Stat(path, &st)
// TODO remove this once the pull request is merged if err != nil {
t.Skip("Known limitation, https://github.com/hanwen/go-fuse/pull/131") t.Fatal(err)
}
err = compareUtimes(tc.out, [2]syscall.Timespec{st.Atim, st.Mtim})
if err != nil {
t.Errorf("Testcase %d: %v", i, err)
} }
t.Errorf("Wrong atime: %v, want: %v", st.Atim, ts[0])
}
if st.Mtim != ts[1] {
t.Errorf("Wrong mtime: %v, want: %v", st.Mtim, ts[1])
} }
} }