15 MSTATUS_UIE
= 0x00000001
16 MSTATUS_SIE
= 0x00000002
17 MSTATUS_HIE
= 0x00000004
18 MSTATUS_MIE
= 0x00000008
19 MSTATUS_UPIE
= 0x00000010
20 MSTATUS_SPIE
= 0x00000020
21 MSTATUS_HPIE
= 0x00000040
22 MSTATUS_MPIE
= 0x00000080
23 MSTATUS_SPP
= 0x00000100
24 MSTATUS_HPP
= 0x00000600
25 MSTATUS_MPP
= 0x00001800
26 MSTATUS_FS
= 0x00006000
27 MSTATUS_XS
= 0x00018000
28 MSTATUS_MPRV
= 0x00020000
29 MSTATUS_PUM
= 0x00040000
30 MSTATUS_MXR
= 0x00080000
31 MSTATUS_VM
= 0x1F000000
32 MSTATUS32_SD
= 0x80000000
33 MSTATUS64_SD
= 0x8000000000000000
35 # pylint: disable=abstract-method
45 g
= testlib
.Gdb(parsed
.gdb
)
50 g
.command("file %s" % binary
)
52 g
.command("set arch riscv:rv%d" % target
.xlen
)
53 g
.command("set remotetimeout %d" % target
.timeout_sec
)
55 g
.command("target extended-remote localhost:%d" % port
)
61 def ihex_line(address
, record_type
, data
):
62 assert len(data
) < 128
63 line
= ":%02X%04X%02X" % (len(data
), address
, record_type
)
65 check
+= address
% 256
71 line
+= "%02X" % value
72 line
+= "%02X\n" % ((256-check
)%256)
76 assert line
.startswith(":")
78 data_len
= int(line
[:2], 16)
79 address
= int(line
[2:6], 16)
80 record_type
= int(line
[6:8], 16)
82 for i
in range(data_len
):
83 data
+= "%c" % int(line
[8+2*i
:10+2*i
], 16)
84 return record_type
, address
, data
86 def readable_binary_string(s
):
87 return "".join("%02x" % ord(c
) for c
in s
)
90 dashes
= '-' * (36 - len(title
))
91 before
= dashes
[:len(dashes
)/2]
92 after
= dashes
[len(dashes
)/2:]
93 print "%s[ %s ]%s" % (before
, title
, after
)
95 class GdbTest(object):
98 def __init__(self
, target
):
109 If compile_args is set, compile a program and set self.binary.
113 Then call test() and return the result, displaying relevant information
114 if an exception is raised.
116 self
.server
= self
.target
.server()
118 print "Running", type(self
).__name
__, "...",
123 compile_args
= getattr(self
, 'compile_args', None)
125 if compile_args
not in GdbTest
.compiled
:
127 # pylint: disable=star-args
128 GdbTest
.compiled
[compile_args
] = \
129 self
.target
.compile(*compile_args
)
130 except Exception: # pylint: disable=broad-except
131 print "exception while compiling in %.2fs" % (
135 traceback
.print_exc(file=sys
.stdout
)
138 self
.binary
= GdbTest
.compiled
.get(compile_args
)
140 self
.gdb
= gdb(self
.target
, self
.server
.port
, self
.binary
)
144 result
= self
.test() # pylint: disable=no-member
145 except Exception as e
: # pylint: disable=broad-except
146 if isinstance(e
, TestFailed
):
150 print "%s in %.2fs" % (result
, time
.time() - start
)
152 if isinstance(e
, TestFailed
):
156 traceback
.print_exc(file=sys
.stdout
)
158 print open("gdb.log", "r").read()
159 header(self
.server
.logname
)
160 print open(self
.server
.logname
, "r").read()
170 print "%s in %.2fs" % (result
, time
.time() - start
)
173 class TestFailed(Exception):
174 def __init__(self
, message
):
175 Exception.__init
__(self
)
176 self
.message
= message
178 def run_all_tests(target
, tests
):
180 module
= sys
.modules
[__name__
]
181 for name
in dir(module
):
182 definition
= getattr(module
, name
)
183 if type(definition
) == type and hasattr(definition
, 'test') and \
184 (not tests
or any(test
in name
for test
in tests
)):
185 instance
= definition(target
)
186 result
= instance
.run()
187 results
.setdefault(result
, []).append(name
)
191 good_results
= set(('pass', 'not_applicable'))
194 for key
, value
in results
.iteritems():
195 print "%d tests returned %s" % (len(value
), key
)
196 if key
not in good_results
:
203 def assertEqual(a
, b
):
205 raise TestFailed("%r != %r" % (a
, b
))
207 def assertNotEqual(a
, b
):
209 raise TestFailed("%r == %r" % (a
, b
))
213 raise TestFailed("%r not in %r" % (a
, b
))
215 def assertNotIn(a
, b
):
217 raise TestFailed("%r in %r" % (a
, b
))
219 def assertGreater(a
, b
):
221 raise TestFailed("%r not greater than %r" % (a
, b
))
225 raise TestFailed("%r is not True" % a
)
227 def assertRegexpMatches(text
, regexp
):
228 if not re
.search(regexp
, text
):
229 raise TestFailed("can't find %r in %r" % (regexp
, text
))
231 class SimpleRegisterTest(GdbTest
):
232 def check_reg(self
, name
):
233 a
= random
.randrange(1<<self
.target
.xlen
)
234 b
= random
.randrange(1<<self
.target
.xlen
)
235 self
.gdb
.p("$%s=0x%x" % (name
, a
))
237 assertEqual(self
.gdb
.p("$%s" % name
), a
)
238 self
.gdb
.p("$%s=0x%x" % (name
, b
))
240 assertEqual(self
.gdb
.p("$%s" % name
), b
)
244 self
.gdb
.command("p *((int*) 0x%x)=0x13" % self
.target
.ram
)
245 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 4))
246 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 8))
247 self
.gdb
.p("$pc=0x%x" % self
.target
.ram
)
249 class SimpleS0Test(SimpleRegisterTest
):
253 class SimpleS1Test(SimpleRegisterTest
):
257 class SimpleT0Test(SimpleRegisterTest
):
261 class SimpleT1Test(SimpleRegisterTest
):
265 class SimpleMemoryTest(GdbTest
):
266 def access_test(self
, size
, data_type
):
267 assertEqual(self
.gdb
.p("sizeof(%s)" % data_type
), size
)
268 a
= 0x86753095555aaaa & ((1<<(size
*8))-1)
269 b
= 0xdeadbeef12345678 & ((1<<(size
*8))-1)
270 self
.gdb
.p("*((%s*)0x%x) = 0x%x" % (data_type
, self
.target
.ram
, a
))
271 self
.gdb
.p("*((%s*)0x%x) = 0x%x" % (data_type
, self
.target
.ram
+ size
,
273 assertEqual(self
.gdb
.p("*((%s*)0x%x)" % (data_type
, self
.target
.ram
)),
275 assertEqual(self
.gdb
.p("*((%s*)0x%x)" % (
276 data_type
, self
.target
.ram
+ size
)), b
)
278 class MemTest8(SimpleMemoryTest
):
280 self
.access_test(1, 'char')
282 class MemTest16(SimpleMemoryTest
):
284 self
.access_test(2, 'short')
286 class MemTest32(SimpleMemoryTest
):
288 self
.access_test(4, 'int')
290 class MemTest64(SimpleMemoryTest
):
292 self
.access_test(8, 'long long')
294 class MemTestBlock(GdbTest
):
298 a
= tempfile
.NamedTemporaryFile(suffix
=".ihex")
300 for i
in range(length
/ line_length
):
301 line_data
= "".join(["%c" % random
.randrange(256)
302 for _
in range(line_length
)])
304 a
.write(ihex_line(i
* line_length
, 0, line_data
))
307 self
.gdb
.command("restore %s 0x%x" % (a
.name
, self
.target
.ram
))
308 for offset
in range(0, length
, 19*4) + [length
-4]:
309 value
= self
.gdb
.p("*((int*)0x%x)" % (self
.target
.ram
+ offset
))
310 written
= ord(data
[offset
]) | \
311 (ord(data
[offset
+1]) << 8) | \
312 (ord(data
[offset
+2]) << 16) | \
313 (ord(data
[offset
+3]) << 24)
314 assertEqual(value
, written
)
316 b
= tempfile
.NamedTemporaryFile(suffix
=".ihex")
317 self
.gdb
.command("dump ihex memory %s 0x%x 0x%x" % (b
.name
,
318 self
.target
.ram
, self
.target
.ram
+ length
))
320 record_type
, address
, line_data
= ihex_parse(line
)
322 assertEqual(readable_binary_string(line_data
),
323 readable_binary_string(
324 data
[address
:address
+len(line_data
)]))
326 class InstantHaltTest(GdbTest
):
328 assertEqual(self
.target
.reset_vector
, self
.gdb
.p("$pc"))
329 # mcycle and minstret have no defined reset value.
330 mstatus
= self
.gdb
.p("$mstatus")
331 assertEqual(mstatus
& (MSTATUS_MIE | MSTATUS_MPRV |
334 class InstantChangePc(GdbTest
):
336 """Change the PC right as we come out of reset."""
338 self
.gdb
.command("p *((int*) 0x%x)=0x13" % self
.target
.ram
)
339 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 4))
340 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 8))
341 self
.gdb
.p("$pc=0x%x" % self
.target
.ram
)
343 assertEqual((self
.target
.ram
+ 4), self
.gdb
.p("$pc"))
345 assertEqual((self
.target
.ram
+ 8), self
.gdb
.p("$pc"))
347 class DebugTest(GdbTest
):
348 # Include malloc so that gdb can make function calls. I suspect this malloc
349 # will silently blow through the memory set aside for it, so be careful.
350 compile_args
= ("programs/debug.c", "programs/checksum.c",
351 "programs/tiny-malloc.c", "-DDEFINE_MALLOC", "-DDEFINE_FREE")
357 def exit(self
, expected_result
=0xc86455d4):
358 output
= self
.gdb
.c()
359 assertIn("Breakpoint", output
)
360 assertIn("_exit", output
)
361 assertEqual(self
.gdb
.p("status"), expected_result
)
363 class DebugFunctionCall(DebugTest
):
365 self
.gdb
.b("main:start")
367 assertEqual(self
.gdb
.p('fib(6)'), 8)
368 assertEqual(self
.gdb
.p('fib(7)'), 13)
371 class DebugChangeString(DebugTest
):
373 text
= "This little piggy went to the market."
374 self
.gdb
.b("main:start")
376 self
.gdb
.p('fox = "%s"' % text
)
377 self
.exit(0x43b497b8)
379 class DebugTurbostep(DebugTest
):
381 """Single step a bunch of times."""
382 self
.gdb
.b("main:start")
384 self
.gdb
.command("p i=0")
390 pc
= self
.gdb
.p("$pc")
391 assertNotEqual(last_pc
, pc
)
392 if last_pc
and pc
> last_pc
and pc
- last_pc
<= 4:
397 # Some basic sanity that we're not running between breakpoints or
399 assertGreater(jumps
, 10)
400 assertGreater(advances
, 50)
402 class DebugExit(DebugTest
):
406 class DebugSymbols(DebugTest
):
410 output
= self
.gdb
.c()
411 assertIn(", main ", output
)
412 output
= self
.gdb
.c()
413 assertIn(", rot13 ", output
)
415 class DebugBreakpoint(DebugTest
):
418 # The breakpoint should be hit exactly 2 times.
420 output
= self
.gdb
.c()
422 assertIn("Breakpoint ", output
)
423 assertIn("rot13 ", output
)
426 class Hwbp1(DebugTest
):
428 if self
.target
.instruction_hardware_breakpoint_count
< 1:
429 return 'not_applicable'
431 self
.gdb
.hbreak("rot13")
432 # The breakpoint should be hit exactly 2 times.
434 output
= self
.gdb
.c()
436 assertRegexpMatches(output
, r
"[bB]reakpoint")
437 assertIn("rot13 ", output
)
440 class Hwbp2(DebugTest
):
442 if self
.target
.instruction_hardware_breakpoint_count
< 2:
443 return 'not_applicable'
445 self
.gdb
.hbreak("main")
446 self
.gdb
.hbreak("rot13")
447 # We should hit 3 breakpoints.
448 for expected
in ("main", "rot13", "rot13"):
449 output
= self
.gdb
.c()
451 assertRegexpMatches(output
, r
"[bB]reakpoint")
452 assertIn("%s " % expected
, output
)
455 class TooManyHwbp(DebugTest
):
458 self
.gdb
.hbreak("*rot13 + %d" % (i
* 4))
460 output
= self
.gdb
.c()
461 assertIn("Cannot insert hardware breakpoint", output
)
462 # Clean up, otherwise the hardware breakpoints stay set and future
464 self
.gdb
.command("D")
466 class Registers(DebugTest
):
468 # Get to a point in the code where some registers have actually been
473 # Try both forms to test gdb.
474 for cmd
in ("info all-registers", "info registers all"):
475 output
= self
.gdb
.command(cmd
)
476 assertNotIn("Could not", output
)
477 for reg
in ('zero', 'ra', 'sp', 'gp', 'tp'):
478 assertIn(reg
, output
)
481 # mcpuid is one of the few registers that should have the high bit set
483 # Leave this commented out until gdb and spike agree on the encoding of
484 # mcpuid (which is going to be renamed to misa in any case).
485 #assertRegexpMatches(output, ".*mcpuid *0x80")
488 # The instret register should always be changing.
491 # instret = self.gdb.p("$instret")
492 # assertNotEqual(instret, last_instret)
493 # last_instret = instret
498 class UserInterrupt(DebugTest
):
500 """Sending gdb ^C while the program is running should cause it to
502 self
.gdb
.b("main:start")
505 self
.gdb
.c(wait
=False)
507 output
= self
.gdb
.interrupt()
508 assert "main" in output
509 assertGreater(self
.gdb
.p("j"), 10)
513 class StepTest(GdbTest
):
514 compile_args
= ("programs/step.S", )
522 main_address
= self
.gdb
.p("$pc")
523 for expected
in (4, 8, 0xc, 0x10, 0x18, 0x1c, 0x28, 0x20, 0x2c, 0x2c):
525 pc
= self
.gdb
.p("$pc")
526 assertEqual("%x" % pc
, "%x" % (expected
+ main_address
))
528 class TriggerTest(GdbTest
):
529 compile_args
= ("programs/trigger.S", )
537 output
= self
.gdb
.c()
538 assertIn("Breakpoint", output
)
539 assertIn("_exit", output
)
541 class TriggerExecuteInstant(TriggerTest
):
542 """Test an execute breakpoint on the first instruction executed out of
545 main_address
= self
.gdb
.p("$pc")
546 self
.gdb
.command("hbreak *0x%x" % (main_address
+ 4))
548 assertEqual(self
.gdb
.p("$pc"), main_address
+4)
550 class TriggerLoadAddress(TriggerTest
):
552 self
.gdb
.command("rwatch *((&data)+1)")
553 output
= self
.gdb
.c()
554 assertIn("read_loop", output
)
555 assertEqual(self
.gdb
.p("$a0"),
556 self
.gdb
.p("(&data)+1"))
559 class TriggerLoadAddressInstant(TriggerTest
):
560 """Test a load address breakpoint on the first instruction executed out of
563 self
.gdb
.command("b just_before_read_loop")
565 read_loop
= self
.gdb
.p("&read_loop")
566 self
.gdb
.command("rwatch data")
568 # Accept hitting the breakpoint before or after the load instruction.
569 assertIn(self
.gdb
.p("$pc"), [read_loop
, read_loop
+ 4])
570 assertEqual(self
.gdb
.p("$a0"), self
.gdb
.p("&data"))
572 class TriggerStoreAddress(TriggerTest
):
574 self
.gdb
.command("watch *((&data)+3)")
575 output
= self
.gdb
.c()
576 assertIn("write_loop", output
)
577 assertEqual(self
.gdb
.p("$a0"),
578 self
.gdb
.p("(&data)+3"))
581 class TriggerStoreAddressInstant(TriggerTest
):
583 """Test a store address breakpoint on the first instruction executed out
585 self
.gdb
.command("b just_before_write_loop")
587 write_loop
= self
.gdb
.p("&write_loop")
588 self
.gdb
.command("watch data")
590 # Accept hitting the breakpoint before or after the store instruction.
591 assertIn(self
.gdb
.p("$pc"), [write_loop
, write_loop
+ 4])
592 assertEqual(self
.gdb
.p("$a0"), self
.gdb
.p("&data"))
594 class TriggerDmode(TriggerTest
):
596 return 'not_applicable'
597 # pylint: disable=unreachable
598 # Temporarily not applicable until spike is fixed to match the spec
600 self
.gdb
.command("hbreak handle_trap")
601 self
.gdb
.p("$pc=write_valid")
602 output
= self
.gdb
.c()
603 assertIn("handle_trap", output
)
604 assertIn("mcause=2", output
)
605 assertIn("mepc=%d" % self
.gdb
.p("&write_invalid_illegal"), output
)
607 class RegsTest(GdbTest
):
608 compile_args
= ("programs/regs.S", )
612 self
.gdb
.b("handle_trap")
615 class WriteGprs(RegsTest
):
617 regs
= [("x%d" % n
) for n
in range(2, 32)]
619 self
.gdb
.p("$pc=write_regs")
620 for i
, r
in enumerate(regs
):
621 self
.gdb
.p("$%s=%d" % (r
, (0xdeadbeef<<i
)+17))
622 self
.gdb
.p("$x1=data")
623 self
.gdb
.command("b all_done")
624 output
= self
.gdb
.c()
625 assertIn("Breakpoint ", output
)
627 # Just to get this data in the log.
628 self
.gdb
.command("x/30gx data")
629 self
.gdb
.command("info registers")
630 for n
in range(len(regs
)):
631 assertEqual(self
.gdb
.x("data+%d" % (8*n
), 'g'),
632 ((0xdeadbeef<<n
)+17) & ((1<<self
.target
.xlen
)-1))
634 class WriteCsrs(RegsTest
):
636 # As much a test of gdb as of the simulator.
637 self
.gdb
.p("$mscratch=0")
639 assertEqual(self
.gdb
.p("$mscratch"), 0)
640 self
.gdb
.p("$mscratch=123")
642 assertEqual(self
.gdb
.p("$mscratch"), 123)
644 self
.gdb
.command("p $pc=write_regs")
645 self
.gdb
.command("p $a0=data")
646 self
.gdb
.command("b all_done")
647 self
.gdb
.command("c")
649 assertEqual(123, self
.gdb
.p("$mscratch"))
650 assertEqual(123, self
.gdb
.p("$x1"))
651 assertEqual(123, self
.gdb
.p("$csr832"))
653 class DownloadTest(GdbTest
):
655 length
= min(2**20, self
.target
.ram_size
- 2048)
656 download_c
= tempfile
.NamedTemporaryFile(prefix
="download_",
658 download_c
.write("#include <stdint.h>\n")
660 "unsigned int crc32a(uint8_t *message, unsigned int size);\n")
661 download_c
.write("uint32_t length = %d;\n" % length
)
662 download_c
.write("uint8_t d[%d] = {\n" % length
)
664 for i
in range(length
/ 16):
665 download_c
.write(" /* 0x%04x */ " % (i
* 16))
667 value
= random
.randrange(1<<8)
668 download_c
.write("%d, " % value
)
669 self
.crc
= binascii
.crc32("%c" % value
, self
.crc
)
670 download_c
.write("\n")
671 download_c
.write("};\n")
672 download_c
.write("uint8_t *data = &d[0];\n")
673 download_c
.write("uint32_t main() { return crc32a(data, length); }\n")
679 self
.binary
= self
.target
.compile(download_c
.name
,
680 "programs/checksum.c")
681 self
.gdb
.command("file %s" % self
.binary
)
685 self
.gdb
.command("b _exit")
687 assertEqual(self
.gdb
.p("status"), self
.crc
)
689 class MprvTest(GdbTest
):
690 compile_args
= ("programs/mprv.S", )
695 """Test that the debugger can access memory when MPRV is set."""
696 self
.gdb
.c(wait
=False)
699 output
= self
.gdb
.command("p/x *(int*)(((char*)&data)-0x80000000)")
700 assertIn("0xbead", output
)
702 class PrivTest(GdbTest
):
703 compile_args
= ("programs/priv.S", )
707 misa
= self
.gdb
.p("$misa")
708 self
.supported
= set()
710 self
.supported
.add(0)
712 self
.supported
.add(1)
714 self
.supported
.add(2)
715 self
.supported
.add(3)
717 class PrivRw(PrivTest
):
719 """Test reading/writing priv."""
720 for privilege
in range(4):
721 self
.gdb
.p("$priv=%d" % privilege
)
723 actual
= self
.gdb
.p("$priv")
724 assertIn(actual
, self
.supported
)
725 if privilege
in self
.supported
:
726 assertEqual(actual
, privilege
)
728 class PrivChange(PrivTest
):
730 """Test that the core's privilege level actually changes."""
732 if 0 not in self
.supported
:
733 return 'not_applicable'
739 self
.gdb
.p("$priv=3")
740 main_address
= self
.gdb
.p("$pc")
742 assertEqual("%x" % self
.gdb
.p("$pc"), "%x" % (main_address
+4))
745 self
.gdb
.p("$priv=0")
747 # Should have taken an exception, so be nowhere near main.
748 pc
= self
.gdb
.p("$pc")
749 assertTrue(pc
< main_address
or pc
> main_address
+ 0x100)
751 class Target(object):
757 temporary_binary
= None
760 raise NotImplementedError
762 def compile(self
, *sources
):
763 binary_name
= "%s_%s-%d" % (
765 os
.path
.basename(os
.path
.splitext(sources
[0])[0]),
768 self
.temporary_binary
= tempfile
.NamedTemporaryFile(
769 prefix
=binary_name
+ "_")
770 binary_name
= self
.temporary_binary
.name
771 Target
.temporary_files
.append(self
.temporary_binary
)
772 testlib
.compile(sources
+
773 ("programs/entry.S", "programs/init.c",
775 "-T", "targets/%s/link.lds" % (self
.directory
or self
.name
),
782 class SpikeTarget(Target
):
785 ram_size
= 5 * 1024 * 1024
786 instruction_hardware_breakpoint_count
= 4
787 reset_vector
= 0x1000
789 class Spike64Target(SpikeTarget
):
794 return testlib
.Spike(parsed
.cmd
, halted
=True)
796 class Spike32Target(SpikeTarget
):
801 return testlib
.Spike(parsed
.cmd
, halted
=True, xlen
=32)
803 class FreedomE300Target(Target
):
804 name
= "freedom-e300"
808 instruction_hardware_breakpoint_count
= 2
811 return testlib
.Openocd(cmd
=parsed
.cmd
,
812 config
="targets/%s/openocd.cfg" % self
.name
)
814 class FreedomE300SimTarget(Target
):
815 name
= "freedom-e300-sim"
819 ram_size
= 256 * 1024 * 1024
820 instruction_hardware_breakpoint_count
= 2
823 sim
= testlib
.VcsSim(simv
=parsed
.run
, debug
=False)
824 openocd
= testlib
.Openocd(cmd
=parsed
.cmd
,
825 config
="targets/%s/openocd.cfg" % self
.name
,
830 class FreedomU500Target(Target
):
831 name
= "freedom-u500"
835 instruction_hardware_breakpoint_count
= 2
838 return testlib
.Openocd(cmd
=parsed
.cmd
,
839 config
="targets/%s/openocd.cfg" % self
.name
)
841 class FreedomU500SimTarget(Target
):
842 name
= "freedom-u500-sim"
846 ram_size
= 256 * 1024 * 1024
847 instruction_hardware_breakpoint_count
= 2
850 sim
= testlib
.VcsSim(simv
=parsed
.run
, debug
=False)
851 openocd
= testlib
.Openocd(cmd
=parsed
.cmd
,
852 config
="targets/%s/openocd.cfg" % self
.name
,
862 FreedomE300SimTarget
,
863 FreedomU500SimTarget
]
867 parser
= argparse
.ArgumentParser(
869 Example command line from the real world:
870 Run all RegsTest cases against a physical FPGA, with custom openocd command:
871 ./gdbserver.py --freedom-e300 --cmd "$HOME/SiFive/openocd/src/openocd -s $HOME/SiFive/openocd/tcl -d" RegsTest
873 group
= parser
.add_mutually_exclusive_group(required
=True)
875 group
.add_argument("--%s" % t
.name
, action
="store_const", const
=t
,
877 parser
.add_argument("--run",
878 help="The command to use to start the actual target (e.g. "
880 parser
.add_argument("--cmd",
881 help="The command to use to start the debug server.")
882 parser
.add_argument("--gdb",
883 help="The command to use to start gdb.")
885 xlen_group
= parser
.add_mutually_exclusive_group()
886 xlen_group
.add_argument("--32", action
="store_const", const
=32, dest
="xlen",
887 help="Force the target to be 32-bit.")
888 xlen_group
.add_argument("--64", action
="store_const", const
=64, dest
="xlen",
889 help="Force the target to be 64-bit.")
891 parser
.add_argument("--isolate", action
="store_true",
892 help="Try to run in such a way that multiple instances can run at "
893 "the same time. This may make it harder to debug a failure if it "
896 parser
.add_argument("test", nargs
='*',
897 help="Run only tests that are named here.")
899 # TODO: remove global
900 global parsed
# pylint: disable=global-statement
901 parsed
= parser
.parse_args()
903 target
= parsed
.target()
905 target
.xlen
= parsed
.xlen
907 return run_all_tests(target
, parsed
.test
)
909 # TROUBLESHOOTING TIPS
910 # If a particular test fails, run just that one test, eg.:
911 # ./gdbserver.py MprvTest.test_mprv
912 # Then inspect gdb.log and spike.log to see what happened in more detail.
914 if __name__
== '__main__':