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
|
2015-01-16 12:14:13 -05:00
|
|
|
self.frequency = regs.identifier_frequency.read()
|
|
|
|
self.time = 0
|
|
|
|
for s in ["start", "sector", "count", "random", "done", "errors", "cycles"]:
|
2015-01-14 03:19:41 -05:00
|
|
|
setattr(self, s, getattr(regs, name + "_"+ s))
|
2014-12-23 13:44:39 -05:00
|
|
|
|
2015-01-16 12:14:13 -05:00
|
|
|
def run(self, sector, count, random):
|
2015-01-14 03:19:41 -05:00
|
|
|
self.sector.write(sector)
|
|
|
|
self.count.write(count)
|
|
|
|
self.random.write(random)
|
|
|
|
self.start.write(1)
|
|
|
|
while (self.done.read() == 0):
|
2015-01-07 16:15:57 -05:00
|
|
|
pass
|
2015-01-16 12:14:13 -05:00
|
|
|
self.time = self.cycles.read()/self.frequency
|
|
|
|
speed = (count*logical_sector_size)/self.time
|
|
|
|
errors = self.errors.read()
|
|
|
|
return (speed, errors)
|
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")
|
|
|
|
|
|
|
|
KB = 1024
|
|
|
|
MB = 1024*KB
|
|
|
|
GB = 1024*MB
|
|
|
|
|
2015-01-16 12:14:13 -05:00
|
|
|
# Note: use IDENTIFY command to find numbers of sectors
|
|
|
|
hdd_max_sector = (32*MB)/logical_sector_size
|
2014-12-23 13:44:39 -05:00
|
|
|
|
|
|
|
def _get_args():
|
|
|
|
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
description="""\
|
|
|
|
SATA BIST utility.
|
|
|
|
""")
|
2015-01-16 12:14:13 -05:00
|
|
|
parser.add_argument("-s", "--transfer_size", default=4, help="transfer sizes (in MB, up to 16MB)")
|
|
|
|
parser.add_argument("-l", "--total_length", default=256, help="total transfer length (in MB, up to HDD capacity)")
|
|
|
|
parser.add_argument("-r", "--random", action="store_true", help="use random data")
|
|
|
|
parser.add_argument("-c", "--continuous", action="store_true", help="continuous mode (Escape to exit)")
|
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")
|
|
|
|
|
2015-01-16 12:14:13 -05:00
|
|
|
sector = 0
|
|
|
|
count = int(args.transfer_size)*MB//logical_sector_size
|
|
|
|
length = int(args.total_length)*MB
|
2015-01-14 03:19:41 -05:00
|
|
|
random = int(args.random)
|
2015-01-16 12:14:13 -05:00
|
|
|
continuous = int(args.continuous)
|
2014-12-23 13:44:39 -05:00
|
|
|
try:
|
2015-01-16 12:14:13 -05:00
|
|
|
while (sector*logical_sector_size < length) or continuous:
|
2015-01-14 03:19:41 -05:00
|
|
|
# generator (write data to HDD)
|
2015-01-16 12:14:13 -05:00
|
|
|
write_speed, write_errors = generator.run(sector, count, random)
|
2015-01-07 16:15:57 -05:00
|
|
|
|
2015-01-14 03:19:41 -05:00
|
|
|
# checker (read and check data from HDD)
|
2015-01-16 12:14:13 -05:00
|
|
|
read_speed, read_errors = checker.run(sector, count, random)
|
2015-01-07 16:15:57 -05:00
|
|
|
|
2015-01-16 12:14:13 -05:00
|
|
|
print("sector=%d write_speed=%4.2fMB/sec read_speed=%4.2fMB/sec errors=%d" %(sector, write_speed/MB, read_speed/MB, write_errors + read_errors))
|
|
|
|
sector += count
|
2015-01-07 16:15:57 -05:00
|
|
|
|
2014-12-23 13:44:39 -05:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
###
|
|
|
|
wb.close()
|