Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / pnacl / driver / tests / fix_private_libs_test.py
1 #!/usr/bin/python
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.
5
6 """ Test that "FixPrivateLibs" function rearranges public and private
7 libraries in the right way. """
8
9 import unittest
10
11 from driver_env import env
12 import driver_test_utils
13 pnacl_ld = __import__("pnacl-ld")
14
15
16 class TestFixPrivateLibs(driver_test_utils.DriverTesterCommon):
17   def setUp(self):
18     super(TestFixPrivateLibs, self).setUp()
19     driver_test_utils.ApplyTestEnvOverrides(env)
20     env.set('USE_IRT', '1')
21
22   def test_nop(self):
23     """Test having no private libs at all -- nothing should happen.
24
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.
28     """
29     input_libs = ['--undefined=main',
30                   'toolchain/linux_x86/pnacl_newlib/lib/crti.bc',
31                   'foo.bc',
32                   '--start-group',
33                   '-lnacl',
34                   '-lc',
35                   '--end-group']
36     expected_libs = list(input_libs)
37     output_libs = pnacl_ld.FixPrivateLibs(input_libs)
38     self.assertEqual(expected_libs, output_libs)
39
40   def test_pthread_no_nacl(self):
41     """Test having pthread_private but not nacl_sys_private.
42
43     pthread_private should replace pthread. However we still keep the
44     original instance of pthread_private where it is, which shouldn't hurt.
45
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.
49     """
50     input_libs = ['foo.bc',
51                   '-lpthread_private',
52                   '--start-group',
53                   '-lpthread',
54                   '-lnacl',
55                   '-lc',
56                   '--end-group']
57     expected_libs = ['foo.bc',
58                      '-lpthread_private',
59                      '--start-group',
60                      '-lpthread_private',
61                      '-lnacl_sys_private',
62                      '-lnacl',
63                      '-lc',
64                      '--end-group']
65     output_libs = pnacl_ld.FixPrivateLibs(input_libs)
66     self.assertEqual(expected_libs, output_libs)
67
68   def test_nacl_private_no_pthread(self):
69     """Test having nacl_sys_private but not pthread_private.
70
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
75     programs.
76     """
77     input_libs = ['foo.bc',
78                   '-lnacl_sys_private',
79                   '--start-group',
80                   '-lpthread',
81                   '-lnacl',
82                   '-lc',
83                   '--end-group']
84     expected_libs = ['foo.bc',
85                      '-lnacl_sys_private',
86                      '--start-group',
87                      '-lpthread_private',
88                      '-lnacl_sys_private',
89                      '-lnacl',
90                      '-lc',
91                      '--end-group']
92     output_libs = pnacl_ld.FixPrivateLibs(input_libs)
93     self.assertEqual(expected_libs, output_libs)
94
95
96   def test_pthread_and_nacl_1(self):
97     """Test having both nacl_sys_private and pthread_private #1.
98
99     In this case, yes we should touch nacl_sys_private.
100     """
101     input_libs = ['foo.bc',
102                   '-lnacl_sys_private',
103                   '-lpthread_private',
104                   '--start-group',
105                   '-lpthread',
106                   '-lnacl',
107                   '-lc',
108                   '--end-group']
109     expected_libs = ['foo.bc',
110                      '-lnacl_sys_private',
111                      '-lpthread_private',
112                      '--start-group',
113                      '-lpthread_private',
114                      '-lnacl_sys_private',
115                      '-lnacl',
116                      '-lc',
117                      '--end-group']
118     output_libs = pnacl_ld.FixPrivateLibs(input_libs)
119     self.assertEqual(expected_libs, output_libs)
120
121   def test_pthread_and_nacl_2(self):
122     """Test having both nacl_sys_private and pthread_private #2.
123
124     Try flipping the order of nacl and pthread to make sure the substitution
125     still works.
126     """
127     input_libs = ['foo.bc',
128                   '-lpthread_private',
129                   '-lnacl_sys_private',
130                   '--start-group',
131                   '-lnacl',
132                   '-lpthread',
133                   '-lc',
134                   '--end-group']
135     expected_libs = ['foo.bc',
136                      '-lpthread_private',
137                      '-lnacl_sys_private',
138                      '--start-group',
139                      '-lnacl_sys_private',
140                      '-lnacl',
141                      '-lpthread_private',
142                      '-lc',
143                      '--end-group']
144     output_libs = pnacl_ld.FixPrivateLibs(input_libs)
145     self.assertEqual(expected_libs, output_libs)