~ubuntu-branches/ubuntu/trusty/binutils-2.26/trusty-security

« back to all changes in this revision

Viewing changes to debian/test-suite-compare.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2017-02-24 13:04:41 UTC
  • Revision ID: package-import@ubuntu.com-20170224130441-8pxcdc3y92eb2fj2
Tags: 2.26.1-1ubuntu1~14.04
* SRU. LP: #1667662. Backport to trusty, required for LLVM 3.9 backport.
* Disable building multiarch and cross packages.
* Make binutils-2.26 co-installable with binutils.
* Provide unversioned binaries in /usr/lib/binutils-2.26/bin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
# Quick'n'dirty regression check for dejagnu testsuites
 
4
# Copyright (C) 2003, 2004, 2005, 2006, 2007  James Troup <james@nocrew.org>
 
5
 
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
 
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
 
 
16
# You should have received a copy of the GNU;5B General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
################################################################################
 
21
 
 
22
import optparse
 
23
import os
 
24
import sys
 
25
 
 
26
################################################################################
 
27
 
 
28
def fubar(msg, exit_code=1):
 
29
    sys.stderr.write("E: %s\n" % (msg))
 
30
    sys.exit(exit_code)
 
31
 
 
32
def warn(msg):
 
33
    sys.stderr.write("W: %s\n" % (msg))
 
34
 
 
35
def info(msg):
 
36
    sys.stderr.write("I: %s\n" % (msg))
 
37
 
 
38
################################################################################
 
39
 
 
40
def read_testsummary(filename):
 
41
    results = {}
 
42
    file = open(filename)
 
43
    for line in file.readlines():
 
44
        if not line:
 
45
            continue
 
46
        if line.startswith("Running"):
 
47
            s = line.split()
 
48
            if "/" in s[1]:
 
49
                x = s[1]
 
50
                if x.find("/testsuite/") == -1:
 
51
                    fubar("Can't find /testsuite/ in '%s'." % (x))
 
52
                # 'Running /home/james/debian/packages/binutils/binutils-2.14.90.0.7/gas/testsuite/gas/hppa/unsorted/unsorted.exp ...' -> 'gas/hppa/unsorted/unsorted.exp'
 
53
                # ... since using basename() isn't dupe safe.
 
54
                section = x[x.find("/testsuite/"):].replace("/testsuite/","").split()[0]
 
55
 
 
56
                # Tests can be duplicated, e.g. hppa/basic/basic.exp
 
57
                # is run twice, once for hppa-linux and once for
 
58
                # hppa64-linux.  This is of course a horrible bodge,
 
59
                # but I can't think of anything trivial and better off
 
60
                # hand.
 
61
 
 
62
                if section in results:
 
63
                    extra = 1
 
64
                    too_many = 10
 
65
                    while section in results and extra < too_many:
 
66
                        section = "%s.%s" % (section, extra)
 
67
                        extra += 1
 
68
                        if extra >= too_many:
 
69
                            fubar("gave up trying to unduplicate %s." % (section))
 
70
 
 
71
                results[section] = {}
 
72
                continue
 
73
 
 
74
        got_state = 0
 
75
        for state in [ "PASS", "XPASS", "FAIL", "XFAIL", "UNRESOLVED",
 
76
                       "UNTESTED", "UNSUPPORTED" ]:
 
77
            if line.startswith(state):
 
78
                s = line.split(':')
 
79
                state = s[0]
 
80
                test = ':'.join(s[1:]).strip()
 
81
                if test in results:
 
82
                    warn("%s/%s is duplicated." % (section, test))
 
83
                results[section][test] = state
 
84
                got_state = 1
 
85
                break
 
86
 
 
87
        if got_state:
 
88
            continue
 
89
 
 
90
    return results
 
91
 
 
92
################################################################################
 
93
 
 
94
def compare_results(old, new):
 
95
    total_num = 0
 
96
    pass_count = 0
 
97
    fail_count = 0
 
98
    xfail_count = 0
 
99
    untested_count = 0
 
100
    regression_count = 0
 
101
    progression_count = 0
 
102
    change_count = 0
 
103
 
 
104
    for section in list(new.keys()):
 
105
        for test in list(new[section].keys()):
 
106
            state = new[section][test]
 
107
 
 
108
            # Stats pr0n
 
109
            total_num += 1
 
110
            if state == "PASS" or state == "XPASS":
 
111
                pass_count += 1
 
112
            elif state == "FAIL" or state == "UNRESOLVED":
 
113
                fail_count += 1
 
114
            elif state == "XFAIL":
 
115
                xfail_count += 1
 
116
            elif state == "UNTESTED":
 
117
                untested_count += 1
 
118
 
 
119
            # Compare to old
 
120
            if section not in old:
 
121
                continue
 
122
            if test not in old[section]:
 
123
                continue
 
124
            old_state = old[section][test]
 
125
            if state == "PASS":
 
126
                if old_state != "PASS":
 
127
                    progression_count += 1
 
128
                    info("[%s] progression (%s -> %s): %s" % (section, old_state, state, test))
 
129
            elif state == "XPASS":
 
130
                if old_state != "XPASS" and old_state != "PASS":
 
131
                    progression_count += 1
 
132
                    warn("[%s] %s: %s" % (section, state, test))
 
133
            elif state == "FAIL":
 
134
                if old_state != "FAIL":
 
135
                    regression_count += 1
 
136
                    warn("[%s] REGRESSION (%s -> %s): %s" % (section, old_state, state, test))
 
137
            elif state == "XFAIL":
 
138
                if old_state != "XFAIL":
 
139
                    change_count += 1
 
140
                    info("[%s] change (%s -> %s): %s" % (section, old_state, state, test))
 
141
            elif state == "UNRESOLVED":
 
142
                if old_state != "UNRESOLVED" and old_state != "FAIL":
 
143
                    regression_count += 1
 
144
                    warn("[%s] REGRESSION (%s -> %s): %s" % (section, old_state, state, test))
 
145
                if old_state == "FAIL":
 
146
                    change_count += 1
 
147
                    info("[%s] change (%s -> %s): %s" % (section, old_state, state, test))
 
148
            elif state == "UNTESTED":
 
149
                if old_state != "UNTESTED":
 
150
                    change_count += 1
 
151
                    warn("[%s] REGRESSION (%s -> %s): %s" % (section, old_state, state, test))
 
152
 
 
153
    if regression_count:
 
154
        print("%d REGRESSIONS (%.2f%%)." % (regression_count, (float(regression_count)/total_num)*100))
 
155
    if progression_count:
 
156
        print("%d progressions (%.2f%%)." % (progression_count, (float(progression_count)/total_num)*100))
 
157
 
 
158
    if change_count:
 
159
        print("%d changes (%.2f%%)." % (change_count, (float(change_count)/total_num)*100))
 
160
 
 
161
    print("%d tests: %d pass (%.2f%%), %d fail (%.2f%%), %d xfail (%.2f%%) %d untested (%.2f%%)." \
 
162
          % (total_num, pass_count, (float(pass_count)/total_num)*100,
 
163
             fail_count, (float(fail_count)/total_num)*100,
 
164
             xfail_count, (float(xfail_count)/total_num)*100,
 
165
             untested_count, (float(untested_count)/total_num)*100))
 
166
 
 
167
    if regression_count:
 
168
        sys.exit(1)
 
169
 
 
170
################################################################################
 
171
 
 
172
def compare_multiple(directory, first_version, second_version):
 
173
    architectures = [ "alpha", "arm", "hppa", "i386", "ia64", "mips",
 
174
                      "m68k", "mipsel", "powerpc", "s390", "sparc" ]
 
175
 
 
176
    for arch in architectures:
 
177
        print("*********************************** %s ******************************" % (arch))
 
178
        second_filename = "%s/%s_%s" % (directory, second_version, arch)
 
179
        if not os.path.exists(second_filename):
 
180
            print("   -- NOT AVAILABLE --")
 
181
            continue
 
182
 
 
183
        new = read_testsummary(second_filename)
 
184
        first_filename = "%s/%s_%s" % (directory, first_version, arch)
 
185
        old = read_testsummary(first_filename)
 
186
        compare_results(old, new)
 
187
 
 
188
################################################################################
 
189
 
 
190
def init():
 
191
    """Initalization, including parsing of options."""
 
192
 
 
193
    usage = """usage: %prog [OPTIONS] <OLD> <NEW>
 
194
compare (binutils) dejagnu testsuite results.
 
195
 
 
196
Example usage:
 
197
 
 
198
  test-suite-compare.py binutils-2.17/test-summary binutils-2.18/test-summary
 
199
 
 
200
Or to compare across all architectures (with test results stored in a
 
201
'test-summary' directory):
 
202
 
 
203
  test-suite-compare.py -mtest-summary 2.17-3 2.18-1"""
 
204
    parser = optparse.OptionParser(usage)
 
205
    parser.add_option("-m", "--multiple", dest="multiple",
 
206
                      nargs=1, type="string",
 
207
                      help="compare multiple architectures")
 
208
    (options, args) = parser.parse_args()
 
209
 
 
210
    if len(args) > 2 or len(args) < 2:
 
211
        parser.error("takes 2 arguments (old and new)")
 
212
    (old_version, new_version) = args
 
213
 
 
214
    return options, old_version, new_version
 
215
            
 
216
################################################################################
 
217
 
 
218
def main():
 
219
    (options, old_version, new_version) = init()
 
220
    if options.multiple:
 
221
        compare_multiple(options.multiple, old_version, new_version)
 
222
    else:
 
223
        old = read_testsummary(old_version)
 
224
        new = read_testsummary(new_version)
 
225
        compare_results(old, new)
 
226
 
 
227
################################################################################
 
228
 
 
229
if __name__ == '__main__':
 
230
    main()