2017-08-15 20:37:45 +05:30
|
|
|
(library
|
|
|
|
(thin-functional-tests)
|
|
|
|
|
|
|
|
(export register-thin-tests)
|
|
|
|
|
|
|
|
(import
|
|
|
|
(chezscheme)
|
2017-09-28 19:06:01 +05:30
|
|
|
(bcache block-manager)
|
2017-08-25 15:55:37 +05:30
|
|
|
(disk-units)
|
2017-08-15 20:37:45 +05:30
|
|
|
(fmt fmt)
|
|
|
|
(functional-tests)
|
2017-08-25 14:16:56 +05:30
|
|
|
(process)
|
2017-08-25 15:42:18 +05:30
|
|
|
(scenario-string-constants)
|
2017-08-23 15:18:33 +05:30
|
|
|
(temp-file)
|
2017-09-15 16:56:54 +05:30
|
|
|
(thin xml)
|
2017-09-14 20:39:43 +05:30
|
|
|
(srfi s8 receive))
|
2017-08-15 20:37:45 +05:30
|
|
|
|
|
|
|
(define-tool thin-check)
|
|
|
|
(define-tool thin-delta)
|
|
|
|
(define-tool thin-dump)
|
|
|
|
(define-tool thin-restore)
|
|
|
|
(define-tool thin-rmap)
|
2017-09-29 14:49:56 +05:30
|
|
|
(define-tool thin-repair)
|
2020-05-26 15:25:03 +05:30
|
|
|
(define-tool thin-metadata-pack)
|
|
|
|
(define-tool thin-metadata-unpack)
|
2017-08-15 20:37:45 +05:30
|
|
|
|
2017-08-24 18:33:07 +05:30
|
|
|
(define-syntax with-thin-xml
|
|
|
|
(syntax-rules ()
|
|
|
|
((_ (v) b1 b2 ...)
|
2017-08-29 19:16:59 +05:30
|
|
|
(with-temp-file-containing ((v "thin.xml" (fmt #f (generate-xml 10 1000))))
|
2017-08-24 18:33:07 +05:30
|
|
|
b1 b2 ...))))
|
2017-08-15 20:37:45 +05:30
|
|
|
|
|
|
|
(define-syntax with-valid-metadata
|
|
|
|
(syntax-rules ()
|
2017-08-25 15:42:18 +05:30
|
|
|
((_ (md) b1 b2 ...)
|
2017-08-29 19:16:59 +05:30
|
|
|
(with-temp-file-sized ((md "thin.bin" (meg 4)))
|
2017-08-25 15:42:18 +05:30
|
|
|
(with-thin-xml (xml)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok (thin-restore "-i" xml "-o" md))
|
2017-08-25 15:42:18 +05:30
|
|
|
b1 b2 ...)))))
|
2017-08-15 20:37:45 +05:30
|
|
|
|
|
|
|
;;; It would be nice if the metadata was at least similar to valid data.
|
2019-10-08 19:04:24 +05:30
|
|
|
;;; Here I'm just using the start of the ls binary as 'random' data.
|
2017-08-15 20:37:45 +05:30
|
|
|
(define-syntax with-corrupt-metadata
|
|
|
|
(syntax-rules ()
|
2017-08-25 15:42:18 +05:30
|
|
|
((_ (md) b1 b2 ...)
|
2017-08-29 19:16:59 +05:30
|
|
|
(with-temp-file-sized ((md "thin.bin" (meg 4)))
|
2019-10-08 19:04:24 +05:30
|
|
|
(system (fmt #f "dd if=/usr/bin/ls of=" md " bs=4096 > /dev/null 2>&1"))
|
2017-08-25 15:42:18 +05:30
|
|
|
b1 b2 ...))))
|
2017-08-15 20:37:45 +05:30
|
|
|
|
2017-08-29 19:25:48 +05:30
|
|
|
(define-syntax with-empty-metadata
|
|
|
|
(syntax-rules ()
|
|
|
|
((_ (md) b1 b2 ...)
|
|
|
|
(with-temp-file-sized ((md "thin.bin" (meg 4)))
|
|
|
|
b1 b2 ...))))
|
|
|
|
|
2019-10-25 15:02:56 +05:30
|
|
|
(define (damage-superblock md)
|
|
|
|
(system (string-append "dd if=/dev/zero of=" md " bs=4K count=1 conv=notrunc > /dev/null 2>&1")))
|
|
|
|
|
|
|
|
(define-syntax with-damaged-superblock
|
|
|
|
(syntax-rules ()
|
|
|
|
((_ (md) b1 b2 ...)
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(damage-superblock md)
|
|
|
|
b1 b2 ...))))
|
|
|
|
|
2017-08-15 20:37:45 +05:30
|
|
|
;; We have to export something that forces all the initialisation expressions
|
|
|
|
;; to run.
|
2017-08-17 16:00:28 +05:30
|
|
|
(define (register-thin-tests) #t)
|
2017-08-15 20:37:45 +05:30
|
|
|
|
2017-08-17 20:54:10 +05:30
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_check scenarios
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
|
2017-08-17 15:53:43 +05:30
|
|
|
(define-scenario (thin-check v)
|
2017-08-31 14:39:58 +05:30
|
|
|
"thin_check -V"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-check "-V")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-check version)
|
|
|
|
"thin_check --version"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-check "--version")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-check h)
|
|
|
|
"print help (-h)"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-check "-h")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-check-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-check help)
|
|
|
|
"print help (--help)"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-check "--help")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-check-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-check bad-option)
|
|
|
|
"Unrecognised option should cause failure"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail (thin-check "--hedgehogs-only")))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
2020-07-21 18:09:25 +05:30
|
|
|
(define-scenario (thin-check incompatible-options fix-metadata-leaks)
|
|
|
|
"Incompatible options should cause failure"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-fail (thin-check "--fix-metadata-leaks" "-m" md))
|
|
|
|
(run-fail (thin-check "--fix-metadata-leaks" "--override-mapping-root 123" md))
|
|
|
|
(run-fail (thin-check "--fix-metadata-leaks" "--super-block-only" md))
|
|
|
|
(run-fail (thin-check "--fix-metadata-leaks" "--skip-mappings" md))
|
|
|
|
(run-fail (thin-check "--fix-metadata-leaks" "--ignore-non-fatal-errors" md))))
|
|
|
|
|
|
|
|
(define-scenario (thin-check incompatible-options clear-needs-check-flag)
|
|
|
|
"Incompatible options should cause failure"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-fail (thin-check "--clear-needs-check-flag" "-m" md))
|
|
|
|
(run-fail (thin-check "--clear-needs-check-flag" "--override-mapping-root 123" md))
|
|
|
|
(run-fail (thin-check "--clear-needs-check-flag" "--super-block-only" md))
|
|
|
|
(run-fail (thin-check "--clear-needs-check-flag" "--skip-mappings" md))
|
|
|
|
(run-fail (thin-check "--clear-needs-check-flag" "--ignore-non-fatal-errors" md))))
|
|
|
|
|
2017-08-31 14:39:58 +05:30
|
|
|
(define-scenario (thin-check superblock-only-valid)
|
|
|
|
"--super-block-only check passes on valid metadata"
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok (thin-check "--super-block-only" md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-check superblock-only-invalid)
|
|
|
|
"--super-block-only check fails with corrupt metadata"
|
|
|
|
(with-corrupt-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail (thin-check "--super-block-only" md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-check skip-mappings-valid)
|
|
|
|
"--skip-mappings check passes on valid metadata"
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok (thin-check "--skip-mappings" md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-check ignore-non-fatal-errors)
|
|
|
|
"--ignore-non-fatal-errors check passes on valid metadata"
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok (thin-check "--ignore-non-fatal-errors" md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-check quiet)
|
|
|
|
"--quiet should give no output"
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout stderr) (thin-check "--quiet" md)
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-eof stdout)
|
|
|
|
(assert-eof stderr))))
|
|
|
|
|
|
|
|
(define-scenario (thin-check clear-needs-check-flag)
|
|
|
|
"Accepts --clear-needs-check-flag"
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok (thin-check "--clear-needs-check-flag" md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
2020-07-21 20:17:59 +05:30
|
|
|
(define-scenario (thin-check fix-metadata-leaks)
|
|
|
|
"Accepts --fix-metadata-leaks"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-ok (thin-check "--fix-metadata-leaks" md))))
|
|
|
|
|
2017-09-15 19:52:04 +05:30
|
|
|
(define-scenario (thin-check tiny-metadata)
|
2017-10-05 20:48:42 +05:30
|
|
|
"Prints helpful message in case tiny metadata given"
|
|
|
|
(with-temp-file-sized ((md "thin.bin" 1024))
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-check md)
|
2017-09-15 19:52:04 +05:30
|
|
|
(assert-starts-with "Metadata device/file too small. Is this binary metadata?" stderr))))
|
|
|
|
|
|
|
|
(define-scenario (thin-check spot-accidental-xml-data)
|
|
|
|
"Prints helpful message if XML metadata given"
|
|
|
|
(with-thin-xml (xml)
|
|
|
|
(system (fmt #f "man bash >> " xml))
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-check xml)
|
2017-09-15 19:52:04 +05:30
|
|
|
(assert-matches ".*This looks like XML. thin_check only checks the binary metadata format." stderr))))
|
|
|
|
|
2018-11-09 18:13:21 +05:30
|
|
|
(define-scenario (thin-check info-fields)
|
|
|
|
"Outputs info fields"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-check md)
|
|
|
|
(assert-matches ".*TRANSACTION_ID=[0-9]+.*" stdout)
|
|
|
|
(assert-matches ".*METADATA_FREE_BLOCKS=[0-9]+.*" stdout))))
|
|
|
|
|
2017-08-31 14:39:58 +05:30
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_restore scenarios
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
|
|
|
|
(define-scenario (thin-restore print-version-v)
|
|
|
|
"print help (-V)"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-restore "-V")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore print-version-long)
|
|
|
|
"print help (--version)"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-restore "--version")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore h)
|
|
|
|
"print help (-h)"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-restore "-h")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-restore-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore help)
|
|
|
|
"print help (-h)"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-restore "--help")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-restore-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore no-input-file)
|
|
|
|
"forget to specify an input file"
|
|
|
|
(with-empty-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-restore "-o" md)
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-starts-with "No input file provided." stderr))))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore missing-input-file)
|
|
|
|
"the input file can't be found"
|
|
|
|
(with-empty-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-restore "-i no-such-file -o" md)
|
2019-10-08 19:04:24 +05:30
|
|
|
(assert-superblock-all-zeroes md)
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-starts-with "Couldn't stat file" stderr))))
|
|
|
|
|
2017-09-28 19:06:01 +05:30
|
|
|
(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))
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-restore "-i " xml "-o" md)
|
2019-10-08 19:04:24 +05:30
|
|
|
(assert-superblock-all-zeroes md)))))
|
2017-09-28 19:06:01 +05:30
|
|
|
|
2017-08-31 14:39:58 +05:30
|
|
|
(define-scenario (thin-restore missing-output-file)
|
|
|
|
"the output file can't be found"
|
|
|
|
(with-thin-xml (xml)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-restore "-i " xml)
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-starts-with "No output file provided." stderr))))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore tiny-output-file)
|
|
|
|
"Fails if the output file is too small."
|
|
|
|
(with-temp-file-sized ((md "thin.bin" 4096))
|
|
|
|
(with-thin-xml (xml)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-restore "-i" xml "-o" md)
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-starts-with thin-restore-outfile-too-small-text stderr)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore q)
|
|
|
|
"thin_restore accepts -q"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(with-thin-xml (xml)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-restore "-i" xml "-o" md "-q")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-eof stdout)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore quiet)
|
|
|
|
"thin_restore accepts --quiet"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(with-thin-xml (xml)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-restore "-i" xml "-o" md "--quiet")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-eof stdout)))))
|
|
|
|
|
2019-10-28 17:22:21 +05:30
|
|
|
(define-scenario (thin-restore override transaction-id)
|
|
|
|
"thin_restore obeys the --transaction-id override"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(with-thin-xml (xml)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-restore "--transaction-id 2345" "-i" xml "-o" md)
|
|
|
|
(assert-eof stderr))
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump md)
|
|
|
|
(assert-matches ".*transaction=\"2345\"" stdout)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore override data-block-size)
|
|
|
|
"thin_restore obeys the --data-block-size override"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(with-thin-xml (xml)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-restore "--data-block-size 8192" "-i" xml "-o" md)
|
|
|
|
(assert-eof stderr))
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump md)
|
|
|
|
(assert-matches ".*data_block_size=\"8192\"" stdout)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-restore override nr-data-blocks)
|
|
|
|
"thin_restore obeys the --nr-data-blocks override"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(with-thin-xml (xml)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-restore "--nr-data-blocks 234500" "-i" xml "-o" md)
|
|
|
|
(assert-eof stderr))
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump md)
|
|
|
|
(assert-matches ".*nr_data_blocks=\"234500\"" stdout)))))
|
|
|
|
|
2017-09-21 14:52:38 +05:30
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_dump scenarios
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
|
|
|
|
(define-scenario (thin-dump small-input-file)
|
|
|
|
"Fails with small input file"
|
|
|
|
(with-temp-file-sized ((md "thin.bin" 512))
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail (thin-dump md))))
|
2017-09-21 14:52:38 +05:30
|
|
|
|
2017-08-31 14:39:58 +05:30
|
|
|
(define-scenario (thin-dump restore-is-noop)
|
|
|
|
"thin_dump followed by thin_restore is a noop."
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (d1-stdout _) (thin-dump md)
|
2017-08-31 14:39:58 +05:30
|
|
|
(with-temp-file-containing ((xml "thin.xml" d1-stdout))
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok (thin-restore "-i" xml "-o" md))
|
|
|
|
(run-ok-rcv (d2-stdout _) (thin-dump md)
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal d1-stdout d2-stdout))))))
|
|
|
|
|
2019-05-27 20:08:45 +05:30
|
|
|
(define-scenario (thin-dump no-stderr)
|
|
|
|
"thin_dump of clean data does not output error messages to stderr"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump md)
|
|
|
|
(assert-eof stderr))))
|
|
|
|
|
2019-10-25 15:02:56 +05:30
|
|
|
(define-scenario (thin-dump override transaction-id)
|
|
|
|
"thin_dump obeys the --transaction-id override"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump "--transaction-id 2345" md)
|
|
|
|
(assert-eof stderr)
|
|
|
|
(assert-matches ".*transaction=\"2345\"" stdout))))
|
|
|
|
|
|
|
|
(define-scenario (thin-dump override data-block-size)
|
|
|
|
"thin_dump obeys the --data-block-size override"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump "--data-block-size 8192" md)
|
|
|
|
(assert-eof stderr)
|
|
|
|
(assert-matches ".*data_block_size=\"8192\"" stdout))))
|
|
|
|
|
|
|
|
(define-scenario (thin-dump override nr-data-blocks)
|
|
|
|
"thin_dump obeys the --nr-data-blocks override"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump "--nr-data-blocks 234500" md)
|
|
|
|
(assert-eof stderr)
|
|
|
|
(assert-matches ".*nr_data_blocks=\"234500\"" stdout))))
|
|
|
|
|
|
|
|
(define-scenario (thin-dump repair-superblock succeeds)
|
|
|
|
"thin_dump can restore a missing superblock"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-ok-rcv (expected-xml stderr) (thin-dump "--transaction-id=5" "--data-block-size=128" "--nr-data-blocks=4096000" md)
|
|
|
|
(damage-superblock md)
|
|
|
|
(run-ok-rcv (repaired-xml stderr) (thin-dump "--repair" "--transaction-id=5" "--data-block-size=128" "--nr-data-blocks=4096000" md)
|
|
|
|
(assert-eof stderr)
|
|
|
|
(assert-equal expected-xml repaired-xml)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-dump repair-superblock missing-transaction-id)
|
|
|
|
"--transaction-id is mandatory if the superblock is damaged"
|
|
|
|
(with-damaged-superblock (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-dump "--repair" "--data-block-size=128" "--nr-data-blocks=4096000" md)
|
|
|
|
(assert-matches ".*transaction id.*" stderr))))
|
|
|
|
|
|
|
|
(define-scenario (thin-dump repair-superblock missing-data-block-size)
|
|
|
|
"--data-block-size is mandatory if the superblock is damaged"
|
|
|
|
(with-damaged-superblock (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-dump "--repair" "--transaction-id=5" "--nr-data-blocks=4096000" md)
|
|
|
|
(assert-matches ".*data block size.*" stderr))))
|
|
|
|
|
|
|
|
(define-scenario (thin-dump repair-superblock missing-nr-data-blocks)
|
|
|
|
"--nr-data-blocks is mandatory if the superblock is damaged"
|
|
|
|
(with-damaged-superblock (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-dump "--repair" "--transaction-id=5" "--data-block-size=128" md)
|
|
|
|
(assert-matches ".*nr data blocks.*" stderr))))
|
|
|
|
|
2017-08-31 14:39:58 +05:30
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_rmap scenarios
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
|
|
|
|
(define-scenario (thin-rmap v)
|
|
|
|
"thin_rmap accepts -V"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-rmap "-V")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-rmap version)
|
|
|
|
"thin_rmap accepts --version"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-rmap "--version")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-rmap h)
|
|
|
|
"thin_rmap accepts -h"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-rmap "-h")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-rmap-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-rmap help)
|
|
|
|
"thin_rmap accepts --help"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-rmap "--help")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-rmap-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-rmap unrecognised-flag)
|
|
|
|
"thin_rmap complains with bad flags."
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail (thin-rmap "--unleash-the-hedgehogs")))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-rmap valid-region-format-should-pass)
|
|
|
|
"thin_rmap with a valid region format should pass."
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok
|
|
|
|
(thin-rmap "--region 23..7890" md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-rmap invalid-region-should-fail)
|
|
|
|
"thin_rmap with an invalid region format should fail."
|
|
|
|
(for-each (lambda (pattern)
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail (thin-rmap "--region" pattern md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
'("23,7890" "23..six" "found..7890" "89..88" "89..89" "89.." "" "89...99")))
|
|
|
|
|
|
|
|
(define-scenario (thin-rmap multiple-regions-should-pass)
|
|
|
|
"thin_rmap should handle multiple regions."
|
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok (thin-rmap "--region 1..23 --region 45..78" md))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
2017-10-05 16:26:53 +05:30
|
|
|
(define-scenario (thin-rmap handles-junk-input)
|
|
|
|
"Fail gracefully if given nonsense"
|
|
|
|
(with-thin-xml (xml)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-rmap "--region 0..-1" xml)
|
2017-10-05 16:26:53 +05:30
|
|
|
#t)))
|
|
|
|
|
2017-08-31 14:39:58 +05:30
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_delta scenarios
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
(define-scenario (thin-delta v)
|
|
|
|
"thin_delta accepts -V"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-delta "-V")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-delta version)
|
|
|
|
"thin_delta accepts --version"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-delta "--version")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal tools-version stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-delta h)
|
|
|
|
"thin_delta accepts -h"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-delta "-h")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-delta-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-delta help)
|
|
|
|
"thin_delta accepts --help"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-delta "--help")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-equal thin-delta-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-delta unrecognised-option)
|
|
|
|
"Unrecognised option should cause failure"
|
2017-09-15 16:56:54 +05:30
|
|
|
(with-valid-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (stdout stderr) (thin-delta "--unleash-the-hedgehogs")
|
|
|
|
(assert-matches ".*thin_delta: unrecognized option '--unleash-the-hedgehogs" stderr))))
|
2017-08-31 14:39:58 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-delta snap1-unspecified)
|
|
|
|
"Fails without --snap1 fails"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-delta "--snap2 45 foo")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-starts-with "--snap1 not specified." stderr)))
|
|
|
|
|
|
|
|
(define-scenario (thin-delta snap2-unspecified)
|
|
|
|
"Fails without --snap2 fails"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-delta "--snap1 45 foo")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-starts-with "--snap2 not specified." stderr)))
|
|
|
|
|
|
|
|
(define-scenario (thin-delta device-unspecified)
|
|
|
|
"Fails if no device given"
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-delta "--snap1 45 --snap2 46")
|
2017-08-31 14:39:58 +05:30
|
|
|
(assert-starts-with "No input device provided." stderr)))
|
|
|
|
|
2017-09-29 14:49:56 +05:30
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_repair scenarios
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
(define-scenario (thin-repair dont-repair-xml)
|
|
|
|
"Fails gracefully if run on XML rather than metadata"
|
|
|
|
(with-thin-xml (xml)
|
|
|
|
(with-empty-metadata (md)
|
2017-10-10 21:21:31 +05:30
|
|
|
(run-fail-rcv (_ stderr) (thin-repair "-i" xml "-o" md)
|
2017-09-29 14:49:56 +05:30
|
|
|
#t))))
|
2019-10-08 19:04:24 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-repair missing-input-file)
|
|
|
|
"the input file can't be found"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-repair "-i no-such-file -o" md)
|
|
|
|
(assert-superblock-all-zeroes md)
|
|
|
|
(assert-starts-with "Couldn't stat file" stderr))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair garbage-input-file)
|
|
|
|
"the input file is just zeroes"
|
|
|
|
(with-empty-metadata (md1)
|
|
|
|
(with-corrupt-metadata (md2)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-repair "-i " md1 "-o" md2)
|
|
|
|
(assert-superblock-all-zeroes md2)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair missing-output-file)
|
|
|
|
"the output file can't be found"
|
|
|
|
(with-thin-xml (xml)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-repair "-i " xml)
|
|
|
|
(assert-starts-with "No output file provided." stderr))))
|
|
|
|
|
2019-10-25 15:02:56 +05:30
|
|
|
(define-scenario (thin-repair override transaction-id)
|
|
|
|
"thin_repair obeys the --transaction-id override"
|
|
|
|
(with-valid-metadata (md1)
|
|
|
|
(with-empty-metadata (md2)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-repair "--transaction-id 2345" "-i" md1 "-o" md2)
|
|
|
|
(assert-eof stderr))
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump md2)
|
|
|
|
(assert-matches ".*transaction=\"2345\"" stdout)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair override data-block-size)
|
|
|
|
"thin_repair obeys the --data-block-size override"
|
|
|
|
(with-valid-metadata (md1)
|
|
|
|
(with-empty-metadata (md2)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-repair "--data-block-size 8192" "-i" md1 "-o" md2)
|
|
|
|
(assert-eof stderr))
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump md2)
|
|
|
|
(assert-matches ".*data_block_size=\"8192\"" stdout)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair override nr-data-blocks)
|
|
|
|
"thin_repair obeys the --nr-data-blocks override"
|
|
|
|
(with-valid-metadata (md1)
|
|
|
|
(with-empty-metadata (md2)
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-repair "--nr-data-blocks 234500" "-i" md1 "-o" md2)
|
|
|
|
(assert-eof stderr))
|
|
|
|
(run-ok-rcv (stdout stderr) (thin-dump md2)
|
|
|
|
(assert-matches ".*nr_data_blocks=\"234500\"" stdout)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair superblock succeeds)
|
|
|
|
"thin_repair can restore a missing superblock"
|
|
|
|
(with-valid-metadata (md1)
|
|
|
|
(run-ok-rcv (expected-xml stderr) (thin-dump "--transaction-id=5" "--data-block-size=128" "--nr-data-blocks=4096000" md1)
|
|
|
|
(damage-superblock md1)
|
|
|
|
(with-empty-metadata (md2)
|
|
|
|
(run-ok-rcv (_ stderr) (thin-repair "--transaction-id=5" "--data-block-size=128" "--nr-data-blocks=4096000" "-i" md1 "-o" md2)
|
|
|
|
(assert-eof stderr))
|
|
|
|
(run-ok-rcv (repaired-xml stderr) (thin-dump md2)
|
|
|
|
(assert-eof stderr)
|
|
|
|
(assert-equal expected-xml repaired-xml))))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair superblock missing-transaction-id)
|
|
|
|
"--transaction-id is mandatory if the superblock is damaged"
|
|
|
|
(with-damaged-superblock (md1)
|
|
|
|
(with-empty-metadata (md2)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-repair "--data-block-size=128" "--nr-data-blocks=4096000" "-i" md1 "-o" md2)
|
|
|
|
(assert-matches ".*transaction id.*" stderr)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair superblock missing-data-block-size)
|
|
|
|
"--data-block-size is mandatory if the superblock is damaged"
|
|
|
|
(with-damaged-superblock (md1)
|
|
|
|
(with-empty-metadata (md2)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-repair "--transaction-id=5" "--nr-data-blocks=4096000" "-i" md1 "-o" md2)
|
|
|
|
(assert-matches ".*data block size.*" stderr)))))
|
|
|
|
|
|
|
|
(define-scenario (thin-repair superblock missing-nr-data-blocks)
|
|
|
|
"--nr-data-blocks is mandatory if the superblock is damaged"
|
|
|
|
(with-damaged-superblock (md1)
|
|
|
|
(with-empty-metadata (md2)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-repair "--transaction-id=5" "--data-block-size=128" "-i" md1 "-o" md2)
|
|
|
|
(assert-matches ".*nr data blocks.*" stderr)))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_metadata_pack scenarios
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
|
|
|
|
(define-scenario (thin-metadata-pack version)
|
2020-06-09 17:33:39 +05:30
|
|
|
"accepts --version"
|
2020-05-26 15:25:03 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-metadata-pack "--version")
|
2020-07-03 17:58:02 +05:30
|
|
|
(assert-equal "thin_metadata_pack 0.9.0-rc2" stdout)))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-pack h)
|
2020-06-09 17:33:39 +05:30
|
|
|
"accepts -h"
|
2020-05-26 15:25:03 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-metadata-pack "-h")
|
|
|
|
(assert-equal thin-metadata-pack-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-metadata-pack help)
|
2020-06-09 17:33:39 +05:30
|
|
|
"accepts --help"
|
2020-05-26 15:25:03 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-metadata-pack "--help")
|
|
|
|
(assert-equal thin-metadata-pack-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-metadata-pack unrecognised-option)
|
|
|
|
"Unrecognised option should cause failure"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-fail-rcv (stdout stderr) (thin-metadata-pack "--unleash-the-hedgehogs")
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "error: Found argument '--unleash-the-hedgehogs'" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-pack missing-input-file)
|
|
|
|
"the input file wasn't specified"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-metadata-pack "-o " md)
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "error: The following required arguments were not provided:\n -i <DEV>" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-pack no-such-input-file)
|
|
|
|
"the input file can't be found"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-metadata-pack "-i no-such-file -o" md)
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "Couldn't find input file" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-pack missing-output-file)
|
|
|
|
"the output file wasn't specified"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-metadata-pack "-i" md)
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "error: The following required arguments were not provided:\n -o <FILE>" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
;;;-----------------------------------------------------------
|
2020-06-09 17:33:39 +05:30
|
|
|
;;; thin_metadata_unpack scenarios
|
2020-05-26 15:25:03 +05:30
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
(define-scenario (thin-metadata-unpack version)
|
2020-06-09 17:33:39 +05:30
|
|
|
"accepts --version"
|
2020-05-26 15:25:03 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-metadata-unpack "--version")
|
2020-07-03 17:58:02 +05:30
|
|
|
(assert-equal "thin_metadata_unpack 0.9.0-rc2" stdout)))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-unpack h)
|
2020-06-09 17:33:39 +05:30
|
|
|
"accepts -h"
|
2020-05-26 15:25:03 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-metadata-unpack "-h")
|
|
|
|
(assert-equal thin-metadata-unpack-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-metadata-unpack help)
|
2020-06-09 17:33:39 +05:30
|
|
|
"accepts --help"
|
2020-05-26 15:25:03 +05:30
|
|
|
(run-ok-rcv (stdout _) (thin-metadata-unpack "--help")
|
|
|
|
(assert-equal thin-metadata-unpack-help stdout)))
|
|
|
|
|
|
|
|
(define-scenario (thin-metadata-unpack unrecognised-option)
|
|
|
|
"Unrecognised option should cause failure"
|
|
|
|
(with-valid-metadata (md)
|
|
|
|
(run-fail-rcv (stdout stderr) (thin-metadata-unpack "--unleash-the-hedgehogs")
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "error: Found argument '--unleash-the-hedgehogs'" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-unpack missing-input-file)
|
|
|
|
"the input file wasn't specified"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-metadata-unpack "-o " md)
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "error: The following required arguments were not provided:\n -i <DEV>" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-unpack no-such-input-file)
|
|
|
|
"the input file can't be found"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-metadata-unpack "-i no-such-file -o" md)
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "Couldn't find input file" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-unpack missing-output-file)
|
|
|
|
"the output file wasn't specified"
|
|
|
|
(with-empty-metadata (md)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-metadata-unpack "-i" md)
|
2020-06-09 17:33:39 +05:30
|
|
|
(assert-starts-with "error: The following required arguments were not provided:\n -o <FILE>" stderr))))
|
2020-05-26 15:25:03 +05:30
|
|
|
|
|
|
|
(define-scenario (thin-metadata-unpack garbage-input-file)
|
|
|
|
"the input file is just zeroes"
|
|
|
|
(with-empty-metadata (bad-pack)
|
|
|
|
(run-fail-rcv (_ stderr) (thin-metadata-unpack "-i " bad-pack "-o junk")
|
|
|
|
(assert-starts-with "Not a pack file." stderr))))
|
|
|
|
|
|
|
|
;;;-----------------------------------------------------------
|
|
|
|
;;; thin_metadata_pack/unpack end to end scenario
|
|
|
|
;;;-----------------------------------------------------------)
|
|
|
|
(define-scenario (thin-metadata-pack end-to-end)
|
|
|
|
"pack -> unpack recovers metadata"
|
|
|
|
(let ((pack-file "md.pack"))
|
|
|
|
(with-valid-metadata (md-in)
|
|
|
|
(with-empty-metadata (md-out)
|
|
|
|
(run-ok (thin-metadata-pack "-i" md-in "-o" pack-file))
|
|
|
|
(run-ok (thin-metadata-unpack "-i" pack-file "-o" md-out))
|
|
|
|
(run-ok-rcv (dump1 _) (thin-dump md-in)
|
|
|
|
(run-ok-rcv (dump2 _) (thin-dump md-out)
|
|
|
|
(assert-equal dump1 dump2)))))))
|
|
|
|
|
|
|
|
)
|