1 import math, tempfile, subprocess
5 import bup._helpers as _helpers
7 from buptest import no_lingering_errors, test_tempdir
12 with no_lingering_errors():
13 WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
14 WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
15 WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
16 WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
17 WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
18 WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
19 WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
20 WVPASSEQ(xstat.timespec_to_nsecs((0, -1)), -1)
21 WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
22 WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))
24 WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
25 WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
26 WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
27 WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
28 WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
29 WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
30 WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
31 x = xstat.nsecs_to_timespec(1977777778)
32 WVPASSEQ(type(x[0]), type(0))
33 WVPASSEQ(type(x[1]), type(0))
34 x = xstat.nsecs_to_timespec(-1977777778)
35 WVPASSEQ(type(x[0]), type(0))
36 WVPASSEQ(type(x[1]), type(0))
38 WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
39 WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
40 WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
41 WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
42 WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
43 WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
44 WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
45 x = xstat.nsecs_to_timeval(1977777778)
46 WVPASSEQ(type(x[0]), type(0))
47 WVPASSEQ(type(x[1]), type(0))
48 x = xstat.nsecs_to_timeval(-1977777778)
49 WVPASSEQ(type(x[0]), type(0))
50 WVPASSEQ(type(x[1]), type(0))
52 WVPASSEQ(xstat.fstime_floor_secs(0), 0)
53 WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
54 WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
55 WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
56 WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
57 WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
58 WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
62 def test_bup_utimensat():
63 if not xstat._bup_utimensat:
65 with no_lingering_errors():
66 with test_tempdir('bup-txstat-') as tmpdir:
67 path = tmpdir + '/foo'
68 open(path, 'w').close()
69 frac_ts = (0, 10**9 / 2)
70 xstat._bup_utimensat(_helpers.AT_FDCWD, path, (frac_ts, frac_ts), 0)
71 st = _helpers.stat(path)
74 WVPASSEQ(atime_ts[0], 0)
75 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1])
76 WVPASSEQ(mtime_ts[0], 0)
77 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1])
81 def test_bup_utimes():
82 if not xstat._bup_utimes:
84 with no_lingering_errors():
85 with test_tempdir('bup-txstat-') as tmpdir:
86 path = tmpdir + '/foo'
87 open(path, 'w').close()
88 frac_ts = (0, 10**6 / 2)
89 xstat._bup_utimes(path, (frac_ts, frac_ts))
90 st = _helpers.stat(path)
93 WVPASSEQ(atime_ts[0], 0)
94 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
95 WVPASSEQ(mtime_ts[0], 0)
96 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)
100 def test_bup_lutimes():
101 if not xstat._bup_lutimes:
103 with no_lingering_errors():
104 with test_tempdir('bup-txstat-') as tmpdir:
105 path = tmpdir + '/foo'
106 open(path, 'w').close()
107 frac_ts = (0, 10**6 / 2)
108 xstat._bup_lutimes(path, (frac_ts, frac_ts))
109 st = _helpers.stat(path)
112 WVPASSEQ(atime_ts[0], 0)
113 WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1] * 1000)
114 WVPASSEQ(mtime_ts[0], 0)
115 WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1] * 1000)