summaryrefslogtreecommitdiffstats
path: root/tests/DumpRenderTree/compare_layout_results.py
blob: c4285f1e7d7878d9f6614d7f8da526bf90bc79ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python
"""
Compares results of two webkit layout test runs and writes
results to a file.
"""

import optparse
import os
import sys

def DiffResults(marker, new_results, old_results, diff_results, strip_reason):
   """ Given two result files, generate diff and
       write to diff_results file. All arguments are absolute paths
       to files.
   """
   old_file = open(old_results, "r")
   new_file = open(new_results, "r")
   diff_file = open(diff_results, "a") 

   # Read lines from each file
   ndict = new_file.readlines()
   cdict = old_file.readlines()

   # Write marker to diff file
   diff_file.writelines(marker + "\n")
   diff_file.writelines("###############\n")

   # Strip reason from result lines
   if strip_reason is True:
     for i in range(0, len(ndict)):
       ndict[i] = ndict[i].split(' ')[0] + "\n"
     for i in range(0, len(cdict)):
       cdict[i] = cdict[i].split(' ')[0] + "\n"

   # Find results in new_results missing in old_results
   new_count=0
   for line in ndict:
     if line not in cdict:
       diff_file.writelines("+ " + line)
       new_count += 1

   # Find results in old_results missing in new_results
   missing_count=0
   for line in cdict:
     if line not in ndict:
       diff_file.writelines("- " + line)
       missing_count += 1

   print marker + "  >>> added " + str(new_count) + " tests, removed " + str(missing_count) + " tests" 

   diff_file.writelines("\n\n")

   old_file.close()
   new_file.close()
   diff_file.close()
   return

def main(options, args):
  results_dir = os.path.abspath(options.results_directory)
  ref_dir = options.ref_directory

  # if ref_dir is null, cannonify ref_dir to the script dir.
  if not ref_dir:
    script_self = sys.argv[0]
    script_dir = os.path.dirname(script_self)
    ref_dir = os.path.join(script_dir, "results")

  ref_dir = os.path.abspath(ref_dir)

  diff_result = os.path.join(results_dir, "layout_tests_diff.txt") 
  if os.path.exists(diff_result):
    os.remove(diff_result)

  files=["passed", "failed", "nontext", "crashed"]
  for f in files:
    result_file_name = "layout_tests_" + f + ".txt"
    DiffResults(f, os.path.join(results_dir, result_file_name),
                os.path.join(ref_dir, result_file_name), diff_result,
                f == "failed")

if '__main__' == __name__:
  option_parser = optparse.OptionParser()
  option_parser.add_option("", "--ref-directory",
                           default=None,
                           dest="ref_directory",
                           help="directory name under which results are stored.")

  option_parser.add_option("", "--results-directory",
                           default="layout-test-results/",
                           dest="results_directory",
                           help="directory name under which results are stored.")
  options, args = option_parser.parse_args()
  main(options, args)