raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 1 | #!/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 | |
| 10 | import optparse |
| 11 | import os |
| 12 | import sys |
| 13 | import build_chromeos |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 14 | from utils import command_executer |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 15 | from utils import utils |
asharif | c151205 | 2013-02-15 04:56:42 +0000 | [diff] [blame] | 16 | from utils import logger |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 17 | |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 18 | |
| 19 | DEJAGNU_DIR = "/tmp/dejagnu" |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 20 | |
| 21 | |
| 22 | def Usage(parser, message): |
| 23 | print "ERROR: " + message |
| 24 | parser.print_help() |
| 25 | sys.exit(0) |
| 26 | |
| 27 | |
| 28 | def 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.") |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 42 | parser.add_option("--vanilla", dest="vanilla", default=False, |
| 43 | action="store_true", |
| 44 | help="Use the toolchain inside the chroot to run tests.") |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 45 | |
| 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 | |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 51 | 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") |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 56 | |
| 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 | |
asharif | c151205 | 2013-02-15 04:56:42 +0000 | [diff] [blame] | 62 | 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 | |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 67 | # Emerge DejaGNU |
| 68 | # Remove the dev-tcltk manifest which is currently incorrect |
| 69 | ret = (build_chromeos. |
asharif | 8697d4e | 2013-02-15 09:18:09 +0000 | [diff] [blame^] | 70 | ExecuteCommandInChroot(options.chromeos_root, |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 71 | "rm -f ~/trunk/src/third_party/portage/" |
asharif | 8697d4e | 2013-02-15 09:18:09 +0000 | [diff] [blame^] | 72 | "dev-tcltk/expect/Manifest"), |
| 73 | options.toolchain_root) |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 74 | utils.AssertExit(ret == 0, "Failed to remove incorrect manifest") |
| 75 | |
| 76 | ret = (build_chromeos. |
asharif | 8697d4e | 2013-02-15 09:18:09 +0000 | [diff] [blame^] | 77 | ExecuteCommandInChroot(options.chromeos_root, |
| 78 | "sudo emerge -u dejagnu"), |
| 79 | options.toolchain_root) |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 80 | utils.AssertExit(ret == 0, "Failed to emerge dejagnu") |
| 81 | |
| 82 | # Find the toolchain objects directory |
| 83 | f = open(options.chromeos_root + "/src/overlays/overlay-" + |
| 84 | options.board.split("_")[0] + "/toolchain.conf", "r") |
| 85 | target = f.read() |
| 86 | f.close() |
| 87 | target = target.strip() |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 88 | if options.vanilla: |
| 89 | gcc_build_dir = "/var/tmp/portage/cross-%s/gcc-*/work/build" % target |
| 90 | else: |
| 91 | gcc_build_dir = ("/usr/local/toolchain_root/output/objects" |
| 92 | "/portage/cross-%s/gcc-9999/work/build" |
| 93 | % target) |
| 94 | |
| 95 | # Copy the dejagnu site.exp into the chroot. |
| 96 | ce = command_executer.GetCommandExecuter() |
| 97 | ce.CopyFiles(utils.GetRoot(sys.argv[0])[0] + "/dejagnu", |
| 98 | options.chromeos_root + "/chroot/" + DEJAGNU_DIR, recursive=True) |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 99 | |
| 100 | # Construct the command to run DejaGNU. |
| 101 | dejagnu_run = ("DEJAGNU=%s/site.exp DEJAGNU_HOSTNAME=%s make " |
| 102 | "RUNTESTFLAGS='%s' check-gcc" |
| 103 | % (DEJAGNU_DIR, options.remote, options.testflags)) |
| 104 | |
| 105 | # Construct command to init the ssh tcp connection |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 106 | init = GetRemoteAccessInitCommand(options.remote) |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 107 | |
| 108 | # Construct the command to cleanup the ssh tcp connection |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 109 | cleanup = GetRemoteAccessCleanupCommand() |
| 110 | |
| 111 | common = GetRemoteAccessCommonCommands(options.remote) |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 112 | |
| 113 | # Run DejaGNU |
| 114 | ret = (build_chromeos. |
asharif | 8697d4e | 2013-02-15 09:18:09 +0000 | [diff] [blame^] | 115 | ExecuteCommandInChroot(options.chromeos_root, |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 116 | "%s ; %s ; %s && cd %s && %s ; %s" % |
| 117 | (common, cleanup, init, gcc_build_dir, |
asharif | 8697d4e | 2013-02-15 09:18:09 +0000 | [diff] [blame^] | 118 | dejagnu_run, cleanup), full_mount=True), |
| 119 | options.toolchain_root) |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 120 | utils.AssertWarning(ret == 0, "Failed to run DejaGNU tests successfully") |
| 121 | |
raymes | 27574ee | 2013-02-15 05:20:41 +0000 | [diff] [blame] | 122 | # Copy results to a not-so-deep location |
asharif | b1e8a3e | 2013-02-15 09:04:44 +0000 | [diff] [blame] | 123 | results_dir = "%s/gcc/testsuite/" % gcc_build_dir |
raymes | 27574ee | 2013-02-15 05:20:41 +0000 | [diff] [blame] | 124 | new_results_dir = "/usr/local/toolchain_root/output/dejagnu/" |
| 125 | ret = (build_chromeos. |
asharif | 8697d4e | 2013-02-15 09:18:09 +0000 | [diff] [blame^] | 126 | ExecuteCommandInChroot(options.chromeos_root, |
asharif | c380f61 | 2013-02-15 09:13:07 +0000 | [diff] [blame] | 127 | "mkdir -p %s ; cp %s/g++/g++.log %s ; " |
raymes | 27574ee | 2013-02-15 05:20:41 +0000 | [diff] [blame] | 128 | "cp %s/gcc/gcc.log %s" % |
| 129 | (new_results_dir, results_dir, new_results_dir, |
asharif | 8697d4e | 2013-02-15 09:18:09 +0000 | [diff] [blame^] | 130 | results_dir, new_results_dir), |
| 131 | options.toolchain_root)) |
raymes | 27574ee | 2013-02-15 05:20:41 +0000 | [diff] [blame] | 132 | |
| 133 | utils.AssertWarning(ret == 0, "Failed to copy results to final destination.") |
| 134 | |
| 135 | |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 136 | def GetRemoteAccessCommonCommands(remote): |
| 137 | command = "\nset -- --remote=" + remote |
| 138 | command += "\n. ~/trunk/src/scripts/common.sh" |
| 139 | command += "\n. ~/trunk/src/scripts/remote_access.sh" |
| 140 | command += "\nTMP=/tmp/chromeos-toolchain" |
| 141 | command += "\nFLAGS \"$@\" || exit 1" |
| 142 | return command |
raymes | 27574ee | 2013-02-15 05:20:41 +0000 | [diff] [blame] | 143 | |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 144 | def GetRemoteAccessInitCommand(remote): |
| 145 | command = ("echo \"Initting access\"" |
| 146 | " && mkdir -p ${TMP}" |
| 147 | " && remote_access_init" |
| 148 | " && ( ssh -t -t -p 22 root@%s" |
| 149 | " -o StrictHostKeyChecking=no" |
| 150 | " -o UserKnownHostsFile=/tmp/chromeos-toolchain/known_hosts" |
| 151 | " -i ${TMP}/private_key" |
| 152 | " -M -S ${TMP}/%%r@%%h:%%p 2>&1 > /dev/null & )" |
| 153 | " ; echo $! > ${TMP}/master-pid" % remote) |
| 154 | return command |
| 155 | |
| 156 | def GetRemoteAccessCleanupCommand(): |
| 157 | command = ("echo \"Cleaning up access\"" |
| 158 | " && set +e " |
asharif | 758f12c | 2013-02-15 09:11:18 +0000 | [diff] [blame] | 159 | " && kill $(cat ${TMP}/master-pid)" |
raymes | c89b857 | 2013-02-15 09:05:42 +0000 | [diff] [blame] | 160 | " && set -e" |
| 161 | " && cleanup_remote_access" |
| 162 | " && rm -rf ${TMP}") |
| 163 | return command |
raymes | a7d219c | 2013-02-15 04:56:23 +0000 | [diff] [blame] | 164 | |
| 165 | |
| 166 | if __name__ == "__main__": |
| 167 | Main(sys.argv) |