2 # Copyright 2013-2016, 2019 Intel Corporation
3 # Copyright 2013, 2014 Advanced Micro Devices
4 # Copyright 2014 VMWare
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 """Generate text summaries to be printed to the console."""
29 from framework
import grouptools
, backends
30 from .common
import Results
36 _SUMMARY_TEMPLATE
= textwrap
.dedent("""\
46 incomplete: {incomplete}
47 dmesg-warn: {dmesg_warn}
48 dmesg-fail: {dmesg_fail}
51 regressions: {regressions}
56 def _print_summary(results
):
57 """print a summary."""
59 lens
= [max(min(len(x
.name
), 20), 8) for x
in results
.results
]
60 print_template
= ' '.join(
61 (lambda x
: '{: >' + '{0}.{0}'.format(x
) + '}')(y
) for y
in lens
)
63 def status_printer(stat
):
64 totals
= [str(x
.totals
['root'][stat
]) for x
in results
.results
]
65 return print_template
.format(*totals
)
67 def elapsed_time(time_elapsed
):
68 """Return elapsed time (in seconds) as a string in HH:MM:SS format."""
69 diff
= time_elapsed
.end
- time_elapsed
.start
70 return time
.strftime("%H:%M:%S", time
.gmtime(diff
))
72 print(_SUMMARY_TEMPLATE
.format(
73 names
=print_template
.format(*[r
.name
for r
in results
.results
]),
74 divider
=print_template
.format(*['-'*l
for l
in lens
]),
75 pass_
=status_printer('pass'),
76 crash
=status_printer('crash'),
77 fail
=status_printer('fail'),
78 skip
=status_printer('skip'),
79 timeout
=status_printer('timeout'),
80 warn
=status_printer('warn'),
81 incomplete
=status_printer('incomplete'),
82 dmesg_warn
=status_printer('dmesg-warn'),
83 dmesg_fail
=status_printer('dmesg-fail'),
84 changes
=print_template
.format(
85 *[str(s
) for s
in results
.counts
.changes
]),
86 fixes
=print_template
.format(
87 *[str(s
) for s
in results
.counts
.fixes
]),
88 regressions
=print_template
.format(
89 *[str(s
) for s
in results
.counts
.regressions
]),
90 total
=print_template
.format(*[
91 str(sum(x
.totals
['root'].values()))
92 for x
in results
.results
]),
93 time
=print_template
.format(
94 *[elapsed_time(r
.time_elapsed
) for r
in results
.results
]),
97 def _print_result(results
, list_
):
98 """Takes a list of test names to print and prints the name and result."""
99 for test
in sorted(list_
):
100 print("{test}: {statuses}".format(
101 test
=grouptools
.format(test
),
102 statuses
=' '.join(str(r
) for r
in results
.get_result(test
))))
105 def console(resultsFiles
, mode
):
106 """ Write summary information to the console for the given list of
107 results files in the given mode."""
108 assert mode
in ['summary', 'diff', 'incomplete', 'fixes', 'problems', 'regressions', 'all'], mode
109 results
= Results([backends
.load(r
) for r
in resultsFiles
])
111 # Print the name of the test and the status from each test run
113 _print_result(results
, results
.names
.all
)
114 _print_summary(results
)
116 _print_result(results
, results
.names
.all_changes
)
117 _print_summary(results
)
118 elif mode
== 'incomplete':
119 _print_result(results
, results
.names
.all_incomplete
)
120 elif mode
== 'fixes':
121 _print_result(results
, results
.names
.all_fixes
)
122 elif mode
== 'problems':
123 _print_result(results
, results
.names
.all_problems
)
124 elif mode
== 'regressions':
125 _print_result(results
, results
.names
.all_regressions
)
126 elif mode
== 'summary':
127 _print_summary(results
)