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.assertRegexpMatches(
                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)
Exemple #2
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)
    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)
    def test_serialize_data_with_all_deps(self):
        """compute_degenerated_vndk() should not remove bad dependencies from
        the output of deps-insight.  This test checks the existance of bad
        dependencies."""

        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()

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

        self.assertNotIn(libvnd_bad, libvndk.deps_good)
        self.assertNotIn(libvnd_bad, libvndk_sp.deps_good)

        strs, mods = DepsInsightCommand.serialize_data(
                list(gb.graph.all_libs()), vndk_sets, ModuleInfo())

        deps = self._get_module_deps(strs, mods, libvndk.path)
        self.assertIn(libvnd_bad.path, deps)

        deps = self._get_module_deps(strs, mods, libvndk_sp.path)
        self.assertIn(libvnd_bad.path, deps)

        users = self._get_module_users(strs, mods, libvnd_bad.path)
        self.assertIn(libvndk.path, users)
        self.assertIn(libvndk_sp.path, users)
    def test_normalize_partition_tags_sp_hal(self):
        """Check whether normalize_partition_tags() keep dependencies to SP-HAL
        libraries as-is."""

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

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

        gb.graph.normalize_partition_tags({libsphal}, None)

        # SP-HALs should be kept as-is.
        self.assertIn(libsphal, libfwk.deps_needed)
        self.assertIn(libfwk, libsphal.users_needed)
Exemple #6
0
    def test_normalize_partition_tags_sp_hal(self):
        """Check whether normalize_partition_tags() keep dependencies to SP-HAL
        libraries as-is."""

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

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

        gb.graph.normalize_partition_tags({libsphal}, None)

        # SP-HALs should be kept as-is.
        self.assertIn(libsphal, libfwk.deps_needed)
        self.assertIn(libfwk, libsphal.users_needed)
    def test_vndk(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', extra_dir='vndk')
        libvndk_sp = gb.add_lib32(PT_SYSTEM, 'libutils', extra_dir='vndk-sp')
        libvnd = gb.add_lib32(PT_VENDOR, 'libvnd',
                              dt_needed=['libvndk.so', 'libutils.so'])
        gb.resolve()

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

        vndk_sets = gb.graph.compute_degenerated_vndk(None)

        self.assertIn(libvndk, vndk_sets.vndk)
        self.assertIn(libvndk_sp, vndk_sets.vndk_sp)
Exemple #8
0
    def test_vndk(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', extra_dir='vndk')
        libvndk_sp = gb.add_lib32(PT_SYSTEM, 'libutils', extra_dir='vndk-sp')
        libvnd = gb.add_lib32(PT_VENDOR, 'libvnd',
                              dt_needed=['libvndk.so', 'libutils.so'])
        gb.resolve()

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

        vndk_sets = gb.graph.compute_degenerated_vndk(None)

        self.assertIn(libvndk, vndk_sets.vndk)
        self.assertIn(libvndk_sp, vndk_sets.vndk_sp)
    def test_sp_ndk_indirect_without_sp_hal(self):
        """Check the computation of sp_ndk_indirect excludes sp_hal."""

        gb = GraphBuilder()
        libEGL = gb.add_lib32(PT_SYSTEM, 'libEGL',
                              dt_needed=['libEGL_dep.so'])
        libEGL_dep = gb.add_lib32(PT_SYSTEM, 'libEGL_dep')
        libEGL_chipset = gb.add_lib32(PT_VENDOR, 'libEGL_chipset',
                                      extra_dir='egl',
                                      dt_needed=['libEGL.so'])
        gb.resolve()

        libEGL.add_dlopen_dep(libEGL_chipset)

        vndk_sets = gb.graph.compute_degenerated_vndk(None)

        self.assertIn(libEGL, vndk_sets.sp_ndk)
        self.assertIn(libEGL_dep, vndk_sets.sp_ndk_indirect)
        self.assertIn(libEGL_chipset, vndk_sets.sp_hal)

        self.assertNotIn(libEGL_chipset, vndk_sets.sp_ndk_indirect)
Exemple #10
0
    def test_sp_ndk_indirect_without_sp_hal(self):
        """Check the computation of sp_ndk_indirect excludes sp_hal."""

        gb = GraphBuilder()
        libEGL = gb.add_lib32(PT_SYSTEM, 'libEGL', dt_needed=['libEGL_dep.so'])
        libEGL_dep = gb.add_lib32(PT_SYSTEM, 'libEGL_dep')
        libEGL_chipset = gb.add_lib32(PT_VENDOR,
                                      'libEGL_chipset',
                                      extra_dir='egl',
                                      dt_needed=['libEGL.so'])
        gb.resolve()

        libEGL.add_dlopen_dep(libEGL_chipset)

        vndk_sets = gb.graph.compute_degenerated_vndk(None)

        self.assertIn(libEGL, vndk_sets.sp_ndk)
        self.assertIn(libEGL_dep, vndk_sets.sp_ndk_indirect)
        self.assertIn(libEGL_chipset, vndk_sets.sp_hal)

        self.assertNotIn(libEGL_chipset, vndk_sets.sp_ndk_indirect)
    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)
Exemple #12
0
    def test_add_dlopen_deps(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/liba.so: /system/lib/libb.so')
            tmp_file.seek(0)
            gb.graph.add_dlopen_deps(tmp_file.name)

        self.assertIn(libb, liba.deps_dlopen)
        self.assertIn(liba, libb.users_dlopen)

        self.assertNotIn(libb, liba.deps_needed)
        self.assertNotIn(liba, libb.users_needed)
Exemple #13
0
    def test_add_dlopen_deps(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/liba.so: /system/lib/libb.so')
            tmp_file.seek(0)
            gb.graph.add_dlopen_deps(tmp_file.name)

        self.assertIn(libb, liba.deps_dlopen)
        self.assertIn(liba, libb.users_dlopen)

        self.assertNotIn(libb, liba.deps_needed)
        self.assertNotIn(liba, libb.users_needed)
Exemple #14
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')
    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: Failed to add dlopen dependency from .* to .*\\.\n')
Exemple #16
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)
Exemple #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)
Exemple #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))
Exemple #19
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))