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

Side by Side Diff: build/fuchsia/test_runner.py

Issue 2692273008: Hacky slashy (Closed)
Patch Set: . Created 3 years, 10 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Packages a user.bootfs for a Fuchsia QEMU image, pulling in the runtime
8 dependencies of a test binary, and then uses QEMU from the Fuchsia SDK to run
9 it."""
10
11 import argparse
12 import os
13 import subprocess
14 import sys
15 import tempfile
16
17
18 DIR_SOURCE_ROOT = os.path.abspath(
19 os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
20 SDK_ROOT = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'fuchsia-sdk')
21
22
23 def MakeTargetImageName(common_prefix, output_directory, location):
24 assert output_directory.startswith(common_prefix)
25 output_dir_no_common_prefix = output_directory[len(common_prefix):]
26 assert location.startswith(common_prefix)
27 loc = location[len(common_prefix):]
28 if loc.startswith(output_dir_no_common_prefix):
29 loc = loc[len(output_dir_no_common_prefix)+1:]
30 return loc
31
32
33 def AddToManifest(manifest_file, target_name, source, mapper):
34 if os.path.isdir(source):
35 files = [os.path.join(dp, f) for dp, dn, fn in os.walk(source) for f in fn]
36 for f in files:
37 # We pass None as the mapper because this should never recurse a 2nd time.
38 AddToManifest(manifest_file, mapper(f), f, None)
39 elif os.path.exists(source):
40 manifest_file.write('%s=%s\n' % (target_name, source))
41 else:
42 raise Exception('%s does not exist' % source)
43
44
45 def BuildBootfs(output_directory, runtime_deps_path, test_name):
46 with open(runtime_deps_path) as f:
47 lines = f.readlines()
48
49 locations_to_add = [os.path.abspath(os.path.join(output_directory, x.strip()))
50 for x in lines]
51 # TODO(scottmg): This is a hokey way to get the test binary. We need to ask
52 # gn (or something) for the binary in addition to the runtime deps.
53 locations_to_add.append(
54 os.path.abspath(os.path.join(output_directory, test_name)))
55
56 common_prefix = os.path.commonprefix(locations_to_add)
57 target_source_pairs = zip(
58 [MakeTargetImageName(common_prefix, output_directory, loc)
59 for loc in locations_to_add],
60 locations_to_add)
61
62 # Add extra .so's that are required for running to system/lib
63 sysroot_libs = [
64 'libc++abi.so.1',
65 'libc++.so.2',
66 'libunwind.so.1',
67 ]
68 sysroot_lib_path = os.path.join(SDK_ROOT, 'sysroot', 'x86_64-fuchsia', 'lib')
69 for lib in sysroot_libs:
70 target_source_pairs.append(
71 ('lib/' + lib, os.path.join(sysroot_lib_path, lib)))
72
73 manifest_file = tempfile.NamedTemporaryFile()
74 bootfs_name = runtime_deps_path + '.bootfs'
75
76 manifest_file.file.write('%s:\n' % bootfs_name)
77 for target, source in target_source_pairs:
78 AddToManifest(manifest_file.file, target, source,
79 lambda x: MakeTargetImageName(
80 common_prefix, output_directory, x))
81
82 mkbootfs_path = os.path.join(SDK_ROOT, 'tools', 'mkbootfs')
83
84 manifest_file.flush()
85 subprocess.check_call([mkbootfs_path, '-o', bootfs_name, manifest_file.name])
86 print 'Wrote bootfs to', bootfs_name
87 return bootfs_name
88
89
90 def main():
91 parser = argparse.ArgumentParser()
92 parser.add_argument('--output-directory',
93 type=os.path.realpath,
94 help=('Path to the directory in which build files are'
95 ' located (must include build type).'))
96 parser.add_argument('--runtime-deps-path',
97 type=os.path.realpath,
98 help='Runtime data dependency file from GN.')
99 parser.add_argument('--test-name',
100 type=os.path.realpath,
101 help='Name of the the test')
102 args = parser.parse_args()
103
104 bootfs = BuildBootfs(args.output_directory, args.runtime_deps_path,
105 args.test_name)
106
107 qemu_path = os.path.join(SDK_ROOT, 'qemu', 'bin', 'qemu-system-x86_64')
108 subprocess.check_call([qemu_path, '-m', '2048', '-nographic', '-net', 'none',
109 '-smp', '4', '-machine', 'q35', '-kernel',
110 os.path.join(SDK_ROOT, 'kernel', 'magenta.bin'),
111 '-cpu', 'Haswell,+smap,-check', '-initrd', bootfs,
112 '-append', 'TERM=xterm-256color'])
113 return 0
114
115
116 if __name__ == '__main__':
117 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698