mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-24 04:34:15 +08:00
6f05548661
Add a convenience script for adding new injection cookies and filter for actual testing. - ./inject-error new - return new unique cookie - ./inject-error file tune/change-csum.c - show all cookies in the given file (takes regexp) Example usage: for i in $(./inject-error file tune/change-csum.c | awk '{print $1}') ; do echo "Inject $i" export INJECT="$i" rm img cp --reflink img.filled img ./btrfstune --csum blake2 img btrfs check img done Where 'img' is a filesystem with sample files and directories. Signed-off-by: David Sterba <dsterba@suse.com>
61 lines
1.5 KiB
Python
Executable File
61 lines
1.5 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import random
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
found = {}
|
|
|
|
def do_new_cookie() -> str:
|
|
global found
|
|
cookie = hex(random.randrange(1, 2**32))
|
|
while cookie in found:
|
|
cookie = hex(random.randrange(1, 2**32))
|
|
return cookie
|
|
|
|
pipe = subprocess.Popen("git grep -n 'inject_error(0x'", shell=True,
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True);
|
|
|
|
ch_stdout = pipe.stdout
|
|
ch_lines = [str(x.decode()).strip('\n') for x in ch_stdout.readlines()]
|
|
|
|
#print("STDOUT", "\n".join(ch_lines))
|
|
|
|
for l in ch_lines:
|
|
m = re.search(r'^([^:]+):(\d+):.*inject_error\((0x[0-9a-fA-F]+)\)', l)
|
|
if m:
|
|
fn = m.group(1)
|
|
line = m.group(2)
|
|
c = m.group(3)
|
|
#print(f"MATCH: {c}")
|
|
if not c in found:
|
|
found[c] = fn + ":" + line
|
|
else:
|
|
print(f"ERROR: cookie {c} in {fn}:{line} not uniqe, please fix it first")
|
|
|
|
if len(sys.argv) == 1:
|
|
cookie = do_new_cookie()
|
|
print(cookie)
|
|
|
|
if len(sys.argv) == 2:
|
|
cmd = sys.argv[1]
|
|
if cmd == 'new':
|
|
cookie = do_new_cookie()
|
|
print(cookie)
|
|
elif cmd == 'known':
|
|
for k, v in found.items():
|
|
print(f"{k}\t{v}")
|
|
else:
|
|
print(f"ERROR: unknown command {cmd} or wrong number of arguments")
|
|
|
|
if len(sys.argv) == 3:
|
|
cmd = sys.argv[1]
|
|
if cmd == 'file':
|
|
regex = sys.argv[2]
|
|
for k, v in found.items():
|
|
if re.search(r'' + regex, v):
|
|
print(f"{k}\t{v}")
|
|
else:
|
|
print(f"ERROR: unknown command {cmd} or wrong number of arguments")
|