8 # Note that gdb comes with its own testsuite. I was unable to figure out how to
9 # run that testsuite against the spike simulator.
12 for directory
in (os
.getcwd(), os
.path
.dirname(testlib
.__file
__)):
13 fullpath
= os
.path
.join(directory
, path
)
14 if os
.path
.exists(fullpath
):
16 raise ValueError("Couldn't find %r." % path
)
18 def compile(src
, dst
):
19 """Compile a single .c file into a binary."""
20 cc
= os
.path
.expandvars("$RISCV/bin/riscv64-unknown-elf-gcc")
21 return os
.system("%s -g -o %s %s" % (cc
, dst
, find_file(src
)))
23 def spike(binary
, halted
=False):
24 cmd
= [find_file("spike")]
28 logfile
= open("spike.log", "w")
29 return subprocess
.Popen(cmd
, stdin
=subprocess
.PIPE
, stdout
=logfile
, stderr
=logfile
)
33 path
= os
.path
.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")
34 self
.child
= pexpect
.spawn(path
)
35 self
.child
.logfile
= file("gdb.log", "w")
37 self
.command("set width 0")
38 self
.command("set height 0")
41 """Wait for prompt."""
42 self
.child
.expect("\(gdb\)")
44 def command(self
, command
):
45 self
.child
.sendline(command
)
46 self
.child
.expect("\n")
47 self
.child
.expect("\(gdb\)")
48 return self
.child
.before
.strip()