blob: cd2cbb87fb3735ceb5ae9ea1c30e926a58284f0e [file] [log] [blame]
asharifb1752c82013-02-15 04:56:37 +00001import getpass
ashariffc33cd92013-02-15 06:31:21 +00002from automation.common import job
asharif7a4a9992013-02-15 04:50:29 +00003from automation.common import machine_description
asharif967d7002013-02-15 04:51:00 +00004import os
asharif7b96a552013-02-15 04:55:33 +00005import re
asharif967d7002013-02-15 04:51:00 +00006import sys
asharifea33a562013-02-15 04:56:09 +00007import time
asharifb1752c82013-02-15 04:56:37 +00008from utils import utils
asharif57a09492013-02-15 04:50:26 +00009
asharif9d40cc22013-02-15 04:56:59 +000010depot2_dir = "//depot2/"
11p4_checkout_dir = "perforce2/"
asharif6ba78c42013-02-15 04:50:40 +000012version_dir = "/gcctools/chromeos/v14/"
asharif6ba78c42013-02-15 04:50:40 +000013p4_version_dir = p4_checkout_dir + version_dir
asharif6ba78c42013-02-15 04:50:40 +000014
asharif2beabd12013-02-15 04:50:38 +000015chromeos_root = "chromeos"
asharif6ba78c42013-02-15 04:50:40 +000016scripts_dir = "src/scripts"
17chromeos_scripts_dir = chromeos_root + "/" + scripts_dir
asharif57a09492013-02-15 04:50:26 +000018
asharif9d40cc22013-02-15 04:56:59 +000019tc_pkgs_dir = "output/pkgs"
20tc_objects_dir = "output/objects"
21
asharif95c25912013-02-15 04:57:10 +000022perflab_binary = "/home/mobiletc-prebuild/perflab-checkout/google3/blaze-bin/platforms/performance/brrd/perflab/perflab"
23perflab_interpreter_arg = "--perflab_interpreter=/home/mobiletc-prebuild/perflab-checkout/google3/blaze-bin/platforms/performance/brrd/run_tools/experiment_job_dag"
24perflab_brrd_config_arg = "--brrd_config=/home/mobiletc-prebuild/perflab-checkout/google3/platforms/performance/brrd/perflab/util/perflab.cfg"
asharif9d6ccaa2013-02-15 04:57:17 +000025perflab_options = "--alsologtostderr"
26perflab_command = ("%s %s %s %s " %
27 (perflab_binary, perflab_interpreter_arg,
28 perflab_brrd_config_arg, perflab_options))
asharif95c25912013-02-15 04:57:10 +000029
asharif57a09492013-02-15 04:50:26 +000030def _GetP4ClientSpec(client_name, p4_paths):
31 p4_string = ""
32 for p4_path in p4_paths:
33 p4_string += " -a \"" + (" //" + client_name + "/").join(p4_path) + "\""
34
35 return p4_string
36
37
asharif967d7002013-02-15 04:51:00 +000038def GetP4Command(p4_port, p4_paths, revision, checkoutdir, p4_snapshot=""):
asharif57a09492013-02-15 04:50:26 +000039 command = ""
asharif967d7002013-02-15 04:51:00 +000040
41 if p4_snapshot:
42 command += "mkdir -p " + checkoutdir
43 for p4_path in p4_paths:
44 real_path = p4_path[1]
45 if real_path.endswith("..."):
46 real_path = real_path.replace("/...", "")
asharif1755b432013-02-15 04:55:29 +000047 command += ("; mkdir -p " + checkoutdir + "/" +
asharif967d7002013-02-15 04:51:00 +000048 os.path.dirname(real_path))
asharif1755b432013-02-15 04:55:29 +000049 command += ("&& rsync -lr " + p4_snapshot + "/" + real_path +
50 " " + checkoutdir + "/" + os.path.dirname(real_path))
asharif967d7002013-02-15 04:51:00 +000051 return command
52
asharif95c25912013-02-15 04:57:10 +000053 client_name = "p4-automation-$HOSTNAME-$JOB_ID"
asharif57a09492013-02-15 04:50:26 +000054 command += " export P4CONFIG=.p4config"
55 command += " && mkdir -p " + checkoutdir
56 command += " && cd " + checkoutdir
57 command += " && cp ${HOME}/.p4config ."
58 command += " && chmod u+w .p4config"
59 command += " && echo \"P4PORT=" + p4_port + "\" >> .p4config"
60 command += " && echo \"P4CLIENT=" + client_name + "\" >> .p4config"
61 command += (" && g4 client " +
62 _GetP4ClientSpec(client_name, p4_paths))
63 command += " && g4 sync ..."
64 command += " && g4 client -d " + client_name
asharif2beabd12013-02-15 04:50:38 +000065 command += " && cd -"
asharif57a09492013-02-15 04:50:26 +000066 return command
67
asharif7cbe0692013-02-15 06:17:33 +000068def CreateLinuxJob(command, lock=False):
asharif2beabd12013-02-15 04:50:38 +000069 to_return = job.Job(command)
asharif7cbe0692013-02-15 06:17:33 +000070 to_return.AddRequiredMachine("", "linux", lock)
asharif57a09492013-02-15 04:50:26 +000071 return to_return
72
asharif2beabd12013-02-15 04:50:38 +000073def CreateP4Job(p4_port, p4_paths, revision, checkoutdir):
74 to_return = CreateLinuxJob(GetP4Command(p4_port, p4_paths,
75 revision, checkoutdir))
76 return to_return
77
asharif3a7f5a92013-02-15 05:15:55 +000078def _GetChromeOSGoldenBuildLocation():
79 return "/home/mobiletc-prebuild/www/chromeos_builds/"
asharif2beabd12013-02-15 04:50:38 +000080
asharif6ba78c42013-02-15 04:50:40 +000081def GetInitialCommand():
82 return "pwd && uname -a"
83
84def GetCopyTreeCommand(source, dest):
85 command = ""
86 command += "mkdir -p " + dest
87 command += "&& cp -pr " + source + "/* " + dest
88 return command
89
asharif967d7002013-02-15 04:51:00 +000090def GetP4VersionDirCommand(p4_snapshot=""):
asharif6ba78c42013-02-15 04:50:40 +000091 p4_port = "perforce2:2666"
92 p4_paths = []
93 p4_paths.append(("//depot2/gcctools/chromeos/v14/...", "gcctools/chromeos/v14/..."))
94 p4_revision = 1
asharif967d7002013-02-15 04:51:00 +000095 command = GetP4Command(p4_port, p4_paths, p4_revision, p4_checkout_dir, p4_snapshot)
asharif6ba78c42013-02-15 04:50:40 +000096 return command
97
asharif95c25912013-02-15 04:57:10 +000098def GetP4BenchmarksDirCommand(p4_snapshot=""):
99 p4_port = "perforce2:2666"
100 p4_paths = []
101 p4_paths.append(("//depot2/third_party/android_bench/v2_0/...", "gcctools/chromeos/v14/third_party/android_bench/v2_0/..."))
102 p4_revision = 1
103 command = GetP4Command(p4_port, p4_paths, p4_revision, p4_checkout_dir, p4_snapshot)
104 return command
asharif6ba78c42013-02-15 04:50:40 +0000105
asharif9d40cc22013-02-15 04:56:59 +0000106def GetTCRootDir(toolchain="trunk"):
asharif9d40cc22013-02-15 04:56:59 +0000107 if toolchain == "trunk":
asharifd5c2b2f2013-02-15 05:15:29 +0000108 gcctools_prefix = ""
109 elif toolchain == "v1":
110 gcctools_prefix = "branches/chromeos_toolchain_v1_release_branch/"
asharife9433c32013-02-15 05:53:27 +0000111 elif toolchain == "v2":
112 gcctools_prefix = "branches/mobile_toolchain_v14_release_branch/"
asharif9d40cc22013-02-15 04:56:59 +0000113 else:
asharife9433c32013-02-15 05:53:27 +0000114 utils.AssertExit(False, "Wrong value for toolchain %s" % toolchain)
asharifd5c2b2f2013-02-15 05:15:29 +0000115 local_path = p4_checkout_dir + gcctools_prefix + "gcctools/"
116 depot_path = depot2_dir + gcctools_prefix + "gcctools/"
asharif9d40cc22013-02-15 04:56:59 +0000117 return depot_path, local_path
118
asharif29775b22013-02-15 05:15:38 +0000119def _GetToolchainCheckoutCommand(toolchain="trunk", p4_snapshot=""):
asharif2beabd12013-02-15 04:50:38 +0000120 p4_port = "perforce2:2666"
121 p4_paths = []
122 p4_paths.append(("//depot2/gcctools/chromeos/v14/...", "gcctools/chromeos/v14/..."))
asharif9d40cc22013-02-15 04:56:59 +0000123 depot_path, local_path = GetTCRootDir(toolchain)
124 short_local_path = "/".join(local_path.split("/")[1:])
125 p4_paths.append((depot_path + "google_vendor_src_branch/gcc/gcc-4.4.3/...",
126 short_local_path + "google_vendor_src_branch/gcc/gcc-4.4.3/..."))
127 p4_paths.append((depot_path + "google_vendor_src_branch/binutils/binutils-2.20.1-mobile/...",
128 short_local_path + "google_vendor_src_branch/binutils/binutils-2.20.1-mobile/..."))
129 p4_paths.append((depot_path + "google_vendor_src_branch/binutils/binutils-20100303/...",
130 short_local_path + "google_vendor_src_branch/binutils/binutils-20100303/..."))
asharif2beabd12013-02-15 04:50:38 +0000131 p4_revision = 1
132
asharif29775b22013-02-15 05:15:38 +0000133 command = GetP4Command(p4_port, p4_paths,
asharif967d7002013-02-15 04:51:00 +0000134 p4_revision, p4_checkout_dir, p4_snapshot)
asharif29775b22013-02-15 05:15:38 +0000135 return command
136
137
138
139def CreateBuildTCJob(chromeos_version="top",
140 board="x86-generic",
141 p4_snapshot="",
142 toolchain="trunk"):
143
144 depot_path, local_path = GetTCRootDir(toolchain)
145 command = GetInitialCommand()
146 command += "&& " + _GetToolchainCheckoutCommand(toolchain, p4_snapshot)
asharif2beabd12013-02-15 04:50:38 +0000147
asharif4a336e32013-02-15 05:15:32 +0000148 # When g4 syncs this file, often times the timestamp of this file is earlier
149 # than that of the file that is its dependency (ldlex.l).
150 # Since we mount the filesystem as r/o in the build, we cannot regenerate
151 # this file (we also link instead of copy in the 9999 ebuild).
152 # Longer-term, we would want to change the fileattr of this file in g4
153 # so it syncs the timestamp as well as the file contents.
154 # This is a workaround.
155 command += ("&& touch " + local_path + "google_vendor_src_branch/" +
156 "binutils/binutils-2.20.1-mobile/ld/ldlex.c")
157
asharif7cbe0692013-02-15 06:17:33 +0000158 command += "&& " + _GetSetupChromeOSCommand(chromeos_version)
asharif2beabd12013-02-15 04:50:38 +0000159
asharif4a336e32013-02-15 05:15:32 +0000160 command += "&& " + _GetBuildTCCommand(toolchain, board, False, True)
asharif2beabd12013-02-15 04:50:38 +0000161 tc_job = CreateLinuxJob(command)
162 return tc_job
163
asharif29775b22013-02-15 05:15:38 +0000164def _GetMakeChrootCommand(delete=False):
165 make_chroot_args = ""
raymes85ef5db2013-02-15 05:20:49 +0000166 if delete == True:
asharif29775b22013-02-15 05:15:38 +0000167 make_chroot_args = " --delete"
168 command = "cd " + chromeos_scripts_dir
169 command += "&& ./make_chroot --fast " + make_chroot_args
170 command += "&& cd -"
171 return command
172
raymes85ef5db2013-02-15 05:20:49 +0000173def CreateDejaGNUJob(chromeos_version="top",
asharif29775b22013-02-15 05:15:38 +0000174 board="x86-generic", p4_snapshot="", toolchain="trunk"):
asharif4a336e32013-02-15 05:15:32 +0000175 local_path = GetTCRootDir(toolchain)[1]
asharifc1512052013-02-15 04:56:42 +0000176 command = GetInitialCommand()
asharif29775b22013-02-15 05:15:38 +0000177 command += "&& " + _GetToolchainCheckoutCommand(toolchain)
asharif7cbe0692013-02-15 06:17:33 +0000178 command += "&& " + _GetSetupChromeOSCommand(chromeos_version)
asharif67966872013-02-15 05:15:44 +0000179 command += "&& " + _GetBuildTCCommand(toolchain, board)
asharifc1512052013-02-15 04:56:42 +0000180 command += ("&& " + p4_version_dir + "/run_dejagnu.py" +
asharife9433c32013-02-15 05:53:27 +0000181 " --testflags=\"\"" +
raymesb619ea52013-02-15 05:20:54 +0000182 " --chromeos_root=chromeos" +
asharif4a336e32013-02-15 05:15:32 +0000183 " --toolchain_root=" + local_path +
asharifc1512052013-02-15 04:56:42 +0000184 " --remote=$SECONDARY_MACHINES[0]" +
185 " --board=" + board)
raymes6eece822013-02-15 05:53:31 +0000186 command += ("&& " + p4_version_dir + "/summarize_results.py " + local_path +
187 "/output/dejagnu/gcc.log")
188 command += ("&& " + p4_version_dir + "/summarize_results.py " + local_path +
189 "/output/dejagnu/g++.log")
asharifc1512052013-02-15 04:56:42 +0000190 to_return = CreateLinuxJob(command)
asharif4a336e32013-02-15 05:15:32 +0000191 to_return.AddRequiredMachine("", "chromeos", True, False)
asharifc1512052013-02-15 04:56:42 +0000192 return to_return
193
asharif95c25912013-02-15 04:57:10 +0000194def CreateBuildAndTestChromeOSJob(chromeos_version="latest",
asharif1755b432013-02-15 04:55:29 +0000195 board="x86-generic",
asharif4a336e32013-02-15 05:15:32 +0000196 p4_snapshot="",
asharif67966872013-02-15 05:15:44 +0000197 toolchain="trunk",
198 tests=[]):
asharif6ba78c42013-02-15 04:50:40 +0000199 command = GetInitialCommand()
asharifb5493df2013-02-15 04:50:46 +0000200 # TODO(asharif): Get rid of this hack at some point.
201 command += "&& mkdir -p perforce2/gcctools/google_vendor_src_branch/gcc"
asharif4a336e32013-02-15 05:15:32 +0000202 command += "&& " + GetP4VersionDirCommand(p4_snapshot)
asharif6ba78c42013-02-15 04:50:40 +0000203
asharif7cbe0692013-02-15 06:17:33 +0000204 command += "&& " + _GetSetupChromeOSCommand(chromeos_version)
asharif4a336e32013-02-15 05:15:32 +0000205 command += "&& " + _GetBuildTCCommand(toolchain, board)
206 command += ("&& " + p4_version_dir + "/build_chromeos.py" +
asharif2beabd12013-02-15 04:50:38 +0000207 " --chromeos_root=" + chromeos_root +
asharif1755b432013-02-15 04:55:29 +0000208 " --board=" + board)
209
asharif4a336e32013-02-15 05:15:32 +0000210 command += "&& " + _GetImageChromeOSCommand()
ashariffc0277c2013-02-15 04:50:50 +0000211
asharif67966872013-02-15 05:15:44 +0000212 autotests = "bvt" + " ".join(tests)
asharif4a336e32013-02-15 05:15:32 +0000213 command += ("&& " + p4_version_dir + "/run_tests.py" +
asharif3cb08992013-02-15 04:50:47 +0000214 " --remote=$SECONDARY_MACHINES[0] " +
asharif7b96a552013-02-15 04:55:33 +0000215 " --chromeos_root=" + chromeos_root +
asharifea33a562013-02-15 04:56:09 +0000216 " --board=" + board +
asharif67966872013-02-15 05:15:44 +0000217 " " + autotests)
raymes6eece822013-02-15 05:53:31 +0000218 command += ("&& " + p4_version_dir + "/summarize_results.py " + p4_version_dir
219 + "logs/run_tests.py.out")
ashariffc0277c2013-02-15 04:50:50 +0000220
asharif7cbe0692013-02-15 06:17:33 +0000221 to_return = CreateLinuxJob(command, lock=True)
asharif2beabd12013-02-15 04:50:38 +0000222
asharif4a336e32013-02-15 05:15:32 +0000223 to_return.AddRequiredMachine("", "chromeos", True, False)
ashariffc0277c2013-02-15 04:50:50 +0000224
asharif57a09492013-02-15 04:50:26 +0000225 return to_return
226
asharif4a336e32013-02-15 05:15:32 +0000227def _GetImageChromeOSCommand():
228 command = (p4_version_dir + "/image_chromeos.py" +
229 " --chromeos_root=chromeos" +
230 " --remote=$SECONDARY_MACHINES[0]")
231 return command
232
asharif7cbe0692013-02-15 06:17:33 +0000233def _GetSetupChromeOSCommand(version, use_minilayout=True):
asharif9d6ccaa2013-02-15 04:57:17 +0000234 version_re = "^\d+\.\d+\.\d+\.[a-zA-Z0-9]+$"
asharife9433c32013-02-15 05:53:27 +0000235 tarred_re = "(bz2|gz)$"
asharif9d6ccaa2013-02-15 04:57:17 +0000236 if version == "weekly" or version == "quarterly":
asharif3a7f5a92013-02-15 05:15:55 +0000237 location = _GetChromeOSGoldenBuildLocation() + "/" + version
asharif9d6ccaa2013-02-15 04:57:17 +0000238 utils.AssertExit(os.path.islink(location) == True,
239 "Symlink: " + location + " does not exist.")
240 location_expanded = os.path.realpath(location)
asharifb572fca2013-02-15 05:16:01 +0000241 version = utils.GetRoot(location_expanded)[1]
242 if (version == "top" or version == "latest" or
asharif9d6ccaa2013-02-15 04:57:17 +0000243 re.match(version_re, version)):
244 chromeos_version = version
asharife9433c32013-02-15 05:53:27 +0000245 elif re.search(tarred_re, version):
246 command = "mkdir " + chromeos_root
247 command += "&& tar xf " + location_expanded + " -C " + chromeos_root
248 return command
asharif95c25912013-02-15 04:57:10 +0000249 else:
asharife9433c32013-02-15 05:53:27 +0000250 signature_file = "/src/scripts/enter_chroot.sh"
251 signature_file_location = ("/home/mobiletc-prebuild/www/chromeos_builds/"
252 + version + signature_file)
253 utils.AssertExit(os.path.exists(signature_file_location))
254 command += "rsync -a " + version + "/ chromeos/"
asharif9d6ccaa2013-02-15 04:57:17 +0000255 return command
256
asharife9433c32013-02-15 05:53:27 +0000257 command = (p4_version_dir + "/setup_chromeos.py" +
asharif9d6ccaa2013-02-15 04:57:17 +0000258 " --dir=" + chromeos_root +
259 " --version=" + chromeos_version)
260 if use_minilayout == True:
261 command += " --minilayout"
asharif95c25912013-02-15 04:57:10 +0000262 return command
263
asharif4a336e32013-02-15 05:15:32 +0000264def _GetBuildTCCommand(toolchain, board, use_binary=True, rebuild=False):
265 local_path = GetTCRootDir(toolchain)[1]
266 command = (p4_version_dir + "/build_tc.py" +
267 " --toolchain_root=" + local_path +
asharif7cbe0692013-02-15 06:17:33 +0000268 " --chromeos_root=" + chromeos_root +
269 " --board=" + board)
asharif4a336e32013-02-15 05:15:32 +0000270 if use_binary:
271 command += " -B"
272 return command
273
asharif7cbe0692013-02-15 06:17:33 +0000274def CreatePerflabJob(chromeos_version, benchmark, board="x86-agz",
raymes8fbf10d2013-02-15 05:51:45 +0000275 p4_snapshot="", toolchain="trunk"):
asharif4a336e32013-02-15 05:15:32 +0000276 toolchain_root = GetTCRootDir("trunk")[1]
asharif95c25912013-02-15 04:57:10 +0000277 command = GetInitialCommand()
278 command += "&& " + GetP4VersionDirCommand(p4_snapshot)
279 command += "&& " + GetP4BenchmarksDirCommand(p4_snapshot)
asharif8de2c732013-02-15 05:15:25 +0000280
asharif7cbe0692013-02-15 06:17:33 +0000281 command += "&& " + _GetSetupChromeOSCommand(chromeos_version)
asharif4a336e32013-02-15 05:15:32 +0000282 command += "&& " + _GetBuildTCCommand(toolchain, board)
asharif67966872013-02-15 05:15:44 +0000283 command += ("&& %s --crosstool=$PWD/%s --chromeos_root=$PWD/%s"
asharif05d1e5c2013-02-15 05:15:40 +0000284 " --machines=chromeos_x86-agz_1 build %s" %
285 (perflab_command, toolchain_root, chromeos_root, benchmark))
asharif67966872013-02-15 05:15:44 +0000286 command += ("&& %s --crosstool=$PWD/%s --chromeos_root=$PWD/%s"
asharif05d1e5c2013-02-15 05:15:40 +0000287 " --machines=chromeos_x86-agz_1 run %s" %
288 (perflab_command, toolchain_root, chromeos_root, benchmark))
asharif60d7b432013-02-15 08:56:05 +0000289 for b in benchmark.split(","):
290 benchmark_log = b.replace("/", "__")
291 benchmark_log += "/results.txt"
292 benchmark_log_path = ("perflab-output/*/*/chromeos_%s/*/*/%s" %
293 (board,
294 benchmark_log))
295
296 command += ("&& " + p4_version_dir + "/summarize_results.py " +
297 benchmark_log_path)
asharif7cbe0692013-02-15 06:17:33 +0000298 to_return = CreateLinuxJob(command, lock=True)
asharif95c25912013-02-15 04:57:10 +0000299 return to_return
300
asharif2beabd12013-02-15 04:50:38 +0000301
asharif9d6ccaa2013-02-15 04:57:17 +0000302def CreateUpdateJob(chromeos_versions,
asharifb1752c82013-02-15 04:56:37 +0000303 create_image=True,
304 p4_snapshot="",
asharif3a7f5a92013-02-15 05:15:55 +0000305 boards="x86-generic"):
asharifea33a562013-02-15 04:56:09 +0000306 command = GetInitialCommand()
asharif4a336e32013-02-15 05:15:32 +0000307 command += "&& " + GetP4VersionDirCommand(p4_snapshot)
308 command += ("&& " + p4_version_dir + "/setup_chromeos.py" +
asharifb1752c82013-02-15 04:56:37 +0000309 " --dir=" + chromeos_root +
asharifea33a562013-02-15 04:56:09 +0000310 " --version=latest")
asharif3a7f5a92013-02-15 05:15:55 +0000311 board_list = boards.split(",")
312 for board in board_list:
313 command += ("&& " + p4_version_dir + "/build_chromeos.py" +
314 " --chromeos_root=" + chromeos_root +
315 " --vanilla --board=" + board)
asharifb1752c82013-02-15 04:56:37 +0000316
ashariff64f88d2013-02-15 05:44:39 +0000317 dirname = "$(cd chromeos/src/scripts; git describe --tags --always HEAD)"
asharif3a7f5a92013-02-15 05:15:55 +0000318 build_location = _GetChromeOSGoldenBuildLocation() + "/" + dirname
319 for board in board_list:
320 board_build = build_location + "/" + board
321 command += "&& mkdir -p " + board_build
322 command += ("&& rsync -a chromeos/src/build/images/" + board + "/" +
323 " " + board_build + "/")
asharif9d6ccaa2013-02-15 04:57:17 +0000324
asharif9d6ccaa2013-02-15 04:57:17 +0000325 for chromeos_version in chromeos_versions.split(","):
asharif3a7f5a92013-02-15 05:15:55 +0000326 build_link = chromeos_version
asharifb572fca2013-02-15 05:16:01 +0000327 command += ("&& ln -fs -T " + dirname + " " +
328 _GetChromeOSGoldenBuildLocation() + chromeos_version)
asharifea33a562013-02-15 04:56:09 +0000329 to_return = CreateLinuxJob(command)
330 return to_return
331