2 from __future__ import absolute_import
3 import math, tempfile, subprocess
7 import bup._helpers as _helpers
12 WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
13 WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
14 WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
15 WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
16 WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
17 WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
18 WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
19 WVPASSEQ(xstat.timespec_to_nsecs((0, -1)), -1)
20 WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
21 WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))
23 WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
24 WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
25 WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
26 WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
27 WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
28 WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
29 WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
30 x = xstat.nsecs_to_timespec(1977777778)
31 WVPASSEQ(type(x[0]), type(0))
32 WVPASSEQ(type(x[1]), type(0))
33 x = xstat.nsecs_to_timespec(-1977777778)
34 WVPASSEQ(type(x[0]), type(0))
35 WVPASSEQ(type(x[1]), type(0))
37 WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
38 WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
39 WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
40 WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
41 WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
42 WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
43 WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
44 x = xstat.nsecs_to_timeval(1977777778)
45 WVPASSEQ(type(x[0]), type(0))
46 WVPASSEQ(type(x[1]), type(0))
47 x = xstat.nsecs_to_timeval(-1977777778)
48 WVPASSEQ(type(x[0]), type(0))
49 WVPASSEQ(type(x[1]), type(0))
51 WVPASSEQ(xstat.fstime_floor_secs(0), 0)
52 WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
53 WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
54 WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
55 WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
56 WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
57 WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
60 def test_bup_utimensat(tmpdir):
61 if not xstat._bup_utimensat:
63 path = tmpdir + b'/foo'
64 open(path, 'w').close()
65 frac_ts = (0, 10**9 // 2)
66 xstat._bup_utimensat(_helpers.AT_FDCWD, path, (frac_ts, frac_ts), 0)
67 st = _helpers.stat(path)
70 WVPASSEQ(atime_ts[0], 0)
71 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1])
72 WVPASSEQ(mtime_ts[0], 0)
73 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1])
76 def test_bup_utimes(tmpdir):
77 if not xstat._bup_utimes:
79 path = tmpdir + b'/foo'
80 open(path, 'w').close()
81 frac_ts = (0, 10**6 // 2)
82 xstat._bup_utimes(path, (frac_ts, frac_ts))
83 st = _helpers.stat(path)
86 WVPASSEQ(atime_ts[0], 0)
87 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
88 WVPASSEQ(mtime_ts[0], 0)
89 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
92 def test_bup_lutimes(tmpdir):
93 if not xstat._bup_lutimes:
95 path = tmpdir + b'/foo'
96 open(path, 'w').close()
97 frac_ts = (0, 10**6 // 2)
98 xstat._bup_lutimes(path, (frac_ts, frac_ts))
99 st = _helpers.stat(path)
102 WVPASSEQ(atime_ts[0], 0)
103 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
104 WVPASSEQ(mtime_ts[0], 0)
105 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)