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

Side by Side Diff: tools/isolate/tests/run_test_cases_test.py

Issue 11045023: Move src/tools/isolate to src/tools/swarm_client as a DEPS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use r159961 Created 8 years, 2 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
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 import logging
7 import os
8 import sys
9 import unittest
10
11 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
12 sys.path.insert(0, ROOT_DIR)
13
14 import run_test_cases
15
16 SLEEP = os.path.join(ROOT_DIR, 'tests', 'run_test_cases', 'sleep.py')
17
18
19 def to_native_eol(string):
20 if sys.platform == 'win32':
21 return string.replace('\n', '\r\n')
22 return string
23
24
25 class ListTestCasesTest(unittest.TestCase):
26 def test_shards(self):
27 test_cases = (
28 (range(10), 10, 0, 1),
29
30 ([0, 1], 5, 0, 3),
31 ([2, 3], 5, 1, 3),
32 ([4 ], 5, 2, 3),
33
34 ([0], 5, 0, 7),
35 ([1], 5, 1, 7),
36 ([2], 5, 2, 7),
37 ([3], 5, 3, 7),
38 ([4], 5, 4, 7),
39 ([ ], 5, 5, 7),
40 ([ ], 5, 6, 7),
41
42 ([0, 1], 4, 0, 2),
43 ([2, 3], 4, 1, 2),
44 )
45 for expected, range_length, index, shards in test_cases:
46 result = run_test_cases.filter_shards(range(range_length), index, shards)
47 self.assertEquals(
48 expected, result, (result, expected, range_length, index, shards))
49
50
51 class RunTestCases(unittest.TestCase):
52 def test_call(self):
53 cmd = [sys.executable, SLEEP, '0.001']
54 # 0 means no timeout, like None.
55 output, code = run_test_cases.call_with_timeout(cmd, 0)
56 self.assertEquals(to_native_eol('Sleeping.\nSlept.\n'), output)
57 self.assertEquals(0, code)
58
59 def test_call_eol(self):
60 cmd = [sys.executable, SLEEP, '0.001']
61 # 0 means no timeout, like None.
62 output, code = run_test_cases.call_with_timeout(
63 cmd, 0, universal_newlines=True)
64 self.assertEquals('Sleeping.\nSlept.\n', output)
65 self.assertEquals(0, code)
66
67 def test_call_timed_out_kill(self):
68 cmd = [sys.executable, SLEEP, '100']
69 # On a loaded system, this can be tight.
70 output, code = run_test_cases.call_with_timeout(cmd, timeout=1)
71 self.assertEquals(to_native_eol('Sleeping.\n'), output)
72 if sys.platform == 'win32':
73 self.assertEquals(1, code)
74 else:
75 self.assertEquals(-9, code)
76
77 def test_call_timed_out_kill_eol(self):
78 cmd = [sys.executable, SLEEP, '100']
79 # On a loaded system, this can be tight.
80 output, code = run_test_cases.call_with_timeout(
81 cmd, timeout=1, universal_newlines=True)
82 self.assertEquals('Sleeping.\n', output)
83 if sys.platform == 'win32':
84 self.assertEquals(1, code)
85 else:
86 self.assertEquals(-9, code)
87
88 def test_call_timeout_no_kill(self):
89 cmd = [sys.executable, SLEEP, '0.001']
90 output, code = run_test_cases.call_with_timeout(cmd, timeout=100)
91 self.assertEquals(to_native_eol('Sleeping.\nSlept.\n'), output)
92 self.assertEquals(0, code)
93
94 def test_call_timeout_no_kill_eol(self):
95 cmd = [sys.executable, SLEEP, '0.001']
96 output, code = run_test_cases.call_with_timeout(
97 cmd, timeout=100, universal_newlines=True)
98 self.assertEquals('Sleeping.\nSlept.\n', output)
99 self.assertEquals(0, code)
100
101 def test_gtest_filter(self):
102 old = run_test_cases.run_test_cases
103 exe = os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_pass.py')
104 def expect(executable, test_cases, jobs, timeout, run_all, result_file):
105 self.assertEquals(run_test_cases.fix_python_path([exe]), executable)
106 self.assertEquals(['Foo.Bar1', 'Foo.Bar3'], test_cases)
107 self.assertEquals(run_test_cases.num_processors(), jobs)
108 self.assertEquals(120, timeout)
109 self.assertEquals(False, run_all)
110 self.assertEquals(exe + '.run_test_cases', result_file)
111 return 89
112
113 try:
114 run_test_cases.run_test_cases = expect
115 result = run_test_cases.main([exe, '--gtest_filter=Foo.Bar*-*.Bar2'])
116 self.assertEquals(89, result)
117 finally:
118 run_test_cases.run_test_cases = old
119
120 def testRunSome(self):
121 tests = [
122 # Try with named arguments. Accepts 3*1 failures.
123 (
124 run_test_cases.RunSome(
125 expected_count=10,
126 retries=3,
127 min_failures=1,
128 max_failure_ratio=0.001),
129 [False] * 4),
130 # Same without named arguments.
131 (run_test_cases.RunSome( 10, 3, 1, 0.001), [False] * 4),
132
133 (run_test_cases.RunSome( 10, 1, 1, 0.001), [False] * 2),
134 (run_test_cases.RunSome( 10, 1, 1, 0.010), [False] * 2),
135
136 # For low expected_count value, retries * min_failures is the minimum
137 # bound of accepted failures.
138 (run_test_cases.RunSome( 10, 3, 1, 0.010), [False] * 4),
139 (run_test_cases.RunSome( 10, 3, 1, 0.020), [False] * 4),
140 (run_test_cases.RunSome( 10, 3, 1, 0.050), [False] * 4),
141 (run_test_cases.RunSome( 10, 3, 1, 0.100), [False] * 4),
142 (run_test_cases.RunSome( 10, 3, 1, 0.110), [False] * 4),
143
144 # Allows expected_count + retries failures at maximum.
145 (run_test_cases.RunSome( 10, 3, 1, 0.200), [False] * 6),
146 (run_test_cases.RunSome( 10, 3, 1, 0.999), [False] * 30),
147
148 # The asympthote is nearing max_failure_ratio for large expected_count
149 # values.
150 (run_test_cases.RunSome(1000, 3, 1, 0.050), [False] * 150),
151 ]
152 for index, (decider, rounds) in enumerate(tests):
153 for index2, r in enumerate(rounds):
154 self.assertFalse(decider.should_stop(), (index, index2, str(decider)))
155 decider.got_result(r)
156 self.assertTrue(decider.should_stop(), (index, str(decider)))
157
158 def testStatsInfinite(self):
159 decider = run_test_cases.RunAll()
160 for _ in xrange(200):
161 self.assertFalse(decider.should_stop())
162 decider.got_result(False)
163
164
165 class WorkerPoolTest(unittest.TestCase):
166 def test_normal(self):
167 mapper = lambda value: -value
168 with run_test_cases.ThreadPool(8) as pool:
169 for i in range(32):
170 pool.add_task(mapper, i)
171 results = pool.join()
172 self.assertEquals(range(-31, 1), sorted(results))
173
174 def test_exception(self):
175 class FearsomeException(Exception):
176 pass
177 def mapper(value):
178 raise FearsomeException(value)
179 task_added = False
180 try:
181 with run_test_cases.ThreadPool(8) as pool:
182 pool.add_task(mapper, 0)
183 task_added = True
184 pool.join()
185 self.fail()
186 except FearsomeException:
187 self.assertEquals(True, task_added)
188
189
190 if __name__ == '__main__':
191 VERBOSE = '-v' in sys.argv
192 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
193 unittest.main()
OLDNEW
« no previous file with comments | « tools/isolate/tests/run_test_cases_smoke_test.py ('k') | tools/isolate/tests/run_test_from_archive/check_files.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698