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

Side by Side Diff: pydir/crosstest.py

Issue 987503004: Subzero: Run cross tests as a much more configurable python script. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add import to be safe Created 5 years, 9 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 | « crosstest/runtests.sh ('k') | pydir/crosstest_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python2 1 #!/usr/bin/env python2
2 2
3 import argparse 3 import argparse
4 import os 4 import os
5 import subprocess 5 import subprocess
6 import sys 6 import sys
7 import tempfile 7 import tempfile
8 8
9 from utils import shellcmd 9 from utils import shellcmd
10 from utils import FindBaseNaCl 10 from utils import FindBaseNaCl
11 11
12 def main(): 12 def main():
13 """Builds a cross-test binary that allows functions translated by 13 """Builds a cross-test binary for comparing Subzero and llc translation.
14 Subzero and llc to be compared.
15 14
16 Each --test argument is compiled once by llc and once by Subzero. 15 Each --test argument is compiled once by llc and once by Subzero. C/C++
17 C/C++ tests are first compiled down to PNaCl bitcode by the 16 tests are first compiled down to PNaCl bitcode using pnacl-clang and
18 build-pnacl-ir.py script. The --prefix argument ensures that 17 pnacl-opt. The --prefix argument ensures that symbol names are different
19 symbol names are different between the two object files, to avoid 18 between the two object files, to avoid linking errors.
20 linking errors.
21 19
22 There is also a --driver argument that specifies the C/C++ file 20 There is also a --driver argument that specifies the C/C++ file that calls
23 that calls the test functions with a variety of interesting inputs 21 the test functions with a variety of interesting inputs and compares their
24 and compares their results. 22 results.
23
25 """ 24 """
26 # arch_map maps a Subzero target string to an llvm-mc -triple string. 25 # arch_map maps a Subzero target string to an llvm-mc -triple string.
27 arch_map = { 'x8632':'i686', 'x8664':'x86_64', 'arm':'armv7a' } 26 arch_map = { 'x8632':'i686', 'x8664':'x86_64', 'arm':'armv7a' }
28 desc = 'Build a cross-test that compares Subzero and llc translation.' 27 desc = 'Build a cross-test that compares Subzero and llc translation.'
29 argparser = argparse.ArgumentParser(description=desc) 28 argparser = argparse.ArgumentParser(description=desc)
30 argparser.add_argument('--test', required=True, action='append', 29 argparser.add_argument('--test', required=True, action='append',
31 metavar='TESTFILE_LIST', 30 metavar='TESTFILE_LIST',
32 help='List of C/C++/.ll files with test functions') 31 help='List of C/C++/.ll files with test functions')
33 argparser.add_argument('--driver', required=True, 32 argparser.add_argument('--driver', required=True,
34 metavar='DRIVER', 33 metavar='DRIVER',
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ' Default %(default)d.') 68 ' Default %(default)d.')
70 argparser.add_argument('--filetype', default='obj', dest='filetype', 69 argparser.add_argument('--filetype', default='obj', dest='filetype',
71 choices=['obj', 'asm', 'iasm'], 70 choices=['obj', 'asm', 'iasm'],
72 help='Output file type. Default %(default)s.') 71 help='Output file type. Default %(default)s.')
73 args = argparser.parse_args() 72 args = argparser.parse_args()
74 73
75 nacl_root = FindBaseNaCl() 74 nacl_root = FindBaseNaCl()
76 bindir = ('{root}/toolchain/linux_x86/pnacl_newlib/bin' 75 bindir = ('{root}/toolchain/linux_x86/pnacl_newlib/bin'
77 .format(root=nacl_root)) 76 .format(root=nacl_root))
78 triple = arch_map[args.target] + ('-nacl' if args.sandbox else '') 77 triple = arch_map[args.target] + ('-nacl' if args.sandbox else '')
78 mypath = os.path.abspath(os.path.dirname(sys.argv[0]))
79 79
80 objs = [] 80 objs = []
81 for arg in args.test: 81 for arg in args.test:
82 # Construct a "unique key" for each test so that tests can be run in
83 # parallel without race conditions on temporary file creation.
84 key = '{target}.{sb}.O{opt}.{attr}'.format(
85 target=args.target, sb='sb' if args.sandbox else 'nat',
86 opt=args.optlevel, attr=args.attr)
82 base, ext = os.path.splitext(arg) 87 base, ext = os.path.splitext(arg)
83 if ext == '.ll': 88 if ext == '.ll':
84 bitcode = arg 89 bitcode = arg
85 else: 90 else:
86 bitcode = os.path.join(args.dir, base + '.pnacl.ll') 91 # Use pnacl-clang and pnacl-opt to produce PNaCl bitcode.
87 shellcmd(['../pydir/build-pnacl-ir.py', '--disable-verify', 92 bitcode_nonfinal = os.path.join(args.dir, base + '.' + key + '.bc')
88 '--dir', args.dir, arg]) 93 bitcode = os.path.join(args.dir, base + '.' + key + '.pnacl.ll')
94 shellcmd(['{bin}/pnacl-clang'.format(bin=bindir),
95 '-O2', '-c', arg, '-o', bitcode_nonfinal])
96 shellcmd(['{bin}/pnacl-opt'.format(bin=bindir),
97 '-pnacl-abi-simplify-preopt',
98 '-pnacl-abi-simplify-postopt',
99 '-pnaclabi-allow-debug-metadata',
100 bitcode_nonfinal, '-S', '-o', bitcode])
89 101
90 base_sz = '{base}.{sb}.O{opt}.{attr}.{target}'.format( 102 base_sz = '{base}.{key}'.format(base=base, key=key)
91 base=base, sb='sb' if args.sandbox else 'nat', opt=args.optlevel,
92 attr=args.attr, target=args.target)
93 asm_sz = os.path.join(args.dir, base_sz + '.sz.s') 103 asm_sz = os.path.join(args.dir, base_sz + '.sz.s')
94 obj_sz = os.path.join(args.dir, base_sz + '.sz.o') 104 obj_sz = os.path.join(args.dir, base_sz + '.sz.o')
95 obj_llc = os.path.join(args.dir, base_sz + '.llc.o') 105 obj_llc = os.path.join(args.dir, base_sz + '.llc.o')
96 shellcmd(['../pnacl-sz', 106 shellcmd(['{path}/pnacl-sz'.format(path=os.path.dirname(mypath)),
97 '-O' + args.optlevel, 107 '-O' + args.optlevel,
98 '-mattr=' + args.attr, 108 '-mattr=' + args.attr,
99 '--target=' + args.target, 109 '--target=' + args.target,
100 '--sandbox=' + str(args.sandbox), 110 '--sandbox=' + str(args.sandbox),
101 '--prefix=' + args.prefix, 111 '--prefix=' + args.prefix,
102 '-allow-uninitialized-globals', 112 '-allow-uninitialized-globals',
103 '-externalize', 113 '-externalize',
104 '-filetype=' + args.filetype, 114 '-filetype=' + args.filetype,
105 '-o=' + (obj_sz if args.filetype == 'obj' else asm_sz), 115 '-o=' + (obj_sz if args.filetype == 'obj' else asm_sz),
106 bitcode]) 116 bitcode])
(...skipping 30 matching lines...) Expand all
137 bin=bindir, prefix='pnacl-' if args.sandbox else '', 147 bin=bindir, prefix='pnacl-' if args.sandbox else '',
138 cc='clang' if pure_c else 'clang++') 148 cc='clang' if pure_c else 'clang++')
139 sb_native_args = (['-O0', '--pnacl-allow-native', '-arch', 'x8632'] 149 sb_native_args = (['-O0', '--pnacl-allow-native', '-arch', 'x8632']
140 if args.sandbox else 150 if args.sandbox else
141 ['-g', '-m32', '-lm', '-lpthread']) 151 ['-g', '-m32', '-lm', '-lpthread'])
142 shellcmd([compiler, args.driver] + objs + 152 shellcmd([compiler, args.driver] + objs +
143 ['-o', os.path.join(args.dir, args.output)] + sb_native_args) 153 ['-o', os.path.join(args.dir, args.output)] + sb_native_args)
144 154
145 if __name__ == '__main__': 155 if __name__ == '__main__':
146 main() 156 main()
OLDNEW
« no previous file with comments | « crosstest/runtests.sh ('k') | pydir/crosstest_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698