[functional-tests] Port 3 --auto-repair tests from Scheme to Rust
This commit is contained in:
parent
5a16f21199
commit
c254ebe384
@ -1,97 +0,0 @@
|
|||||||
(library
|
|
||||||
(thin-functional-tests)
|
|
||||||
|
|
||||||
(export register-thin-tests)
|
|
||||||
|
|
||||||
(import
|
|
||||||
(chezscheme)
|
|
||||||
(bcache block-manager)
|
|
||||||
(disk-units)
|
|
||||||
(fmt fmt)
|
|
||||||
(functional-tests)
|
|
||||||
(process)
|
|
||||||
(scenario-string-constants)
|
|
||||||
(temp-file)
|
|
||||||
(thin xml)
|
|
||||||
(srfi s8 receive))
|
|
||||||
|
|
||||||
(define-tool thin-check)
|
|
||||||
(define-tool thin-delta)
|
|
||||||
(define-tool thin-dump)
|
|
||||||
(define-tool thin-restore)
|
|
||||||
(define-tool thin-rmap)
|
|
||||||
(define-tool thin-repair)
|
|
||||||
(define-tool thin-metadata-pack)
|
|
||||||
(define-tool thin-metadata-unpack)
|
|
||||||
|
|
||||||
(define-syntax with-thin-xml
|
|
||||||
(syntax-rules ()
|
|
||||||
((_ (v) b1 b2 ...)
|
|
||||||
(with-temp-file-containing ((v "thin.xml" (fmt #f (generate-xml 10 1000))))
|
|
||||||
b1 b2 ...))))
|
|
||||||
|
|
||||||
(define-syntax with-valid-metadata
|
|
||||||
(syntax-rules ()
|
|
||||||
((_ (md) b1 b2 ...)
|
|
||||||
(with-temp-file-sized ((md "thin.bin" (meg 4)))
|
|
||||||
(with-thin-xml (xml)
|
|
||||||
(run-ok (thin-restore "-i" xml "-o" md))
|
|
||||||
b1 b2 ...)))))
|
|
||||||
|
|
||||||
;;; It would be nice if the metadata was at least similar to valid data.
|
|
||||||
;;; Here I'm just using the start of the ls binary as 'random' data.
|
|
||||||
(define-syntax with-corrupt-metadata
|
|
||||||
(syntax-rules ()
|
|
||||||
((_ (md) b1 b2 ...)
|
|
||||||
(with-temp-file-sized ((md "thin.bin" (meg 4)))
|
|
||||||
(system (fmt #f "dd if=/usr/bin/ls of=" md " bs=4096 > /dev/null 2>&1"))
|
|
||||||
b1 b2 ...))))
|
|
||||||
|
|
||||||
(define-syntax with-empty-metadata
|
|
||||||
(syntax-rules ()
|
|
||||||
((_ (md) b1 b2 ...)
|
|
||||||
(with-temp-file-sized ((md "thin.bin" (meg 4)))
|
|
||||||
b1 b2 ...))))
|
|
||||||
|
|
||||||
(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 ...))))
|
|
||||||
|
|
||||||
;; We have to export something that forces all the initialisation expressions
|
|
||||||
;; to run.
|
|
||||||
(define (register-thin-tests) #t)
|
|
||||||
|
|
||||||
;;;-----------------------------------------------------------
|
|
||||||
;;; thin_check scenarios
|
|
||||||
;;;-----------------------------------------------------------
|
|
||||||
|
|
||||||
(define-scenario (thin-check incompatible-options auto-repair)
|
|
||||||
"Incompatible options should cause failure"
|
|
||||||
(with-valid-metadata (md)
|
|
||||||
(run-fail (thin-check "--auto-repair" "-m" md))
|
|
||||||
(run-fail (thin-check "--auto-repair" "--override-mapping-root 123" md))
|
|
||||||
(run-fail (thin-check "--auto-repair" "--super-block-only" md))
|
|
||||||
(run-fail (thin-check "--auto-repair" "--skip-mappings" md))
|
|
||||||
(run-fail (thin-check "--auto-repair" "--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))))
|
|
||||||
|
|
||||||
(define-scenario (thin-check auto-repair)
|
|
||||||
"Accepts --auto-repair"
|
|
||||||
(with-valid-metadata (md)
|
|
||||||
(run-ok (thin-check "--auto-repair" md))))
|
|
||||||
|
|
||||||
)
|
|
@ -79,6 +79,11 @@ fn accepts_quiet() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn accepts_auto_repair() -> Result<()> {
|
||||||
|
accepts_flag("--auto-repair")
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn detects_corrupt_superblock_with_superblock_only() -> Result<()> {
|
fn detects_corrupt_superblock_with_superblock_only() -> Result<()> {
|
||||||
let mut td = TestDir::new()?;
|
let mut td = TestDir::new()?;
|
||||||
@ -124,4 +129,28 @@ fn prints_info_fields() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn auto_repair_incompatible_opts() -> Result<()> {
|
||||||
|
let mut td = TestDir::new()?;
|
||||||
|
let md = mk_valid_md(&mut td)?;
|
||||||
|
run_fail(thin_check!("--auto-repair", "-m", &md))?;
|
||||||
|
run_fail(thin_check!("--auto-repair", "--override-mapping-root", "123", &md))?;
|
||||||
|
run_fail(thin_check!("--auto-repair", "--super-block-only", &md))?;
|
||||||
|
run_fail(thin_check!("--auto-repair", "--skip-mappings", &md))?;
|
||||||
|
run_fail(thin_check!("--auto-repair", "--ignore-non-fatal-errors", &md))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn clear_needs_check_incompatible_opts() -> Result<()> {
|
||||||
|
let mut td = TestDir::new()?;
|
||||||
|
let md = mk_valid_md(&mut td)?;
|
||||||
|
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))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user