Example #1
0
    def test_enumerate_paths(self):
        self.assertEqual(
                ['/system/lib/libc.so'],
                list(TaggedPathDict._enumerate_paths('/system/lib/libc.so')))

        self.assertEqual(
                ['/system/lib/libc.so', '/system/lib64/libc.so'],
                list(TaggedPathDict._enumerate_paths('/system/${LIB}/libc.so')))
Example #2
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_private = \
            self.graph.add('/system/lib/lib_ll_ndk_private.so')

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

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

        self.lib_system_only = \
            self.graph.add('/system/lib/lib_system_only.so')
        self.lib_system_only_rs = \
            self.graph.add('/system/lib/lib_system_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_vendor_only = self.graph.add('/vendor/lib/lib_vendor_only.so')

        self.tagged_libs = TaggedLibDict.create_from_graph(
            self.graph, self.tagged_paths)
    def test_create_from_csv_path(self):
        with tempfile.NamedTemporaryFile('w+') as f:
            f.write(_TEST_DATA)
            f.flush()

            d = TaggedPathDict.create_from_csv_path(f.name)
            self._check_test_data_loaded(d)
Example #4
0
    def test_create_from_csv_path(self):
        with tempfile.NamedTemporaryFile('w+') as f:
            f.write(_TEST_DATA)
            f.flush()

            d = TaggedPathDict.create_from_csv_path(f.name)
            self._check_test_data_loaded(d)
    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)
Example #6
0
    def test_load_from_csv_with_header(self):
        fp = StringIO('Path,Tag\nliba.so,system-only\n')
        d = TaggedPathDict()
        d.load_from_csv(fp)
        self.assertIn('liba.so', d.system_only)

        fp = StringIO('Tag,Path\nsystem-only,liba.so\n')
        d = TaggedPathDict()
        d.load_from_csv(fp)
        self.assertIn('liba.so', d.system_only)
    def test_enumerate_paths(self):
        tagged_paths = TaggedPathDict()

        self.assertEqual(
            ['/system/lib/libc.so'],
            list(tagged_paths._enumerate_paths('/system/lib/libc.so')))

        self.assertEqual(
            ['/system/lib/libc.so', '/system/lib64/libc.so'],
            list(tagged_paths._enumerate_paths('/system/${LIB}/libc.so')))

        self.assertEqual(
            ['/system/lib/vndk/libutils.so',
             '/system/lib64/vndk/libutils.so'],
            list(tagged_paths._enumerate_paths(
                '/system/${LIB}/vndk${VNDK_VER}/libutils.so')))

        tagged_paths = TaggedPathDict(['current', '27', '28'])

        self.assertEqual(
            ['/system/lib/vndk/libutils.so',
             '/system/lib64/vndk/libutils.so',
             '/system/lib/vndk-27/libutils.so',
             '/system/lib64/vndk-27/libutils.so',
             '/system/lib/vndk-28/libutils.so',
             '/system/lib64/vndk-28/libutils.so'],
            list(tagged_paths._enumerate_paths(
                '/system/${LIB}/vndk${VNDK_VER}/libutils.so')))

        self.assertEqual(
            ['/system/lib/vndk/libutils.so',
             '/system/lib/vndk-27/libutils.so',
             '/system/lib/vndk-28/libutils.so'],
            list(tagged_paths._enumerate_paths(
                '/system/lib/vndk${VNDK_VER}/libutils.so')))
    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)
Example #9
0
    def test_enumerate_paths(self):
        tagged_paths = TaggedPathDict()

        self.assertEqual(
            ['/system/lib/libc.so'],
            list(tagged_paths._enumerate_paths('/system/lib/libc.so')))

        self.assertEqual(
            ['/system/lib/libc.so', '/system/lib64/libc.so'],
            list(tagged_paths._enumerate_paths('/system/${LIB}/libc.so')))

        self.assertEqual(
            ['/system/lib/vndk/libutils.so', '/system/lib64/vndk/libutils.so'],
            list(
                tagged_paths._enumerate_paths(
                    '/system/${LIB}/vndk${VNDK_VER}/libutils.so')))

        tagged_paths = TaggedPathDict(['current', '27', '28'])

        self.assertEqual(
            [
                '/system/lib/vndk/libutils.so',
                '/system/lib64/vndk/libutils.so',
                '/system/lib/vndk-27/libutils.so',
                '/system/lib64/vndk-27/libutils.so',
                '/system/lib/vndk-28/libutils.so',
                '/system/lib64/vndk-28/libutils.so'
            ],
            list(
                tagged_paths._enumerate_paths(
                    '/system/${LIB}/vndk${VNDK_VER}/libutils.so')))

        self.assertEqual([
            '/system/lib/vndk/libutils.so', '/system/lib/vndk-27/libutils.so',
            '/system/lib/vndk-28/libutils.so'
        ],
                         list(
                             tagged_paths._enumerate_paths(
                                 '/system/lib/vndk${VNDK_VER}/libutils.so')))
Example #10
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_private',
                         d.get_path_tag('/system/lib/lib_ll_ndk_private.so'))
        self.assertEqual('vndk_sp',
                         d.get_path_tag('/system/lib/lib_vndk_sp.so'))
        self.assertEqual('vndk_sp_private',
                         d.get_path_tag('/system/lib/lib_vndk_sp_private.so'))
        self.assertEqual('vndk', d.get_path_tag('/system/lib/lib_vndk.so'))
        self.assertEqual('vndk_private',
                         d.get_path_tag('/system/lib/lib_vndk_private.so'))
        self.assertEqual('system_only',
                         d.get_path_tag('/system/lib/lib_system_only.so'))
        self.assertEqual('system_only_rs',
                         d.get_path_tag('/system/lib/lib_system_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('vendor_only',
                         d.get_path_tag('/vendor/lib/lib_vendor_only.so'))
        self.assertEqual('remove', d.get_path_tag('/system/lib/lib_remove.so'))

        # Aliases
        self.assertEqual('system_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_private',
                         d.get_path_tag('/system/lib/lib_vndk_indirect.so'))
        self.assertEqual('vndk_sp',
                         d.get_path_tag('/system/lib/lib_vndk_sp_indirect.so'))
        self.assertEqual(
            'vndk_sp_private',
            d.get_path_tag('/system/lib/' + 'lib_vndk_sp_indirect_private.so'))
        self.assertEqual('system_only',
                         d.get_path_tag('/system/lib/lib_fwk_only.so'))
        self.assertEqual('system_only_rs',
                         d.get_path_tag('/system/lib/lib_fwk_only_rs.so'))
        self.assertEqual('vendor_only',
                         d.get_path_tag('/vendor/lib/lib_vendor_only.so'))

        # Unmatched paths
        self.assertEqual('system_only',
                         d.get_path_tag('/system/lib/unknown.so'))
        self.assertEqual('system_only', d.get_path_tag('/data/lib/unknown.so'))
        self.assertEqual('vendor_only',
                         d.get_path_tag('/vendor/lib/unknown.so'))
Example #11
0
 def test_create_from_csv(self):
     d = TaggedPathDict.create_from_csv(StringIO(_TEST_DATA))
     self._check_test_data_loaded(d)
Example #12
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)
Example #13
0
 def test_load_from_csv_without_header(self):
     fp = StringIO('liba.so,system-only\n')
     d = TaggedPathDict()
     d.load_from_csv(fp)
     self.assertIn('liba.so', d.system_only)
 def test_load_from_csv_tags(self):
     fp = StringIO(_TEST_DATA)
     d = TaggedPathDict()
     d.load_from_csv(fp)
     self._check_test_data_loaded(d)
    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)
    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('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'))
 def test_create_from_csv(self):
     d = TaggedPathDict.create_from_csv(StringIO(_TEST_DATA))
     self._check_test_data_loaded(d)
Example #18
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_private.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_ll_ndk_private.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_private.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk_sp_private.so',
            '/system/lib/lib_system_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_private.so',
            '/system/lib/lib_vndk.so',
            '/system/lib/lib_vndk_private.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)

        # SYSTEM-ONLY
        from_paths = {
            '/system/lib/lib_system_only.so',
            '/system/lib/lib_system_only_rs.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_ll_ndk_private.so',
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk_sp_private.so',
            '/system/lib/lib_vndk.so',
            '/system/lib/lib_vndk_private.so',
            '/system/lib/lib_system_only.so',
            '/system/lib/lib_system_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)

        # VENDOR-ONLY
        from_paths = {
            '/vendor/lib/lib_vendor_only.so',
        }
        visible_paths = {
            '/system/lib/lib_ll_ndk.so',
            '/system/lib/lib_vndk_sp.so',
            '/system/lib/lib_vndk.so',
            '/vendor/lib/lib_sp_hal.so',
            '/vendor/lib/lib_sp_hal_dep.so',
            '/vendor/lib/lib_vendor_only.so',
        }
        self._check_path_visibility(d, all_paths, from_paths, visible_paths)
Example #19
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')
 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)