[functional-tests] Add some cache tests

This commit is contained in:
Joe Thornber 2017-08-25 15:03:50 +01:00
parent 2eea8c4e84
commit be34337b06
6 changed files with 166 additions and 267 deletions

View File

@ -1,100 +0,0 @@
Feature: cache_check
Scenario: print version (-V flag)
When I run `cache_check -V`
Then it should pass with version
Scenario: print version (--version flag)
When I run `cache_check --version`
Then it should pass with version
Scenario: print help
When I run `cache_check --help`
Then it should pass
And cache_usage to stdout
Scenario: print help
When I run `cache_check -h`
Then it should pass
And cache_usage to stdout
Scenario: Metadata file must be specified
When I run `cache_check`
Then it should fail
And cache_usage to stderr
And the stderr should contain:
"""
No input file provided.
"""
Scenario: Metadata file doesn't exist
When I run `cache_check /arbitrary/filename`
Then it should fail
And the stderr should contain:
"""
/arbitrary/filename: No such file or directory
"""
Scenario: Metadata file cannot be a directory
Given a directory called foo
When I run `cache_check foo`
Then it should fail
And the stderr should contain:
"""
foo: Not a block device or regular file
"""
# This test will fail if you're running as root
Scenario: Metadata file exists, but can't be opened
Given input without read permissions
When I run `cache_check input`
Then it should fail
And the stderr should contain:
"""
Permission denied
"""
Scenario: Metadata file full of zeroes
Given input file
And block 1 is zeroed
When I run `cache_check input`
Then it should fail
Scenario: --quiet is observed
Given input file
And block 1 is zeroed
When I run `cache_check --quiet input`
Then it should fail
And it should give no output
Scenario: -q is observed
Given input file
And block 1 is zeroed
When I run `cache_check -q input`
Then it should fail
And it should give no output
Scenario: A valid metadata area passes
Given valid cache metadata
When I run `cache_check metadata.bin`
Then it should pass
Scenario: Invalid metadata version causes a fail
Given a small xml file
And input file
And I run cache_restore with -i metadata.xml -o input --debug-override-metadata-version 12345
When I run `cache_check input`
Then it should fail
Scenario: Accepts --clear-needs-check-flag
Given valid cache metadata
When I run `cache_check --clear-needs-check-flag metadata.bin`
Then it should pass

View File

@ -1,50 +0,0 @@
Feature: cache_dump
Scenario: print version (-V flag)
When I run cache_dump with -V
Then it should pass with version
Scenario: print version (--version flag)
When I run cache_dump with --version
Then it should pass with version
@announce
Scenario: print help (-h)
When I run cache_dump with -h
Then it should pass with:
"""
Usage: cache_dump [options] {device|file}
Options:
{-h|--help}
{-o <xml file>}
{-V|--version}
"""
Scenario: print help (--help)
When I run cache_dump with -h
Then it should pass with:
"""
Usage: cache_dump [options] {device|file}
Options:
{-h|--help}
{-o <xml file>}
{-V|--version}
"""
Scenario: accepts an output file
Given valid cache metadata
When I run cache_dump with -o metadata.xml metadata.bin
Then it should pass
Scenario: missing input file
When I run cache_dump
Then it should fail with:
"""
No input file provided.
"""
Scenario: dump/restore is a noop
Given valid cache metadata
When I cache dump
And I cache restore
And I cache dump
Then cache dumps 1 and 2 should be identical

View File

@ -1,107 +0,0 @@
Feature: cache_restore
Scenario: print version (-V flag)
When I run cache_restore with -V
Then it should pass with version
Scenario: print version (--version flag)
When I run cache_restore with --version
Then it should pass with version
Scenario: print help (-h)
When I run cache_restore with -h
Then it should pass
And the output should contain exactly:
"""
Usage: cache_restore [options]
Options:
{-h|--help}
{-i|--input} <input xml file>
{-o|--output} <output device or file>
{-q|--quiet}
{-V|--version}
{--debug-override-metadata-version} <integer>
{--omit-clean-shutdown}
"""
Scenario: print help (--help)
When I run cache_restore with -h
Then it should pass
And the output should contain exactly:
"""
Usage: cache_restore [options]
Options:
{-h|--help}
{-i|--input} <input xml file>
{-o|--output} <output device or file>
{-q|--quiet}
{-V|--version}
{--debug-override-metadata-version} <integer>
{--omit-clean-shutdown}
"""
Scenario: missing input file
Given the dev file metadata.bin
When I run cache_restore with -o metadata.bin
Then it should fail with:
"""
No input file provided.
"""
Scenario: input file not found
Given the dev file metadata.bin
When I run cache_restore with -i foo.xml -o metadata.bin
Then it should fail
Scenario: missing output file
When I run cache_restore with -i metadata.xml
Then it should fail with:
"""
No output file provided.
"""
Scenario: successfully restores a valid xml file
Given a small xml file
And an empty dev file
When I run cache_restore with -i metadata.xml -o metadata.bin
Then it should pass
Scenario: accepts --debug-override-metadata-version
Given a small xml file
And an empty dev file
When I run cache_restore with -i metadata.xml -o metadata.bin --debug-override-metadata-version 10298
Then it should pass
Scenario: accepts --omit-clean-shutdown
Given a small xml file
And an empty dev file
When I run cache_restore with -i metadata.xml -o metadata.bin --omit-clean-shutdown
Then it should pass
Scenario: --quiet is accepted
Given valid cache metadata
When I run cache_restore with -i metadata.xml -o metadata.bin --quiet
Then it should pass
And the output should contain exactly:
"""
"""
Scenario: -q is accepted
Given valid cache metadata
When I run cache_restore with -i metadata.xml -o metadata.bin -q
Then it should pass
And the output should contain exactly:
"""
"""
Scenario: dump/restore is a noop
Given valid cache metadata
When I cache dump
And I cache restore
And I cache dump
Then dumps 1 and 2 should be identical

View File

@ -37,6 +37,12 @@
(with-temp-file-sized ((md (meg 4))) (with-temp-file-sized ((md (meg 4)))
b1 b2 ...)))) b1 b2 ...))))
(define-syntax with-empty-metadata
(syntax-rules ()
((_ (md) b1 b2 ...)
(with-temp-file-sized ((md (meg 4)))
b1 b2 ...))))
;; We have to export something that forces all the initialisation expressions ;; We have to export something that forces all the initialisation expressions
;; to run. ;; to run.
(define (register-cache-tests) #t) (define (register-cache-tests) #t)
@ -89,14 +95,12 @@
(string-append bad-path ": Not a block device or regular file") (string-append bad-path ": Not a block device or regular file")
stderr)))) stderr))))
#|
(define-scenario (cache-check unreadable-metadata) (define-scenario (cache-check unreadable-metadata)
"Metadata file exists, but is unreadable." "Metadata file exists, but is unreadable."
(with-valid-metadata (with-valid-metadata (md)
(run-ok "chmod" "-r" (current-metadata)) (run-ok "chmod" "-r" md)
(receive (_ stderr) (run-fail "cache_check" (current-metadata)) (receive (_ stderr) (run-fail "cache_check" md)
(assert-starts-with "syscall 'open' failed: Permission denied" stderr)))) (assert-starts-with "syscall 'open' failed: Permission denied" stderr))))
|#
(define-scenario (cache-check fails-with-corrupt-metadata) (define-scenario (cache-check fails-with-corrupt-metadata)
"Fail with corrupt superblock" "Fail with corrupt superblock"
@ -129,7 +133,129 @@
(define-scenario (cache-check bad-metadata-version) (define-scenario (cache-check bad-metadata-version)
"Invalid metadata version fails" "Invalid metadata version fails"
(with-cache-xml (xml) (with-cache-xml (xml)
(with-temp-file-sized ((md (meg 4))) (with-empty-metadata (md)
(cache-restore "-i" xml "-o" md "--debug-override-metadata-version" "12345") (cache-restore "-i" xml "-o" md "--debug-override-metadata-version" "12345")
(run-fail "cache_check" md)))) (run-fail "cache_check" md))))
;;;-----------------------------------------------------------
;;; cache_restore scenarios
;;;-----------------------------------------------------------
(define-scenario (cache-restore v)
"print version (-V flag)"
(receive (stdout _) (cache-restore "-V")
(assert-equal tools-version stdout)))
(define-scenario (cache-restore version)
"print version (--version flags)"
(receive (stdout _) (cache-restore "--version")
(assert-equal tools-version stdout)))
(define-scenario (cache-restore h)
"cache_restore -h"
(receive (stdout _) (cache-restore "-h")
(assert-equal cache-restore-help stdout)))
(define-scenario (cache-restore help)
"cache_restore --help"
(receive (stdout _) (cache-restore "--help")
(assert-equal cache-restore-help stdout)))
(define-scenario (cache-restore no-input-file)
"forget to specify an input file"
(with-empty-metadata (md)
(receive (_ stderr) (run-fail "cache_restore" "-o" md)
(assert-starts-with "No input file provided." stderr))))
(define-scenario (cache-restore missing-input-file)
"the input file can't be found"
(with-empty-metadata (md)
(receive (_ stderr) (run-fail "cache_restore -i no-such-file -o" md)
(assert-starts-with "Couldn't stat file" stderr))))
(define-scenario (cache-restore missing-output-file)
"the output file can't be found"
(with-cache-xml (xml)
(receive (_ stderr) (run-fail "cache_restore -i " xml)
(assert-starts-with "No output file provided." stderr))))
(define-scenario (cache-restore tiny-output-file)
"Fails if the output file is too small."
(with-temp-file-sized ((md (* 1024 4)))
(with-cache-xml (xml)
(receive (_ stderr) (run-fail "cache_restore" "-i" xml "-o" md)
(assert-starts-with cache-restore-outfile-too-small-text stderr)))))
(define-scenario (cache-restore successfully-restores)
"Restore succeeds."
(with-empty-metadata (md)
(with-cache-xml (xml)
(cache-restore "-i" xml "-o" md))))
(define-scenario (cache-restore q)
"cache_restore accepts -q"
(with-empty-metadata (md)
(with-cache-xml (xml)
(receive (stdout stderr) (cache-restore "-i" xml "-o" md "-q")
(assert-eof stdout)
(assert-eof stderr)))))
(define-scenario (cache-restore quiet)
"cache_restore accepts --quiet"
(with-empty-metadata (md)
(with-cache-xml (xml)
(receive (stdout stderr) (cache-restore "-i" xml "-o" md "--quiet")
(assert-eof stdout)
(assert-eof stderr)))))
;; Failing due to a genuine bug in cache_restore
(define-scenario (cache-restore override-metadata-version)
"we can set any metadata version"
(with-empty-metadata (md)
(with-cache-xml (xml)
(cache-restore "-i" xml "-o" md "--debug-override-metadata-version 10298"))))
(define-scenario (cache-restore omit-clean-shutdown)
"accepts --omit-clean-shutdown"
(with-empty-metadata (md)
(with-cache-xml (xml)
(cache-restore "-i" xml "-o" md "--omit-clean-shutdown"))))
;;;-----------------------------------------------------------
;;; cache_dump scenarios
;;;-----------------------------------------------------------
(define-scenario (cache-dump v)
"print version (-V flag)"
(receive (stdout _) (cache-dump "-V")
(assert-equal tools-version stdout)))
(define-scenario (cache-dump version)
"print version (--version flags)"
(receive (stdout _) (cache-dump "--version")
(assert-equal tools-version stdout)))
(define-scenario (cache-dump h)
"cache_dump -h"
(receive (stdout _) (cache-dump "-h")
(assert-equal cache-dump-help stdout)))
(define-scenario (cache-dump help)
"cache_dump --help"
(receive (stdout _) (cache-dump "--help")
(assert-equal cache-dump-help stdout)))
(define-scenario (cache-dump missing-input-file)
"Fails with missing input file."
(receive (stdout stderr) (run-fail "cache_dump")
(assert-starts-with "No input file provided." stderr)))
(define-scenario (cache-dump restore-is-noop)
"cache_dump followed by cache_restore is a noop."
(with-valid-metadata (md)
(receive (d1-stdout _) (cache-dump md)
(with-temp-file-containing ((xml d1-stdout))
(cache-restore "-i" xml "-o" md)
(receive (d2-stdout _) (cache-dump md)
(assert-equal d1-stdout d2-stdout))))))
) )

View File

@ -7,6 +7,9 @@
thin-rmap-help thin-rmap-help
cache-check-help cache-check-help
cache-restore-help
cache-restore-outfile-too-small-text
cache-dump-help
) )
(import (rnrs)) (import (rnrs))
@ -62,4 +65,31 @@ Options:
{--skip-hints} {--skip-hints}
{--skip-discards}") {--skip-discards}")
(define cache-restore-help
"Usage: cache_restore [options]
Options:
{-h|--help}
{-i|--input} <input xml file>
{-o|--output} <output device or file>
{-q|--quiet}
{--metadata-version} <1 or 2>
{-V|--version}
{--debug-override-metadata-version} <integer>
{--omit-clean-shutdown}")
(define cache-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 cache-dump-help
"Usage: cache_dump [options] {device|file}
Options:
{-h|--help}
{-o <xml file>}
{-V|--version}
{--repair}")
) )

View File

@ -143,10 +143,10 @@
(assert-starts-with "Couldn't stat file" stderr)))) (assert-starts-with "Couldn't stat file" stderr))))
(define-scenario (thin-restore missing-output-file) (define-scenario (thin-restore missing-output-file)
"the input file can't be found" "the output file can't be found"
(with-temp-file-sized ((md (meg 4))) (with-thin-xml (xml)
(receive (_ stderr) (run-fail "thin_restore -i no-such-file -o" md) (receive (_ stderr) (run-fail "thin_restore -i " xml)
(assert-starts-with "Couldn't stat file" stderr)))) (assert-starts-with "No output file provided." stderr))))
(define-scenario (thin-restore tiny-output-file) (define-scenario (thin-restore tiny-output-file)
"Fails if the output file is too small." "Fails if the output file is too small."