2 # Copyright (c) 2013 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """ Test that "FixPrivateLibs" function rearranges public and private
7 libraries in the right way. """
11 from driver_env import env
12 import driver_test_utils
13 pnacl_ld = __import__("pnacl-ld")
16 class TestFixPrivateLibs(driver_test_utils.DriverTesterCommon):
18 super(TestFixPrivateLibs, self).setUp()
19 driver_test_utils.ApplyTestEnvOverrides(env)
20 env.set('USE_IRT', '1')
23 """Test having no private libs at all -- nothing should happen.
25 NOTE: The "user_libs" parameter can have flags as well as files
26 and libraries. Basically it's just the commandline for the bitcode linker.
27 Test that the flags and normal files aren't disturbed.
29 input_libs = ['--undefined=main',
30 'toolchain/linux_x86/pnacl_newlib/lib/crti.bc',
36 expected_libs = list(input_libs)
37 output_libs = pnacl_ld.FixPrivateLibs(input_libs)
38 self.assertEqual(expected_libs, output_libs)
40 def test_pthread_no_nacl(self):
41 """Test having pthread_private but not nacl_sys_private.
43 pthread_private should replace pthread. However we still keep the
44 original instance of pthread_private where it is, which shouldn't hurt.
46 Also test that nacl stays the same, if nacl_sys_private was never
47 requested by the user. We can't pull in nacl_sys_private spuriously,
48 because chrome never builds nacl_sys_private w/ gyp.
50 input_libs = ['foo.bc',
57 expected_libs = ['foo.bc',
65 output_libs = pnacl_ld.FixPrivateLibs(input_libs)
66 self.assertEqual(expected_libs, output_libs)
68 def test_nacl_private_no_pthread(self):
69 """Test having nacl_sys_private but not pthread_private.
71 Since pthread is added as an implicit lib for libc++, for non-IRT
72 programs we need to swap pthread with pthread_private even if it
73 wasn't explicitly asked for. Otherwise pthread will try to query the
74 IRT and crash. Use nacl_sys_private as the signal for non-IRT
77 input_libs = ['foo.bc',
84 expected_libs = ['foo.bc',
92 output_libs = pnacl_ld.FixPrivateLibs(input_libs)
93 self.assertEqual(expected_libs, output_libs)
96 def test_pthread_and_nacl_1(self):
97 """Test having both nacl_sys_private and pthread_private #1.
99 In this case, yes we should touch nacl_sys_private.
101 input_libs = ['foo.bc',
102 '-lnacl_sys_private',
109 expected_libs = ['foo.bc',
110 '-lnacl_sys_private',
114 '-lnacl_sys_private',
118 output_libs = pnacl_ld.FixPrivateLibs(input_libs)
119 self.assertEqual(expected_libs, output_libs)
121 def test_pthread_and_nacl_2(self):
122 """Test having both nacl_sys_private and pthread_private #2.
124 Try flipping the order of nacl and pthread to make sure the substitution
127 input_libs = ['foo.bc',
129 '-lnacl_sys_private',
135 expected_libs = ['foo.bc',
137 '-lnacl_sys_private',
139 '-lnacl_sys_private',
144 output_libs = pnacl_ld.FixPrivateLibs(input_libs)
145 self.assertEqual(expected_libs, output_libs)