[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / native_client_sdk / src / tools / tests / nacl_config_test.py
blob31957c59aeb97ba4b6a283ce2a523810a78fc4ba
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 import os
7 import sys
8 import unittest
10 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
11 TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
12 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
13 MOCK_DIR = os.path.join(CHROME_SRC, "third_party", "pymock")
15 # For the mock library
16 sys.path.append(MOCK_DIR)
17 import mock
19 # For nacl_config, the module under test
20 sys.path.append(TOOLS_DIR)
21 import nacl_config
24 class TestNaclConfig(unittest.TestCase):
25 def setUp(self):
26 self.patches = []
28 get_sdk_path = self.AddAndStartPatch('getos.GetSDKPath')
29 get_sdk_path.return_value = '/sdk_root'
31 get_platform = self.AddAndStartPatch('getos.GetPlatform')
32 get_platform.return_value = 'mac'
34 def tearDown(self):
35 for patch in self.patches:
36 patch.stop()
38 def AddAndStartPatch(self, name):
39 patch = mock.patch(name)
40 self.patches.append(patch)
41 return patch.start()
43 def testCFlags(self):
44 cases = {
45 'newlib': '-I/sdk_root/include -I/sdk_root/include/newlib',
46 'glibc': '-I/sdk_root/include -I/sdk_root/include/glibc',
47 'pnacl': '-I/sdk_root/include -I/sdk_root/include/pnacl',
48 'win': '-I/sdk_root/include -I/sdk_root/include/win',
49 'mac': '-I/sdk_root/include -I/sdk_root/include/mac',
50 'linux': '-I/sdk_root/include -I/sdk_root/include/linux'
52 for toolchain, expected in cases.iteritems():
53 self.assertEqual(expected, nacl_config.GetCFlags(toolchain))
54 self.assertRaises(nacl_config.Error, nacl_config.GetCFlags, 'foo')
56 def testIncludeDirs(self):
57 cases = {
58 'newlib': '/sdk_root/include /sdk_root/include/newlib',
59 'glibc': '/sdk_root/include /sdk_root/include/glibc',
60 'pnacl': '/sdk_root/include /sdk_root/include/pnacl',
61 'win': '/sdk_root/include /sdk_root/include/win',
62 'mac': '/sdk_root/include /sdk_root/include/mac',
63 'linux': '/sdk_root/include /sdk_root/include/linux'
65 for toolchain, expected in cases.iteritems():
66 self.assertEqual(expected, nacl_config.GetIncludeDirs(toolchain))
67 self.assertRaises(nacl_config.Error, nacl_config.GetIncludeDirs, 'foo')
69 def testLDFlags(self):
70 self.assertEqual('-L/sdk_root/lib', nacl_config.GetLDFlags())
72 def _TestTool(self, tool, nacl_tool=None, pnacl_tool=None):
73 nacl_tool = nacl_tool or tool
74 pnacl_tool = pnacl_tool or tool
76 cases = {
77 ('newlib', 'x86_32'):
78 '/sdk_root/toolchain/mac_x86_newlib/bin/i686-nacl-%s' % nacl_tool,
79 ('newlib', 'x86_64'):
80 '/sdk_root/toolchain/mac_x86_newlib/bin/x86_64-nacl-%s' % nacl_tool,
81 ('newlib', 'arm'):
82 '/sdk_root/toolchain/mac_arm_newlib/bin/arm-nacl-%s' % nacl_tool,
84 ('glibc', 'x86_32'):
85 '/sdk_root/toolchain/mac_x86_glibc/bin/i686-nacl-%s' % nacl_tool,
86 ('glibc', 'x86_64'):
87 '/sdk_root/toolchain/mac_x86_glibc/bin/x86_64-nacl-%s' % nacl_tool,
89 'pnacl': '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool,
90 ('pnacl', 'pnacl'):
91 '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool,
94 for tc_arch, expected in cases.iteritems():
95 if isinstance(tc_arch, tuple):
96 toolchain = tc_arch[0]
97 arch = tc_arch[1]
98 else:
99 toolchain = tc_arch
100 arch = None
101 self.assertEqual(expected, nacl_config.GetToolPath(toolchain, arch, tool))
103 for toolchain in ('host', 'mac', 'win', 'linux'):
104 self.assertRaises(nacl_config.Error,
105 nacl_config.GetToolPath, toolchain, None, tool)
107 # Using toolchain=pnacl with any arch other than None, or 'pnacl' is an
108 # error.
109 for arch in ('x86_32', 'x86_64', 'arm', 'foobar'):
110 self.assertRaises(nacl_config.Error,
111 nacl_config.GetToolPath, toolchain, arch, tool)
113 # No arm glibc.
114 self.assertRaises(nacl_config.Error,
115 nacl_config.GetToolPath, 'glibc', 'arm', tool)
117 def testCC(self):
118 self._TestTool('cc', 'gcc', 'clang')
120 def testCXX(self):
121 self._TestTool('c++', 'g++', 'clang++')
123 def testLD(self):
124 self._TestTool('ld', 'g++', 'clang++')
126 def testStandardTool(self):
127 for tool in ('nm', 'strip', 'ar', 'ranlib'):
128 self._TestTool(tool)
130 def testGDB(self):
131 # We always use the same gdb (it supports multiple toolchains/architectures)
132 expected = '/sdk_root/toolchain/mac_x86_newlib/bin/x86_64-nacl-gdb'
133 for toolchain in ('newlib', 'glibc', 'pnacl'):
134 for arch in ('x86_32', 'x86_64', 'arm'):
135 self.assertEqual(expected,
136 nacl_config.GetToolPath(toolchain, arch, 'gdb'))
139 if __name__ == '__main__':
140 unittest.main()