Exemple #1
0
    def test_cbfs_bad_attribute(self):
        """Check handling of bad attribute tag"""
        if not self.have_lz4:
            self.skipTest('lz4 --no-frame-crc not available')
        size = 0x140
        cbw = CbfsWriter(size)
        cbw.add_file_raw('u-boot',
                         COMPRESS_DATA,
                         None,
                         compress=cbfs_util.COMPRESS_LZ4)
        data = cbw.get_data()

        # Search the CBFS for the expected compression tag
        with io.BytesIO(data) as fd:
            while True:
                pos = fd.tell()
                tag, = struct.unpack('>I', fd.read(4))
                if tag == cbfs_util.FILE_ATTR_TAG_COMPRESSION:
                    break

        # Create a new CBFS with the tag changed to something invalid
        newdata = data[:pos] + struct.pack('>I', 0x123) + data[pos + 4:]
        with test_util.capture_sys_output() as (stdout, _stderr):
            cbfs_util.CbfsReader(newdata)
        self.assertEqual('Unknown attribute tag 123\n', stdout.getvalue())
Exemple #2
0
    def test_cbfs_missing_attribute(self):
        """Check handling of an incomplete attribute tag"""
        if not self.have_lz4:
            self.skipTest('lz4 --no-frame-crc not available')
        size = 0x140
        cbw = CbfsWriter(size)
        cbw.add_file_raw('u-boot',
                         COMPRESS_DATA,
                         None,
                         compress=cbfs_util.COMPRESS_LZ4)
        data = cbw.get_data()

        # Read in the CBFS master header (only), then stop
        cbr = cbfs_util.CbfsReader(data, read=False)
        with io.BytesIO(data) as fd:
            self.assertTrue(cbr._find_and_read_header(fd, len(data)))
            pos = fd.tell()

        # Create a new CBFS with only the first 4 bytes of the compression tag,
        # then try to read the file
        tag_pos = pos + cbfs_util.FILE_HEADER_LEN + cbfs_util.FILENAME_ALIGN
        newdata = data[:tag_pos + 4]
        with test_util.capture_sys_output() as (stdout, _stderr):
            with io.BytesIO(newdata) as fd:
                fd.seek(pos)
                self.assertEqual(False, cbr._read_next_file(fd))
        self.assertIn('Attribute tag at %x ran out of data' % tag_pos,
                      stdout.getvalue())
Exemple #3
0
 def testToolchainDownload(self):
     """Test that we can download toolchains"""
     if use_network:
         with test_util.capture_sys_output() as (stdout, stderr):
             url = self.toolchains.LocateArchUrl('arm')
         self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
                 'crosstool/files/bin/x86_64/.*/'
                 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz')
Exemple #4
0
 def testToolchainDownload(self):
     """Test that we can download toolchains"""
     if use_network:
         with test_util.capture_sys_output() as (stdout, stderr):
             url = self.toolchains.LocateArchUrl('arm')
         self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
                 'crosstool/files/bin/x86_64/.*/'
                 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz')
Exemple #5
0
 def testMissingSymbolOptional(self):
     image = Image('name', 'node', test=True)
     image._entries = {}
     with capture_sys_output() as (stdout, stderr):
         val = image.LookupSymbol('_binman_type_prop_pname', True, 'msg', 0)
     self.assertEqual(val, None)
     self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
                      stderr.getvalue())
     self.assertEqual('', stdout.getvalue())
Exemple #6
0
 def testDebug(self):
     elf.debug = True
     entry = FakeEntry(20)
     section = FakeSection()
     elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
     with test_util.capture_sys_output() as (stdout, stderr):
         syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
     elf.debug = False
     self.assertTrue(len(stdout.getvalue()) > 0)
Exemple #7
0
 def testDebug(self):
     """Check that enabling debug in the elf module produced debug output"""
     elf.debug = True
     entry = FakeEntry(20)
     section = FakeSection()
     elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
     with test_util.capture_sys_output() as (stdout, stderr):
         syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
     elf.debug = False
     self.assertTrue(len(stdout.getvalue()) > 0)
Exemple #8
0
 def testMissingSymbolOptional(self):
     image = Image('name', 'node', test=True)
     section = image._section
     section._entries = {}
     with capture_sys_output() as (stdout, stderr):
         val = section.LookupSymbol('_binman_type_prop_pname', True, 'msg')
     self.assertEqual(val, None)
     self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
                      stderr.getvalue())
     self.assertEqual('', stdout.getvalue())
Exemple #9
0
 def testDebug(self):
     """Check that enabling debug in the elf module produced debug output"""
     try:
         tout.Init(tout.DEBUG)
         entry = FakeEntry(20)
         section = FakeSection()
         elf_fname = self.ElfTestFile('u_boot_binman_syms')
         with test_util.capture_sys_output() as (stdout, stderr):
             syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
         self.assertTrue(len(stdout.getvalue()) > 0)
     finally:
         tout.Init(tout.WARNING)
Exemple #10
0
    def test_cbfs_debug(self):
        """Check debug output"""
        size = 0x70
        cbw = CbfsWriter(size)
        cbw.add_file_raw('u-boot', U_BOOT_DATA)
        data = cbw.get_data()

        try:
            cbfs_util.DEBUG = True
            with test_util.capture_sys_output() as (stdout, _stderr):
                cbfs_util.CbfsReader(data)
            self.assertEqual('name u-boot\ndata %s\n' % U_BOOT_DATA,
                             stdout.getvalue())
        finally:
            cbfs_util.DEBUG = False
Exemple #11
0
    def test_cbfs_bad_header(self):
        """Check handling of a bad master header"""
        size = 0x70
        cbw = CbfsWriter(size)
        cbw.add_file_raw('u-boot', U_BOOT_DATA)
        data = cbw.get_data()

        # Drop most of the header and try reading the modified CBFS
        newdata = data[:cbw._header_offset + 4]

        with test_util.capture_sys_output() as (stdout, _stderr):
            with self.assertRaises(ValueError) as e:
                cbfs_util.CbfsReader(newdata)
        self.assertIn('Relative offset seems wrong', stdout.getvalue())
        self.assertIn('Cannot find master header', str(e.exception))
Exemple #12
0
    def test_cbfs_bad_header_ptr(self):
        """Check handling of a bad master-header pointer"""
        size = 0x70
        cbw = CbfsWriter(size)
        cbw.add_file_raw('u-boot', U_BOOT_DATA)
        data = cbw.get_data()

        # Add one to the pointer to make it invalid
        newdata = data[:-4] + struct.pack('<I', cbw._header_offset + 1)

        # We should still be able to find the master header by searching
        with test_util.capture_sys_output() as (stdout, _stderr):
            cbfs = cbfs_util.CbfsReader(newdata)
        self.assertIn('Relative offset seems wrong', stdout.getvalue())
        self.assertIn('u-boot', cbfs.files)
        self.assertEqual(size, cbfs.rom_size)
Exemple #13
0
 def test_cbfstool_failure(self):
     """Test failure to run cbfstool"""
     if not self.have_cbfstool:
         self.skipTest('No cbfstool available')
     try:
         # In verbose mode this test fails since stderr is not captured. Fix
         # this by turning off verbosity.
         old_verbose = cbfs_util.VERBOSE
         cbfs_util.VERBOSE = False
         with test_util.capture_sys_output() as (_stdout, stderr):
             with self.assertRaises(Exception) as e:
                 cbfs_util.cbfstool('missing-file', 'bad-command')
     finally:
         cbfs_util.VERBOSE = old_verbose
     self.assertIn('Unknown command', stderr.getvalue())
     self.assertIn('Failed to run', str(e.exception))
Exemple #14
0
    def test_cbfs_bad_file_header(self):
        """Check handling of a bad file header"""
        size = 0x70
        cbw = CbfsWriter(size)
        cbw.add_file_raw('u-boot', U_BOOT_DATA)
        data = cbw.get_data()

        # Read in the CBFS master header (only), then stop
        cbr = cbfs_util.CbfsReader(data, read=False)
        with io.BytesIO(data) as fd:
            self.assertTrue(cbr._find_and_read_header(fd, len(data)))
            pos = fd.tell()

        # Remove all but 4 bytes of the file headerm and try to read the file
        newdata = data[:pos + 4]
        with test_util.capture_sys_output() as (stdout, _stderr):
            with io.BytesIO(newdata) as fd:
                fd.seek(pos)
                self.assertEqual(False, cbr._read_next_file(fd))
        self.assertIn('File header at 0x0 ran out of data', stdout.getvalue())
    def test_cbfs_bad_file_string(self):
        """Check handling of an incomplete filename string"""
        size = 0x70
        cbw = CbfsWriter(size)
        cbw.add_file_raw('16-characters xx', U_BOOT_DATA)
        data = cbw.get_data()

        # Read in the CBFS master header (only), then stop
        cbr = cbfs_util.CbfsReader(data, read=False)
        with io.BytesIO(data) as fd:
            self.assertTrue(cbr._find_and_read_header(fd, len(data)))
            pos = fd.tell()

        # Create a new CBFS with only the first 16 bytes of the file name, then
        # try to read the file
        newdata = data[:pos + cbfs_util.FILE_HEADER_LEN + 16]
        with test_util.capture_sys_output() as (stdout, _stderr):
            with io.BytesIO(newdata) as fd:
                fd.seek(pos)
                self.assertEqual(False, cbr._read_next_file(fd))
        self.assertIn('String at %#x ran out of data' %
                      cbfs_util.FILE_HEADER_LEN, stdout.getvalue())
Exemple #16
0
 def testStdout(self):
     """Test output to stdout"""
     dtb_file = get_dtb_file('dtoc_test_simple.dts')
     with test_util.capture_sys_output() as (stdout, stderr):
         dtb_platdata.run_steps(['struct'], dtb_file, False, '-')
Exemple #17
0
 def testStdout(self):
     """Test output to stdout"""
     dtb_file = get_dtb_file('dtoc_test_simple.dts')
     with test_util.capture_sys_output() as (stdout, stderr):
         dtb_platdata.run_steps(['struct'], dtb_file, False, '-')