run_tests.py revision f81680c018729fd4499e1e200d04b48c4b90127c
1#!/usr/bin/python2.6
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4
5"""Script to wrap run_remote_tests.sh script.
6
7This script calls run_remote_tests.sh with standard tests.
8"""
9
10__author__ = "asharif@google.com (Ahmad Sharif)"
11
12import optparse
13import os
14import re
15import sys
16
17from utils import command_executer
18from utils import logger
19import build_chromeos
20
21
22def Main(argv):
23  """The main function."""
24  parser = optparse.OptionParser()
25  parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
26                    help="ChromeOS root checkout directory.")
27  parser.add_option("-r", "--remote", dest="remote",
28                    help="The IP address of the remote ChromeOS machine.")
29  parser.add_option("-b", "--board", dest="board",
30                    help="The board of the target.")
31
32  (options, args) = parser.parse_args(argv)
33
34  tests = ""
35
36  if options.board is None or options.remote is None:
37    parser.print_help()
38    return -1
39
40  if options.chromeos_root is None:
41    m = "--chromeos_root not given. Setting ../../ as chromeos_root"
42    logger.GetLogger().LogWarning(m)
43    options.chromeos_root = "../.."
44
45  rrt_file = "%s/src/scripts/run_remote_tests.sh" % options.chromeos_root
46  if not os.path.isfile(rrt_file):
47    m = "File %s not found" % rrt_file
48    logger.GetLogger().LogError(m)
49    return -1
50
51  if args:
52    tests = " " + " ".join(args[1:])
53
54  case_insensitive_page = re.compile("page", re.IGNORECASE)
55  tests = case_insensitive_page.sub("Page", tests)
56
57  return RunRemoteTests(options.chromeos_root, options.remote,
58                        options.board, tests)
59
60
61def RunRemoteTests(chromeos_root, remote, board, tests):
62  """Run the remote tests."""
63  ce = command_executer.GetCommandExecuter()
64  command = ("./run_remote_tests.sh"
65             " --remote=%s"
66             " --board=%s"
67             " %s" %
68             (remote,
69              board,
70              tests))
71  retval = ce.ChrootRunCommand(chromeos_root, command)
72  return retval
73
74if __name__ == "__main__":
75  sys.exit(Main(sys.argv))
76