[functional tests] Use dd to create zeroed files

Previously I was using fallocate, which has issues on some filesystems.
This commit is contained in:
Joe Thornber 2018-12-12 13:14:09 +00:00
parent e03b878df3
commit 95ae4fef6a
1 changed files with 17 additions and 1 deletions

View File

@ -100,10 +100,26 @@
(to-bytes maybe-size)
maybe-size))
(define (suitable-block-size size)
(let loop ((bs (* 1024 1024 4)))
(if (> (mod size bs) 0)
(loop (/ bs 2))
bs)))
;; It's much faster if we write large blocks
(define (dd-zero-file path size)
(let* ((bytes (safe-to-bytes size))
(bs (suitable-block-size bytes))
(count (floor (/ bytes bs))))
(system (fmt #f "dd if=/dev/zero of=" path
" bs=" (wrt bs)
" count=" (wrt count)
" 2> /dev/null > /dev/null"))))
(define (with-temp-file-sized-thunk filename size fn)
(with-temp-file-thunk filename
(lambda (path)
(system (fmt #f "fallocate -l " (wrt (safe-to-bytes size)) " " path))
(dd-zero-file path size)
(fn path))))
(define-syntax with-temp-file-sized