コード例 #1
0
 def test_random_read(self):
     '''
     Test a reading from a random sample, with a random size and a random
     start address
     '''
     sample = random.sample(self.samples, 1)[0]
     self.opts.filename = sample
     self.assertTrue(os.path.exists(sample))
     sample_size = os.path.getsize(sample)
     self.opts.address = random.randrange(sample_size)
     size_range = sample_size - self.opts.address
     self.opts.size = random.randrange(size_range)
     sys.stdout = StringIO()  # Suppress output
     device, memsize = interface.initialize(self.opts, self.module)
     memspace = memory.MemorySpace(device, memsize)
     dump.run(self.opts, memspace)
     sys.stdout = sys.__stdout__  # Restore output
     output_fn = dump.filename
     self.assertTrue(os.path.exists(output_fn))
     md5 = hashlib.md5()
     f = open(sample, 'rb')
     f.seek(self.opts.address)
     read = f.read(self.opts.size)
     md5.update(read)
     self.assertEqual(md5.digest(), self.file_md5(output_fn))
     f.close()
コード例 #2
0
 def test_fulldump(self):
     for sample in self.samples:
         self.opts.interface = 'file'
         self.opts.filename = sample
         sys.stdout = StringIO()  # Suppress output
         device, memsize = interface.initialize(self.opts, self.module)
         memspace = memory.MemorySpace(device, memsize)
         dump.run(self.opts, memspace)
         sys.stdout = sys.__stdout__  # Restore output
         output_fn = dump.filename
         self.assertTrue(os.path.exists(output_fn))
         self.assertEqual(self.file_md5(sample), self.file_md5(output_fn))