blob: ee9c693f6cca184bd3af5578b2035380316aa4f7 [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)
Caroline Ticeb47bff42013-08-19 15:59:02 -070024 elif benchmark.use_test_that:
25 return self.Test_That_Run(machine, label, benchmark, test_args)
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070026 else:
27 return self.Pyauto_Run(machine, label, benchmark, test_args)
28
29 def RebootMachine(self, machine_name, chromeos_root):
30 command ="reboot && exit"
31 self._ce.CrosRunCommand(command, machine=machine_name,
32 chromeos_root=chromeos_root)
33 time.sleep(60)
34
35
36 def Pyauto_Run(self, machine, label, benchmark, test_args):
37 """Run the run_remote_test."""
38 options = ""
39 if label.board:
40 options += " --board=%s" % label.board
41 if test_args:
42 options += " %s" % test_args
43 command = "rm -rf /usr/local/autotest/results/*"
44 self._ce.CrosRunCommand(command, machine=machine, username="root",
45 chromeos_root=label.chromeos_root)
46
47 self.RebootMachine(machine, label.chromeos_root)
48
49 command = ("./run_remote_tests.sh --remote=%s %s %s" %
50 (machine, options, benchmark.test_name))
51 return self._ce.ChrootRunCommand(label.chromeos_root,
52 command,
53 True,
54 self._ct)
55
Caroline Ticeb47bff42013-08-19 15:59:02 -070056 def Test_That_Run(self, machine, label, benchmark, test_args):
57 """Run the test_that 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
69 command = ("/usr/bin/test_that %s %s %s" %
70 (options, machine, benchmark.test_name))
71 return self._ce.ChrootRunCommand(label.chromeos_root,
72 command,
73 True,
74 self._ct)
75
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070076 def Telemetry_Run(self, machine, label, benchmark):
77 if not os.path.isdir(label.chrome_src):
Caroline Tice6aa85282013-08-06 16:02:04 -070078 self._logger.LogFatal("Cannot find chrome src dir to"
79 " run telemetry.")
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070080 rsa_key = os.path.join(label.chromeos_root,
81 "src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa")
82
83 cmd = ("cd {0} && "
Yunlian Jiangfefa5c02013-07-02 15:47:02 -070084 "./tools/perf/run_measurement "
Yunlian Jiang04dc5dc2013-04-23 15:05:05 -070085 "--browser=cros-chrome "
86 "--output-format=csv "
87 "--remote={1} "
88 "--identity {2} "
89 "{3} {4}".format(label.chrome_src, machine,
90 rsa_key,
91 benchmark.test_name,
92 benchmark.test_args))
93 return self._ce.RunCommand(cmd, return_output=True,
94 print_to_console=False)
95
96 def Terminate(self):
97 self._ct.Terminate()
98
99
100class MockSuiteRunner(object):
101 def __init__(self):
102 pass
103
104 def Run(self, *args):
105 return ["", "", 0]