sbs_diff.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python
  2. # Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
  3. # All rights reserved.
  4. # This component and the accompanying materials are made available
  5. # under the terms of "Eclipse Public License v1.0"
  6. # which accompanies this distribution, and is available
  7. # at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. #
  9. # Initial Contributors:
  10. # Nokia Corporation - initial contribution.
  11. #
  12. # Contributors:
  13. #
  14. # Description:
  15. """
  16. Compare the raptor XML logs from two builds and produce a short report.
  17. """
  18. import optparse
  19. import os
  20. import sys
  21. import sbs_env
  22. import allo.diff
  23. parser = optparse.OptionParser(usage = """%prog [options] dir_or_file1 dir_or_file2
  24. When a directory is specified, all the logs in that directory are combined into
  25. a single file for comparison. If a single file is specified then only that one
  26. file is compared.""")
  27. parser.add_option("--force", action="store_true", default=False, help =
  28. "Re-read the original logs, do not use the intermediate files generated "
  29. "by a previous run of this script. The default is '%default'."
  30. )
  31. parser.add_option("--limit", action="store", type=int, default=0, help =
  32. "If you have particularly huge error or warning messages then the CSV "
  33. "reader may bomb out. This parameter, if greater than zero, can be used "
  34. "to increase the maximum field size to whatever you need. "
  35. "The default is '%default'."
  36. )
  37. parser.add_option("--verbose", action="store_true", default=False, help =
  38. "Print out information about the processing as we go. Some very big builds "
  39. "can take more than ten minutes to run over. The default is '%default'."
  40. )
  41. # parse the command-line arguments
  42. (options, leftover_args) = parser.parse_args()
  43. # there should be exactly 2 leftover_args
  44. if len(leftover_args) == 2:
  45. build_a = leftover_args[0]
  46. build_b = leftover_args[1]
  47. else:
  48. sys.stderr.write("error: expected 2 names, got '{0}'\n".format(", ".join(leftover_args)))
  49. sys.exit(1)
  50. # generate the intermediate files which make it possible to compare the builds
  51. log_a = allo.diff.DiffableLog(build_a, **options.__dict__)
  52. log_b = allo.diff.DiffableLog(build_b, **options.__dict__)
  53. # now do the comparison
  54. log_diff = allo.diff.LogDiff(log_a, log_b)
  55. # print the short report. it gives a good idea of how similar the results are
  56. print("\nComponent differences (if any) ======================================")
  57. for (bldinf, counts) in log_diff.components.items():
  58. if counts[0] != counts[1]:
  59. print("{0:>8} {1:<8} {2}".format(counts[0], counts[1], bldinf))
  60. print("\nOverall totals ======================================================")
  61. for (event, counts) in log_diff.events.items():
  62. print("{0:>8} {1:<8} {2}".format(counts[0], counts[1], event))
  63. # take the detailed diff and create diff_left.txt and diff_right.txt
  64. # which should be manageable by a graphical diff tool. we trim the size
  65. # by replacing blocks of matching lines with "== block 1", "== block 2" etc.
  66. different = log_diff.dump_to_files("diff_left.txt", "diff_right.txt")
  67. if different:
  68. print("\nThe build logs are different.")
  69. sys.exit(1)
  70. print("\nThe build logs are probably equivalent.")
  71. sys.exit(0)