blob: b94d1567b413e02dc8f95c761d5016132a170ee0 [file] [log] [blame]
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -07001#!/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
7import os
8import time
9
10from utils import command_executer
11
Caroline Tice92774192013-09-10 16:29:18 -070012TEST_THAT_PATH = '/usr/bin/test_that'
13CHROME_MOUNT_DIR = '/tmp/chrome_root'
14
15def 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 Jiang04dc5dc2013-04-23 15:05:05 -070029
30class SuiteRunner(object):
31 """ This defines the interface from crosperf to test script.
32 """
Caroline Tice92774192013-09-10 16:29:18 -070033
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070034 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 Tice92774192013-09-10 16:29:18 -070042 elif benchmark.suite == "telemetry_Crosperf":
43 return self.Telemetry_Crosperf_Run(machine, label, benchmark)
Caroline Ticeb47bff42013-08-19 15:59:02 -070044 elif benchmark.use_test_that:
45 return self.Test_That_Run(machine, label, benchmark, test_args)
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070046 else:
47 return self.Pyauto_Run(machine, label, benchmark, test_args)
48
49 def RebootMachine(self, machine_name, chromeos_root):
Caroline Tice92774192013-09-10 16:29:18 -070050 command = "reboot && exit"
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070051 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 Ticef8b3a5a2013-09-25 10:45:57 -070069 command = ("./run_remote_tests.sh --use_emerged --remote=%s %s %s" %
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070070 (machine, options, benchmark.test_name))
71 return self._ce.ChrootRunCommand(label.chromeos_root,
72 command,
73 True,
74 self._ct)
75
Caroline Ticeb47bff42013-08-19 15:59:02 -070076 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 Tice92774192013-09-10 16:29:18 -070089 command = ("%s %s %s %s" %
90 (TEST_THAT_PATH, options, machine, benchmark.test_name))
Caroline Ticeb47bff42013-08-19 15:59:02 -070091 return self._ce.ChrootRunCommand(label.chromeos_root,
92 command,
93 True,
94 self._ct)
95
Caroline Tice92774192013-09-10 16:29:18 -070096
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 Jiang04dc5dc2013-04-23 15:05:05 -0700128 def Telemetry_Run(self, machine, label, benchmark):
129 if not os.path.isdir(label.chrome_src):
Caroline Tice6aa85282013-08-06 16:02:04 -0700130 self._logger.LogFatal("Cannot find chrome src dir to"
131 " run telemetry.")
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -0700132 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 Jiangfefa5c02013-07-02 15:47:02 -0700136 "./tools/perf/run_measurement "
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -0700137 "--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
152class MockSuiteRunner(object):
153 def __init__(self):
Caroline Tice92774192013-09-10 16:29:18 -0700154 self._true = True
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -0700155
Caroline Tice92774192013-09-10 16:29:18 -0700156 def Run(self, *_args):
157 if self._true:
158 return ["", "", 0]
159 else:
160 return ["", "", 0]