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

Side by Side Diff: tests/abi_corpus/validator_regression_test.py

Issue 9950041: Adding a startup regression test. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: adding missing file Created 8 years, 8 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/python
2 # Copyright (c) 2012 The Native Client 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 optparse
7 import os
8 import subprocess
9 import tempfile
10
11 import corpus_utils
12
13
14 KNOWN_BAD = set([
15 '1c2b051cb60367cf103128c9cd76769ffa1cf356',
16 ])
17
18
19 class UnexpectedValidateResult(Exception):
20 pass
21
22
23 def ValidateNexe(options, path, src_path, expect_pass):
24 """Run the validator on a nexe, check if the result is expected.
25
26 Args:
27 options: bag of options.
28 path: path to the nexe.
29 src_path: path to nexe on server.
30 expect_pass: boolean indicating if the nexe is expected to validate.
31 Returns:
32 True if validation matches expectations.
33 """
34 process = subprocess.Popen(
35 [options.validator, path],
36 stdout=subprocess.PIPE,
37 stderr=subprocess.PIPE)
38 process_stdout, process_stderr = process.communicate()
39 # Check if result is what we expect.
40 did_pass = (process.returncode == 0)
41 if expect_pass != did_pass:
42 if options.verbose:
43 print '-' * 70
44 print 'Validating: %s' % path
45 print 'From: %s' % src_path
46 print 'Size: %d' % os.path.getsize(path)
47 print 'SHA1: %s' % corpus_utils.Sha1FromFilename(path)
48 print 'Validator: %s' % options.validator
49 print 'Unexpected return code: %s' % process.returncode
50 print '>>> STDOUT'
51 print process_stdout
52 print '>>> STDERR'
53 print process_stderr
54 print '-' * 70
55 else:
56 print 'Failed on sha1: %s' % corpus_utils.Sha1FromFilename(path)
Nick Bray 2012/04/03 20:34:29 Very optional because this is not under review: yo
bradn 2012/04/12 17:45:54 Done.
57 return False
58 return True
59
60
61 def NexeShouldValidate(path):
62 """Checks a blacklist to decide if a nexe should validate.
63
64 Args:
65 path: path to the nexe.
66 Returns:
67 Boolean indicating if the nexe should validate.
68 """
69 return corpus_utils.Sha1FromFilename(path) not in KNOWN_BAD
70
71
72 def TestValidators(options, work_dir):
73 """Test x86 validators on current snapshot.
74
75 Args:
76 options: bag of options.
77 work_dir: directory to operate in.
78 """
79 nexe_filename = os.path.join(work_dir, 'test.nexe')
80 list_filename = os.path.join(work_dir, 'naclapps.list')
81 filenames = corpus_utils.DownloadNexeList(list_filename)
82 progress = corpus_utils.Progress(len(filenames))
83 for filename in filenames:
84 progress.Tally()
85 corpus_utils.PrimeCache(options, filename)
86 # Stop here if downloading only.
87 if options.download_only:
88 continue
89 # Skip if not the right architecture.
90 architecture = corpus_utils.NexeArchitecture(
91 corpus_utils.CachedPath(options, filename))
92 if architecture != options.architecture:
93 continue
94 # Validate a copy in case validator is mutating.
95 corpus_utils.CopyFromCache(options, filename, nexe_filename)
96 try:
97 result = ValidateNexe(
98 options, nexe_filename, filename,
99 NexeShouldValidate(filename))
100 progress.Result(result)
101 if not result and not options.keep_going:
102 break
103 finally:
104 try:
105 os.remove(nexe_filename)
106 except OSError:
107 print 'ERROR - unable to remove %s' % nexe_filename
108 progress.Summary(warn_only=True)
109
110
111 def Main():
112 parser = optparse.OptionParser()
113 corpus_utils.SetupOptions(parser)
114 parser.add_option(
115 '--download-only', dest='download_only',
116 default=False, action='store_true',
117 help='download to cache without running the tests')
118 parser.add_option(
119 '-k', '--keep-going', dest='keep_going',
120 default=False, action='store_true',
121 help='keep going on failure')
122 parser.add_option(
123 '--validator', dest='validator',
124 help='location of validator executable')
125 parser.add_option(
126 '--arch', dest='architecture',
127 help='architecture of validator')
128 parser.add_option(
129 '-v', '--verbose', dest='verbose', default=False, action='store_true',
130 help='run in verbose mode')
131 options, args = parser.parse_args()
132 if args:
133 parser.error('unused arguments')
134 if not options.download_only:
135 if not options.validator:
136 parser.error('no validator specified')
137 if not options.architecture:
138 parser.error('no architecture specified')
139
140 work_dir = tempfile.mkdtemp(suffix='validate_nexes', prefix='tmp')
141 try:
142 TestValidators(options, work_dir)
143 finally:
144 corpus_utils.RemoveDir(work_dir)
145
146
147 if __name__ == '__main__':
148 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698