Skip to content

Commit ecd4141

Browse files
authored
Merge pull request #3 from bjohnsto/fix_corrupt_vdo
dmtest: Write random data instead of zeroes to geometry block
2 parents 244faab + faa8bc6 commit ecd4141

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/dmtest/assertions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
def assert_raises(callback):
24
failed = False
35
try:
@@ -28,3 +30,9 @@ def assert_string_in(actual, expected, message=None):
2830
error_message = f"{message}: " if message else ""
2931
error_message += f"expected '{expected}', but got {actual}"
3032
raise AssertionError(error_message)
33+
34+
def assert_matches(actual, pattern, message=None):
35+
if not re.search(pattern, actual):
36+
error_message = f"{message}: " if message else ""
37+
error_message += f"expected match for '{pattern}', but got {actual}"
38+
raise AssertionError(error_message)

src/dmtest/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ def wipe_device(dev, sectors=None):
149149
_dd_device("/dev/zero", _to_path(dev), "oflag=direct", sectors, sync=True)
150150

151151

152+
def trash_device(dev, sectors=None):
153+
_dd_device("/dev/urandom", _to_path(dev), "oflag=direct", sectors, sync=True)
154+
155+
152156
def dev_size(dev):
153157
(_, stdout, _) = process.run(f"blockdev --getsz {_to_path(dev)}")
154158
return int(stdout)

src/dmtest/vdo/load_failure_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from dmtest.assertions import assert_string_in
1+
from dmtest.assertions import assert_matches, assert_string_in
22
from dmtest.vdo.utils import standard_vdo, standard_stack
3-
from dmtest.utils import get_dmesg_log, wipe_device
3+
from dmtest.utils import get_dmesg_log, trash_device
44
import logging as log
55
import time
66

@@ -52,8 +52,8 @@ def t_corrupt_geometry(fix):
5252
with standard_vdo(fix) as vdo:
5353
pass
5454
start_time = time.time()
55-
# Trash just one (4kB) block
56-
wipe_device(fix.cfg["data_dev"], 8)
55+
# Overwrite just one (4kB) block with random data
56+
trash_device(fix.cfg["data_dev"], 8)
5757
stack = standard_stack(fix, format = False)
5858
started = False
5959
try:
@@ -62,7 +62,7 @@ def t_corrupt_geometry(fix):
6262
except:
6363
message = get_dmesg_log(start_time)
6464
log.info(message)
65-
assert_string_in(message, "Could not load geometry block")
65+
assert_matches(message, r"Could not (load|parse) geometry block")
6666
if started:
6767
raise AssertionError("VDO device shouldn't have started")
6868

0 commit comments

Comments
 (0)