aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcgsfv <cgsfv@users.noreply.github.com>2018-10-03 15:58:00 +0200
committercgsfv <cgsfv@users.noreply.github.com>2018-10-03 15:58:00 +0200
commit6ac2c6350757a07b4469f37eca61bf44854f41c6 (patch)
tree107a96665449b128e280cc9f0ae0ea8c75b7e4c4
parentfbd7e037ec947c6e9dddc9b78c1cd6bc0fce9993 (diff)
downloadriscv-tests-6ac2c6350757a07b4469f37eca61bf44854f41c6.zip
riscv-tests-6ac2c6350757a07b4469f37eca61bf44854f41c6.tar.gz
riscv-tests-6ac2c6350757a07b4469f37eca61bf44854f41c6.tar.bz2
Added tests for hw and sw watchpoints
-rwxr-xr-xdebug/gdbserver.py56
-rw-r--r--debug/programs/counting_loop.c17
-rw-r--r--debug/testlib.py15
3 files changed, 88 insertions, 0 deletions
diff --git a/debug/gdbserver.py b/debug/gdbserver.py
index 17e1734..eaf390f 100755
--- a/debug/gdbserver.py
+++ b/debug/gdbserver.py
@@ -303,6 +303,62 @@ class InstantChangePc(GdbTest):
self.gdb.stepi()
assertEqual((self.hart.ram + 8), self.gdb.p("$pc"))
+class ProgramTest(GdbSingleHartTest):
+ # Include malloc so that gdb can make function calls. I suspect this malloc
+ # will silently blow through the memory set aside for it, so be careful.
+ compile_args = ("programs/counting_loop.c", "-DDEFINE_MALLOC", "-DDEFINE_FREE")
+
+ def setup(self):
+ self.gdb.load()
+ self.gdb.b("_exit")
+
+ def exit(self, expected_result=10):
+ output = self.gdb.c()
+ assertIn("Breakpoint", output)
+ assertIn("_exit", output)
+ assertEqual(self.gdb.p("status"), expected_result)
+
+class ProgramHwWatchpoint(ProgramTest):
+ def test(self):
+ self.gdb.b("main")
+ output = self.gdb.c()
+ assertIn("Breakpoint", output)
+ assertIn("main", output)
+ self.gdb.watch("counter == 5")
+ # Currently the watchpoint is generating a trap at init and all updates
+ for _ in range(11):
+ output = self.gdb.c()
+ assertIn("Trace/breakpoint trap", output)
+ # The watchpoint is going out of scope
+ output = self.gdb.c()
+ assertIn("Watchpoint", output)
+ assertIn("deleted", output)
+ self.exit()
+
+class ProgramSwWatchpoint(ProgramTest):
+ def test(self):
+ self.gdb.b("main")
+ output = self.gdb.c()
+ assertIn("Breakpoint", output)
+ assertIn("main", output)
+ self.gdb.swatch("counter == 5")
+ # The watchpoint is triggered when the expression changes
+ output = self.gdb.c()
+ assertIn("Watchpoint", output)
+ assertIn("counter == 5", output)
+ output = self.gdb.p_raw("counter")
+ assertIn("5", output)
+ output = self.gdb.c()
+ assertIn("Watchpoint", output)
+ assertIn("counter == 5", output)
+ output = self.gdb.p_raw("counter")
+ assertIn("6", output)
+ output = self.gdb.c()
+ # The watchpoint is going out of scope
+ assertIn("Watchpoint", output)
+ assertIn("deleted", output)
+ self.exit()
+
class DebugTest(GdbSingleHartTest):
# Include malloc so that gdb can make function calls. I suspect this malloc
# will silently blow through the memory set aside for it, so be careful.
diff --git a/debug/programs/counting_loop.c b/debug/programs/counting_loop.c
new file mode 100644
index 0000000..2116e52
--- /dev/null
+++ b/debug/programs/counting_loop.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+int main()
+{
+ int sum = 0;
+ int counter = 0;
+
+ while (counter < 10) {
+ counter = counter + 1;
+ sum = sum + counter;
+ }
+
+ return counter;
+}
diff --git a/debug/testlib.py b/debug/testlib.py
index 59440b3..76f09f9 100644
--- a/debug/testlib.py
+++ b/debug/testlib.py
@@ -587,6 +587,21 @@ class Gdb(object):
assert "Hardware assisted breakpoint" in output
return output
+ def watch(self, expr):
+ output = self.command("watch %s" % expr, ops=5)
+ assert "not defined" not in output
+ assert "atchpoint" in output
+ return output
+
+ def swatch(self, expr):
+ hstate = self.command("show can-use-hw-watchpoints")
+ self.command("set can-use-hw-watchpoints 0")
+ output = self.command("watch %s" % expr, ops=5)
+ assert "not defined" not in output
+ assert "atchpoint" in output
+ self.command("set can-use-hw-watchpoints 1")
+ return output
+
def threads(self):
output = self.command("info threads", ops=100)
threads = []