blob: d89f307d66e584f252505322d1cb96f0ad0eb585 [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
12
13class SuiteRunner(object):
14 """ This defines the interface from crosperf to test script.
15 """
16 def __init__(self, logger_to_use=None):
17 self._logger = logger_to_use
18 self._ce = command_executer.GetCommandExecuter(self._logger)
19 self._ct = command_executer.CommandTerminator()
20
21 def Run(self, machine, label, benchmark, test_args):
22 if benchmark.suite == "telemetry":
23 return self.Telemetry_Run(machine, label, benchmark)
24 else:
25 return self.Pyauto_Run(machine, label, benchmark, test_args)
26
27 def RebootMachine(self, machine_name, chromeos_root):
28 command ="reboot && exit"
29 self._ce.CrosRunCommand(command, machine=machine_name,
30 chromeos_root=chromeos_root)
31 time.sleep(60)
32
33
34 def Pyauto_Run(self, machine, label, benchmark, test_args):
35 """Run the run_remote_test."""
36 options = ""
37 if label.board:
38 options += " --board=%s" % label.board
39 if test_args:
40 options += " %s" % test_args
41 command = "rm -rf /usr/local/autotest/results/*"
42 self._ce.CrosRunCommand(command, machine=machine, username="root",
43 chromeos_root=label.chromeos_root)
44
45 self.RebootMachine(machine, label.chromeos_root)
46
47 command = ("./run_remote_tests.sh --remote=%s %s %s" %
48 (machine, options, benchmark.test_name))
49 return self._ce.ChrootRunCommand(label.chromeos_root,
50 command,
51 True,
52 self._ct)
53
54 def Telemetry_Run(self, machine, label, benchmark):
55 if not os.path.isdir(label.chrome_src):
56 self._logger.GetLogger().LogFatal("Cannot find chrome src dir to"
57 "run telemetry.")
58 rsa_key = os.path.join(label.chromeos_root,
59 "src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa")
60
61 cmd = ("cd {0} && "
62 "./tools/perf/run_multipage_benchmarks "
63 "--browser=cros-chrome "
64 "--output-format=csv "
65 "--remote={1} "
66 "--identity {2} "
67 "{3} {4}".format(label.chrome_src, machine,
68 rsa_key,
69 benchmark.test_name,
70 benchmark.test_args))
71 return self._ce.RunCommand(cmd, return_output=True,
72 print_to_console=False)
73
74 def Terminate(self):
75 self._ct.Terminate()
76
77
78class MockSuiteRunner(object):
79 def __init__(self):
80 pass
81
82 def Run(self, *args):
83 return ["", "", 0]