tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / kyua-atf-compat / dist / atf-report.sh
blobc8d1034b4d3b4d0ccba8537c2dbf9bb4a5eb671e
1 #! __SH__
2 # Copyright 2012 Google Inc.
3 # All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of Google Inc. nor the names of its contributors
15 # may be used to endorse or promote products derived from this software
16 # without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # \file atf-report.sh
31 # Kyua-based compatibility replacement for atf-report.
34 . "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/lib.subr"
37 # Gets the action identifier from the output of 'kyua test'.
39 # \param file The file that contains the output of 'kyua test'. Can be
40 # /dev/stdout.
42 # \post Prints the action identifier.
43 get_action() {
44 local file="${1}"; shift
45 grep '^Committed action ' "${file}" | cut -d ' ' -f 3
49 # Generates an HTML report.
51 # The original atf-report generates HTML reports that are made up of solely a
52 # single HTML page. Because of this, such reports can be written directly to
53 # the file specified by the user.
55 # Because Kyua generates "rich" HTML reports (i.e. reports that consist of more
56 # than one HTML page), we cannot perfectly emulate atf-report. Instead, we
57 # create an auxiliary directory to hold all the files, and then place a link to
58 # such files in the file specified by the user. The drawback is that HTML
59 # reports sent to stdout are no longer possible.
61 # \param output_file The name of the file to which to write the HTML report.
62 # This file will end up being a symlink to the real report.
63 report_html() {
64 local output_file="${1}"; shift
66 [ "${output_file}" != "/dev/stdout" ] || \
67 lib_usage_error "Cannot write HTML reports to stdout"
69 local dir="$(dirname "${output_file}")"
70 local index_name="${output_file##*/}"
71 local files_name="$(echo "${index_name}" | sed -e 's,\.[a-zA-Z]*$,,').files"
73 kyua report-html --action="$(get_action /dev/stdin)" \
74 --output="${dir}/${files_name}"
76 echo "Pointing ${index_name} to ${files_name}/index.html"
77 ( cd "${dir}" && ln -s "${files_name}/index.html" "${index_name}" )
81 # Genereates an XML report.
83 # For our compatibility purposes, we assume that the XML report is just an HTML
84 # report.
86 # \param output_file The name of the file to which to write the HTML report.
87 # This file will end up being a symlink to the real report.
88 report_xml() {
89 local output_file="${1}"; shift
91 lib_warning "XML output not supported; generating HTML instead"
92 report_html "${output_file}"
96 # Generates progressive textual reports.
98 # This wrapper attempts to emulate atf-report's ticker output by reading the
99 # output of 'kyua test' progressively and sending it to the screen as soon as it
100 # becomes available. The tail of the 'kyua test' report that includes summaries
101 # for the run is suppressed and is replaced with the more-detailed output of
102 # 'kyua report'.
104 # \param output_file The name of the file to which to write the textual report.
105 # Can be /dev/stdout.
106 report_ticker() {
107 local output_file="${1}"; shift
109 local print=yes
110 while read line; do
111 [ -n "${line}" ] || print=no
113 if [ "${print}" = yes ]; then
114 case "${line}" in
115 Committed*)
116 echo "${line}" >>"${Lib_TempDir}/output"
119 echo "${line}"
121 esac
122 else
123 echo "${line}" >>"${Lib_TempDir}/output"
125 done
127 kyua report --action="$(get_action "${Lib_TempDir}/output")" \
128 --output="${output_file}"
132 # Generates a report based on an output specification.
134 # \param output_spec The format:file specification of the output.
135 report() {
136 local output_spec="${1}"; shift
138 local output_format="$(echo "${output_spec}" | cut -d : -f 1)"
139 local output_file="$(echo "${output_spec}" | cut -d : -f 2)"
140 [ "${output_file}" != - ] || output_file=/dev/stdout
142 case "${output_format}" in
143 html|ticker|xml)
144 "report_${output_format}" "${output_file}"
148 lib_usage_error "Unknown output format '${output_format}'"
150 esac
154 # Prints program usage to stdout.
156 # \param progname The name of the program to use for the syntax help.
157 usage() {
158 local progname="${1}"; shift
159 echo "Usage: ${progname} [-o output-spec]"
163 # Entry point for the program.
165 # \param ... The user-provided arguments.
166 main()
168 local output_spec="ticker:-"
169 while getopts ':o:' arg "${@}"; do
170 case "${arg}" in
172 output_spec="${OPTARG}"
175 lib_usage_error "Unknown option -${OPTARG}"
177 esac
178 done
179 shift $((${OPTIND} - 1))
181 [ ${#} -eq 0 ] || lib_usage_error "No arguments allowed"
183 lib_init_tempdir
185 report "${output_spec}"
187 lib_cleanup
191 main "${@}"