Exemple #1
0
def test_get_section2():
    img = Image(join=True)
    img.insert_section(data=range(16), start_address=0x030)
    img.insert_section(data=range(16), start_address=0x020)
    img.insert_section(data=range(16), start_address=0x010)
    img.insert_section(data=range(16), start_address=0x000)
    sec = img.get_section(0x33)
    assert sec.start_address == 0x00
    assert len(sec) == 64
 def createImage(self, record_type, s5record, start_address=None):
     image = Image()
     image.insert_section(range(10), 0x1000)
     image.join_sections()
     return dumps("srec",
                  image,
                  record_type=record_type,
                  s5record=s5record,
                  start_address=start_address)
 def testLoadsWorks(self):
     image = Image()
     image.insert_section(
         "Wow! Did you really go through al that trouble to read this?",
         0xb000)
     image.join_sections()
     self.assertEqual(
         dumps("srec",
               image,
               record_type=1,
               s5record=False,
               start_address=0x0000), SREC1)
Exemple #4
0
def test_get_section_raises(join):
    img = Image(join=join)
    img.insert_section(data=range(10), start_address=0x030)
    img.insert_section(data=range(10), start_address=0x020)
    img.insert_section(data=range(10), start_address=0x010)
    img.insert_section(data=range(10), start_address=0x000)
    with pytest.raises(InvalidAddressError):
        sec = img.get_section(0x3a)
    with pytest.raises(InvalidAddressError):
        sec = img.get_section(0x2b)
    with pytest.raises(InvalidAddressError):
        sec = img.get_section(0x1c)
    with pytest.raises(InvalidAddressError):
        sec = img.get_section(0x0d)
Exemple #5
0
def test_get_section1():
    img = Image(join=False)
    img.insert_section(data=range(16), start_address=0x030)
    img.insert_section(data=range(16), start_address=0x020)
    img.insert_section(data=range(16), start_address=0x010)
    img.insert_section(data=range(16), start_address=0x000)
    sec = img.get_section(0x33)
    assert sec.start_address == 0x30
    sec = img.get_section(0x22)
    assert sec.start_address == 0x20
    sec = img.get_section(0x11)
    assert sec.start_address == 0x10
    sec = img.get_section(0x02)
    assert sec.start_address == 0x00
Exemple #6
0
class TestHexfile(unittest.TestCase):
    def setUp(self):
        self.image = Image()

    def tearDown(self):
        del self.image

    def testAddSectionAliasWorks(self):
        self.image.insert_section(range(64), 0x1000)
        # Ok, if no exception gets raised.

    def testRaisesInvalidChecksumError(self):
        self.assertRaises(hexfile.InvalidRecordChecksumError, loads, "srec",
                          b'S110000048656C6C6F2C20776F726C6421AA')

    def testRaisesError(self):
        #        self.assertRaises(hexfile.InvalidRecordChecksumError, loads, "srec", b'S110000048656C6C6F20776F726C642166')
        pass
Exemple #7
0
def test_sorting8(capsys):
    RES = """
Section #0000
-------------
00000000  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f  |................|
          *
00000030  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f  |................|
---------------
       64 bytes
---------------
"""
    img = Image(join=True)
    img.insert_section(data=range(16), start_address=0x030)
    img.insert_section(data=range(16), start_address=0x020)
    img.insert_section(data=range(16), start_address=0x010)
    img.insert_section(data=range(16), start_address=0x000)
    img.hexdump(sys.stdout)
    captured = capsys.readouterr()
    assert captured.out == RES
Exemple #8
0
 def testImageRepresentation(self):
     image = Image()
     image.insert_section([x % 256 for x in range(10000)])
     image.join_sections()
     self.assertEqual(repr(image), RESULT)
Exemple #9
0
def test_sorting2(capsys):
    RES = """
Section #0000
-------------
00000010  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0001
-------------
00000020  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0002
-------------
00000030  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0003
-------------
00000040  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0004
-------------
00000050  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0005
-------------
00000060  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0006
-------------
00000070  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0007
-------------
00000080  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0008
-------------
00000090  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------

Section #0009
-------------
00000100  30 31 32 33 34 35 36 37 38 39                    |0123456789      |
---------------
       10 bytes
---------------
"""
    img = Image(join=False)
    img.insert_section(data=b"0123456789", start_address=0x100)
    img.insert_section(data=b"0123456789", start_address=0x090)
    img.insert_section(data=b"0123456789", start_address=0x080)
    img.insert_section(data=b"0123456789", start_address=0x070)
    img.insert_section(data=b"0123456789", start_address=0x060)
    img.insert_section(data=b"0123456789", start_address=0x050)
    img.insert_section(data=b"0123456789", start_address=0x040)
    img.insert_section(data=b"0123456789", start_address=0x030)
    img.insert_section(data=b"0123456789", start_address=0x020)
    img.insert_section(data=b"0123456789", start_address=0x010)
    img.hexdump(sys.stdout)
    captured = capsys.readouterr()
    assert captured.out == RES