Beispiel #1
0
class TestFirmware(unittest.TestCase):
    """Test cases for firmware."""
    
    @classmethod
    def setUpClass(cls):
        # create firmware file
        filename = "tmpdeadbeaf.bin"
        cls._files = [filename]
        with open(filename, "wb") as firmware_file:
            firmware_file.write(header)
            for sec in sections:
                firmware_file.write(sec)
            firmware_file.write(footer)
    
    @classmethod
    def tearDownClass(cls):
        # delete firmware file
        for filename in cls._files:
            os.remove(filename)
    
    def setUp(self):
        # open firmware
        self._fw = Firmware()
        self._fw.load_from_file(self._files[0])
    
    def test_save(self):
        """Test saving to file"""
        
        # save firmware
        filename = "tmpsave.bin"
        self._fw.save(filename)
        
        # compare files
        assertFileEqual(self, self._files[0], filename, 
            "saved firmware differs from loaded firmware")
        
        # delete saved file
        os.remove(filename)
        
    def test_get_section_data(self):
        """Test access to section data."""
        for i in xrange(len(sections)):
            self.assertSequenceEqual(self._fw.get_section(i).get_all(), 
                sections[i], 
                "%s returned incorrect" % section_index_to_name(i))
    
    def test_find_pattern(self):
        """Test pattern matching."""
        for pattern, offset, expected in pattern_search:
            res = self._fw.find_pattern(pattern, offset)
            self.assertEqual(res, expected, 
                "got %s, but expected %s" % (res, expected))
    
    def test_get_last_free_chunk(self):
        """Test computation of last free chunk."""
        for i in xrange(len(sections)):
            self.assertEqual(self._fw.get_last_free_chunk(i),
                free_chunks[i],
                "free chunk wrong for %s" % section_index_to_name(i))
Beispiel #2
0
class TestFirmware(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # create firmware file
        filename = "tmpdeadbeaf.bin"
        cls._files = [filename]
        with open(filename, "wb") as firmware_file:
            firmware_file.write(header)
            for sec in sections:
                firmware_file.write(sec)
            firmware_file.write(footer)
    
    @classmethod
    def tearDownClass(cls):
        # delete firmware file
        for filename in cls._files:
            os.remove(filename)
    
    def setUp(self):
        # open firmware
        self._fw = Firmware()
        self._fw.load_from_file(self._files[0])
    
    def test_save(self):
        # save firmware
        filename = "tmpsave.bin"
        self._fw.save(filename)
        
        # compare files
        assertFileEqual(self, self._files[0], filename, 
            "saved firmware differs from loaded firmware")
        
        # delete saved file
        os.remove(filename)
        
    def test_get_section_data(self):
        for i in xrange(len(sections)):
            self.assertSequenceEqual(self._fw.get_section(i).get_all(), 
                sections[i], 
                "%s returned incorrect" % section_index_to_name(i))
    
    def test_find_pattern(self):
        for pattern, offset, expected in pattern_search:
            res = self._fw.find_pattern(pattern, offset)
            self.assertEqual(res, expected, 
                "got %s, but expected %s" % (res, expected))
    
    def test_get_last_free_chunk(self):
        for i in xrange(len(sections)):
            self.assertEqual(self._fw.get_last_free_chunk(i),
                free_chunks[i],
                "free chunk wrong for %s" % section_index_to_name(i))
Beispiel #3
0
 def setUp(self):
     # open firmware
     self._fw = Firmware()
     self._fw.load_from_file(self._files[0])
Beispiel #4
0
 def setUp(self):
     # open firmware
     self._fw = Firmware()
     self._fw.load_from_file(self._files[0])