2014-12-23 13:44:39 -05:00
|
|
|
import time
|
|
|
|
import argparse
|
|
|
|
from config import *
|
|
|
|
|
2015-01-06 10:48:19 -05:00
|
|
|
logical_sector_size = 512
|
2014-12-23 13:44:39 -05:00
|
|
|
|
|
|
|
class SATABISTDriver:
|
2015-01-14 03:19:41 -05:00
|
|
|
def __init__(self, regs, name):
|
2014-12-23 13:44:39 -05:00
|
|
|
self.regs = regs
|
2015-01-14 03:19:41 -05:00
|
|
|
self.name = name
|
|
|
|
for s in ["start", "sector", "count", "loops", "random", "done", "errors"]:
|
|
|
|
setattr(self, s, getattr(regs, name + "_"+ s))
|
2014-12-23 13:44:39 -05:00
|
|
|
|
2015-01-14 03:19:41 -05:00
|
|
|
def run(self, sector, count, loops, random):
|
|
|
|
self.sector.write(sector)
|
|
|
|
self.count.write(count)
|
|
|
|
self.loops.write(loops)
|
|
|
|
self.random.write(random)
|
|
|
|
self.start.write(1)
|
|
|
|
while (self.done.read() == 0):
|
2015-01-07 16:15:57 -05:00
|
|
|
pass
|
2015-01-14 03:19:41 -05:00
|
|
|
return self.errors.read()
|
2014-12-23 13:44:39 -05:00
|
|
|
|
2015-01-14 03:19:41 -05:00
|
|
|
class SATABISTGeneratorDriver(SATABISTDriver):
|
|
|
|
def __init__(self, regs, name):
|
|
|
|
SATABISTDriver.__init__(self, regs, name + "_generator")
|
2014-12-23 13:44:39 -05:00
|
|
|
|
2015-01-14 03:19:41 -05:00
|
|
|
class SATABISTCheckerDriver(SATABISTDriver):
|
|
|
|
def __init__(self, regs, name):
|
|
|
|
SATABISTDriver.__init__(self, regs, name + "_checker")
|
|
|
|
|
|
|
|
class Timer:
|
|
|
|
def __init__(self):
|
|
|
|
self.value = None
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self._start = time.time()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self._stop = time.time()
|
|
|
|
self.value = self._stop - self._start
|
|
|
|
|
|
|
|
KB = 1024
|
|
|
|
MB = 1024*KB
|
|
|
|
GB = 1024*MB
|
|
|
|
|
|
|
|
def compute_speed(loops, count, elapsed_time, unit):
|
|
|
|
return loops*count*logical_sector_size/unit/elapsed_time
|
2014-12-23 13:44:39 -05:00
|
|
|
|
|
|
|
def _get_args():
|
|
|
|
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
description="""\
|
|
|
|
SATA BIST utility.
|
|
|
|
""")
|
2015-01-14 03:19:41 -05:00
|
|
|
parser.add_argument("-s", "--sector", default=0, help="start sector")
|
|
|
|
parser.add_argument("-c", "--count", default=16384, help="number of sectors per transaction")
|
|
|
|
parser.add_argument("-l", "--loops", default=4, help="number of loop for each transaction")
|
|
|
|
parser.add_argument("-r", "--random", default=True, help="use random data")
|
2014-12-23 13:44:39 -05:00
|
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = _get_args()
|
|
|
|
wb.open()
|
|
|
|
###
|
2015-01-14 03:19:41 -05:00
|
|
|
generator = SATABISTGeneratorDriver(wb.regs, "sata_bist")
|
|
|
|
checker = SATABISTCheckerDriver(wb.regs, "sata_bist")
|
|
|
|
timer = Timer()
|
|
|
|
|
2015-01-07 16:15:57 -05:00
|
|
|
sector = int(args.sector)
|
|
|
|
count = int(args.count)
|
|
|
|
loops = int(args.loops)
|
2015-01-14 03:19:41 -05:00
|
|
|
random = int(args.random)
|
2014-12-23 13:44:39 -05:00
|
|
|
try:
|
|
|
|
while True:
|
2015-01-14 03:19:41 -05:00
|
|
|
# generator (write data to HDD)
|
|
|
|
timer.start()
|
|
|
|
generator.run(sector, count, loops, random)
|
|
|
|
timer.stop()
|
|
|
|
write_speed = compute_speed(loops, count, timer.value, MB)
|
2015-01-07 16:15:57 -05:00
|
|
|
|
2015-01-14 03:19:41 -05:00
|
|
|
# checker (read and check data from HDD)
|
|
|
|
timer.start()
|
|
|
|
errors = checker.run(sector, count, loops, random)
|
|
|
|
timer.stop()
|
|
|
|
read_speed = compute_speed(loops, count, timer.value, MB)
|
2015-01-07 16:15:57 -05:00
|
|
|
sector += count
|
|
|
|
|
2015-01-14 03:19:41 -05:00
|
|
|
print("sector=%d write_speed=%4.2fMB/sec read_speed=%4.2fMB/sec errors=%d" %(sector, write_speed, read_speed, errors))
|
2015-01-07 16:15:57 -05:00
|
|
|
|
2014-12-23 13:44:39 -05:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
###
|
|
|
|
wb.close()
|