import targets
import testlib
-from testlib import assertEqual, assertNotEqual, assertIn, assertNotIn
-from testlib import assertGreater, assertTrue, assertRegexpMatches
+from testlib import assertEqual, assertNotEqual, assertIn
+from testlib import assertGreater, assertTrue, assertRegexpMatches, assertLess
MSTATUS_UIE = 0x00000001
MSTATUS_SIE = 0x00000002
def test(self):
self.check_reg("t1")
+class SimpleF18Test(SimpleRegisterTest):
+ def check_reg(self, name):
+ a = random.random()
+ b = random.random()
+ self.gdb.p_raw("$%s=%f" % (name, a))
+ self.gdb.stepi()
+ assertLess(abs(float(self.gdb.p_raw("$%s" % name)) - a), .001)
+ self.gdb.p_raw("$%s=%f" % (name, b))
+ self.gdb.stepi()
+ assertLess(abs(float(self.gdb.p_raw("$%s" % name)) - b), .001)
+
+ def test(self):
+ misa = self.gdb.p("$misa")
+ if not misa & (1<<(ord('F')-ord('A'))):
+ return 'not_applicable'
+ self.check_reg("f18")
+
class SimpleMemoryTest(GdbTest):
def access_test(self, size, data_type):
assertEqual(self.gdb.p("sizeof(%s)" % data_type), size)
# Try both forms to test gdb.
for cmd in ("info all-registers", "info registers all"):
output = self.gdb.command(cmd)
- assertNotIn("Could not", output)
for reg in ('zero', 'ra', 'sp', 'gp', 'tp'):
assertIn(reg, output)
testlib.compile(sources +
("programs/entry.S", "programs/init.c",
"-I", "../env",
+ "-march=RV%dIMAF" % self.xlen,
"-T", "targets/%s/link.lds" % (self.directory or self.name),
"-nostartfiles",
"-mcmodel=medany",
value = int(output.split(':')[1].strip(), 0)
return value
+ def p_raw(self, obj):
+ output = self.command("p %s" % obj)
+ m = re.search("Cannot access memory at address (0x[0-9a-f]+)", output)
+ if m:
+ raise CannotAccess(int(m.group(1), 0))
+ return output.split('=')[-1].strip()
+
def p(self, obj):
output = self.command("p/x %s" % obj)
m = re.search("Cannot access memory at address (0x[0-9a-f]+)", output)
if not a > b:
raise TestFailed("%r not greater than %r" % (a, b))
+def assertLess(a, b):
+ if not a < b:
+ raise TestFailed("%r not less than %r" % (a, b))
+
def assertTrue(a):
if not a:
raise TestFailed("%r is not True" % a)