Updated the disassembler stress tester with two
new features: (1) it outputs the instruction currently being tested to a log file, if a path is provided (2) if instructed, it prints the time remaining in the exhaustive test llvm-svn: 154205
This commit is contained in:
parent
543036a447
commit
ceabd2d712
@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import argparse, re, subprocess, sys
|
import argparse, datetime, re, subprocess, sys, time
|
||||||
|
|
||||||
#-- This code fragment loads LLDB --
|
|
||||||
|
|
||||||
def AddLLDBToSysPathOnMacOSX():
|
def AddLLDBToSysPathOnMacOSX():
|
||||||
def GetLLDBFrameworkPath():
|
def GetLLDBFrameworkPath():
|
||||||
@ -25,8 +23,6 @@ AddLLDBToSysPathOnMacOSX()
|
|||||||
|
|
||||||
import lldb
|
import lldb
|
||||||
|
|
||||||
#-- End of code fragment that loads LLDB --
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Run an exhaustive test of the LLDB disassembler for a specific architecture.")
|
parser = argparse.ArgumentParser(description="Run an exhaustive test of the LLDB disassembler for a specific architecture.")
|
||||||
|
|
||||||
parser.add_argument('--arch', required=True, action='store', help='The architecture whose disassembler is to be tested')
|
parser.add_argument('--arch', required=True, action='store', help='The architecture whose disassembler is to be tested')
|
||||||
@ -34,6 +30,8 @@ parser.add_argument('--bytes', required=True, action='store', type=int, help='Th
|
|||||||
parser.add_argument('--random', required=False, action='store_true', help='Enables non-sequential testing')
|
parser.add_argument('--random', required=False, action='store_true', help='Enables non-sequential testing')
|
||||||
parser.add_argument('--start', required=False, action='store', type=int, help='The first instruction value to test')
|
parser.add_argument('--start', required=False, action='store', type=int, help='The first instruction value to test')
|
||||||
parser.add_argument('--skip', required=False, action='store', type=int, help='The interval between instructions to test')
|
parser.add_argument('--skip', required=False, action='store', type=int, help='The interval between instructions to test')
|
||||||
|
parser.add_argument('--log', required=False, action='store', help='A log file to write the most recent instruction being tested')
|
||||||
|
parser.add_argument('--time', required=False, action='store_true', help='Every 100,000 instructions, print an ETA to standard out')
|
||||||
|
|
||||||
arguments = sys.argv[1:]
|
arguments = sys.argv[1:]
|
||||||
|
|
||||||
@ -51,24 +49,39 @@ if target.IsValid() == False:
|
|||||||
print "Couldn't create an SBTarget for architecture " + arg_ns.arch
|
print "Couldn't create an SBTarget for architecture " + arg_ns.arch
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
def ResetLogFile(log_file):
|
||||||
|
if log_file != sys.stdout:
|
||||||
|
log_file.seek(0)
|
||||||
|
log_file.truncate(0)
|
||||||
|
|
||||||
|
def PrintByteArray(log_file, byte_array):
|
||||||
|
for byte in byte_array:
|
||||||
|
print >>log_file, hex(byte) + " ",
|
||||||
|
print >>log_file
|
||||||
|
|
||||||
class SequentialInstructionProvider:
|
class SequentialInstructionProvider:
|
||||||
def __init__(self, byte_width, start=0, skip=1):
|
def __init__(self, byte_width, log_file, start=0, skip=1):
|
||||||
self.m_byte_width = byte_width
|
self.m_byte_width = byte_width
|
||||||
|
self.m_log_file = log_file
|
||||||
self.m_start = start
|
self.m_start = start
|
||||||
self.m_skip = skip
|
self.m_skip = skip
|
||||||
self.m_value = start
|
self.m_value = start
|
||||||
self.m_last = (1 << (byte_width * 8)) - 1
|
self.m_last = (1 << (byte_width * 8)) - 1
|
||||||
|
def PrintCurrentState(self, ret):
|
||||||
|
ResetLogFile(self.m_log_file)
|
||||||
|
print >>self.m_log_file, self.m_value
|
||||||
|
PrintByteArray(self.m_log_file, ret)
|
||||||
def GetNextInstruction(self):
|
def GetNextInstruction(self):
|
||||||
# Print current state
|
|
||||||
print self.m_value
|
|
||||||
# Done printing current state
|
|
||||||
if self.m_value > self.m_last:
|
if self.m_value > self.m_last:
|
||||||
return None
|
return None
|
||||||
ret = bytearray(self.m_byte_width)
|
ret = bytearray(self.m_byte_width)
|
||||||
for i in range(self.m_byte_width):
|
for i in range(self.m_byte_width):
|
||||||
ret[self.m_byte_width - (i + 1)] = (self.m_value >> (i * 8)) & 255
|
ret[self.m_byte_width - (i + 1)] = (self.m_value >> (i * 8)) & 255
|
||||||
|
self.PrintCurrentState(ret)
|
||||||
self.m_value += self.m_skip
|
self.m_value += self.m_skip
|
||||||
return ret
|
return ret
|
||||||
|
def GetNumInstructions(self):
|
||||||
|
return self.m_last / self.m_skip
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
def next(self):
|
def next(self):
|
||||||
@ -78,18 +91,18 @@ class SequentialInstructionProvider:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
class RandomInstructionProvider:
|
class RandomInstructionProvider:
|
||||||
def __init__(self, byte_width):
|
def __init__(self, byte_width, log_file):
|
||||||
self.m_byte_width = byte_width
|
self.m_byte_width = byte_width
|
||||||
|
self.m_log_file = log_file
|
||||||
self.m_random_file = open("/dev/random", 'r')
|
self.m_random_file = open("/dev/random", 'r')
|
||||||
|
def PrintCurrentState(self, ret):
|
||||||
|
ResetLogFile(self.m_log_file)
|
||||||
|
PrintByteArray(self.m_log_file, ret)
|
||||||
def GetNextInstruction(self):
|
def GetNextInstruction(self):
|
||||||
ret = bytearray(self.m_byte_width)
|
ret = bytearray(self.m_byte_width)
|
||||||
for i in range(self.m_byte_width):
|
for i in range(self.m_byte_width):
|
||||||
ret[i] = self.m_random_file.read(1)
|
ret[i] = self.m_random_file.read(1)
|
||||||
# Print current state
|
self.PrintCurrentState(ret)
|
||||||
for ret_byte in ret:
|
|
||||||
print hex(ret_byte) + " ",
|
|
||||||
print
|
|
||||||
# Done printing current state
|
|
||||||
return ret
|
return ret
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
@ -99,10 +112,17 @@ class RandomInstructionProvider:
|
|||||||
raise StopIteration
|
raise StopIteration
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
log_file = None
|
||||||
|
|
||||||
def GetProviderWithArguments(args):
|
def GetProviderWithArguments(args):
|
||||||
|
global log_file
|
||||||
|
if args.log != None:
|
||||||
|
log_file = open(args.log, 'w')
|
||||||
|
else:
|
||||||
|
log_file = sys.stdout
|
||||||
instruction_provider = None
|
instruction_provider = None
|
||||||
if args.random == True:
|
if args.random == True:
|
||||||
instruction_provider = RandomInstructionProvider(args.bytes)
|
instruction_provider = RandomInstructionProvider(args.bytes, log_file)
|
||||||
else:
|
else:
|
||||||
start = 0
|
start = 0
|
||||||
skip = 1
|
skip = 1
|
||||||
@ -110,22 +130,36 @@ def GetProviderWithArguments(args):
|
|||||||
start = args.start
|
start = args.start
|
||||||
if args.skip != None:
|
if args.skip != None:
|
||||||
skip = args.skip
|
skip = args.skip
|
||||||
instruction_provider = SequentialInstructionProvider(args.bytes, start, skip)
|
instruction_provider = SequentialInstructionProvider(args.bytes, log_file, start, skip)
|
||||||
return instruction_provider
|
return instruction_provider
|
||||||
|
|
||||||
instruction_provider = GetProviderWithArguments(arg_ns)
|
instruction_provider = GetProviderWithArguments(arg_ns)
|
||||||
|
|
||||||
fake_address = lldb.SBAddress()
|
fake_address = lldb.SBAddress()
|
||||||
|
|
||||||
|
actually_time = arg_ns.time and not arg_ns.random
|
||||||
|
|
||||||
|
if actually_time:
|
||||||
|
num_instructions_logged = 0
|
||||||
|
total_num_instructions = instruction_provider.GetNumInstructions()
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
for inst_bytes in instruction_provider:
|
for inst_bytes in instruction_provider:
|
||||||
|
if actually_time:
|
||||||
|
if (num_instructions_logged != 0) and (num_instructions_logged % 100000 == 0):
|
||||||
|
curr_time = time.time()
|
||||||
|
elapsed_time = curr_time - start_time
|
||||||
|
remaining_time = float(total_num_instructions - num_instructions_logged) * (float(elapsed_time) / float(num_instructions_logged))
|
||||||
|
print str(datetime.timedelta(seconds=remaining_time))
|
||||||
|
num_instructions_logged = num_instructions_logged + 1
|
||||||
inst_list = target.GetInstructions(fake_address, inst_bytes)
|
inst_list = target.GetInstructions(fake_address, inst_bytes)
|
||||||
if not inst_list.IsValid():
|
if not inst_list.IsValid():
|
||||||
print "Invalid instruction list"
|
print >>log_file, "Invalid instruction list"
|
||||||
continue
|
continue
|
||||||
inst = inst_list.GetInstructionAtIndex(0)
|
inst = inst_list.GetInstructionAtIndex(0)
|
||||||
if not inst.IsValid():
|
if not inst.IsValid():
|
||||||
print "Invalid instruction"
|
print >>log_file, "Invalid instruction"
|
||||||
continue
|
continue
|
||||||
instr_output_stream = lldb.SBStream()
|
instr_output_stream = lldb.SBStream()
|
||||||
inst.GetDescription(instr_output_stream)
|
inst.GetDescription(instr_output_stream)
|
||||||
print instr_output_stream.GetData()
|
print >>log_file, instr_output_stream.GetData()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user