| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The PDFium Authors. All rights reserved. | 2 # Copyright 2015 The PDFium 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 glob |
| 6 import os | 7 import os |
| 7 import subprocess | 8 import subprocess |
| 8 import sys | 9 import sys |
| 9 | 10 |
| 10 def os_name(): | 11 def os_name(): |
| 11 if sys.platform.startswith('linux'): | 12 if sys.platform.startswith('linux'): |
| 12 return 'linux' | 13 return 'linux' |
| 13 if sys.platform.startswith('win'): | 14 if sys.platform.startswith('win'): |
| 14 return 'win' | 15 return 'win' |
| 15 if sys.platform.startswith('darwin'): | 16 if sys.platform.startswith('darwin'): |
| 16 return 'mac' | 17 return 'mac' |
| 17 raise Exception('Confused, can not determine OS, aborting.') | 18 raise Exception('Confused, can not determine OS, aborting.') |
| 18 | 19 |
| 19 | 20 |
| 20 def RunCommand(cmd, redirect_output=False): | 21 def RunCommand(cmd, redirect_output=False): |
| 21 try: | 22 try: |
| 22 if redirect_output: | 23 if redirect_output: |
| 23 sys.stdout.write(subprocess.check_output(cmd, stderr=subprocess.STDOUT)) | 24 sys.stdout.write(subprocess.check_output(cmd, stderr=subprocess.STDOUT)) |
| 24 else: | 25 else: |
| 25 subprocess.check_call(cmd) | 26 subprocess.check_call(cmd) |
| 26 return None | 27 return None |
| 27 except subprocess.CalledProcessError as e: | 28 except subprocess.CalledProcessError as e: |
| 28 return e | 29 return e |
| 29 | 30 |
| 31 # Adjust Dr. Memory wrapper to have separate log directory for each test |
| 32 # for better error reporting. |
| 33 def DrMemoryWrapper(wrapper, pdf_name): |
| 34 if not wrapper: |
| 35 return [] |
| 36 # convert string to list |
| 37 cmd_to_run = wrapper.split() |
| 38 |
| 39 # Do nothing if using default log directory. |
| 40 if cmd_to_run.count("-logdir") == 0: |
| 41 return cmd_to_run |
| 42 # Usually, we pass "-logdir" "foo\bar\spam path" args to Dr. Memory. |
| 43 # To group reports per test, we want to put the reports for each test into a |
| 44 # separate directory. This code can be simplified when we have |
| 45 # https://github.com/DynamoRIO/drmemory/issues/684 fixed. |
| 46 logdir_idx = cmd_to_run.index("-logdir") |
| 47 old_logdir = cmd_to_run[logdir_idx + 1] |
| 48 wrapper_pid = str(os.getpid()) |
| 49 |
| 50 # We are using the same pid of the same python process, so append the number |
| 51 # of entries in the logdir at the end of wrapper_pid to avoid conflict. |
| 52 wrapper_pid += "_%d" % len(glob.glob(old_logdir + "\\*")) |
| 53 |
| 54 cmd_to_run[logdir_idx + 1] += "\\testcase.%s.logs" % wrapper_pid |
| 55 os.makedirs(cmd_to_run[logdir_idx + 1]) |
| 56 |
| 57 f = open(old_logdir + "\\testcase.%s.name" % wrapper_pid, "w") |
| 58 print >>f, pdf_name + ".pdf" |
| 59 f.close() |
| 60 |
| 61 return cmd_to_run |
| 62 |
| 30 | 63 |
| 31 class DirectoryFinder: | 64 class DirectoryFinder: |
| 32 '''A class for finding directories and paths under either a standalone | 65 '''A class for finding directories and paths under either a standalone |
| 33 checkout or a chromium checkout of PDFium.''' | 66 checkout or a chromium checkout of PDFium.''' |
| 34 | 67 |
| 35 def __init__(self, build_location): | 68 def __init__(self, build_location): |
| 36 # |build_location| is typically "out/Debug" or "out/Release". | 69 # |build_location| is typically "out/Debug" or "out/Release". |
| 37 # Expect |my_dir| to be .../pdfium/testing/tools. | 70 # Expect |my_dir| to be .../pdfium/testing/tools. |
| 38 self.my_dir = os.path.dirname(os.path.realpath(__file__)) | 71 self.my_dir = os.path.dirname(os.path.realpath(__file__)) |
| 39 self.testing_dir = os.path.dirname(self.my_dir) | 72 self.testing_dir = os.path.dirname(self.my_dir) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if other_components: | 106 if other_components: |
| 74 result = os.path.join(result, other_components) | 107 result = os.path.join(result, other_components) |
| 75 return result | 108 return result |
| 76 | 109 |
| 77 def TestingDir(self, other_components=''): | 110 def TestingDir(self, other_components=''): |
| 78 '''Finds test files somewhere under the testing directory.''' | 111 '''Finds test files somewhere under the testing directory.''' |
| 79 result = self.testing_dir | 112 result = self.testing_dir |
| 80 if other_components: | 113 if other_components: |
| 81 result = os.path.join(result, other_components) | 114 result = os.path.join(result, other_components) |
| 82 return result | 115 return result |
| OLD | NEW |