]> arthur.barton.de Git - bup.git/blobdiff - t/ns-timestamp-resolutions
Don't fail tests when the timestamp read resolution is higher than write.
[bup.git] / t / ns-timestamp-resolutions
diff --git a/t/ns-timestamp-resolutions b/t/ns-timestamp-resolutions
new file mode 100755 (executable)
index 0000000..d1bb785
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+import os, sys
+
+argv = sys.argv
+exe = os.path.realpath(argv[0])
+exepath = os.path.split(exe)[0] or '.'
+exeprefix = os.path.split(os.path.abspath(exepath))[0]
+
+# fix the PYTHONPATH to include our lib dir
+libpath = os.path.join(exepath, '..', 'lib')
+sys.path[:0] = [libpath]
+os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
+
+import bup.xstat as xstat
+from bup.helpers import handle_ctrl_c, saved_errors
+from bup import metadata, options
+
+optspec = """
+ns-timestamp-resolutions TEST_FILE_NAME
+--
+"""
+
+handle_ctrl_c()
+
+o = options.Options(optspec)
+(opt, flags, extra) = o.parse(sys.argv[1:])
+
+if len(extra) != 1:
+    o.fatal('must specify a test file name')
+
+target = extra[0]
+
+open(target, 'w').close()
+xstat.utime(target, (123456789, 123456789))
+meta = metadata.from_path(target)
+
+def ns_resolution(x):
+    n = 1;
+    while n < 10**9 and x % 10 == 0:
+        x /= 10
+        n *= 10
+    return n
+
+print ns_resolution(meta.atime), ns_resolution(meta.mtime)
+
+if saved_errors:
+    log('warning: %d errors encountered\n' % len(saved_errors))
+    sys.exit(1)