]> arthur.barton.de Git - bup.git/blob - lib/bup/t/txstat.py
a4b1f523836ffb8fa5b0e4644b11c2019da2cd2d
[bup.git] / lib / bup / t / txstat.py
1 import math, tempfile, subprocess
2 from wvtest import *
3 import bup._helpers as _helpers
4 from bup import xstat
5
6 bup_tmp = os.path.realpath('../../../t/tmp')
7
8 @wvtest
9 def test_fstime():
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))
20
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))
34
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))
48
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))
56
57
58 @wvtest
59 def test_bup_utimensat():
60     initial_failures = wvfailure_count()
61     if not xstat._bup_utimensat:
62         return
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)
69     atime_ts = st[8]
70     mtime_ts = st[9]
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])
77
78
79 @wvtest
80 def test_bup_utimes():
81     initial_failures = wvfailure_count()
82     if not xstat._bup_utimes:
83         return
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)
90     atime_ts = st[8]
91     mtime_ts = st[9]
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])
98
99
100 @wvtest
101 def test_bup_lutimes():
102     initial_failures = wvfailure_count()
103     if not xstat._bup_lutimes:
104         return
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)
111     atime_ts = st[8]
112     mtime_ts = st[9]
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])