1 import math, tempfile, subprocess
3 import bup._helpers as _helpers
6 bup_tmp = os.path.realpath('../../../t/tmp')
10 WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
11 WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
12 WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
13 WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
14 WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
15 WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
16 WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
17 WVPASSEQ(xstat.timespec_to_nsecs((0, -1)), -1)
18 WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
19 WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))
21 WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
22 WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
23 WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
24 WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
25 WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
26 WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
27 WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
28 x = xstat.nsecs_to_timespec(1977777778)
29 WVPASSEQ(type(x[0]), type(0))
30 WVPASSEQ(type(x[1]), type(0))
31 x = xstat.nsecs_to_timespec(-1977777778)
32 WVPASSEQ(type(x[0]), type(0))
33 WVPASSEQ(type(x[1]), type(0))
35 WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
36 WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
37 WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
38 WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
39 WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
40 WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
41 WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
42 x = xstat.nsecs_to_timeval(1977777778)
43 WVPASSEQ(type(x[0]), type(0))
44 WVPASSEQ(type(x[1]), type(0))
45 x = xstat.nsecs_to_timeval(-1977777778)
46 WVPASSEQ(type(x[0]), type(0))
47 WVPASSEQ(type(x[1]), type(0))
49 WVPASSEQ(xstat.fstime_floor_secs(0), 0)
50 WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
51 WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
52 WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
53 WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
54 WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
55 WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
59 def test_bup_utimensat():
60 initial_failures = wvfailure_count()
61 if not xstat._bup_utimensat:
63 tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-txstat-')
64 path = tmpdir + '/foo'
65 open(path, 'w').close()
66 frac_ts = (0, 10**9 / 2)
67 xstat._bup_utimensat(_helpers.AT_FDCWD, path, (frac_ts, frac_ts), 0)
68 st = _helpers.stat(path)
71 WVPASSEQ(atime_ts[0], 0)
72 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1])
73 WVPASSEQ(mtime_ts[0], 0)
74 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1])
75 if wvfailure_count() == initial_failures:
76 subprocess.call(['rm', '-rf', tmpdir])
80 def test_bup_utimes():
81 initial_failures = wvfailure_count()
82 if not xstat._bup_utimes:
84 tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-txstat-')
85 path = tmpdir + '/foo'
86 open(path, 'w').close()
87 frac_ts = (0, 10**6 / 2)
88 xstat._bup_utimes(path, (frac_ts, frac_ts))
89 st = _helpers.stat(path)
92 WVPASSEQ(atime_ts[0], 0)
93 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
94 WVPASSEQ(mtime_ts[0], 0)
95 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
96 if wvfailure_count() == initial_failures:
97 subprocess.call(['rm', '-rf', tmpdir])
101 def test_bup_lutimes():
102 initial_failures = wvfailure_count()
103 if not xstat._bup_lutimes:
105 tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-txstat-')
106 path = tmpdir + '/foo'
107 open(path, 'w').close()
108 frac_ts = (0, 10**6 / 2)
109 xstat._bup_lutimes(path, (frac_ts, frac_ts))
110 st = _helpers.stat(path)
113 WVPASSEQ(atime_ts[0], 0)
114 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
115 WVPASSEQ(mtime_ts[0], 0)
116 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
117 if wvfailure_count() == initial_failures:
118 subprocess.call(['rm', '-rf', tmpdir])