1#!/usr/bin/env python3 2 3from __future__ import print_function 4 5import os 6import sys 7import unittest 8 9sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 10 11from compat import StringIO, patch 12from vndk_definition_tool import ( 13 DepsInsightCommand, ModuleInfo, PT_SYSTEM, PT_VENDOR) 14from utils import GraphBuilder 15 16 17class DepsInsightCommandTest(unittest.TestCase): 18 _PATH_FIELD = 0 19 _ELF_CLASS_FIELD = 1 20 _TAGS_FIELD = 2 21 _DEPS_FIELD = 3 22 _USERS_FIELD = 4 23 _SOURCE_DIRS_FIELD = 5 24 25 26 @classmethod 27 def _get_module(cls, strs, mods, path): 28 for mod in mods: 29 if strs[mod[cls._PATH_FIELD]] == path: 30 return mod 31 return None 32 33 34 @classmethod 35 def _get_module_deps(cls, strs, mods, path): 36 mod = cls._get_module(strs, mods, path) 37 result = set() 38 for deps in mod[cls._DEPS_FIELD]: 39 result.update(strs[mods[x][cls._PATH_FIELD]] for x in deps) 40 return result 41 42 43 @classmethod 44 def _get_module_users(cls, strs, mods, path): 45 mod = cls._get_module(strs, mods, path) 46 users = mod[cls._USERS_FIELD] 47 return set(strs[mods[x][cls._PATH_FIELD]] for x in users) 48 49 50 def test_serialize_data_with_all_deps(self): 51 """compute_degenerated_vndk() should not remove bad dependencies from 52 the output of deps-insight. This test checks the existance of bad 53 dependencies.""" 54 55 gb = GraphBuilder() 56 libfwk = gb.add_lib32(PT_SYSTEM, 'libfwk') 57 libvndk = gb.add_lib32(PT_SYSTEM, 'libvndk', 58 dt_needed=['libvnd_bad.so'], extra_dir='vndk') 59 libvndk_sp = gb.add_lib32(PT_SYSTEM, 'libutils', 60 dt_needed=['libvnd_bad.so'], 61 extra_dir='vndk-sp') 62 libvnd = gb.add_lib32(PT_VENDOR, 'libvnd', 63 dt_needed=['libvndk.so', 'libutils.so']) 64 libvnd_bad = gb.add_lib32(PT_VENDOR, 'libvnd_bad', extra_dir='vndk-sp') 65 gb.resolve() 66 67 with patch('sys.stderr', StringIO()): 68 vndk_sets = gb.graph.compute_degenerated_vndk(set(), None) 69 70 self.assertNotIn(libvnd_bad, libvndk.deps_good) 71 self.assertNotIn(libvnd_bad, libvndk_sp.deps_good) 72 73 strs, mods = DepsInsightCommand.serialize_data( 74 list(gb.graph.all_libs()), vndk_sets, ModuleInfo()) 75 76 deps = self._get_module_deps(strs, mods, libvndk.path) 77 self.assertIn(libvnd_bad.path, deps) 78 79 deps = self._get_module_deps(strs, mods, libvndk_sp.path) 80 self.assertIn(libvnd_bad.path, deps) 81 82 users = self._get_module_users(strs, mods, libvnd_bad.path) 83 self.assertIn(libvndk.path, users) 84 self.assertIn(libvndk_sp.path, users) 85 86 87if __name__ == '__main__': 88 unittest.main() 89