aboutsummaryrefslogtreecommitdiff
path: root/run_tests.py
blob: 31f1708f503a384e6cf5fe3b5c68588e9e5a31f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
#
# Copyright 2010 Google Inc. All Rights Reserved.

"""Script to wrap run_remote_tests.sh script.

This script calls run_remote_tests.sh with standard tests.
"""

__author__ = "asharif@google.com (Ahmad Sharif)"

import optparse
import os
import re
import sys

from utils import command_executer
from utils import logger
import build_chromeos


def Main(argv):
  """The main function."""
  parser = optparse.OptionParser()
  parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
                    help="ChromeOS root checkout directory.")
  parser.add_option("-r", "--remote", dest="remote",
                    help="The IP address of the remote ChromeOS machine.")
  parser.add_option("-b", "--board", dest="board",
                    help="The board of the target.")

  (options, args) = parser.parse_args(argv)

  tests = ""

  if options.board is None or options.remote is None:
    parser.print_help()
    return -1

  if options.chromeos_root is None:
    m = "--chromeos_root not given. Setting ../../ as chromeos_root"
    logger.GetLogger().LogWarning(m)
    options.chromeos_root = "../.."

  rrt_file = "%s/src/scripts/run_remote_tests.sh" % options.chromeos_root
  if not os.path.isfile(rrt_file):
    m = "File %s not found" % rrt_file
    logger.GetLogger().LogError(m)
    return -1

  if args:
    tests = " " + " ".join(args[1:])

  case_insensitive_page = re.compile("page", re.IGNORECASE)
  tests = case_insensitive_page.sub("Page", tests)

  return RunRemoteTests(options.chromeos_root, options.remote,
                        options.board, tests)


def RunRemoteTests(chromeos_root, remote, board, tests):
  """Run the remote tests."""
  ce = command_executer.GetCommandExecuter()
  command = ("./run_remote_tests.sh"
             " --remote=%s"
             " --board=%s"
             " %s" %
             (remote,
              board,
              tests))
  retval = ce.ChrootRunCommand(chromeos_root, command)
  return retval

if __name__ == "__main__":
  sys.exit(Main(sys.argv))