def __enter__(self): emulator_args = [ test_harness.EMULATOR_PATH, '-m', 'gdb', '-v', self.hexfile ] if test_harness.DEBUG: self.output = None else: self.output = open(os.devnull, 'w') self.emulator_proc = subprocess.Popen(emulator_args, stdout=self.output, stderr=subprocess.STDOUT) lldb_args = [test_harness.COMPILER_BIN + 'lldb-mi'] # XXX race condition: the emulator needs to be ready before # lldb tries to connect to it. try: self.lldb_proc = subprocess.Popen(lldb_args, stdout=subprocess.PIPE, stdin=subprocess.PIPE) self.outstr = self.lldb_proc.stdin self.instr = self.lldb_proc.stdout except: test_harness.kill_gently(self.emulator_proc) raise return self
def __enter__(self): verilator_args = [ test_harness.VSIM_PATH, '+bin=' + self.hexfile, '+jtag_port=' + str(CONTROL_PORT), self.hexfile ] self.process = subprocess.Popen(verilator_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # The process may take a little time to start listening for incoming # connections so retry a few times if it isn't ready yet. for _ in range(10): try: time.sleep(0.3) self.sock = socket.socket() self.sock.connect(('localhost', CONTROL_PORT)) self.sock.settimeout(5) break except socket.error: pass else: test_harness.kill_gently(self.process) raise test_harness.TestException( 'failed to connect to verilator model') self.reader_thread = Thread(target=self._read_output) self.reader_thread.daemon = True self.reader_thread.start() return self
def shared_memory(*unused): '''See coprocessor.c for an explanation of this test''' test_harness.build_program(['coprocessor.c']) # Start the emulator memory_file = tempfile.NamedTemporaryFile() args = [ test_harness.EMULATOR_PATH, '-s', memory_file.name, test_harness.HEX_FILE ] process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) try: # Hack: Need to wait for the emulator to create the shared memory # file and initialize it. There's currently no way for the emulator # to signal that this has completed, so just sleep a bit and hope # it's done. time.sleep(1.0) memory = mmap.mmap(memory_file.fileno(), 0) testvalues = [random.randint(0, 0xffffffff) for __ in range(10)] for value in testvalues: computed = sharedmem_transact(memory, value) if computed != (value ^ 0xffffffff): raise test_harness.TestException( 'Incorrect value from coprocessor expected ' + hex(value ^ 0xffffffff) + ' got ' + hex(computed)) finally: test_harness.kill_gently(process)
def shared_memory(*unused): """See coprocessor.c for an explanation of this test""" test_harness.build_program(['coprocessor.c']) # Start the emulator memory_file = tempfile.NamedTemporaryFile() args = [test_harness.EMULATOR_PATH, '-s', memory_file.name, test_harness.HEX_FILE] process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) try: # Hack: Need to wait for the emulator to create the shared memory # file and initialize it. There's currently no way for the emulator # to signal that this has completed, so just sleep a bit and hope # it's done. time.sleep(1.0) memory = mmap.mmap(memory_file.fileno(), 0) testvalues = [random.randint(0, 0xffffffff) for __ in range(10)] for value in testvalues: computed = sharedmem_transact(memory, value) if computed != (value ^ 0xffffffff): raise test_harness.TestException('Incorrect value from coprocessor expected ' + hex(value ^ 0xffffffff) + ' got ' + hex(computed)) finally: test_harness.kill_gently(process)
def __enter__(self): emulator_args = [ test_harness.EMULATOR_PATH, '-m', 'gdb', '-v', self.hexfile ] if test_harness.DEBUG: self.output = None else: self.output = open(os.devnull, 'w') self.emulator_proc = subprocess.Popen(emulator_args, stdout=self.output, stderr=subprocess.STDOUT) lldb_args = [ test_harness.COMPILER_DIR + 'lldb-mi' ] # XXX race condition: the emulator needs to be ready before # lldb tries to connect to it. try: self.lldb_proc = subprocess.Popen(lldb_args, stdout=subprocess.PIPE, stdin=subprocess.PIPE) self.outstr = self.lldb_proc.stdin self.instr = self.lldb_proc.stdout except: test_harness.kill_gently(self.emulator_proc) raise return self
def run_cosimulation_test(source_file, *unused): verilator_args = [ test_harness.VSIM_PATH, '+trace', '+memdumpfile=' + VERILATOR_MEM_DUMP, '+memdumpbase=800000', '+memdumplen=400000', '+autoflushl2' ] # XXX this should probably be a command line option in test_harness.py if 'RANDSEED' in os.environ: verilator_args += ['+randseed=' + os.environ['RANDSEED']] emulator_args = [ test_harness.EMULATOR_PATH, '-m', 'cosim', '-d', EMULATOR_MEM_DUMP + ',0x800000,0x400000' ] if test_harness.DEBUG: emulator_args += ['-v'] hexfile = test_harness.build_program([source_file]) p1 = subprocess.Popen( verilator_args + ['+bin=' + hexfile], stdout=subprocess.PIPE) p2 = subprocess.Popen( emulator_args + [hexfile], stdin=p1.stdout, stdout=subprocess.PIPE) output = '' while True: got = p2.stdout.read(0x1000) if not got: break if test_harness.DEBUG: print(got.decode()) else: output += got.decode() p2.wait() time.sleep(1) # Give verilator a chance to clean up test_harness.kill_gently(p2) # Make sure verilator has exited if p2.returncode: raise test_harness.TestException( 'FAIL: cosimulation mismatch\n' + output) test_harness.assert_files_equal(VERILATOR_MEM_DUMP, EMULATOR_MEM_DUMP, 'final memory contents to not match')
def __exit__(self, *unused): test_harness.kill_gently(self.emulator_proc) test_harness.kill_gently(self.lldb_proc)
def __exit__(self, *unused): test_harness.kill_gently(self.process) if self.output: self.output.close()
def __exit__(self, *unused): test_harness.kill_gently(self.process) if self.sock: self.sock.close()