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