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