[functional-tests] Check *_restore doesn't touch the metadata if the xml doesn't exists, or isn't xml.

This commit is contained in:
Joe Thornber 2017-09-28 14:36:01 +01:00
parent 7796b4eecb
commit f018e6ecf7
5 changed files with 51 additions and 4 deletions

View File

@ -167,8 +167,16 @@
"the input file can't be found" "the input file can't be found"
(with-empty-metadata (md) (with-empty-metadata (md)
(receive (_ stderr) (run-fail "cache_restore -i no-such-file -o" md) (receive (_ stderr) (run-fail "cache_restore -i no-such-file -o" md)
(assert-superblock-untouched md)
(assert-starts-with "Couldn't stat file" stderr)))) (assert-starts-with "Couldn't stat file" stderr))))
(define-scenario (cache-restore garbage-input-file)
"the input file is just zeroes"
(with-empty-metadata (md)
(with-temp-file-sized ((xml "cache.xml" 4096))
(receive (_ stderr) (run-fail "cache_restore -i " xml "-o" md)
(assert-superblock-untouched md)))))
(define-scenario (cache-restore missing-output-file) (define-scenario (cache-restore missing-output-file)
"the output file can't be found" "the output file can't be found"
(with-cache-xml (xml) (with-cache-xml (xml)

View File

@ -136,6 +136,20 @@
(receive (_ stderr) (run-fail "era_restore" "-o" md) (receive (_ stderr) (run-fail "era_restore" "-o" md)
(assert-starts-with "No input file provided." stderr)))) (assert-starts-with "No input file provided." stderr))))
(define-scenario (era-restore missing-input-file)
"the input file can't be found"
(with-empty-metadata (md)
(receive (_ stderr) (run-fail "era_restore -i no-such-file -o" md)
(assert-superblock-untouched md)
(assert-starts-with "Couldn't stat file" stderr))))
(define-scenario (era-restore garbage-input-file)
"the input file is just zeroes"
(with-empty-metadata (md)
(with-temp-file-sized ((xml "era.xml" 4096))
(receive (_ stderr) (run-fail "era_restore -i " xml "-o" md)
(assert-superblock-untouched md)))))
(define-scenario (era-restore output-unspecified) (define-scenario (era-restore output-unspecified)
"Fails if no metadata dev specified" "Fails if no metadata dev specified"
(with-era-xml (xml) (with-era-xml (xml)

View File

@ -20,10 +20,12 @@
assert-equal assert-equal
assert-eof assert-eof
assert-starts-with assert-starts-with
assert-matches) assert-matches
assert-superblock-untouched)
(import (import
(chezscheme) (chezscheme)
(bcache block-manager)
(fmt fmt) (fmt fmt)
(list-utils) (list-utils)
(logging) (logging)
@ -221,5 +223,20 @@
(unless ((regex pattern) str) (unless ((regex pattern) str)
(fail (fmt #f "string should match: " pattern ", " str)))) (fail (fmt #f "string should match: " pattern ", " str))))
(define (all-zeroes? ptr count)
(let ((u8-ptr (make-ftype-pointer unsigned-8 ptr)))
(let loop ((i 0))
(if (= count i)
#t
(if (zero? (ftype-ref unsigned-8 () u8-ptr i))
(loop (+ i 1))
#f)))))
(define (assert-superblock-untouched md)
(with-bcache (cache md 1)
(with-block (b cache 0 (get-flags))
(unless (all-zeroes? (block-data b) 4096)
(fail "superblock contains non-zero data")))))
) )

View File

@ -97,9 +97,8 @@
(define (with-temp-file-sized-thunk filename size fn) (define (with-temp-file-sized-thunk filename size fn)
(with-temp-file-thunk filename (with-temp-file-thunk filename
(lambda (path) (lambda (path)
(let ((cmd (fmt #f (dsp "fallocate -l ") (wrt size) (dsp " ") (dsp path)))) (system (fmt #f "fallocate -l " (wrt size) " " path))
(system cmd) (fn path))))
(fn path)))))
(define-syntax with-temp-file-sized (define-syntax with-temp-file-sized
(syntax-rules () (syntax-rules ()

View File

@ -5,6 +5,7 @@
(import (import
(chezscheme) (chezscheme)
(bcache block-manager)
(disk-units) (disk-units)
(fmt fmt) (fmt fmt)
(functional-tests) (functional-tests)
@ -158,8 +159,16 @@
"the input file can't be found" "the input file can't be found"
(with-empty-metadata (md) (with-empty-metadata (md)
(receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" md) (receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" md)
(assert-superblock-untouched md)
(assert-starts-with "Couldn't stat file" stderr)))) (assert-starts-with "Couldn't stat file" stderr))))
(define-scenario (thin-restore garbage-input-file)
"the input file is just zeroes"
(with-empty-metadata (md)
(with-temp-file-sized ((xml "thin.xml" 4096))
(receive (_ stderr) (run-fail "thin_restore -i " xml "-o" md)
(assert-superblock-untouched md)))))
(define-scenario (thin-restore missing-output-file) (define-scenario (thin-restore missing-output-file)
"the output file can't be found" "the output file can't be found"
(with-thin-xml (xml) (with-thin-xml (xml)