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
, fail_fast
):
179 good_results
= set(('pass', 'not_applicable'))
182 module
= sys
.modules
[__name__
]
183 for name
in dir(module
):
184 definition
= getattr(module
, name
)
185 if type(definition
) == type and hasattr(definition
, 'test') and \
186 (not tests
or any(test
in name
for test
in tests
)):
187 instance
= definition(target
)
188 result
= instance
.run()
189 results
.setdefault(result
, []).append(name
)
190 if result
not in good_results
and fail_fast
:
196 for key
, value
in results
.iteritems():
197 print "%d tests returned %s" % (len(value
), key
)
198 if key
not in good_results
:
205 def assertEqual(a
, b
):
207 raise TestFailed("%r != %r" % (a
, b
))
209 def assertNotEqual(a
, b
):
211 raise TestFailed("%r == %r" % (a
, b
))
215 raise TestFailed("%r not in %r" % (a
, b
))
217 def assertNotIn(a
, b
):
219 raise TestFailed("%r in %r" % (a
, b
))
221 def assertGreater(a
, b
):
223 raise TestFailed("%r not greater than %r" % (a
, b
))
227 raise TestFailed("%r is not True" % a
)
229 def assertRegexpMatches(text
, regexp
):
230 if not re
.search(regexp
, text
):
231 raise TestFailed("can't find %r in %r" % (regexp
, text
))
233 class SimpleRegisterTest(GdbTest
):
234 def check_reg(self
, name
):
235 a
= random
.randrange(1<<self
.target
.xlen
)
236 b
= random
.randrange(1<<self
.target
.xlen
)
237 self
.gdb
.p("$%s=0x%x" % (name
, a
))
239 assertEqual(self
.gdb
.p("$%s" % name
), a
)
240 self
.gdb
.p("$%s=0x%x" % (name
, b
))
242 assertEqual(self
.gdb
.p("$%s" % name
), b
)
246 self
.gdb
.command("p *((int*) 0x%x)=0x13" % self
.target
.ram
)
247 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 4))
248 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 8))
249 self
.gdb
.p("$pc=0x%x" % self
.target
.ram
)
251 class SimpleS0Test(SimpleRegisterTest
):
255 class SimpleS1Test(SimpleRegisterTest
):
259 class SimpleT0Test(SimpleRegisterTest
):
263 class SimpleT1Test(SimpleRegisterTest
):
267 class SimpleMemoryTest(GdbTest
):
268 def access_test(self
, size
, data_type
):
269 assertEqual(self
.gdb
.p("sizeof(%s)" % data_type
), size
)
270 a
= 0x86753095555aaaa & ((1<<(size
*8))-1)
271 b
= 0xdeadbeef12345678 & ((1<<(size
*8))-1)
272 self
.gdb
.p("*((%s*)0x%x) = 0x%x" % (data_type
, self
.target
.ram
, a
))
273 self
.gdb
.p("*((%s*)0x%x) = 0x%x" % (data_type
, self
.target
.ram
+ size
,
275 assertEqual(self
.gdb
.p("*((%s*)0x%x)" % (data_type
, self
.target
.ram
)),
277 assertEqual(self
.gdb
.p("*((%s*)0x%x)" % (
278 data_type
, self
.target
.ram
+ size
)), b
)
280 class MemTest8(SimpleMemoryTest
):
282 self
.access_test(1, 'char')
284 class MemTest16(SimpleMemoryTest
):
286 self
.access_test(2, 'short')
288 class MemTest32(SimpleMemoryTest
):
290 self
.access_test(4, 'int')
292 class MemTest64(SimpleMemoryTest
):
294 self
.access_test(8, 'long long')
296 class MemTestReadInvalid(SimpleMemoryTest
):
298 # This test relies on 'gdb_report_data_abort enable' being executed in
299 # the openocd.cfg file.
301 self
.gdb
.p("*((int*)0xdeadbeef)")
302 assert False, "Access should have failed."
303 except testlib
.CannotAccess
as e
:
304 assertEqual(e
.address
, 0xdeadbeef)
306 class MemTestBlock(GdbTest
):
310 a
= tempfile
.NamedTemporaryFile(suffix
=".ihex")
312 for i
in range(length
/ line_length
):
313 line_data
= "".join(["%c" % random
.randrange(256)
314 for _
in range(line_length
)])
316 a
.write(ihex_line(i
* line_length
, 0, line_data
))
319 self
.gdb
.command("restore %s 0x%x" % (a
.name
, self
.target
.ram
))
320 for offset
in range(0, length
, 19*4) + [length
-4]:
321 value
= self
.gdb
.p("*((int*)0x%x)" % (self
.target
.ram
+ offset
))
322 written
= ord(data
[offset
]) | \
323 (ord(data
[offset
+1]) << 8) | \
324 (ord(data
[offset
+2]) << 16) | \
325 (ord(data
[offset
+3]) << 24)
326 assertEqual(value
, written
)
328 b
= tempfile
.NamedTemporaryFile(suffix
=".ihex")
329 self
.gdb
.command("dump ihex memory %s 0x%x 0x%x" % (b
.name
,
330 self
.target
.ram
, self
.target
.ram
+ length
))
332 record_type
, address
, line_data
= ihex_parse(line
)
334 assertEqual(readable_binary_string(line_data
),
335 readable_binary_string(
336 data
[address
:address
+len(line_data
)]))
338 class InstantHaltTest(GdbTest
):
340 assertEqual(self
.target
.reset_vector
, self
.gdb
.p("$pc"))
341 # mcycle and minstret have no defined reset value.
342 mstatus
= self
.gdb
.p("$mstatus")
343 assertEqual(mstatus
& (MSTATUS_MIE | MSTATUS_MPRV |
346 class InstantChangePc(GdbTest
):
348 """Change the PC right as we come out of reset."""
350 self
.gdb
.command("p *((int*) 0x%x)=0x13" % self
.target
.ram
)
351 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 4))
352 self
.gdb
.command("p *((int*) 0x%x)=0x13" % (self
.target
.ram
+ 8))
353 self
.gdb
.p("$pc=0x%x" % self
.target
.ram
)
355 assertEqual((self
.target
.ram
+ 4), self
.gdb
.p("$pc"))
357 assertEqual((self
.target
.ram
+ 8), self
.gdb
.p("$pc"))
359 class DebugTest(GdbTest
):
360 # Include malloc so that gdb can make function calls. I suspect this malloc
361 # will silently blow through the memory set aside for it, so be careful.
362 compile_args
= ("programs/debug.c", "programs/checksum.c",
363 "programs/tiny-malloc.c", "-DDEFINE_MALLOC", "-DDEFINE_FREE")
369 def exit(self
, expected_result
=0xc86455d4):
370 output
= self
.gdb
.c()
371 assertIn("Breakpoint", output
)
372 assertIn("_exit", output
)
373 assertEqual(self
.gdb
.p("status"), expected_result
)
375 class DebugFunctionCall(DebugTest
):
377 self
.gdb
.b("main:start")
379 assertEqual(self
.gdb
.p('fib(6)'), 8)
380 assertEqual(self
.gdb
.p('fib(7)'), 13)
383 class DebugChangeString(DebugTest
):
385 text
= "This little piggy went to the market."
386 self
.gdb
.b("main:start")
388 self
.gdb
.p('fox = "%s"' % text
)
389 self
.exit(0x43b497b8)
391 class DebugTurbostep(DebugTest
):
393 """Single step a bunch of times."""
394 self
.gdb
.b("main:start")
396 self
.gdb
.command("p i=0")
402 pc
= self
.gdb
.p("$pc")
403 assertNotEqual(last_pc
, pc
)
404 if last_pc
and pc
> last_pc
and pc
- last_pc
<= 4:
409 # Some basic sanity that we're not running between breakpoints or
411 assertGreater(jumps
, 10)
412 assertGreater(advances
, 50)
414 class DebugExit(DebugTest
):
418 class DebugSymbols(DebugTest
):
422 output
= self
.gdb
.c()
423 assertIn(", main ", output
)
424 output
= self
.gdb
.c()
425 assertIn(", rot13 ", output
)
427 class DebugBreakpoint(DebugTest
):
430 # The breakpoint should be hit exactly 2 times.
432 output
= self
.gdb
.c()
434 assertIn("Breakpoint ", output
)
435 assertIn("rot13 ", output
)
438 class Hwbp1(DebugTest
):
440 if self
.target
.instruction_hardware_breakpoint_count
< 1:
441 return 'not_applicable'
443 self
.gdb
.hbreak("rot13")
444 # The breakpoint should be hit exactly 2 times.
446 output
= self
.gdb
.c()
448 assertRegexpMatches(output
, r
"[bB]reakpoint")
449 assertIn("rot13 ", output
)
452 class Hwbp2(DebugTest
):
454 if self
.target
.instruction_hardware_breakpoint_count
< 2:
455 return 'not_applicable'
457 self
.gdb
.hbreak("main")
458 self
.gdb
.hbreak("rot13")
459 # We should hit 3 breakpoints.
460 for expected
in ("main", "rot13", "rot13"):
461 output
= self
.gdb
.c()
463 assertRegexpMatches(output
, r
"[bB]reakpoint")
464 assertIn("%s " % expected
, output
)
467 class TooManyHwbp(DebugTest
):
470 self
.gdb
.hbreak("*rot13 + %d" % (i
* 4))
472 output
= self
.gdb
.c()
473 assertIn("Cannot insert hardware breakpoint", output
)
474 # Clean up, otherwise the hardware breakpoints stay set and future
476 self
.gdb
.command("D")
478 class Registers(DebugTest
):
480 # Get to a point in the code where some registers have actually been
485 # Try both forms to test gdb.
486 for cmd
in ("info all-registers", "info registers all"):
487 output
= self
.gdb
.command(cmd
)
488 assertNotIn("Could not", output
)
489 for reg
in ('zero', 'ra', 'sp', 'gp', 'tp'):
490 assertIn(reg
, output
)
493 # mcpuid is one of the few registers that should have the high bit set
495 # Leave this commented out until gdb and spike agree on the encoding of
496 # mcpuid (which is going to be renamed to misa in any case).
497 #assertRegexpMatches(output, ".*mcpuid *0x80")
500 # The instret register should always be changing.
503 # instret = self.gdb.p("$instret")
504 # assertNotEqual(instret, last_instret)
505 # last_instret = instret
510 class UserInterrupt(DebugTest
):
512 """Sending gdb ^C while the program is running should cause it to
514 self
.gdb
.b("main:start")
517 self
.gdb
.c(wait
=False)
519 output
= self
.gdb
.interrupt()
520 assert "main" in output
521 assertGreater(self
.gdb
.p("j"), 10)
525 class StepTest(GdbTest
):
526 compile_args
= ("programs/step.S", )
534 main_address
= self
.gdb
.p("$pc")
535 for expected
in (4, 8, 0xc, 0x10, 0x18, 0x1c, 0x28, 0x20, 0x2c, 0x2c):
537 pc
= self
.gdb
.p("$pc")
538 assertEqual("%x" % pc
, "%x" % (expected
+ main_address
))
540 class TriggerTest(GdbTest
):
541 compile_args
= ("programs/trigger.S", )
549 output
= self
.gdb
.c()
550 assertIn("Breakpoint", output
)
551 assertIn("_exit", output
)
553 class TriggerExecuteInstant(TriggerTest
):
554 """Test an execute breakpoint on the first instruction executed out of
557 main_address
= self
.gdb
.p("$pc")
558 self
.gdb
.command("hbreak *0x%x" % (main_address
+ 4))
560 assertEqual(self
.gdb
.p("$pc"), main_address
+4)
562 class TriggerLoadAddress(TriggerTest
):
564 self
.gdb
.command("rwatch *((&data)+1)")
565 output
= self
.gdb
.c()
566 assertIn("read_loop", output
)
567 assertEqual(self
.gdb
.p("$a0"),
568 self
.gdb
.p("(&data)+1"))
571 class TriggerLoadAddressInstant(TriggerTest
):
572 """Test a load address breakpoint on the first instruction executed out of
575 self
.gdb
.command("b just_before_read_loop")
577 read_loop
= self
.gdb
.p("&read_loop")
578 self
.gdb
.command("rwatch data")
580 # Accept hitting the breakpoint before or after the load instruction.
581 assertIn(self
.gdb
.p("$pc"), [read_loop
, read_loop
+ 4])
582 assertEqual(self
.gdb
.p("$a0"), self
.gdb
.p("&data"))
584 class TriggerStoreAddress(TriggerTest
):
586 self
.gdb
.command("watch *((&data)+3)")
587 output
= self
.gdb
.c()
588 assertIn("write_loop", output
)
589 assertEqual(self
.gdb
.p("$a0"),
590 self
.gdb
.p("(&data)+3"))
593 class TriggerStoreAddressInstant(TriggerTest
):
595 """Test a store address breakpoint on the first instruction executed out
597 self
.gdb
.command("b just_before_write_loop")
599 write_loop
= self
.gdb
.p("&write_loop")
600 self
.gdb
.command("watch data")
602 # Accept hitting the breakpoint before or after the store instruction.
603 assertIn(self
.gdb
.p("$pc"), [write_loop
, write_loop
+ 4])
604 assertEqual(self
.gdb
.p("$a0"), self
.gdb
.p("&data"))
606 class TriggerDmode(TriggerTest
):
607 def check_triggers(self
, tdata1_lsbs
, tdata2
):
608 dmode
= 1 << (self
.target
.xlen
-5)
612 if self
.target
.xlen
== 32:
614 elif self
.target
.xlen
== 64:
615 xlen_type
= 'long long'
617 raise NotImplementedError
622 tdata1
= self
.gdb
.p("((%s *)&data)[%d]" % (xlen_type
, 2*i
))
625 tdata2
= self
.gdb
.p("((%s *)&data)[%d]" % (xlen_type
, 2*i
+1))
630 assertEqual(tdata1
& 0xffff, tdata1_lsbs
)
631 assertEqual(tdata2
, tdata2
)
634 assertEqual(dmode_count
, 1)
639 self
.gdb
.command("hbreak write_load_trigger")
640 self
.gdb
.b("clear_triggers")
641 self
.gdb
.p("$pc=write_store_trigger")
642 output
= self
.gdb
.c()
643 assertIn("write_load_trigger", output
)
644 self
.check_triggers((1<<6) |
(1<<1), 0xdeadbee0)
645 output
= self
.gdb
.c()
646 assertIn("clear_triggers", output
)
647 self
.check_triggers((1<<6) |
(1<<0), 0xfeedac00)
649 class RegsTest(GdbTest
):
650 compile_args
= ("programs/regs.S", )
654 self
.gdb
.b("handle_trap")
657 class WriteGprs(RegsTest
):
659 regs
= [("x%d" % n
) for n
in range(2, 32)]
661 self
.gdb
.p("$pc=write_regs")
662 for i
, r
in enumerate(regs
):
663 self
.gdb
.p("$%s=%d" % (r
, (0xdeadbeef<<i
)+17))
664 self
.gdb
.p("$x1=data")
665 self
.gdb
.command("b all_done")
666 output
= self
.gdb
.c()
667 assertIn("Breakpoint ", output
)
669 # Just to get this data in the log.
670 self
.gdb
.command("x/30gx data")
671 self
.gdb
.command("info registers")
672 for n
in range(len(regs
)):
673 assertEqual(self
.gdb
.x("data+%d" % (8*n
), 'g'),
674 ((0xdeadbeef<<n
)+17) & ((1<<self
.target
.xlen
)-1))
676 class WriteCsrs(RegsTest
):
678 # As much a test of gdb as of the simulator.
679 self
.gdb
.p("$mscratch=0")
681 assertEqual(self
.gdb
.p("$mscratch"), 0)
682 self
.gdb
.p("$mscratch=123")
684 assertEqual(self
.gdb
.p("$mscratch"), 123)
686 self
.gdb
.command("p $pc=write_regs")
687 self
.gdb
.command("p $a0=data")
688 self
.gdb
.command("b all_done")
689 self
.gdb
.command("c")
691 assertEqual(123, self
.gdb
.p("$mscratch"))
692 assertEqual(123, self
.gdb
.p("$x1"))
693 assertEqual(123, self
.gdb
.p("$csr832"))
695 class DownloadTest(GdbTest
):
697 length
= min(2**20, self
.target
.ram_size
- 2048)
698 download_c
= tempfile
.NamedTemporaryFile(prefix
="download_",
700 download_c
.write("#include <stdint.h>\n")
702 "unsigned int crc32a(uint8_t *message, unsigned int size);\n")
703 download_c
.write("uint32_t length = %d;\n" % length
)
704 download_c
.write("uint8_t d[%d] = {\n" % length
)
706 for i
in range(length
/ 16):
707 download_c
.write(" /* 0x%04x */ " % (i
* 16))
709 value
= random
.randrange(1<<8)
710 download_c
.write("%d, " % value
)
711 self
.crc
= binascii
.crc32("%c" % value
, self
.crc
)
712 download_c
.write("\n")
713 download_c
.write("};\n")
714 download_c
.write("uint8_t *data = &d[0];\n")
715 download_c
.write("uint32_t main() { return crc32a(data, length); }\n")
721 self
.binary
= self
.target
.compile(download_c
.name
,
722 "programs/checksum.c")
723 self
.gdb
.command("file %s" % self
.binary
)
727 self
.gdb
.command("b _exit")
729 assertEqual(self
.gdb
.p("status"), self
.crc
)
731 class MprvTest(GdbTest
):
732 compile_args
= ("programs/mprv.S", )
737 """Test that the debugger can access memory when MPRV is set."""
738 self
.gdb
.c(wait
=False)
741 output
= self
.gdb
.command("p/x *(int*)(((char*)&data)-0x80000000)")
742 assertIn("0xbead", output
)
744 class PrivTest(GdbTest
):
745 compile_args
= ("programs/priv.S", )
749 misa
= self
.gdb
.p("$misa")
750 self
.supported
= set()
752 self
.supported
.add(0)
754 self
.supported
.add(1)
756 self
.supported
.add(2)
757 self
.supported
.add(3)
759 class PrivRw(PrivTest
):
761 """Test reading/writing priv."""
762 for privilege
in range(4):
763 self
.gdb
.p("$priv=%d" % privilege
)
765 actual
= self
.gdb
.p("$priv")
766 assertIn(actual
, self
.supported
)
767 if privilege
in self
.supported
:
768 assertEqual(actual
, privilege
)
770 class PrivChange(PrivTest
):
772 """Test that the core's privilege level actually changes."""
774 if 0 not in self
.supported
:
775 return 'not_applicable'
781 self
.gdb
.p("$priv=3")
782 main_address
= self
.gdb
.p("$pc")
784 assertEqual("%x" % self
.gdb
.p("$pc"), "%x" % (main_address
+4))
787 self
.gdb
.p("$priv=0")
789 # Should have taken an exception, so be nowhere near main.
790 pc
= self
.gdb
.p("$pc")
791 assertTrue(pc
< main_address
or pc
> main_address
+ 0x100)
793 class Target(object):
799 temporary_binary
= None
802 raise NotImplementedError
804 def compile(self
, *sources
):
805 binary_name
= "%s_%s-%d" % (
807 os
.path
.basename(os
.path
.splitext(sources
[0])[0]),
810 self
.temporary_binary
= tempfile
.NamedTemporaryFile(
811 prefix
=binary_name
+ "_")
812 binary_name
= self
.temporary_binary
.name
813 Target
.temporary_files
.append(self
.temporary_binary
)
814 testlib
.compile(sources
+
815 ("programs/entry.S", "programs/init.c",
817 "-T", "targets/%s/link.lds" % (self
.directory
or self
.name
),
824 class SpikeTarget(Target
):
827 ram_size
= 5 * 1024 * 1024
828 instruction_hardware_breakpoint_count
= 4
829 reset_vector
= 0x1000
831 class Spike64Target(SpikeTarget
):
836 return testlib
.Spike(parsed
.cmd
, halted
=True)
838 class Spike32Target(SpikeTarget
):
843 return testlib
.Spike(parsed
.cmd
, halted
=True, xlen
=32)
845 class FreedomE300Target(Target
):
846 name
= "freedom-e300"
850 instruction_hardware_breakpoint_count
= 2
853 return testlib
.Openocd(cmd
=parsed
.cmd
,
854 config
="targets/%s/openocd.cfg" % self
.name
)
856 class FreedomE300SimTarget(Target
):
857 name
= "freedom-e300-sim"
861 ram_size
= 256 * 1024 * 1024
862 instruction_hardware_breakpoint_count
= 2
865 sim
= testlib
.VcsSim(simv
=parsed
.run
, debug
=False)
866 openocd
= testlib
.Openocd(cmd
=parsed
.cmd
,
867 config
="targets/%s/openocd.cfg" % self
.name
,
872 class FreedomU500Target(Target
):
873 name
= "freedom-u500"
877 instruction_hardware_breakpoint_count
= 2
880 return testlib
.Openocd(cmd
=parsed
.cmd
,
881 config
="targets/%s/openocd.cfg" % self
.name
)
883 class FreedomU500SimTarget(Target
):
884 name
= "freedom-u500-sim"
888 ram_size
= 256 * 1024 * 1024
889 instruction_hardware_breakpoint_count
= 2
892 sim
= testlib
.VcsSim(simv
=parsed
.run
, debug
=False)
893 openocd
= testlib
.Openocd(cmd
=parsed
.cmd
,
894 config
="targets/%s/openocd.cfg" % self
.name
,
904 FreedomE300SimTarget
,
905 FreedomU500SimTarget
]
909 parser
= argparse
.ArgumentParser(
911 Example command line from the real world:
912 Run all RegsTest cases against a physical FPGA, with custom openocd command:
913 ./gdbserver.py --freedom-e300 --cmd "$HOME/SiFive/openocd/src/openocd -s $HOME/SiFive/openocd/tcl -d" RegsTest
915 group
= parser
.add_mutually_exclusive_group(required
=True)
917 group
.add_argument("--%s" % t
.name
, action
="store_const", const
=t
,
919 parser
.add_argument("--run",
920 help="The command to use to start the actual target (e.g. "
922 parser
.add_argument("--cmd",
923 help="The command to use to start the debug server.")
924 parser
.add_argument("--gdb",
925 help="The command to use to start gdb.")
927 xlen_group
= parser
.add_mutually_exclusive_group()
928 xlen_group
.add_argument("--32", action
="store_const", const
=32, dest
="xlen",
929 help="Force the target to be 32-bit.")
930 xlen_group
.add_argument("--64", action
="store_const", const
=64, dest
="xlen",
931 help="Force the target to be 64-bit.")
933 parser
.add_argument("--isolate", action
="store_true",
934 help="Try to run in such a way that multiple instances can run at "
935 "the same time. This may make it harder to debug a failure if it "
938 parser
.add_argument("--fail-fast", "-f", action
="store_true",
939 help="Exit as soon as any test fails.")
941 parser
.add_argument("test", nargs
='*',
942 help="Run only tests that are named here.")
944 # TODO: remove global
945 global parsed
# pylint: disable=global-statement
946 parsed
= parser
.parse_args()
948 target
= parsed
.target()
950 target
.xlen
= parsed
.xlen
952 return run_all_tests(target
, parsed
.test
, parsed
.fail_fast
)
954 # TROUBLESHOOTING TIPS
955 # If a particular test fails, run just that one test, eg.:
956 # ./gdbserver.py MprvTest.test_mprv
957 # Then inspect gdb.log and spike.log to see what happened in more detail.
959 if __name__
== '__main__':