(library
(thin-functional-tests)
(export register-thin-tests)
(import
(chezscheme)
(fmt fmt)
(functional-tests)
(thin-xml)
(srfi s8 receive)
(only (srfi s1 lists) drop-while))
;; FIXME: don't hard code this
(define tools-version "0.7.0-rc6")
(define (tool-name sym)
(define (to-underscore c)
(if (eq? #\- c) #\_ c))
(list->string (map to-underscore (string->list (symbol->string sym)))))
(define-syntax define-tool
(syntax-rules ()
((_ tool-sym) (define (tool-sym . flags)
(apply run-ok (tool-name 'tool-sym) flags)))))
(define-tool thin-check)
(define-tool thin-delta)
(define-tool thin-dump)
(define-tool thin-restore)
(define-tool thin-rmap)
(define (assert-equal str1 str2)
(unless (equal? str1 str2)
(fail (fmt #f (dsp "values differ: ")
(wrt str1)
(dsp ", ")
(wrt str2)))))
(define (assert-eof obj)
(unless (eof-object? obj)
(fail (fmt #f (dsp "object is not an #!eof: ") (dsp obj)))))
(define (starts-with prefix str)
(and (>= (string-length str) (string-length prefix))
(equal? (substring str 0 (string-length prefix))
prefix)))
(define (assert-starts-with prefix str)
(unless (starts-with prefix str)
(fail (fmt #f (dsp "string should begin with: ")
(wrt prefix)
(dsp ", ")
(wrt str)))))
(define (current-metadata) "metadata.bin")
(define (%with-valid-metadata thunk)
(run-ok "thin_restore" "-i" (temp-thin-xml) "-o" (current-metadata))
(thunk))
(define-syntax with-valid-metadata
(syntax-rules ()
((_ body ...) (%with-valid-metadata (lambda () body ...)))))
;;; 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 ...)))))
;; We have to export something that forces all the initialisation expressions
;; to run.
(define (register-thin-tests) #t)
;;;-----------------------------------------------------------
;;; thin_check scenarios
;;;-----------------------------------------------------------
(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}