Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 # valgrind_test.py | 6 # valgrind_test.py |
| 7 | 7 |
| 8 """Runs an exe through Valgrind and puts the intermediate files in a | 8 """Runs an exe through Valgrind and puts the intermediate files in a |
| 9 directory. | 9 directory. |
| 10 """ | 10 """ |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 "in the tool-specific subclass" | 383 "in the tool-specific subclass" |
| 384 | 384 |
| 385 def CreateBrowserWrapper(self, proc): | 385 def CreateBrowserWrapper(self, proc): |
| 386 """The program being run invokes Python or something else that can't stand | 386 """The program being run invokes Python or something else that can't stand |
| 387 to be valgrinded, and also invokes the Chrome browser. In this case, use a | 387 to be valgrinded, and also invokes the Chrome browser. In this case, use a |
| 388 magic wrapper to only valgrind the Chrome browser. Build the wrapper here. | 388 magic wrapper to only valgrind the Chrome browser. Build the wrapper here. |
| 389 Returns the path to the wrapper. It's up to the caller to use the wrapper | 389 Returns the path to the wrapper. It's up to the caller to use the wrapper |
| 390 appropriately. | 390 appropriately. |
| 391 """ | 391 """ |
| 392 command = " ".join(proc) | 392 command = " ".join(proc) |
| 393 # Add the PID of the browser wrapper to the logfile names so we can | |
| 394 # separate log files for different UI tests at the analyze stage. | |
| 393 command = command.replace("%p", "$$.%p") | 395 command = command.replace("%p", "$$.%p") |
| 394 | 396 |
| 395 (fd, indirect_fname) = tempfile.mkstemp(dir=self.log_dir, | 397 (fd, indirect_fname) = tempfile.mkstemp(dir=self.log_dir, |
| 396 prefix="browser_wrapper.", | 398 prefix="browser_wrapper.", |
| 397 text=True) | 399 text=True) |
| 398 f = os.fdopen(fd, "w") | 400 f = os.fdopen(fd, "w") |
| 399 f.write("#!/bin/bash\n") | 401 f.write('#!/bin/bash\n' |
| 400 f.write('echo "Started Valgrind wrapper for this test, PID=$$"\n\n') | 402 'echo "Started Valgrind wrapper for this test, PID=$$"\n') |
| 401 f.write('for arg in $@\ndo\n') | 403 |
| 402 f.write(' if [[ "$arg" =~ --test-name=(.*) ]]\n then\n') | 404 # Try to get the test case name by looking at the program arguments. |
| 403 f.write(' TESTCASE=${BASH_REMATCH[1]}\n') | 405 # i.e. Chromium ui_tests and friends pass --test-name arg. |
| 404 f.write(' echo $TESTCASE >`dirname $0`/testcase.$$.name\n') | 406 f.write('DIR=`dirname $0`\n' |
| 405 f.write(' fi\ndone\n') | 407 'FOUND_TESTNAME=0\n' |
| 406 # Add the PID of the browser wrapper to the logfile names so we can | 408 'TESTNAME_FILE=$DIR/testcase.$$.name\n' |
| 407 # separate log files for different UI tests at the analyze stage. | 409 'for arg in $@; do\n' |
| 408 f.write(command) | 410 ' # TODO(timurrrr): this doesn\'t handle "--test-name Test.Name"\n' |
| 409 f.write(' "$@"\n') | 411 ' if [[ "$arg" =~ --test-name=(.*) ]]; then\n' |
| 412 ' echo ${BASH_REMATCH[1]} >$TESTNAME_FILE\n' | |
| 413 ' FOUND_TESTNAME=1\n' | |
| 414 ' fi\n' | |
| 415 'done\n\n') | |
| 416 | |
| 417 f.write('if [ "$FOUND_TESTNAME" = "1" ]; then\n' | |
| 418 ' %s "$@"\n' | |
| 419 'else\n' % command) | |
| 420 # Webkit layout_tests print out the test URL as the first line of stdout. | |
| 421 f.write(' %s "$@" | tee $DIR/test.$$.stdout\n' | |
| 422 ' EXITCODE=$PIPESTATUS\n' # $? holds the tee's exit code | |
| 423 ' head -n 1 $DIR/test.$$.stdout |\n' | |
| 424 ' grep URL |\n' | |
|
Timur Iskhodzhanov
2011/11/12 19:42:11
also: extra check won't hurt.
| |
| 425 ' sed "s/^.*third_party\/WebKit\/LayoutTests\///" ' | |
| 426 '>$TESTNAME_FILE\n' | |
| 427 ' exit $EXITCODE\n' | |
| 428 'fi\n' % command) | |
| 429 | |
| 410 f.close() | 430 f.close() |
| 411 os.chmod(indirect_fname, stat.S_IRUSR|stat.S_IXUSR) | 431 os.chmod(indirect_fname, stat.S_IRUSR|stat.S_IXUSR) |
| 412 return indirect_fname | 432 return indirect_fname |
| 413 | 433 |
| 414 def CreateAnalyzer(self): | 434 def CreateAnalyzer(self): |
| 415 raise NotImplementedError, "This method should be implemented " \ | 435 raise NotImplementedError, "This method should be implemented " \ |
| 416 "in the tool-specific subclass" | 436 "in the tool-specific subclass" |
| 417 | 437 |
| 418 def GetAnalyzeResults(self, check_sanity=False): | 438 def GetAnalyzeResults(self, check_sanity=False): |
| 419 # Glob all the files in the "testing.tmp" directory | 439 # Glob all the files in the "testing.tmp" directory |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 platform_name = sys.platform + "(Unknown)" | 1136 platform_name = sys.platform + "(Unknown)" |
| 1117 raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, | 1137 raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, |
| 1118 platform_name) | 1138 platform_name) |
| 1119 | 1139 |
| 1120 def CreateTool(tool): | 1140 def CreateTool(tool): |
| 1121 return ToolFactory().Create(tool) | 1141 return ToolFactory().Create(tool) |
| 1122 | 1142 |
| 1123 if __name__ == '__main__': | 1143 if __name__ == '__main__': |
| 1124 logging.error(sys.argv[0] + " can not be run from command line") | 1144 logging.error(sys.argv[0] + " can not be run from command line") |
| 1125 sys.exit(1) | 1145 sys.exit(1) |
| OLD | NEW |