From: Tim Newsome Date: Mon, 15 Aug 2016 19:52:03 +0000 (-0700) Subject: Simplify test_function_call. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=87b55cae7014a375588a3d24d03903ca170f6d7e;p=riscv-tests.git Simplify test_function_call. Now it doesn't rely on malloc, which can be tricky to get to work in and of itself. --- diff --git a/debug/gdbserver.py b/debug/gdbserver.py index d7527a2..ede7869 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -224,9 +224,8 @@ class DebugTest(DeleteServer): def test_function_call(self): self.gdb.b("main:start") self.gdb.c() - text = "Howdy, Earth!" - gdb_length = self.gdb.p('strlen("%s")' % text) - self.assertEqual(gdb_length, len(text)) + self.assertEqual(self.gdb.p('fib(6)'), 8) + self.assertEqual(self.gdb.p('fib(7)'), 13) self.exit() def test_change_string(self): diff --git a/debug/programs/debug.c b/debug/programs/debug.c index 20b1cdc..3ba51bc 100644 --- a/debug/programs/debug.c +++ b/debug/programs/debug.c @@ -5,6 +5,24 @@ unsigned int crc32a(uint8_t *message, unsigned int size); +unsigned int fib(unsigned int n) +{ + if (n == 0) { + return 0; + } + + unsigned int a = 0; + unsigned int b = 1; + + for (unsigned int i = 1; i < n; i++) { + unsigned int next = a + b; + a = b; + b = next; + } + + return b; +} + void rot13(char *buf) { while (*buf) {