xref: /aosp_15_r20/external/toolchain-utils/crosperf/compare_machines.py (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1# -*- coding: utf-8 -*-
2# Copyright 2014 The ChromiumOS Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Module to compare two machines."""
7
8
9import argparse
10import os.path
11import sys
12
13from machine_manager import CrosMachine
14
15
16def PrintUsage(msg):
17    print(msg)
18    print("Usage: ")
19    print(
20        "\n compare_machines.py --chromeos_root=/path/to/chroot/ "
21        "machine1 machine2 ..."
22    )
23
24
25def Main(argv):
26
27    parser = argparse.ArgumentParser()
28    parser.add_argument(
29        "--chromeos_root",
30        default="/path/to/chromeos",
31        dest="chromeos_root",
32        help="ChromeOS root checkout directory",
33    )
34    parser.add_argument("remotes", nargs=argparse.REMAINDER)
35
36    options = parser.parse_args(argv)
37
38    machine_list = options.remotes
39    if len(machine_list) < 2:
40        PrintUsage("ERROR: Must specify at least two machines.")
41        return 1
42    elif not os.path.exists(options.chromeos_root):
43        PrintUsage(
44            "Error: chromeos_root does not exist %s" % options.chromeos_root
45        )
46        return 1
47
48    chroot = options.chromeos_root
49    cros_machines = []
50    test_machine_checksum = None
51    for m in machine_list:
52        cm = CrosMachine(m, chroot, "average")
53        cros_machines = cros_machines + [cm]
54        test_machine_checksum = cm.machine_checksum
55
56    ret = 0
57    for cm in cros_machines:
58        print("checksum for %s : %s" % (cm.name, cm.machine_checksum))
59        if cm.machine_checksum != test_machine_checksum:
60            ret = 1
61            print("Machine checksums do not all match")
62
63    if ret == 0:
64        print("Machines all match.")
65
66    return ret
67
68
69if __name__ == "__main__":
70    retval = Main(sys.argv[1:])
71    sys.exit(retval)
72