blob: b124e4265b6f00852a9d0911953d743e67e29aaf [file] [log] [blame]
raymesa7d219c2013-02-15 04:56:23 +00001#!/usr/bin/python2.6
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4
5"""This script runs the DejaGNU test suite in the ChromeOS chroot environment.
6"""
7
8__author__ = "raymes@google.com (Raymes Khoury)"
9
10import optparse
11import os
12import sys
13import build_chromeos
raymesc89b8572013-02-15 09:05:42 +000014from utils import command_executer
raymesa7d219c2013-02-15 04:56:23 +000015from utils import utils
asharifc1512052013-02-15 04:56:42 +000016from utils import logger
raymesa7d219c2013-02-15 04:56:23 +000017
raymesc89b8572013-02-15 09:05:42 +000018
19DEJAGNU_DIR = "/tmp/dejagnu"
raymesa7d219c2013-02-15 04:56:23 +000020
21
22def Usage(parser, message):
23 print "ERROR: " + message
24 parser.print_help()
25 sys.exit(0)
26
27
28def Main(argv):
29 # Common initializations
30
31 parser = optparse.OptionParser()
32 parser.add_option("--chromeos_root", dest="chromeos_root",
33 help="Target directory for ChromeOS installation.")
34 parser.add_option("--toolchain_root", dest="toolchain_root",
35 help="The gcctools directory of your P4 checkout.")
36 parser.add_option("--board", dest="board", default="x86-generic",
37 help="board is the argument to the setup_board command.")
38 parser.add_option("--remote", dest="remote",
39 help="The IP address of the machine to run the tests on")
40 parser.add_option("--testflags", dest="testflags", default="",
41 help="Arguments to pass to DejaGNU.")
raymesc89b8572013-02-15 09:05:42 +000042 parser.add_option("--vanilla", dest="vanilla", default=False,
43 action="store_true",
44 help="Use the toolchain inside the chroot to run tests.")
raymesa7d219c2013-02-15 04:56:23 +000045
46 options = parser.parse_args(argv[1:])[0]
47
48 if options.chromeos_root is None:
49 Usage(parser, "--chromeos_root must be set")
50
raymesc89b8572013-02-15 09:05:42 +000051 if options.toolchain_root is None and options.vanilla == False:
52 Usage(parser, "--toolchain_root or --vanilla must be set")
53
54 if options.toolchain_root is not None and options.vanilla == True:
55 Usage(parser, "If --vanilla specified, cannot use --toolchain_root")
raymesa7d219c2013-02-15 04:56:23 +000056
57 if options.remote is None:
58 Usage(parser, "--remote must be set")
59
60 options.chromeos_root = os.path.expanduser(options.chromeos_root)
61
asharifc1512052013-02-15 04:56:42 +000062 if os.path.exists(options.chromeos_root) == False:
63 logger.GetLogger().LogOutput("chroot not found. Creating one.")
64 ret = build_chromeos.MakeChroot(options.chromeos_root)
65 utils.AssertExit(ret == 0, "Failed to make chroot!")
66
raymesa7d219c2013-02-15 04:56:23 +000067 # Emerge DejaGNU
68 # Remove the dev-tcltk manifest which is currently incorrect
69 ret = (build_chromeos.
70 ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root,
71 "rm -f ~/trunk/src/third_party/portage/"
72 "dev-tcltk/expect/Manifest"))
73 utils.AssertExit(ret == 0, "Failed to remove incorrect manifest")
74
75 ret = (build_chromeos.
76 ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root,
77 "sudo emerge -u dejagnu"))
78 utils.AssertExit(ret == 0, "Failed to emerge dejagnu")
79
80 # Find the toolchain objects directory
81 f = open(options.chromeos_root + "/src/overlays/overlay-" +
82 options.board.split("_")[0] + "/toolchain.conf", "r")
83 target = f.read()
84 f.close()
85 target = target.strip()
raymesc89b8572013-02-15 09:05:42 +000086 if options.vanilla:
87 gcc_build_dir = "/var/tmp/portage/cross-%s/gcc-*/work/build" % target
88 else:
89 gcc_build_dir = ("/usr/local/toolchain_root/output/objects"
90 "/portage/cross-%s/gcc-9999/work/build"
91 % target)
92
93 # Copy the dejagnu site.exp into the chroot.
94 ce = command_executer.GetCommandExecuter()
95 ce.CopyFiles(utils.GetRoot(sys.argv[0])[0] + "/dejagnu",
96 options.chromeos_root + "/chroot/" + DEJAGNU_DIR, recursive=True)
raymesa7d219c2013-02-15 04:56:23 +000097
98 # Construct the command to run DejaGNU.
99 dejagnu_run = ("DEJAGNU=%s/site.exp DEJAGNU_HOSTNAME=%s make "
100 "RUNTESTFLAGS='%s' check-gcc"
101 % (DEJAGNU_DIR, options.remote, options.testflags))
102
103 # Construct command to init the ssh tcp connection
raymesc89b8572013-02-15 09:05:42 +0000104 init = GetRemoteAccessInitCommand(options.remote)
raymesa7d219c2013-02-15 04:56:23 +0000105
106 # Construct the command to cleanup the ssh tcp connection
raymesc89b8572013-02-15 09:05:42 +0000107 cleanup = GetRemoteAccessCleanupCommand()
108
109 common = GetRemoteAccessCommonCommands(options.remote)
raymesa7d219c2013-02-15 04:56:23 +0000110
111 # Run DejaGNU
112 ret = (build_chromeos.
113 ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root,
raymesc89b8572013-02-15 09:05:42 +0000114 "%s ; %s ; %s && cd %s && %s ; %s" %
115 (common, cleanup, init, gcc_build_dir,
116 dejagnu_run, cleanup), full_mount=True))
raymesa7d219c2013-02-15 04:56:23 +0000117 utils.AssertWarning(ret == 0, "Failed to run DejaGNU tests successfully")
118
raymes27574ee2013-02-15 05:20:41 +0000119 # Copy results to a not-so-deep location
asharifb1e8a3e2013-02-15 09:04:44 +0000120 results_dir = "%s/gcc/testsuite/" % gcc_build_dir
raymes27574ee2013-02-15 05:20:41 +0000121 new_results_dir = "/usr/local/toolchain_root/output/dejagnu/"
122 ret = (build_chromeos.
123 ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root,
asharifc380f612013-02-15 09:13:07 +0000124 "mkdir -p %s ; cp %s/g++/g++.log %s ; "
raymes27574ee2013-02-15 05:20:41 +0000125 "cp %s/gcc/gcc.log %s" %
126 (new_results_dir, results_dir, new_results_dir,
127 results_dir, new_results_dir)))
128
129 utils.AssertWarning(ret == 0, "Failed to copy results to final destination.")
130
131
raymesc89b8572013-02-15 09:05:42 +0000132def GetRemoteAccessCommonCommands(remote):
133 command = "\nset -- --remote=" + remote
134 command += "\n. ~/trunk/src/scripts/common.sh"
135 command += "\n. ~/trunk/src/scripts/remote_access.sh"
136 command += "\nTMP=/tmp/chromeos-toolchain"
137 command += "\nFLAGS \"$@\" || exit 1"
138 return command
raymes27574ee2013-02-15 05:20:41 +0000139
raymesc89b8572013-02-15 09:05:42 +0000140def GetRemoteAccessInitCommand(remote):
141 command = ("echo \"Initting access\""
142 " && mkdir -p ${TMP}"
143 " && remote_access_init"
144 " && ( ssh -t -t -p 22 root@%s"
145 " -o StrictHostKeyChecking=no"
146 " -o UserKnownHostsFile=/tmp/chromeos-toolchain/known_hosts"
147 " -i ${TMP}/private_key"
148 " -M -S ${TMP}/%%r@%%h:%%p 2>&1 > /dev/null & )"
149 " ; echo $! > ${TMP}/master-pid" % remote)
150 return command
151
152def GetRemoteAccessCleanupCommand():
153 command = ("echo \"Cleaning up access\""
154 " && set +e "
asharif758f12c2013-02-15 09:11:18 +0000155 " && kill $(cat ${TMP}/master-pid)"
raymesc89b8572013-02-15 09:05:42 +0000156 " && set -e"
157 " && cleanup_remote_access"
158 " && rm -rf ${TMP}")
159 return command
raymesa7d219c2013-02-15 04:56:23 +0000160
161
162if __name__ == "__main__":
163 Main(sys.argv)