GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / native_client_sdk / src / tools / tests / nacl_config_test.py
blobb0cbe26f28778dddb086cbf888beeb813a789b91
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 @mock.patch('nacl_config.GetCFlags')
44 def testMainArgParsing(self, mock_get_cflags):
45 mock_get_cflags.return_value = 'flags'
46 with mock.patch('sys.stdout'):
47 nacl_config.main(['--cflags'])
48 mock_get_cflags.assert_called()
50 def testCFlags(self):
51 cases = {
52 'newlib': '-I/sdk_root/include -I/sdk_root/include/newlib',
53 'glibc': '-I/sdk_root/include -I/sdk_root/include/glibc',
54 'pnacl': '-I/sdk_root/include -I/sdk_root/include/pnacl',
55 'win': '-I/sdk_root/include -I/sdk_root/include/win',
56 'mac': '-I/sdk_root/include -I/sdk_root/include/mac',
57 'linux': '-I/sdk_root/include -I/sdk_root/include/linux'
59 for toolchain, expected in cases.iteritems():
60 self.assertEqual(expected, nacl_config.GetCFlags(toolchain))
61 self.assertRaises(nacl_config.Error, nacl_config.GetCFlags, 'foo')
63 def testIncludeDirs(self):
64 cases = {
65 'newlib': '/sdk_root/include /sdk_root/include/newlib',
66 'glibc': '/sdk_root/include /sdk_root/include/glibc',
67 'pnacl': '/sdk_root/include /sdk_root/include/pnacl',
68 'win': '/sdk_root/include /sdk_root/include/win',
69 'mac': '/sdk_root/include /sdk_root/include/mac',
70 'linux': '/sdk_root/include /sdk_root/include/linux'
72 for toolchain, expected in cases.iteritems():
73 self.assertEqual(expected, nacl_config.GetIncludeDirs(toolchain))
74 self.assertRaises(nacl_config.Error, nacl_config.GetIncludeDirs, 'foo')
76 def testLDFlags(self):
77 self.assertEqual('-L/sdk_root/lib', nacl_config.GetLDFlags())
79 def _TestTool(self, tool, nacl_tool=None, pnacl_tool=None):
80 nacl_tool = nacl_tool or tool
81 pnacl_tool = pnacl_tool or tool
83 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,
91 ('glibc', 'x86_32'):
92 '/sdk_root/toolchain/mac_x86_glibc/bin/i686-nacl-%s' % nacl_tool,
93 ('glibc', 'x86_64'):
94 '/sdk_root/toolchain/mac_x86_glibc/bin/x86_64-nacl-%s' % nacl_tool,
96 'pnacl': '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool,
97 ('pnacl', 'pnacl'):
98 '/sdk_root/toolchain/mac_pnacl/bin/pnacl-%s' % pnacl_tool,
101 for tc_arch, expected in cases.iteritems():
102 if isinstance(tc_arch, tuple):
103 toolchain = tc_arch[0]
104 arch = tc_arch[1]
105 else:
106 toolchain = tc_arch
107 arch = None
108 self.assertEqual(expected, nacl_config.GetToolPath(toolchain, arch, tool))
110 for toolchain in ('host', 'mac', 'win', 'linux'):
111 self.assertRaises(nacl_config.Error,
112 nacl_config.GetToolPath, toolchain, None, tool)
114 # Using toolchain=pnacl with any arch other than None, or 'pnacl' is an
115 # error.
116 for arch in ('x86_32', 'x86_64', 'arm', 'foobar'):
117 self.assertRaises(nacl_config.Error,
118 nacl_config.GetToolPath, toolchain, arch, tool)
120 # No arm glibc.
121 self.assertRaises(nacl_config.Error,
122 nacl_config.GetToolPath, 'glibc', 'arm', tool)
124 def testCC(self):
125 self._TestTool('cc', 'gcc', 'clang')
127 def testCXX(self):
128 self._TestTool('c++', 'g++', 'clang++')
130 def testLD(self):
131 self._TestTool('ld', 'g++', 'clang++')
133 def testStandardTool(self):
134 for tool in ('nm', 'strip', 'ar', 'ranlib'):
135 self._TestTool(tool)
137 def testGDB(self):
138 # We always use the same gdb (it supports multiple toolchains/architectures)
139 expected = '/sdk_root/toolchain/mac_x86_newlib/bin/x86_64-nacl-gdb'
140 for toolchain in ('newlib', 'glibc', 'pnacl'):
141 for arch in ('x86_32', 'x86_64', 'arm'):
142 self.assertEqual(expected,
143 nacl_config.GetToolPath(toolchain, arch, 'gdb'))
146 if __name__ == '__main__':
147 unittest.main()