| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 10 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 @mock.patch('nacl_config.GetCFlags') | 43 @mock.patch('nacl_config.GetCFlags') |
| 44 def testMainArgParsing(self, mock_get_cflags): | 44 def testMainArgParsing(self, mock_get_cflags): |
| 45 mock_get_cflags.return_value = 'flags' | 45 mock_get_cflags.return_value = 'flags' |
| 46 with mock.patch('sys.stdout'): | 46 with mock.patch('sys.stdout'): |
| 47 nacl_config.main(['--cflags']) | 47 nacl_config.main(['--cflags']) |
| 48 mock_get_cflags.assert_called() | 48 mock_get_cflags.assert_called() |
| 49 | 49 |
| 50 def testCFlags(self): | 50 def testCFlags(self): |
| 51 cases = { | 51 cases = { |
| 52 'newlib': '-I/sdk_root/include -I/sdk_root/include/newlib', | |
| 53 'glibc': '-I/sdk_root/include -I/sdk_root/include/glibc', | 52 'glibc': '-I/sdk_root/include -I/sdk_root/include/glibc', |
| 54 'pnacl': '-I/sdk_root/include -I/sdk_root/include/pnacl', | 53 'pnacl': '-I/sdk_root/include -I/sdk_root/include/pnacl', |
| 55 'win': '-I/sdk_root/include -I/sdk_root/include/win', | 54 'win': '-I/sdk_root/include -I/sdk_root/include/win', |
| 56 'mac': '-I/sdk_root/include -I/sdk_root/include/mac', | 55 'mac': '-I/sdk_root/include -I/sdk_root/include/mac', |
| 57 'linux': '-I/sdk_root/include -I/sdk_root/include/linux' | 56 'linux': '-I/sdk_root/include -I/sdk_root/include/linux' |
| 58 } | 57 } |
| 59 for toolchain, expected in cases.iteritems(): | 58 for toolchain, expected in cases.iteritems(): |
| 60 self.assertEqual(expected, nacl_config.GetCFlags(toolchain)) | 59 self.assertEqual(expected, nacl_config.GetCFlags(toolchain)) |
| 61 self.assertRaises(nacl_config.Error, nacl_config.GetCFlags, 'foo') | 60 self.assertRaises(nacl_config.Error, nacl_config.GetCFlags, 'foo') |
| 62 | 61 |
| 63 def testIncludeDirs(self): | 62 def testIncludeDirs(self): |
| 64 cases = { | 63 cases = { |
| 65 'newlib': '/sdk_root/include /sdk_root/include/newlib', | |
| 66 'glibc': '/sdk_root/include /sdk_root/include/glibc', | 64 'glibc': '/sdk_root/include /sdk_root/include/glibc', |
| 67 'pnacl': '/sdk_root/include /sdk_root/include/pnacl', | 65 'pnacl': '/sdk_root/include /sdk_root/include/pnacl', |
| 68 'win': '/sdk_root/include /sdk_root/include/win', | 66 'win': '/sdk_root/include /sdk_root/include/win', |
| 69 'mac': '/sdk_root/include /sdk_root/include/mac', | 67 'mac': '/sdk_root/include /sdk_root/include/mac', |
| 70 'linux': '/sdk_root/include /sdk_root/include/linux' | 68 'linux': '/sdk_root/include /sdk_root/include/linux' |
| 71 } | 69 } |
| 72 for toolchain, expected in cases.iteritems(): | 70 for toolchain, expected in cases.iteritems(): |
| 73 self.assertEqual(expected, nacl_config.GetIncludeDirs(toolchain)) | 71 self.assertEqual(expected, nacl_config.GetIncludeDirs(toolchain)) |
| 74 self.assertRaises(nacl_config.Error, nacl_config.GetIncludeDirs, 'foo') | 72 self.assertRaises(nacl_config.Error, nacl_config.GetIncludeDirs, 'foo') |
| 75 | 73 |
| 76 def testLDFlags(self): | 74 def testLDFlags(self): |
| 77 self.assertEqual('-L/sdk_root/lib', nacl_config.GetLDFlags()) | 75 self.assertEqual('-L/sdk_root/lib', nacl_config.GetLDFlags()) |
| 78 | 76 |
| 79 def _TestTool(self, tool, nacl_tool=None, pnacl_tool=None): | 77 def _TestTool(self, tool, nacl_tool=None, pnacl_tool=None): |
| 80 nacl_tool = nacl_tool or tool | 78 nacl_tool = nacl_tool or tool |
| 81 pnacl_tool = pnacl_tool or tool | 79 pnacl_tool = pnacl_tool or tool |
| 82 | 80 |
| 83 cases = { | 81 cases = { |
| 84 ('newlib', 'x86_32'): | |
| 85 '/sdk_root/toolchain/mac_x86_newlib/bin/i686-nacl-%s' % nacl_tool, | |
| 86 ('newlib', 'x86_64'): | |
| 87 '/sdk_root/toolchain/mac_x86_newlib/bin/x86_64-nacl-%s' % nacl_tool, | |
| 88 ('newlib', 'arm'): | |
| 89 '/sdk_root/toolchain/mac_arm_newlib/bin/arm-nacl-%s' % nacl_tool, | |
| 90 | |
| 91 ('glibc', 'arm'): | 82 ('glibc', 'arm'): |
| 92 '/sdk_root/toolchain/mac_arm_glibc/bin/arm-nacl-%s' % nacl_tool, | 83 '/sdk_root/toolchain/mac_arm_glibc/bin/arm-nacl-%s' % nacl_tool, |
| 93 ('glibc', 'x86_32'): | 84 ('glibc', 'x86_32'): |
| 94 '/sdk_root/toolchain/mac_x86_glibc/bin/i686-nacl-%s' % nacl_tool, | 85 '/sdk_root/toolchain/mac_x86_glibc/bin/i686-nacl-%s' % nacl_tool, |
| 95 ('glibc', 'x86_64'): | 86 ('glibc', 'x86_64'): |
| 96 '/sdk_root/toolchain/mac_x86_glibc/bin/x86_64-nacl-%s' % nacl_tool, | 87 '/sdk_root/toolchain/mac_x86_glibc/bin/x86_64-nacl-%s' % nacl_tool, |
| 97 | 88 |
| 98 'pnacl': '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool, | 89 'pnacl': '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool, |
| 99 ('pnacl', 'pnacl'): | 90 ('pnacl', 'pnacl'): |
| 100 '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool, | 91 '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 127 | 118 |
| 128 def testLD(self): | 119 def testLD(self): |
| 129 self._TestTool('ld', 'g++', 'clang++') | 120 self._TestTool('ld', 'g++', 'clang++') |
| 130 | 121 |
| 131 def testStandardTool(self): | 122 def testStandardTool(self): |
| 132 for tool in ('nm', 'strip', 'ar', 'ranlib'): | 123 for tool in ('nm', 'strip', 'ar', 'ranlib'): |
| 133 self._TestTool(tool) | 124 self._TestTool(tool) |
| 134 | 125 |
| 135 def testGDB(self): | 126 def testGDB(self): |
| 136 # We always use the same gdb (it supports multiple toolchains/architectures) | 127 # We always use the same gdb (it supports multiple toolchains/architectures) |
| 137 expected = '/sdk_root/toolchain/mac_x86_newlib/bin/x86_64-nacl-gdb' | 128 expected = '/sdk_root/toolchain/mac_x86_glibc/bin/x86_64-nacl-gdb' |
| 138 for toolchain in ('newlib', 'glibc', 'pnacl'): | 129 for toolchain in ('glibc', 'pnacl'): |
| 139 for arch in ('x86_32', 'x86_64', 'arm'): | 130 for arch in ('x86_32', 'x86_64', 'arm'): |
| 140 self.assertEqual(expected, | 131 self.assertEqual(expected, |
| 141 nacl_config.GetToolPath(toolchain, arch, 'gdb')) | 132 nacl_config.GetToolPath(toolchain, arch, 'gdb')) |
| 142 | 133 |
| 143 | 134 |
| 144 if __name__ == '__main__': | 135 if __name__ == '__main__': |
| 145 unittest.main() | 136 unittest.main() |
| OLD | NEW |