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 os | 6 import os |
7 import subprocess | 7 import subprocess |
8 import sys | 8 import sys |
9 import glob | |
Lei Zhang
2015/11/20 00:17:47
alphabetical order
zhaoqin1
2015/11/21 04:20:45
Done.
| |
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): | |
Lei Zhang
2015/11/20 00:17:47
From reading the code, it looks like |pdf_name| is
zhaoqin1
2015/11/21 04:20:45
handle it in run_corpus_tests.py now.
| |
34 # convert string to list | |
35 cmd_to_run = wrapper.split() | |
36 | |
37 # Usually, we pass "-logdir" "foo\bar\spam path" args to Dr. Memory. | |
38 # To group reports per test, we want to put the reports for each test into a | |
39 # separate directory. This code can be simplified when we have | |
40 # https://github.com/DynamoRIO/drmemory/issues/684 fixed. | |
41 logdir_idx = cmd_to_run.index("-logdir") | |
Lei Zhang
2015/11/20 00:17:47
Can you check this does not return the sentinel va
zhaoqin1
2015/11/21 04:20:45
it raise exception on "not found", add check
| |
42 old_logdir = cmd_to_run[logdir_idx + 1] | |
43 wrapper_pid = str(os.getpid()) | |
44 | |
45 # On Windows, there is a chance of PID collision. We avoid it by appending the | |
Lei Zhang
2015/11/20 00:17:47
Oh boy oh boy oh boy.
zhaoqin1
2015/11/21 04:20:45
It gets worse here.
Originally, this function is
| |
46 # number of entries in the logdir at the end of wrapper_pid. | |
47 # This number is monotonic and we can't have two simultaneously running wrappe rs | |
Lei Zhang
2015/11/20 00:17:47
80 chars
zhaoqin1
2015/11/21 04:20:45
Done.
| |
48 # with the same PID. | |
49 wrapper_pid += "_%d" % len(glob.glob(old_logdir + "\\*")) | |
50 | |
51 cmd_to_run[logdir_idx + 1] += "\\testcase.%s.logs" % wrapper_pid | |
52 os.makedirs(cmd_to_run[logdir_idx + 1]) | |
53 | |
54 f = open(old_logdir + "\\testcase.%s.name" % wrapper_pid, "w") | |
55 print >>f, pdf_name + ".pdf" | |
56 f.close() | |
57 | |
58 return cmd_to_run | |
59 | |
30 | 60 |
31 class DirectoryFinder: | 61 class DirectoryFinder: |
32 '''A class for finding directories and paths under either a standalone | 62 '''A class for finding directories and paths under either a standalone |
33 checkout or a chromium checkout of PDFium.''' | 63 checkout or a chromium checkout of PDFium.''' |
34 | 64 |
35 def __init__(self, build_location): | 65 def __init__(self, build_location): |
36 # |build_location| is typically "out/Debug" or "out/Release". | 66 # |build_location| is typically "out/Debug" or "out/Release". |
37 # Expect |my_dir| to be .../pdfium/testing/tools. | 67 # Expect |my_dir| to be .../pdfium/testing/tools. |
38 self.my_dir = os.path.dirname(os.path.realpath(__file__)) | 68 self.my_dir = os.path.dirname(os.path.realpath(__file__)) |
39 self.testing_dir = os.path.dirname(self.my_dir) | 69 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: | 103 if other_components: |
74 result = os.path.join(result, other_components) | 104 result = os.path.join(result, other_components) |
75 return result | 105 return result |
76 | 106 |
77 def TestingDir(self, other_components=''): | 107 def TestingDir(self, other_components=''): |
78 '''Finds test files somewhere under the testing directory.''' | 108 '''Finds test files somewhere under the testing directory.''' |
79 result = self.testing_dir | 109 result = self.testing_dir |
80 if other_components: | 110 if other_components: |
81 result = os.path.join(result, other_components) | 111 result = os.path.join(result, other_components) |
82 return result | 112 return result |
OLD | NEW |