diff --git a/functional-tests/scenario-string-constants.scm b/functional-tests/scenario-string-constants.scm new file mode 100644 index 0000000..059671d --- /dev/null +++ b/functional-tests/scenario-string-constants.scm @@ -0,0 +1,49 @@ +(library + (scenario-string-constants) + + (export thin-check-help + thin-restore-outfile-too-small-text + thin-restore-help + thin-rmap-help) + + (import (rnrs)) + + ;; These long string constants really confuse vim and mess up Paredit mode. + ;; So moving into a separate file. + (define thin-check-help + "Usage: thin_check [options] {device|file} +Options: + {-q|--quiet} + {-h|--help} + {-V|--version} + {--clear-needs-check-flag} + {--ignore-non-fatal-errors} + {--skip-mappings} + {--super-block-only}") + + (define thin-restore-outfile-too-small-text + "Output file too small. + +The output file should either be a block device, +or an existing file. The file needs to be large +enough to hold the metadata.") + + (define thin-restore-help + "Usage: thin_restore [options] +Options: + {-h|--help} + {-i|--input} + {-o|--output} + {-q|--quiet} + {-V|--version}") + + (define thin-rmap-help + "Usage: thin_rmap [options] {device|file} +Options: + {-h|--help} + {-V|--version} + {--region }* +Where: + is of the form .. + for example 5..45 denotes blocks 5 to 44 inclusive, but not block 45") +) diff --git a/functional-tests/thin-functional-tests.scm b/functional-tests/thin-functional-tests.scm index f4f40cc..913356b 100644 --- a/functional-tests/thin-functional-tests.scm +++ b/functional-tests/thin-functional-tests.scm @@ -8,6 +8,7 @@ (fmt fmt) (functional-tests) (process) + (scenario-string-constants) (temp-file) (thin-xml) (srfi s8 receive) @@ -19,11 +20,9 @@ (define-tool thin-restore) (define-tool thin-rmap) - ;; FIXME: use a temp file - (define (current-metadata) "metadata.bin") - - ;; FIXME: remove - (define cwd "/tmp") + ;; FIXME: start a disk units library + (define (meg n) + (* 1024 1024 n)) (define-syntax with-thin-xml (syntax-rules () @@ -33,61 +32,23 @@ (define-syntax with-valid-metadata (syntax-rules () - ((_ b1 b2 ...) - (with-thin-xml (xml) - (thin-restore "-i" xml "-o" (current-metadata)) - b1 b2 ...)))) + ((_ (md) b1 b2 ...) + (with-temp-file-sized ((md (meg 4))) + (with-thin-xml (xml) + (thin-restore "-i" xml "-o" md) + b1 b2 ...))))) ;;; It would be nice if the metadata was at least similar to valid data. - (define (%with-corrupt-metadata thunk) - (run-ok "dd if=/dev/zero" (fmt #f "of=" (current-metadata)) "bs=64M count=1") - (thunk)) - (define-syntax with-corrupt-metadata (syntax-rules () - ((_ body ...) (%with-corrupt-metadata (lambda () body ...))))) + ((_ (md) b1 b2 ...) + (with-temp-file-sized ((md (meg 4))) + b1 b2 ...)))) ;; We have to export something that forces all the initialisation expressions ;; to run. (define (register-thin-tests) #t) - (define thin-check-help - "Usage: thin_check [options] {device|file} -Options: - {-q|--quiet} - {-h|--help} - {-V|--version} - {--clear-needs-check-flag} - {--ignore-non-fatal-errors} - {--skip-mappings} - {--super-block-only}") - - (define thin-restore-outfile-too-small-text - "Output file too small. - -The output file should either be a block device, -or an existing file. The file needs to be large -enough to hold the metadata.") - - (define thin-restore-help - "Usage: thin_restore [options] -Options: - {-h|--help} - {-i|--input} - {-o|--output} - {-q|--quiet} - {-V|--version}") - - (define thin-rmap-help - "Usage: thin_rmap [options] {device|file} -Options: - {-h|--help} - {-V|--version} - {--region }* -Where: - is of the form .. - for example 5..45 denotes blocks 5 to 44 inclusive, but not block 45") - ;;;----------------------------------------------------------- ;;; thin_check scenarios ;;;----------------------------------------------------------- @@ -118,35 +79,35 @@ Where: (define-scenario (thin-check superblock-only-valid) "--super-block-only check passes on valid metadata" - (with-valid-metadata - (thin-check "--super-block-only" (current-metadata)))) + (with-valid-metadata (md) + (thin-check "--super-block-only" md))) (define-scenario (thin-check superblock-only-invalid) "--super-block-only check fails with corrupt metadata" - (with-corrupt-metadata - (run-fail "thin_check --super-block-only" (current-metadata)))) + (with-corrupt-metadata (md) + (run-fail "thin_check --super-block-only" md))) (define-scenario (thin-check skip-mappings-valid) "--skip-mappings check passes on valid metadata" - (with-valid-metadata - (thin-check "--skip-mappings" (current-metadata)))) + (with-valid-metadata (md) + (thin-check "--skip-mappings" md))) (define-scenario (thin-check ignore-non-fatal-errors) "--ignore-non-fatal-errors check passes on valid metadata" - (with-valid-metadata - (thin-check "--ignore-non-fatal-errors" (current-metadata)))) + (with-valid-metadata (md) + (thin-check "--ignore-non-fatal-errors" md))) (define-scenario (thin-check quiet) "--quiet should give no output" - (with-valid-metadata - (receive (stdout stderr) (thin-check "--quiet" (current-metadata)) + (with-valid-metadata (md) + (receive (stdout stderr) (thin-check "--quiet" md) (assert-eof stdout) (assert-eof stderr)))) (define-scenario (thin-check clear-needs-check-flag) "Accepts --clear-needs-check-flag" - (with-valid-metadata - (thin-check "--clear-needs-check-flag" (current-metadata)))) + (with-valid-metadata (md) + (thin-check "--clear-needs-check-flag" md))) ;;;----------------------------------------------------------- ;;; thin_restore scenarios @@ -174,46 +135,50 @@ Where: (define-scenario (thin-restore no-input-file) "forget to specify an input file" - (receive (_ stderr) (run-fail "thin_restore" "-o" (current-metadata)) - (assert-starts-with "No input file provided." stderr))) + (with-temp-file-sized ((md (meg 4))) + (receive (_ stderr) (run-fail "thin_restore" "-o" md) + (assert-starts-with "No input file provided." stderr)))) (define-scenario (thin-restore missing-input-file) "the input file can't be found" - (receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" (current-metadata)) - (assert-starts-with "Couldn't stat file" stderr))) + (with-temp-file-sized ((md (meg 4))) + (receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" md) + (assert-starts-with "Couldn't stat file" stderr)))) (define-scenario (thin-restore missing-output-file) "the input file can't be found" - (receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" (current-metadata)) - (assert-starts-with "Couldn't stat file" stderr))) + (with-temp-file-sized ((md (meg 4))) + (receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" md) + (assert-starts-with "Couldn't stat file" stderr)))) (define-scenario (thin-restore tiny-output-file) "Fails if the output file is too small." - (with-temp-file (outfile) - (run-ok "dd if=/dev/zero" (fmt #f (dsp "of=") (dsp outfile)) "bs=4k count=1") + (with-temp-file-sized ((md (* 1024 4))) (with-thin-xml (xml) - (receive (_ stderr) (run-fail "thin_restore" "-i" xml "-o" outfile) + (receive (_ stderr) (run-fail "thin_restore" "-i" xml "-o" md) (assert-starts-with thin-restore-outfile-too-small-text stderr))))) (define-scenario (thin-restore q) "thin_restore accepts -q" - (with-thin-xml (xml) - (receive (stdout _) (thin-restore "-i" xml "-o" (current-metadata) "-q") - (assert-eof stdout)))) + (with-temp-file-sized ((md (meg 4))) + (with-thin-xml (xml) + (receive (stdout _) (thin-restore "-i" xml "-o" md "-q") + (assert-eof stdout))))) (define-scenario (thin-restore quiet) "thin_restore accepts --quiet" - (with-thin-xml (xml) - (receive (stdout _) (thin-restore "-i" xml "-o" (current-metadata) "--quiet") - (assert-eof stdout)))) + (with-temp-file-sized ((md (meg 4))) + (with-thin-xml (xml) + (receive (stdout _) (thin-restore "-i" xml "-o" md "--quiet") + (assert-eof stdout))))) (define-scenario (thin-dump restore-is-noop) "thin_dump followed by thin_restore is a noop." - (with-valid-metadata - (receive (d1-stdout _) (thin-dump (current-metadata)) + (with-valid-metadata (md) + (receive (d1-stdout _) (thin-dump md) (with-temp-file-containing ((xml d1-stdout)) - (thin-restore "-i" xml "-o" (current-metadata)) - (receive (d2-stdout _) (thin-dump (current-metadata)) + (thin-restore "-i" xml "-o" md) + (receive (d2-stdout _) (thin-dump md) (assert-equal d1-stdout d2-stdout)))))) ;;;----------------------------------------------------------- @@ -246,18 +211,18 @@ Where: (define-scenario (thin-rmap valid-region-format-should-pass) "thin_rmap with a valid region format should pass." - (with-valid-metadata - (thin-rmap "--region 23..7890" (current-metadata)))) + (with-valid-metadata (md) + (thin-rmap "--region 23..7890" md))) (define-scenario (thin-rmap invalid-region-should-fail) "thin_rmap with an invalid region format should fail." (for-each (lambda (pattern) - (with-valid-metadata - (run-fail "thin_rmap --region" pattern (current-metadata)))) + (with-valid-metadata (md) + (run-fail "thin_rmap --region" pattern md))) '("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 - (thin-rmap "--region 1..23 --region 45..78" (current-metadata))))) + (with-valid-metadata (md) + (thin-rmap "--region 1..23 --region 45..78" md))))