OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 import json | 5 import json |
6 import os | 6 import os |
7 import posixpath | 7 import posixpath |
8 import shutil | 8 import shutil |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 import tempfile | 11 import tempfile |
12 import unittest | 12 import unittest |
13 | 13 |
14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
15 TOOLS_DIR = os.path.dirname(SCRIPT_DIR) | 15 TOOLS_DIR = os.path.dirname(SCRIPT_DIR) |
16 DATA_DIR = os.path.join(TOOLS_DIR, 'lib', 'tests', 'data') | 16 DATA_DIR = os.path.join(TOOLS_DIR, 'lib', 'tests', 'data') |
| 17 BUILD_TOOLS_DIR = os.path.join(os.path.dirname(TOOLS_DIR), 'build_tools') |
17 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR))) | 18 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR))) |
18 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock') | 19 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock') |
19 | 20 |
20 # For the mock library | 21 # For the mock library |
21 sys.path.append(MOCK_DIR) | 22 sys.path.append(MOCK_DIR) |
22 sys.path.append(TOOLS_DIR) | 23 sys.path.append(TOOLS_DIR) |
| 24 sys.path.append(BUILD_TOOLS_DIR) |
23 | 25 |
24 import build_paths | 26 import build_paths |
25 import create_nmf | 27 import create_nmf |
26 import getos | 28 import getos |
27 import mock | 29 from mock import patch, Mock |
28 | 30 |
29 TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain') | 31 TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain') |
30 NACL_X86_GLIBC_TOOLCHAIN = os.path.join(TOOLCHAIN_OUT, | 32 NACL_X86_GLIBC_TOOLCHAIN = os.path.join(TOOLCHAIN_OUT, |
31 '%s_x86' % getos.GetPlatform(), | 33 '%s_x86' % getos.GetPlatform(), |
32 'nacl_x86_glibc') | 34 'nacl_x86_glibc') |
33 | 35 |
34 PosixRelPath = create_nmf.PosixRelPath | 36 PosixRelPath = create_nmf.PosixRelPath |
35 | 37 |
36 | 38 |
37 def StripSo(name): | 39 def StripSo(name): |
(...skipping 16 matching lines...) Expand all Loading... |
54 class TestPosixRelPath(unittest.TestCase): | 56 class TestPosixRelPath(unittest.TestCase): |
55 def testBasic(self): | 57 def testBasic(self): |
56 # Note that PosixRelPath only converts from native path format to posix | 58 # Note that PosixRelPath only converts from native path format to posix |
57 # path format, that's why we have to use os.path.join here. | 59 # path format, that's why we have to use os.path.join here. |
58 path = os.path.join(os.path.sep, 'foo', 'bar', 'baz.blah') | 60 path = os.path.join(os.path.sep, 'foo', 'bar', 'baz.blah') |
59 start = os.path.sep + 'foo' | 61 start = os.path.sep + 'foo' |
60 self.assertEqual(PosixRelPath(path, start), 'bar/baz.blah') | 62 self.assertEqual(PosixRelPath(path, start), 'bar/baz.blah') |
61 | 63 |
62 | 64 |
63 class TestDefaultLibpath(unittest.TestCase): | 65 class TestDefaultLibpath(unittest.TestCase): |
64 def testWithoutNaClSDKRoot(self): | 66 def setUp(self): |
65 """GetDefaultLibPath wihtout NACL_SDK_ROOT set | 67 patcher = patch('create_nmf.GetSDKRoot', Mock(return_value='/dummy/path')) |
| 68 patcher.start() |
| 69 self.addCleanup(patcher.stop) |
66 | 70 |
67 In the absence of NACL_SDK_ROOT GetDefaultLibPath should | 71 def testUsesSDKRoot(self): |
68 return the empty list.""" | 72 paths = create_nmf.GetDefaultLibPath('Debug') |
69 with mock.patch.dict('os.environ', clear=True): | |
70 paths = create_nmf.GetDefaultLibPath('Debug') | |
71 self.assertEqual(paths, []) | |
72 | |
73 def testHonorNaClSDKRoot(self): | |
74 with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}): | |
75 paths = create_nmf.GetDefaultLibPath('Debug') | |
76 for path in paths: | 73 for path in paths: |
77 self.assertTrue(path.startswith('/dummy/path')) | 74 self.assertTrue(path.startswith('/dummy/path')) |
78 | 75 |
79 def testIncludesNaClPorts(self): | 76 def testIncludesNaClPorts(self): |
80 with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}): | 77 paths = create_nmf.GetDefaultLibPath('Debug') |
81 paths = create_nmf.GetDefaultLibPath('Debug') | |
82 self.assertTrue(any(os.path.join('ports', 'lib') in p for p in paths), | 78 self.assertTrue(any(os.path.join('ports', 'lib') in p for p in paths), |
83 "naclports libpath missing: %s" % str(paths)) | 79 "naclports libpath missing: %s" % str(paths)) |
84 | 80 |
85 | 81 |
86 class TestNmfUtils(unittest.TestCase): | 82 class TestNmfUtils(unittest.TestCase): |
87 """Tests for the main NmfUtils class in create_nmf.""" | 83 """Tests for the main NmfUtils class in create_nmf.""" |
88 | 84 |
89 def setUp(self): | 85 def setUp(self): |
90 self.tempdir = None | 86 self.tempdir = None |
91 self.toolchain = NACL_X86_GLIBC_TOOLCHAIN | 87 self.toolchain = NACL_X86_GLIBC_TOOLCHAIN |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 'optlevel': 0, | 593 'optlevel': 0, |
598 } | 594 } |
599 } | 595 } |
600 } | 596 } |
601 } | 597 } |
602 self.assertManifestEquals(nmf, expected_manifest) | 598 self.assertManifestEquals(nmf, expected_manifest) |
603 | 599 |
604 | 600 |
605 if __name__ == '__main__': | 601 if __name__ == '__main__': |
606 unittest.main() | 602 unittest.main() |
OLD | NEW |