Skip to content

Instantly share code, notes, and snippets.

@gmmephisto
Created April 9, 2018 07:11
Show Gist options
  • Save gmmephisto/aa23ef4b5a39c4559a326a95583c16b8 to your computer and use it in GitHub Desktop.
Save gmmephisto/aa23ef4b5a39c4559a326a95583c16b8 to your computer and use it in GitHub Desktop.
scaleio zero tests
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
from pcore import constants
from psys import Error, b
from psh import sh
import psh
parser = argparse.ArgumentParser(description="scaleio zero tests")
parser.add_argument("path", help="path to scini device")
args = parser.parse_args()
if not os.path.exists(args.path):
raise Errro("Path '{0}' not found.", args.path)
def _print_command(process):
"""Prints currently executing command on stdout."""
print(b("> " + unicode(process)))
options = {
"_defer": False,
"_wait_for_output": True,
"_on_execute": _print_command,
"_stdout": psh.STDOUT,
}
assert not sh.qemu_io("-f", "raw", "-n", "-c", "read -q -P 0x0 0 1G", args.path, **options).status()
length = 512
pattern = "0xc"
sector_size = constants.MEGABYTE
for i in range(1, 11):
offset = i * sector_size
print("\ntry to allocate sector at %s offset" % (offset,))
assert not sh.qemu_io("-f", "raw", "-n", "-c", "write -q -P {} {} {}".format(pattern, offset, length),
args.path, **options).status()
assert not sh.qemu_io("-f", "raw", "-n", "-c", "read -q -P {} {} {}".format(pattern, offset, length),
args.path, **options).status()
assert not sh.qemu_io("-f", "raw", "-n", "-c", "read -q -P 0x0 {} {}".format(offset + length, sector_size - length),
args.path, **options).status()
offset = 90 * sector_size
length = sector_size
print("\ntry to reallocate sector after pattern write at %s offset" % (offset,))
assert not sh.qemu_io("-f", "raw", "-n", "-c", "write -q -P {} {} {}".format(pattern, offset, length),
args.path, **options).status()
assert not sh.qemu_io("-f", "raw", "-n", "-c", "read -q -P {} {} {}".format(pattern, offset, length),
args.path, **options).status()
assert not sh.blkdiscard("-o", offset, "-l", length, args.path, **options).status()
assert not sh.qemu_io("-f", "raw", "-n", "-c", "read -q -P 0x0 {} {}".format(offset, length),
args.path, **options).status()
length = 4 * constants.KILOBYTE
assert not sh.qemu_io("-f", "raw", "-n", "-c", "write -q -P {} {} {}".format(pattern, offset, length),
args.path, **options).status()
assert not sh.qemu_io("-f", "raw", "-n", "-c", "read -q -P {} {} {}".format(pattern, offset, length),
args.path, **options).status()
assert not sh.qemu_io("-f", "raw", "-n", "-c", "read -q -P 0x0 {} {}".format(offset + length, sector_size - length),
args.path, **options).status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment