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

Side by Side Diff: run_unit_tests.py

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 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
« no previous file with comments | « recovery/repair_exe/repair_goopdate_unittest.cc ('k') | service/build.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 #
3 # Copyright 2010 Google Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ========================================================================
17
18 """Runs a set of unit tests and returns success only if they all succeed.
19
20 This script assumes it is being run from the omaha directory.
21
22 To run unit tests for Omaha's default set of test directories, just run the file
23 from the command line.
24 """
25
26
27 import dircache
28 import os
29
30 TEST_EXECUTABLE_RHS = '_unittest.exe'
31
32 # Build paths that contain tests.
33 STAGING_PATH = 'scons-out\\dbg-win\\staging'
34 TESTS_PATH = 'scons-out\\dbg-win\\tests'
35
36
37 def RunTest(test_path):
38 """Runs a test and returns its exit code.
39
40 Assumes the tests can be run from any directory. In other words, it does not
41 chdir.
42
43 Args:
44 test_path: Path to test executables.
45
46 Returns:
47 The exit code from the test process.
48 """
49
50 print '\nRunning %s . . .\n' % test_path
51
52 # Put './' in front of the file name to avoid accidentally running a file with
53 # the same name in some other directory if test_path were just a file name.
54 return os.system(os.path.join('.', test_path))
55
56
57 def RunTests(test_paths):
58 """Runs all tests specified by test_paths.
59
60 Args:
61 test_paths: A list of paths to test executables.
62
63 Returns:
64 0 if all tests are successful.
65 1 if some tests fail, or if there is an error.
66 """
67
68 if not test_paths or len(test_paths) < 1:
69 return 1
70
71 print 'Found the following tests to run:'
72 for test in test_paths:
73 print '\t%s' % test
74
75 # Run all tests and remembers those that failed.
76 failed_tests = [t for t in test_paths if RunTest(t)]
77
78 print '\n\n%s test executables were run.' % len(test_paths)
79
80 failed_test_count = len(failed_tests)
81 if failed_test_count:
82 # Lists the executables that failed so the user can investigate them.
83 print 'FAILED!'
84 print 'The following %s tests failed:\n' % failed_test_count
85 for test in failed_tests:
86 print test
87 return 1
88 else:
89 # No, there is none.
90 if test_paths:
91 print 'All of them PASSED!'
92 return 0
93
94
95 def GetTestsInDirs(test_dirs):
96 """Returns a list of all unit test executables in test_dirs.
97
98 Does not search subdirectories.
99
100 Args:
101 test_dirs: A list of directories to search.
102
103 Returns:
104 List of all unit tests.
105 """
106
107 tests = []
108
109 for test_dir in test_dirs:
110 # Use dircache.listdir so order is alphabetical and thus deterministic.
111 files = dircache.listdir(test_dir)
112
113 for test_file in files:
114 if test_file.endswith(TEST_EXECUTABLE_RHS):
115 relative_path = os.path.join(test_dir, test_file)
116 if os.path.isfile(relative_path):
117 tests += [relative_path]
118
119 return tests
120
121 # Run a unit test when the module is run directly.
122 if __name__ == '__main__':
123 # List of paths that contain unit tests to run.
124 dirs_containing_tests = [STAGING_PATH, TESTS_PATH]
125
126 tests_to_run = GetTestsInDirs(dirs_containing_tests)
127
128 RunTests(tests_to_run)
OLDNEW
« no previous file with comments | « recovery/repair_exe/repair_goopdate_unittest.cc ('k') | service/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698