1#!/usr/bin/env python3 2 3from __future__ import print_function 4 5from vndk_definition_tool import (PT_SYSTEM, PT_VENDOR) 6 7from .compat import StringIO, TestCase, patch 8from .utils import GraphBuilder 9 10 11class ELFLinkerVNDKTest(TestCase): 12 def test_normalize_partition_tags_bad_vendor_deps(self): 13 """Check whether normalize_partition_tags() hides the dependencies from 14 the system partition to the vendor partition if the dependencies are 15 not SP-HAL libraries.""" 16 17 gb = GraphBuilder() 18 libfwk = gb.add_lib32(PT_SYSTEM, 'libfwk', dt_needed=['libvnd.so']) 19 libvnd = gb.add_lib32(PT_VENDOR, 'libvnd') 20 gb.resolve() 21 22 self.assertIn(libvnd, libfwk.deps_needed) 23 self.assertIn(libfwk, libvnd.users_needed) 24 25 stderr = StringIO() 26 with patch('sys.stderr', stderr): 27 gb.graph.normalize_partition_tags(set(), None) 28 29 self.assertRegex( 30 stderr.getvalue(), 31 'error: .*: system exe/lib must not depend on vendor lib .*. ' 32 'Assume such dependency does not exist.') 33 34 self.assertNotIn(libvnd, libfwk.deps_needed) 35 self.assertNotIn(libfwk, libvnd.users_needed) 36 37 self.assertIn(libvnd, libfwk.deps_needed_hidden) 38 self.assertIn(libfwk, libvnd.users_needed_hidden) 39 40 self.assertIn(libvnd, libfwk.deps_all) 41 self.assertIn(libvnd, libfwk.deps_needed_all) 42 self.assertNotIn(libvnd, libfwk.deps_good) 43 44 self.assertIn(libfwk, libvnd.users_all) 45 self.assertIn(libfwk, libvnd.users_needed_all) 46 self.assertNotIn(libfwk, libvnd.users_good) 47 48 49 def test_normalize_partition_tags_sp_hal(self): 50 """Check whether normalize_partition_tags() keep dependencies to SP-HAL 51 libraries as-is.""" 52 53 gb = GraphBuilder() 54 libfwk = gb.add_lib32(PT_SYSTEM, 'libfwk', dt_needed=['libsphal.so']) 55 libsphal = gb.add_lib32(PT_VENDOR, 'libsphal') 56 gb.resolve() 57 58 self.assertIn(libsphal, libfwk.deps_needed) 59 self.assertIn(libfwk, libsphal.users_needed) 60 61 gb.graph.normalize_partition_tags({libsphal}, None) 62 63 # SP-HALs should be kept as-is. 64 self.assertIn(libsphal, libfwk.deps_needed) 65 self.assertIn(libfwk, libsphal.users_needed) 66 67 68 def test_vndk(self): 69 """Check the computation of vndk without generic references.""" 70 71 gb = GraphBuilder() 72 gb.add_lib32(PT_SYSTEM, 'libfwk') 73 libvndk = gb.add_lib32(PT_SYSTEM, 'libvndk', extra_dir='vndk') 74 libvndk_sp = gb.add_lib32(PT_SYSTEM, 'libutils', extra_dir='vndk-sp') 75 libvnd = gb.add_lib32(PT_VENDOR, 'libvnd', 76 dt_needed=['libvndk.so', 'libutils.so']) 77 gb.resolve() 78 79 self.assertIn(libvndk, libvnd.deps_all) 80 self.assertIn(libvndk_sp, libvnd.deps_all) 81 82 vndk_sets = gb.graph.compute_degenerated_vndk(None) 83 84 self.assertIn(libvndk, vndk_sets.vndk) 85 self.assertIn(libvndk_sp, vndk_sets.vndk_sp) 86 87 88 def test_vndk_bad_vendor_deps(self): 89 """Check the computation of vndk without generic references.""" 90 91 gb = GraphBuilder() 92 93 libvndk = gb.add_lib32( 94 PT_SYSTEM, 'libvndk', dt_needed=['libvnd_bad.so'], 95 extra_dir='vndk') 96 97 libvndk_sp = gb.add_lib32( 98 PT_SYSTEM, 'libutils', dt_needed=['libvnd_bad.so'], 99 extra_dir='vndk-sp') 100 101 libvnd_bad = gb.add_lib32(PT_VENDOR, 'libvnd_bad', extra_dir='vndk-sp') 102 103 gb.resolve() 104 105 self.assertIn(libvnd_bad, libvndk.deps_all) 106 self.assertIn(libvnd_bad, libvndk_sp.deps_all) 107 108 with patch('sys.stderr', StringIO()): 109 vndk_sets = gb.graph.compute_degenerated_vndk(None) 110 111 self.assertNotIn(libvnd_bad, vndk_sets.vndk) 112 self.assertNotIn(libvnd_bad, vndk_sets.vndk_sp) 113 114 115 def test_ll_ndk_private_without_sp_hal(self): 116 """Check the computation of ll_ndk_private excludes sp_hal.""" 117 118 gb = GraphBuilder() 119 libEGL = gb.add_lib32(PT_SYSTEM, 'libEGL', 120 dt_needed=['libEGL_dep.so']) 121 libEGL_dep = gb.add_lib32(PT_SYSTEM, 'libEGL_dep') 122 libEGL_chipset = gb.add_lib32(PT_VENDOR, 'libEGL_chipset', 123 extra_dir='egl', 124 dt_needed=['libEGL.so']) 125 gb.resolve() 126 127 libEGL.add_dlopen_dep(libEGL_chipset) 128 129 vndk_sets = gb.graph.compute_degenerated_vndk(None) 130 131 self.assertIn(libEGL, vndk_sets.ll_ndk) 132 self.assertIn(libEGL_dep, vndk_sets.ll_ndk_private) 133 self.assertIn(libEGL_chipset, vndk_sets.sp_hal) 134 135 self.assertNotIn(libEGL_chipset, vndk_sets.ll_ndk_private) 136