Ejemplo n.º 1
0
    def test_get_property(self):
        property_file = StringIO('ro.vndk.version=example\n')
        ans = VNDKLibDir._get_property(property_file, 'ro.vndk.version')
        self.assertEqual('example', ans)

        property_file = StringIO('# comments\n')
        ans = VNDKLibDir._get_property(property_file, 'ro.vndk.version')
        self.assertEqual(None, ans)
Ejemplo n.º 2
0
    def test_load_from_csv_with_header(self):
        fp = StringIO('Path,Tag\nliba.so,fwk-only\n')
        d = TaggedPathDict()
        d.load_from_csv(fp)
        self.assertIn('liba.so', d.fwk_only)

        fp = StringIO('Tag,Path\nfwk-only,liba.so\n')
        d = TaggedPathDict()
        d.load_from_csv(fp)
        self.assertIn('liba.so', d.fwk_only)
Ejemplo n.º 3
0
 def get(self, f, file_name='', width=None, height=None):
     # ZipFile requires seek:
     if not isinstance(f, basestring) and not hasattr(f, 'seek'):
         d = StringIO()
         shutil.copyfileobj(f, d)
         d.seek(0)
         f = d
     # Extract: 'Thumbnails/thumbnail.png'
     png = StringIO(zipfile.ZipFile(f, 'r').read('Thumbnails/thumbnail.png', 'r'))
     return super(OfficeBackend, self).get(png, width=width, height=height)
Ejemplo n.º 4
0
    def test_normalize_partition_tags_bad_vendor_deps(self):
        """Check whether normalize_partition_tags() hides the dependencies from
        the system partition to the vendor partition if the dependencies are
        not SP-HAL libraries."""

        gb = GraphBuilder()
        libfwk = gb.add_lib32(PT_SYSTEM, 'libfwk', dt_needed=['libvnd.so'])
        libvnd = gb.add_lib32(PT_VENDOR, 'libvnd')
        gb.resolve()

        self.assertIn(libvnd, libfwk.deps_needed)
        self.assertIn(libfwk, libvnd.users_needed)

        stderr = StringIO()
        with patch('sys.stderr', stderr):
            gb.graph.normalize_partition_tags(set(), None)

        self.assertRegex(
                stderr.getvalue(),
                'error: .*: system exe/lib must not depend on vendor lib .*.  '
                'Assume such dependency does not exist.')

        self.assertNotIn(libvnd, libfwk.deps_needed)
        self.assertNotIn(libfwk, libvnd.users_needed)

        self.assertIn(libvnd, libfwk.deps_needed_hidden)
        self.assertIn(libfwk, libvnd.users_needed_hidden)

        self.assertIn(libvnd, libfwk.deps_all)
        self.assertIn(libvnd, libfwk.deps_needed_all)
        self.assertNotIn(libvnd, libfwk.deps_good)

        self.assertIn(libfwk, libvnd.users_all)
        self.assertIn(libfwk, libvnd.users_needed_all)
        self.assertNotIn(libfwk, libvnd.users_good)
Ejemplo n.º 5
0
def run_level36():
    f = """\
4
    2 1 1 2
   3 3 3 . .
  2 3 3 . 4 .
 . 2 . 2 4 3 2
  2 2 . . . 2
   4 3 4 . .
    3 2 3 3
"""
    order = DESCENDING
    strategy = Done.FIRST_STRATEGY
    output = StringIO()
    solve_file(f, strategy, order, output)
    expected = """\
   3 4 3 2 
  3 4 4 . 3 
 2 . . 3 4 3 
2 . 1 . 3 . 2 
 3 3 . 2 . 2 
  3 . 2 . 2 
   2 2 . 1 
"""
    if output.getvalue() != expected:
        raise AssertionError("got a wrong answer:\n%s" % output.getvalue())
    def test_vndk_bad_vendor_deps(self):
        """Check the computation of vndk without generic references."""

        gb = GraphBuilder()
        libfwk = gb.add_lib32(PT_SYSTEM, 'libfwk')
        libvndk = gb.add_lib32(PT_SYSTEM,
                               'libvndk',
                               dt_needed=['libvnd_bad.so'],
                               extra_dir='vndk')
        libvndk_sp = gb.add_lib32(PT_SYSTEM,
                                  'libutils',
                                  dt_needed=['libvnd_bad.so'],
                                  extra_dir='vndk-sp')
        libvnd = gb.add_lib32(PT_VENDOR,
                              'libvnd',
                              dt_needed=['libvndk.so', 'libutils.so'])
        libvnd_bad = gb.add_lib32(PT_VENDOR, 'libvnd_bad', extra_dir='vndk-sp')
        gb.resolve()

        self.assertIn(libvnd_bad, libvndk.deps_all)
        self.assertIn(libvnd_bad, libvndk_sp.deps_all)

        with patch('sys.stderr', StringIO()):
            vndk_sets = gb.graph.compute_degenerated_vndk(None)

        self.assertNotIn(libvnd_bad, vndk_sets.vndk)
        self.assertNotIn(libvnd_bad, vndk_sets.vndk_sp)
Ejemplo n.º 7
0
    def test_dump(self):
        elf = ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB, 183, ['a'], ['b'],
                  ['libc.so', 'libm.so'], {'hello', 'world'}, {'d', 'e'})

        f = StringIO()
        elf.dump(f)
        actual_output = f.getvalue()

        self.assertEqual(
            'EI_CLASS\t32\n'
            'EI_DATA\t\tLittle-Endian\n'
            'E_MACHINE\tEM_AARCH64\n'
            'FILE_SIZE\t0\n'
            'RO_SEG_FILE_SIZE\t0\n'
            'RO_SEG_MEM_SIZE\t0\n'
            'RW_SEG_FILE_SIZE\t0\n'
            'RW_SEG_MEM_SIZE\t0\n'
            'DT_RPATH\ta\n'
            'DT_RUNPATH\tb\n'
            'DT_NEEDED\tlibc.so\n'
            'DT_NEEDED\tlibm.so\n'
            'EXP_SYMBOL\thello\n'
            'EXP_SYMBOL\tworld\n'
            'IMP_SYMBOL\td\n'
            'IMP_SYMBOL\te\n', actual_output)
Ejemplo n.º 8
0
    def setUp(self):
        self.tagged_paths = TaggedPathDict.create_from_csv(
            StringIO(_TEST_DATA))

        self.graph = MockELFGraph()

        self.lib_ll_ndk = self.graph.add('/system/lib/lib_ll_ndk.so')
        self.lib_ll_ndk_indirect = \
                self.graph.add('/system/lib/lib_ll_ndk_indirect.so')

        self.lib_vndk_sp = self.graph.add('/system/lib/lib_vndk_sp.so')
        self.lib_vndk_sp_indirect = \
                self.graph.add('/system/lib/lib_vndk_sp_indirect.so')
        self.lib_vndk_sp_indirect_private = \
                self.graph.add('/system/lib/lib_vndk_sp_indirect_private.so')

        self.lib_vndk = self.graph.add('/system/lib/lib_vndk.so')

        self.lib_fwk_only = self.graph.add('/system/lib/lib_fwk_only.so')
        self.lib_fwk_only_rs = self.graph.add('/system/lib/lib_fwk_only_rs.so')

        self.lib_sp_hal = self.graph.add('/vendor/lib/lib_sp_hal.so')
        self.lib_sp_hal_dep = self.graph.add('/vendor/lib/lib_sp_hal_dep.so')

        self.lib_vnd_only = self.graph.add('/vendor/lib/lib_vnd_only.so')

        self.tagged_libs = TaggedLibDict.create_from_graph(
            self.graph, self.tagged_paths)
Ejemplo n.º 9
0
    def test_shouldReportParseErrors(self):
        output = StringIO()

        report_parse_error(output, path.join(pardir, 'foo', 'myprog.py'),
                           ParseError('the message'))

        self.assertEqual(output.getvalue(),
                         'myprog: parse error: the message\n')
Ejemplo n.º 10
0
    def test_dump_exported_symbols(self):
        elf = ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB, 183, 'a', 'b',
                  ['libc.so', 'libm.so'], ['hello', 'world'])

        with StringIO() as f:
            elf.dump_exported_symbols(f)
            actual_output = f.getvalue()

        self.assertEqual('hello\nworld\n', actual_output)
Ejemplo n.º 11
0
 def get(self, f, file_name='', width=None, height=None):
     width = width or self.width
     height = height or self.height
     image = Image.open(f)
     image.thumbnail((width, height), Image.ANTIALIAS)
     thumb = StringIO()
     image.save(thumb, 'png')
     thumb.seek(0)
     return thumb
Ejemplo n.º 12
0
    def _get_stream(self):
        self._is_file = False
        if isinstance(self.dotenv_path, StringIO):
            return self.dotenv_path

        if os.path.exists(self.dotenv_path):
            self._is_file = True
            return open(self.dotenv_path)

        if self.verbose:
            warnings.warn("File doesn't exist {}".format(self.dotenv_path))

        return StringIO('')
Ejemplo n.º 13
0
    def test_add_dlopen_deps_error(self):
        gb = GraphBuilder()
        liba = gb.add_lib32(PT_SYSTEM, 'liba')
        libb = gb.add_lib32(PT_SYSTEM, 'libb')
        gb.resolve()

        with tempfile.NamedTemporaryFile(mode='w') as tmp_file:
            tmp_file.write('/system/lib/libc.so: /system/lib/libd.so')
            tmp_file.seek(0)

            stderr = StringIO()
            with patch('sys.stderr', stderr):
                gb.graph.add_dlopen_deps(tmp_file.name)

            self.assertRegexpMatches(
                stderr.getvalue(), 'error:' + re.escape(tmp_file.name) +
                ':1: ' + 'Failed to add dlopen dependency from .* to .*\\.\n')
Ejemplo n.º 14
0
 def get(self, f, file_name='', width=None, height=None):
     args = list(GS_ARGS)
     if not isinstance(f, basestring):
         if hasattr(f, 'name'):
             f = f.name
         else:
             # Convert a file-like object to a file on disk.
             t = tempfile.NamedTemporaryFile(suffix='.pdf')
             try:
                 shutil.copyfileobj(f, t)
                 t.flush()
             finally:
                 f.close()
             f = t.name
     args.append(f)
     stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
     return super(PdfBackend, self).get(StringIO(stdout), width=width, height=height)
Ejemplo n.º 15
0
    def test_get_path_tag(self):
        fp = StringIO(_TEST_DATA)
        d = TaggedPathDict()
        d.load_from_csv(fp)

        self.assertEqual('ll_ndk', d.get_path_tag('/system/lib/lib_ll_ndk.so'))
        self.assertEqual('ll_ndk_indirect',
                         d.get_path_tag('/system/lib/lib_ll_ndk_indirect.so'))
        self.assertEqual('sp_ndk', d.get_path_tag('/system/lib/lib_sp_ndk.so'))
        self.assertEqual('sp_ndk_indirect',
                         d.get_path_tag('/system/lib/lib_sp_ndk_indirect.so'))
        self.assertEqual('vndk_sp',
                         d.get_path_tag('/system/lib/lib_vndk_sp.so'))
        self.assertEqual('vndk_sp_indirect',
                         d.get_path_tag('/system/lib/lib_vndk_sp_indirect.so'))
        self.assertEqual(
                'vndk_sp_indirect_private',
                d.get_path_tag('/system/lib/lib_vndk_sp_indirect_private.so'))
        self.assertEqual('vndk', d.get_path_tag('/system/lib/lib_vndk.so'))
        self.assertEqual('fwk_only',
                         d.get_path_tag('/system/lib/lib_fwk_only.so'))
        self.assertEqual('fwk_only_rs',
                         d.get_path_tag('/system/lib/lib_fwk_only_rs.so'))
        self.assertEqual('sp_hal',
                         d.get_path_tag('/vendor/lib/lib_sp_hal.so'))
        self.assertEqual('sp_hal_dep',
                         d.get_path_tag('/vendor/lib/lib_sp_hal_dep.so'))
        self.assertEqual('vnd_only',
                         d.get_path_tag('/vendor/lib/lib_vnd_only.so'))
        self.assertEqual('remove',
                         d.get_path_tag('/system/lib/lib_remove.so'))

        # Aliases
        self.assertEqual('fwk_only',
                         d.get_path_tag('/system/lib/lib_hl_ndk.so'))
        self.assertEqual('vndk_sp',
                         d.get_path_tag('/system/lib/lib_vndk_sp_hal.so'))
        self.assertEqual('vndk_sp',
                         d.get_path_tag('/system/lib/lib_vndk_sp_both.so'))
        self.assertEqual('vndk',
                         d.get_path_tag('/system/lib/lib_vndk_indirect.so'))

        # Unmatched paths
        self.assertEqual('fwk_only', d.get_path_tag('/system/lib/unknown.so'))
        self.assertEqual('fwk_only', d.get_path_tag('/data/lib/unknown.so'))
        self.assertEqual('vnd_only', d.get_path_tag('/vendor/lib/unknown.so'))
Ejemplo n.º 16
0
    def test_dump(self):
        elf = ELF(ELF.ELFCLASS32, ELF.ELFDATA2LSB, 183, 'a', 'b',
                  ['libc.so', 'libm.so'], ['hello', 'world'])

        with StringIO() as f:
            elf.dump(f)
            actual_output = f.getvalue()

        self.assertEqual(
            'EI_CLASS\t32\n'
            'EI_DATA\t\tLittle-Endian\n'
            'E_MACHINE\tEM_AARCH64\n'
            'DT_RPATH\ta\n'
            'DT_RUNPATH\tb\n'
            'DT_NEEDED\tlibc.so\n'
            'DT_NEEDED\tlibm.so\n'
            'SYMBOL\t\thello\n'
            'SYMBOL\t\tworld\n', actual_output)
Ejemplo n.º 17
0
    def test_add_dlopen_deps_regex(self):
        gb = GraphBuilder()
        liba = gb.add_lib32(PT_SYSTEM, 'liba')
        libb = gb.add_lib32(PT_SYSTEM, 'libb')
        gb.resolve()

        with tempfile.NamedTemporaryFile(mode='w') as tmp_file:
            tmp_file.write('[regex].*libb\\.so: [regex].*/${LIB}/liba\\.so')
            tmp_file.seek(0)

            stderr = StringIO()
            with patch('sys.stderr', stderr):
                gb.graph.add_dlopen_deps(tmp_file.name)

            self.assertEqual('', stderr.getvalue())

        self.assertIn(liba, libb.deps_dlopen)
        self.assertIn(libb, liba.users_dlopen)
Ejemplo n.º 18
0
    def test_add_dlopen_deps_lib_subset_single_bitness(self):
        gb = GraphBuilder()
        liba_32, liba_64 = gb.add_multilib(PT_SYSTEM, 'liba')
        libb_32 = gb.add_lib32(PT_SYSTEM, 'libb')
        gb.resolve()

        with tempfile.NamedTemporaryFile(mode='w') as tmp_file:
            tmp_file.write('/system/${LIB}/libb.so: /system/${LIB}/liba.so')
            tmp_file.seek(0)

            stderr = StringIO()
            with patch('sys.stderr', stderr):
                gb.graph.add_dlopen_deps(tmp_file.name)

            self.assertEqual('', stderr.getvalue())

        self.assertIn(liba_32, libb_32.deps_dlopen)
        self.assertIn(libb_32, liba_32.users_dlopen)

        self.assertEqual(0, len(liba_64.users_dlopen))
Ejemplo n.º 19
0
 def _extract_error(self, type, err, tb):
     file = StringIO()
     traceback.print_exception(type, err, tb, None, file)
     return file.getvalue()
Ejemplo n.º 20
0
 def test_load_from_csv_empty(self):
     try:
         TaggedPathDict().load_from_csv(StringIO(''))
     except StopIteration:
         self.fail('empty file should be considered as a valid input')
Ejemplo n.º 21
0
def gunzip(text):
    buf = StringIO(text)
    f = gzip.GzipFile(fileobj=buf)
    return f.read()
Ejemplo n.º 22
0
 def assertASTShows(self, ast, string):
     showbuf = StringIO()
     ast.show(buf=showbuf, nodenames=True, attrnames=True)
     self.assertEqual(showbuf.getvalue(), string)
Ejemplo n.º 23
0
 def __init__(self):
     self.closed = 0
     self.stream = StringIO()
Ejemplo n.º 24
0
def make_editor_icons_action(target, source, env):

    dst = target[0]
    svg_icons = source

    icons_string = StringIO()

    for f in svg_icons:

        fname = str(f)

        icons_string.write('\t"')

        with open(fname, 'rb') as svgf:
            b = svgf.read(1)
            while (len(b) == 1):
                icons_string.write("\\" + str(hex(ord(b)))[1:])
                b = svgf.read(1)

        icons_string.write('"')
        if fname != svg_icons[-1]:
            icons_string.write(",")
        icons_string.write('\n')

    s = StringIO()
    s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
    s.write("#ifndef _EDITOR_ICONS_H\n")
    s.write("#define _EDITOR_ICONS_H\n")
    s.write("static const int editor_icons_count = {};\n".format(
        len(svg_icons)))
    s.write("static const char *editor_icons_sources[] = {\n")
    s.write(icons_string.getvalue())
    s.write('};\n\n')
    s.write("static const char *editor_icons_names[] = {\n")

    # this is used to store the indices of thumbnail icons
    thumb_medium_indices = []
    thumb_big_indices = []
    index = 0
    for f in svg_icons:

        fname = str(f)

        # Trim the `.svg` extension from the string.
        icon_name = os.path.basename(fname)[:-4]
        # some special cases
        if icon_name.endswith(
                "MediumThumb"):  # don't know a better way to handle this
            thumb_medium_indices.append(str(index))
        if icon_name.endswith(
                "BigThumb"):  # don't know a better way to handle this
            thumb_big_indices.append(str(index))

        s.write('\t"{0}"'.format(icon_name))

        if fname != svg_icons[-1]:
            s.write(",")
        s.write('\n')

        index += 1

    s.write('};\n')

    if thumb_medium_indices:
        s.write("\n\n")
        s.write("static const int editor_md_thumbs_count = {};\n".format(
            len(thumb_medium_indices)))
        s.write("static const int editor_md_thumbs_indices[] = {")
        s.write(", ".join(thumb_medium_indices))
        s.write("};\n")
    if thumb_big_indices:
        s.write("\n\n")
        s.write("static const int editor_bg_thumbs_count = {};\n".format(
            len(thumb_big_indices)))
        s.write("static const int editor_bg_thumbs_indices[] = {")
        s.write(", ".join(thumb_big_indices))
        s.write("};\n")

    s.write("#endif\n")

    with open(dst, "w") as f:
        f.write(s.getvalue())

    s.close()
    icons_string.close()
Ejemplo n.º 25
0
 def prepare_lines(ih):
     sio = StringIO()
     ih.dump(sio)
     dump = sio.getvalue()
     lines = dump.splitlines()
     return lines
Ejemplo n.º 26
0
 def test_load_from_csv_without_header(self):
     fp = StringIO('liba.so,fwk-only\n')
     d = TaggedPathDict()
     d.load_from_csv(fp)
     self.assertIn('liba.so', d.fwk_only)
Ejemplo n.º 27
0
 def setUp(self):
     self.hBuffer = StringIO()
Ejemplo n.º 28
0
 def test_load_from_csv_tags(self):
     fp = StringIO(_TEST_DATA)
     d = TaggedPathDict()
     d.load_from_csv(fp)
     self._check_test_data_loaded(d)
Ejemplo n.º 29
0
 def test_create_from_csv(self):
     d = TaggedPathDict.create_from_csv(StringIO(_TEST_DATA))
     self._check_test_data_loaded(d)
Ejemplo n.º 30
0
    def test_is_path_visible(self):
        fp = StringIO(_TEST_DATA)
        d = TaggedPathDict()
        d.load_from_csv(fp)

        # Collect path universe set.
        all_paths = set()
        for tag in TaggedPathDict.TAGS:
            all_paths |= getattr(d, tag)
        all_paths -= _TEST_DATA_ALIAS_PATHS

        # LL-NDK
        from_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_ll_ndk_indirect.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_ll_ndk_indirect.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)

        # VNDK-SP
        from_paths = {
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk_sp_indirect.so',
            '/system/lib/lib_vndk_sp_indirect_private.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk_sp_indirect.so',
            '/system/lib/lib_vndk_sp_indirect_private.so',
            '/system/lib/lib_fwk_only_rs.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)

        # VNDK
        from_paths = {
            '/system/lib/lib_vndk.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk_sp_indirect.so',
            '/system/lib/lib_vndk.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)

        # FWK-ONLY
        from_paths = {
            '/system/lib/lib_fwk_only.so',
            '/system/lib/lib_fwk_only_rs.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_ll_ndk_indirect.so',
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk_sp_indirect.so',
            '/system/lib/lib_vndk_sp_indirect_private.so',
            '/system/lib/lib_vndk.so',
            '/system/lib/lib_fwk_only.so',
            '/system/lib/lib_fwk_only_rs.so',
            '/vendor/lib/lib_sp_hal.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)

        # SP-HAL
        from_paths = {
            '/vendor/lib/lib_sp_hal.so',
            '/vendor/lib/lib_sp_hal_dep.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_vndk_sp.so',
            '/vendor/lib/lib_sp_hal.so',
            '/vendor/lib/lib_sp_hal_dep.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)

        # VND-ONLY
        from_paths = {
            '/vendor/lib/lib_vnd_only.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk_sp_indirect.so',
            '/system/lib/lib_vndk.so',
            '/vendor/lib/lib_sp_hal.so',
            '/vendor/lib/lib_sp_hal_dep.so',
            '/vendor/lib/lib_vnd_only.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)