+class DownloadTest(unittest.TestCase):
+ def setUp(self):
+ length = 2**16
+ fd = file("data.c", "w")
+ fd.write("#include <stdint.h>\n")
+ fd.write("uint32_t length = %d;\n" % length)
+ fd.write("uint8_t d[%d] = {\n" % length)
+ self.crc = 0
+ for _ in range(length / 16):
+ fd.write(" ");
+ for _ in range(16):
+ value = random.randrange(1<<8)
+ fd.write("%d, " % value)
+ self.crc = binascii.crc32("%c" % value, self.crc)
+ fd.write("\n");
+ fd.write("};\n");
+ fd.write("uint8_t *data = &d[0];\n");
+ fd.close()
+
+ self.binary = testlib.compile("checksum.c", "data.c", "start.S",
+ "-mcmodel=medany",
+ "-T", "standalone.lds",
+ "-nostartfiles"
+ )
+ self.spike = testlib.Spike(None, halted=True)
+ self.gdb = testlib.Gdb()
+ self.gdb.command("file %s" % self.binary)
+ self.gdb.command("target extended-remote localhost:%d" % self.spike.port)
+
+ def test_download(self):
+ output = self.gdb.command("load")
+ self.assertNotIn("failed", output)
+ self.assertIn("Transfer rate", output)
+ self.gdb.command("b done")
+ self.gdb.c()
+ result = self.gdb.p("$a0")
+ self.assertEqual(self.crc, result)
+