Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # Copyright (c) 2013 The Chromium OS 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 | import os |
| 8 | import time |
| 9 | |
| 10 | from utils import command_executer |
| 11 | |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 12 | TEST_THAT_PATH = '/usr/bin/test_that' |
| 13 | CHROME_MOUNT_DIR = '/tmp/chrome_root' |
| 14 | |
| 15 | def GetProfilerArgs (benchmark): |
| 16 | if benchmark.perf_args: |
| 17 | perf_args_list = benchmark.perf_args.split(" ") |
| 18 | perf_args_list = [perf_args_list[0]] + ["-a"] + perf_args_list[1:] |
| 19 | perf_args = " ".join(perf_args_list) |
| 20 | if not perf_args_list[0] in ["record", "stat"]: |
| 21 | raise Exception("perf_args must start with either record or stat") |
| 22 | extra_test_args = ["profiler=custom_perf", |
| 23 | ("profiler_args=\"'%s'\"" % |
| 24 | perf_args)] |
| 25 | return " ".join(extra_test_args) |
| 26 | else: |
| 27 | return "" |
| 28 | |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 29 | |
| 30 | class SuiteRunner(object): |
| 31 | """ This defines the interface from crosperf to test script. |
| 32 | """ |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 33 | |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 34 | def __init__(self, logger_to_use=None): |
| 35 | self._logger = logger_to_use |
| 36 | self._ce = command_executer.GetCommandExecuter(self._logger) |
| 37 | self._ct = command_executer.CommandTerminator() |
| 38 | |
| 39 | def Run(self, machine, label, benchmark, test_args): |
| 40 | if benchmark.suite == "telemetry": |
| 41 | return self.Telemetry_Run(machine, label, benchmark) |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 42 | elif benchmark.suite == "telemetry_Crosperf": |
| 43 | return self.Telemetry_Crosperf_Run(machine, label, benchmark) |
Caroline Tice | b47bff4 | 2013-08-19 15:59:02 -0700 | [diff] [blame] | 44 | elif benchmark.use_test_that: |
| 45 | return self.Test_That_Run(machine, label, benchmark, test_args) |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 46 | else: |
| 47 | return self.Pyauto_Run(machine, label, benchmark, test_args) |
| 48 | |
| 49 | def RebootMachine(self, machine_name, chromeos_root): |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 50 | command = "reboot && exit" |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 51 | self._ce.CrosRunCommand(command, machine=machine_name, |
| 52 | chromeos_root=chromeos_root) |
| 53 | time.sleep(60) |
| 54 | |
| 55 | |
| 56 | def Pyauto_Run(self, machine, label, benchmark, test_args): |
| 57 | """Run the run_remote_test.""" |
| 58 | options = "" |
| 59 | if label.board: |
| 60 | options += " --board=%s" % label.board |
| 61 | if test_args: |
| 62 | options += " %s" % test_args |
| 63 | command = "rm -rf /usr/local/autotest/results/*" |
| 64 | self._ce.CrosRunCommand(command, machine=machine, username="root", |
| 65 | chromeos_root=label.chromeos_root) |
| 66 | |
| 67 | self.RebootMachine(machine, label.chromeos_root) |
| 68 | |
Caroline Tice | f8b3a5a | 2013-09-25 10:45:57 -0700 | [diff] [blame^] | 69 | command = ("./run_remote_tests.sh --use_emerged --remote=%s %s %s" % |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 70 | (machine, options, benchmark.test_name)) |
| 71 | return self._ce.ChrootRunCommand(label.chromeos_root, |
| 72 | command, |
| 73 | True, |
| 74 | self._ct) |
| 75 | |
Caroline Tice | b47bff4 | 2013-08-19 15:59:02 -0700 | [diff] [blame] | 76 | def Test_That_Run(self, machine, label, benchmark, test_args): |
| 77 | """Run the test_that test..""" |
| 78 | options = "" |
| 79 | if label.board: |
| 80 | options += " --board=%s" % label.board |
| 81 | if test_args: |
| 82 | options += " %s" % test_args |
| 83 | command = "rm -rf /usr/local/autotest/results/*" |
| 84 | self._ce.CrosRunCommand(command, machine=machine, username="root", |
| 85 | chromeos_root=label.chromeos_root) |
| 86 | |
| 87 | self.RebootMachine(machine, label.chromeos_root) |
| 88 | |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 89 | command = ("%s %s %s %s" % |
| 90 | (TEST_THAT_PATH, options, machine, benchmark.test_name)) |
Caroline Tice | b47bff4 | 2013-08-19 15:59:02 -0700 | [diff] [blame] | 91 | return self._ce.ChrootRunCommand(label.chromeos_root, |
| 92 | command, |
| 93 | True, |
| 94 | self._ct) |
| 95 | |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 96 | |
| 97 | def Telemetry_Crosperf_Run (self, machine, label, benchmark): |
| 98 | if not os.path.isdir(label.chrome_src): |
| 99 | self._logger.LogFatal("Cannot find chrome src dir to" |
| 100 | " run telemetry.") |
| 101 | |
| 102 | profiler_args = GetProfilerArgs (benchmark) |
| 103 | chrome_root_options = "" |
| 104 | |
| 105 | # If chrome_src is outside the chroot, mount it when entering the |
| 106 | # chroot. |
| 107 | if label.chrome_src.find(label.chromeos_root) == -1: |
| 108 | chrome_root_options = (" --chrome_root={0} --chrome_root_mount={1} " |
| 109 | " FEATURES=\"-usersandbox\" " |
| 110 | "CHROME_ROOT={2}".format(label.chrome_src, |
| 111 | CHROME_MOUNT_DIR, |
| 112 | CHROME_MOUNT_DIR)) |
| 113 | |
| 114 | cmd = ('{0} --board={1} --args="iterations={2} test={3} ' |
| 115 | '{4}" {5} telemetry_Crosperf'.format(TEST_THAT_PATH, |
| 116 | label.board, |
| 117 | benchmark.iterations, |
| 118 | benchmark.test_name, |
| 119 | profiler_args, |
| 120 | machine)) |
| 121 | return self._ce.ChrootRunCommand (label.chromeos_root, |
| 122 | cmd, |
| 123 | return_output=True, |
| 124 | command_terminator=self._ct, |
| 125 | cros_sdk_options=chrome_root_options) |
| 126 | |
| 127 | |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 128 | def Telemetry_Run(self, machine, label, benchmark): |
| 129 | if not os.path.isdir(label.chrome_src): |
Caroline Tice | 6aa8528 | 2013-08-06 16:02:04 -0700 | [diff] [blame] | 130 | self._logger.LogFatal("Cannot find chrome src dir to" |
| 131 | " run telemetry.") |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 132 | rsa_key = os.path.join(label.chromeos_root, |
| 133 | "src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa") |
| 134 | |
| 135 | cmd = ("cd {0} && " |
Yunlian Jiang | fefa5c0 | 2013-07-02 15:47:02 -0700 | [diff] [blame] | 136 | "./tools/perf/run_measurement " |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 137 | "--browser=cros-chrome " |
| 138 | "--output-format=csv " |
| 139 | "--remote={1} " |
| 140 | "--identity {2} " |
| 141 | "{3} {4}".format(label.chrome_src, machine, |
| 142 | rsa_key, |
| 143 | benchmark.test_name, |
| 144 | benchmark.test_args)) |
| 145 | return self._ce.RunCommand(cmd, return_output=True, |
| 146 | print_to_console=False) |
| 147 | |
| 148 | def Terminate(self): |
| 149 | self._ct.Terminate() |
| 150 | |
| 151 | |
| 152 | class MockSuiteRunner(object): |
| 153 | def __init__(self): |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 154 | self._true = True |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 155 | |
Caroline Tice | 9277419 | 2013-09-10 16:29:18 -0700 | [diff] [blame] | 156 | def Run(self, *_args): |
| 157 | if self._true: |
| 158 | return ["", "", 0] |
| 159 | else: |
| 160 | return ["", "", 0] |