Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: googletest/tests/isolate_test_cases_smoke_test.py

Issue 19917006: Move all googletest related scripts into googletest/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/swarm_client
Patch Set: Remove unnecessary pylint warning disable Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 5
6 import hashlib 6 import hashlib
7 import json 7 import json
8 import logging 8 import logging
9 import os 9 import os
10 import re 10 import re
11 import shutil 11 import shutil
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 import tempfile 14 import tempfile
15 import unittest 15 import unittest
16 16
17 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 17 GOOGLETEST_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18 ROOT_DIR = os.path.dirname(BASE_DIR) 18 ROOT_DIR = os.path.dirname(GOOGLETEST_DIR)
19
20 sys.path.insert(0, GOOGLETEST_DIR)
19 sys.path.insert(0, ROOT_DIR) 21 sys.path.insert(0, ROOT_DIR)
20 22
21 import isolate 23 import isolate
22 import trace_test_cases 24 import trace_test_cases
23 25
24 26
25 class IsolateTestCases(unittest.TestCase): 27 class IsolateTestCases(unittest.TestCase):
26 def setUp(self): 28 def setUp(self):
27 self.tempdir = None 29 self.tempdir = None
28 30
(...skipping 21 matching lines...) Expand all
50 52
51 def tearDown(self): 53 def tearDown(self):
52 if self.tempdir: 54 if self.tempdir:
53 if VERBOSE: 55 if VERBOSE:
54 # If -v is used, this means the user wants to do further analisys on 56 # If -v is used, this means the user wants to do further analisys on
55 # the data. 57 # the data.
56 print('Leaking %s' % self.tempdir) 58 print('Leaking %s' % self.tempdir)
57 else: 59 else:
58 shutil.rmtree(self.tempdir) 60 shutil.rmtree(self.tempdir)
59 61
60 def _copy(self, *relpath): 62 def _copy(self, root, *relpath):
61 relpath = os.path.join(*relpath) 63 relpath = os.path.join(*relpath)
62 shutil.copy( 64 shutil.copy(
63 os.path.join(ROOT_DIR, relpath), 65 os.path.join(root, relpath),
64 os.path.join(self.tempdir, relpath)) 66 os.path.join(self.tempdir, relpath))
65 67
66 def test_simple(self): 68 def test_simple(self):
67 # Create a directory and re-use tests/gtest_fake/gtest_fake_pass.isolate. 69 # Create a directory and re-use tests/gtest_fake/gtest_fake_pass.isolate.
68 # Warning: we need to copy the files around, since the original .isolate 70 # Warning: we need to copy the files around, since the original .isolate
69 # file is modified. 71 # file is modified.
70 gtest_fake_base_py = os.path.join( 72 gtest_fake_base_py = os.path.join(
71 'tests', 'gtest_fake', 'gtest_fake_base.py') 73 'tests', 'gtest_fake', 'gtest_fake_base.py')
72 gtest_fake_pass_py = os.path.join( 74 gtest_fake_pass_py = os.path.join(
73 'tests', 'gtest_fake', 'gtest_fake_pass.py') 75 'tests', 'gtest_fake', 'gtest_fake_pass.py')
74 gtest_fake_pass_isolate = os.path.join( 76 gtest_fake_pass_isolate = os.path.join(
75 'tests', 'isolate_test_cases', 'gtest_fake_pass.isolate') 77 'tests', 'isolate_test_cases', 'gtest_fake_pass.isolate')
76 78
77 self.tempdir = tempfile.mkdtemp(prefix='isolate_test_cases_test') 79 self.tempdir = tempfile.mkdtemp(prefix='isolate_test_cases_test')
78 os.mkdir(os.path.join(self.tempdir, 'isolated')) 80 os.mkdir(os.path.join(self.tempdir, 'isolated'))
79 os.mkdir(os.path.join(self.tempdir, 'tests')) 81 os.mkdir(os.path.join(self.tempdir, 'tests'))
80 os.mkdir(os.path.join(self.tempdir, 'tests', 'gtest_fake')) 82 os.mkdir(os.path.join(self.tempdir, 'tests', 'gtest_fake'))
81 os.mkdir(os.path.join(self.tempdir, 'tests', 'isolate_test_cases')) 83 os.mkdir(os.path.join(self.tempdir, 'tests', 'isolate_test_cases'))
82 self._copy('isolate.py') 84 self._copy(ROOT_DIR, 'isolate.py')
83 self._copy(gtest_fake_base_py) 85 self._copy(GOOGLETEST_DIR, gtest_fake_base_py)
84 self._copy(gtest_fake_pass_isolate) 86 self._copy(GOOGLETEST_DIR, gtest_fake_pass_isolate)
85 self._copy(gtest_fake_pass_py) 87 self._copy(GOOGLETEST_DIR, gtest_fake_pass_py)
86 88
87 basename = os.path.join(self.tempdir, 'isolated', 'gtest_fake_pass') 89 basename = os.path.join(self.tempdir, 'isolated', 'gtest_fake_pass')
88 isolated = basename + '.isolated' 90 isolated = basename + '.isolated'
89 91
90 # Create a proper .isolated file. 92 # Create a proper .isolated file.
91 cmd = [ 93 cmd = [
92 sys.executable, 'isolate.py', 94 sys.executable, 'isolate.py',
93 'check', 95 'check',
94 '--variable', 'FLAG', 'run', 96 '--variable', 'FLAG', 'run',
95 '--isolate', os.path.join(self.tempdir, gtest_fake_pass_isolate), 97 '--isolate', os.path.join(self.tempdir, gtest_fake_pass_isolate),
96 '--isolated', isolated, 98 '--isolated', isolated,
97 ] 99 ]
98 if VERBOSE: 100 if VERBOSE:
99 cmd.extend(['-v'] * 3) 101 cmd.extend(['-v'] * 3)
100 subprocess.check_call(cmd, cwd=ROOT_DIR) 102 subprocess.check_call(cmd, cwd=ROOT_DIR)
101 103
102 # Assert the content of the .isolated file. 104 # Assert the content of the .isolated file.
103 with open(isolated) as f: 105 with open(isolated) as f:
104 actual_isolated = json.load(f) 106 actual_isolated = json.load(f)
105 root_dir_gtest_fake_pass_py = os.path.join(ROOT_DIR, gtest_fake_pass_py) 107 root_dir_gtest_fake_pass_py = os.path.join(
108 GOOGLETEST_DIR, gtest_fake_pass_py)
106 rel_gtest_fake_pass_py = os.path.join(u'gtest_fake', 'gtest_fake_pass.py') 109 rel_gtest_fake_pass_py = os.path.join(u'gtest_fake', 'gtest_fake_pass.py')
107 expected_isolated = { 110 expected_isolated = {
108 u'command': [u'../gtest_fake/gtest_fake_pass.py'], 111 u'command': [u'../gtest_fake/gtest_fake_pass.py'],
109 u'files': { 112 u'files': {
110 rel_gtest_fake_pass_py: { 113 rel_gtest_fake_pass_py: {
111 u'm': 488, 114 u'm': 488,
112 u'h': unicode(hashlib.sha1( 115 u'h': unicode(hashlib.sha1(
113 open(root_dir_gtest_fake_pass_py, 'rb').read()).hexdigest()), 116 open(root_dir_gtest_fake_pass_py, 'rb').read()).hexdigest()),
114 u's': os.stat(root_dir_gtest_fake_pass_py).st_size, 117 u's': os.stat(root_dir_gtest_fake_pass_py).st_size,
115 }, 118 },
116 }, 119 },
117 u'os': unicode(isolate.get_flavor()), 120 u'os': unicode(isolate.get_flavor()),
118 u'relative_cwd': u'isolate_test_cases', 121 u'relative_cwd': u'isolate_test_cases',
119 } 122 }
120 if sys.platform == 'win32': 123 if sys.platform == 'win32':
121 expected_isolated['files'][rel_gtest_fake_pass_py].pop('m') 124 expected_isolated['files'][rel_gtest_fake_pass_py].pop('m')
122 self.assertEqual(expected_isolated, actual_isolated) 125 self.assertEqual(expected_isolated, actual_isolated)
123 126
124 cmd = [ 127 cmd = [
125 sys.executable, 128 sys.executable,
126 os.path.join(ROOT_DIR, 'isolate_test_cases.py'), 129 os.path.join(GOOGLETEST_DIR, 'isolate_test_cases.py'),
127 # Forces 4 parallel jobs. 130 # Forces 4 parallel jobs.
128 '--jobs', '4', 131 '--jobs', '4',
129 '--isolated', isolated, 132 '--isolated', isolated,
130 ] 133 ]
131 if VERBOSE: 134 if VERBOSE:
132 cmd.extend(['-v'] * 3) 135 cmd.extend(['-v'] * 3)
133 logging.debug(' '.join(cmd)) 136 logging.debug(' '.join(cmd))
134 proc = subprocess.Popen( 137 proc = subprocess.Popen(
135 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 138 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
136 out, err = proc.communicate() or ('', '') # pylint is confused. 139 out, err = proc.communicate() or ('', '') # pylint is confused.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 }], 207 }],
205 ]), 208 ]),
206 } 209 }
207 self.assertEqual(expected, actual) 210 self.assertEqual(expected, actual)
208 211
209 212
210 if __name__ == '__main__': 213 if __name__ == '__main__':
211 VERBOSE = '-v' in sys.argv 214 VERBOSE = '-v' in sys.argv
212 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 215 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
213 unittest.main() 216 unittest.main()
OLDNEW
« no previous file with comments | « googletest/tests/isolate_test_cases/gtest_fake_pass.isolate ('k') | googletest/tests/list_test_cases_smoke_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698