xref: /aosp_15_r20/external/toolchain-utils/remote_test.py (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright 2020 The ChromiumOS Authors
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8"""Script to wrap test_that script.
9
10This script can login to the chromeos machine using the test private key.
11"""
12
13
14__author__ = "[email protected] (Ahmad Sharif)"
15
16import argparse
17import os
18import sys
19
20from cros_utils import command_executer
21from cros_utils import misc
22
23
24def Usage(parser, message):
25    print("ERROR: %s" % message)
26    parser.print_help()
27    sys.exit(0)
28
29
30def Main(argv):
31    parser = argparse.ArgumentParser()
32    parser.add_argument(
33        "-c",
34        "--chromeos_root",
35        dest="chromeos_root",
36        help="ChromeOS root checkout directory",
37    )
38    parser.add_argument(
39        "-r", "--remote", dest="remote", help="Remote chromeos device."
40    )
41    options = parser.parse_args(argv)
42    if options.chromeos_root is None:
43        Usage(parser, "chromeos_root must be given")
44
45    if options.remote is None:
46        Usage(parser, "remote must be given")
47
48    options.chromeos_root = os.path.expanduser(options.chromeos_root)
49
50    command = "ls -lt /"
51    ce = command_executer.GetCommandExecuter()
52    ce.CrosRunCommand(
53        command, chromeos_root=options.chromeos_root, machine=options.remote
54    )
55
56    version_dir_path, script_name = misc.GetRoot(sys.argv[0])
57    version_dir = misc.GetRoot(version_dir_path)[1]
58
59    # Tests to copy directories and files to the chromeos box.
60    ce.CopyFiles(
61        version_dir_path,
62        "/tmp/" + version_dir,
63        dest_machine=options.remote,
64        dest_cros=True,
65        chromeos_root=options.chromeos_root,
66    )
67    ce.CopyFiles(
68        version_dir_path,
69        "/tmp/" + version_dir + "1",
70        dest_machine=options.remote,
71        dest_cros=True,
72        chromeos_root=options.chromeos_root,
73    )
74    ce.CopyFiles(
75        sys.argv[0],
76        "/tmp/" + script_name,
77        recursive=False,
78        dest_machine=options.remote,
79        dest_cros=True,
80        chromeos_root=options.chromeos_root,
81    )
82    ce.CopyFiles(
83        sys.argv[0],
84        "/tmp/" + script_name + "1",
85        recursive=False,
86        dest_machine=options.remote,
87        dest_cros=True,
88        chromeos_root=options.chromeos_root,
89    )
90
91    # Test to copy directories and files from the chromeos box.
92    ce.CopyFiles(
93        "/tmp/" + script_name,
94        "/tmp/hello",
95        recursive=False,
96        src_machine=options.remote,
97        src_cros=True,
98        chromeos_root=options.chromeos_root,
99    )
100    ce.CopyFiles(
101        "/tmp/" + script_name,
102        "/tmp/" + script_name,
103        recursive=False,
104        src_machine=options.remote,
105        src_cros=True,
106        chromeos_root=options.chromeos_root,
107    )
108    board = ce.CrosLearnBoard(options.chromeos_root, options.remote)
109    print(board)
110    return 0
111
112
113if __name__ == "__main__":
114    Main(sys.argv[1:])
115