From 95ae4fef6af5ccf865a8caf6e85f5aca899104f4 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 12 Dec 2018 13:14:09 +0000 Subject: [PATCH] [functional tests] Use dd to create zeroed files Previously I was using fallocate, which has issues on some filesystems. --- functional-tests/temp-file.scm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/functional-tests/temp-file.scm b/functional-tests/temp-file.scm index d8981b1..64fdfe1 100644 --- a/functional-tests/temp-file.scm +++ b/functional-tests/temp-file.scm @@ -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