atf2kyua.sh revision 1.1.1.1.6.2 1 1.1.1.1.6.2 tls #! __SH__
2 1.1.1.1.6.2 tls # Copyright 2011 Google Inc.
3 1.1.1.1.6.2 tls # All rights reserved.
4 1.1.1.1.6.2 tls #
5 1.1.1.1.6.2 tls # Redistribution and use in source and binary forms, with or without
6 1.1.1.1.6.2 tls # modification, are permitted provided that the following conditions are
7 1.1.1.1.6.2 tls # met:
8 1.1.1.1.6.2 tls #
9 1.1.1.1.6.2 tls # * Redistributions of source code must retain the above copyright
10 1.1.1.1.6.2 tls # notice, this list of conditions and the following disclaimer.
11 1.1.1.1.6.2 tls # * Redistributions in binary form must reproduce the above copyright
12 1.1.1.1.6.2 tls # notice, this list of conditions and the following disclaimer in the
13 1.1.1.1.6.2 tls # documentation and/or other materials provided with the distribution.
14 1.1.1.1.6.2 tls # * Neither the name of Google Inc. nor the names of its contributors
15 1.1.1.1.6.2 tls # may be used to endorse or promote products derived from this software
16 1.1.1.1.6.2 tls # without specific prior written permission.
17 1.1.1.1.6.2 tls #
18 1.1.1.1.6.2 tls # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 1.1.1.1.6.2 tls # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 1.1.1.1.6.2 tls # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 1.1.1.1.6.2 tls # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 1.1.1.1.6.2 tls # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 1.1.1.1.6.2 tls # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 1.1.1.1.6.2 tls # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.1.1.1.6.2 tls # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.1.1.1.6.2 tls # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.1.1.1.6.2 tls # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 1.1.1.1.6.2 tls # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.1.1.1.6.2 tls
30 1.1.1.1.6.2 tls # \file atf2kyua.sh
31 1.1.1.1.6.2 tls # Converts Atffiles to Kyuafiles for a particular test suite.
32 1.1.1.1.6.2 tls
33 1.1.1.1.6.2 tls
34 1.1.1.1.6.2 tls . "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/lib.subr"
35 1.1.1.1.6.2 tls
36 1.1.1.1.6.2 tls
37 1.1.1.1.6.2 tls # Prunes all Kyuafiles from a test suite in preparation for regeneration.
38 1.1.1.1.6.2 tls #
39 1.1.1.1.6.2 tls # \param target_root The path to the test suite.
40 1.1.1.1.6.2 tls remove_kyuafiles() {
41 1.1.1.1.6.2 tls local target_root="${1}"; shift
42 1.1.1.1.6.2 tls
43 1.1.1.1.6.2 tls if [ -d "${target_root}" ]; then
44 1.1.1.1.6.2 tls lib_info "Removing stale Kyuafiles from ${target_root}"
45 1.1.1.1.6.2 tls find "${target_root}" -name Kyuafile -exec rm -f {} \;
46 1.1.1.1.6.2 tls fi
47 1.1.1.1.6.2 tls }
48 1.1.1.1.6.2 tls
49 1.1.1.1.6.2 tls
50 1.1.1.1.6.2 tls # Obtains the list of test programs and subdirectories referenced by an Atffile.
51 1.1.1.1.6.2 tls #
52 1.1.1.1.6.2 tls # Any globs within the Atffile are expanded relative to the directory in which
53 1.1.1.1.6.2 tls # the Atffile lives.
54 1.1.1.1.6.2 tls #
55 1.1.1.1.6.2 tls # \param atffile The path to the Atffile to process.
56 1.1.1.1.6.2 tls #
57 1.1.1.1.6.2 tls # \post Prints the list of files referenced by the Atffile on stdout.
58 1.1.1.1.6.2 tls extract_files() {
59 1.1.1.1.6.2 tls local atffile="${1}"; shift
60 1.1.1.1.6.2 tls
61 1.1.1.1.6.2 tls local dir="$(dirname "${atffile}")"
62 1.1.1.1.6.2 tls
63 1.1.1.1.6.2 tls local globs="$(grep '^tp-glob:' "${atffile}" | cut -d ' ' -f 2-)"
64 1.1.1.1.6.2 tls local files="$(grep '^tp:' "${atffile}" | cut -d ' ' -f 2-)"
65 1.1.1.1.6.2 tls
66 1.1.1.1.6.2 tls for file in ${files} $(cd "$(dirname "${atffile}")" && echo ${globs}); do
67 1.1.1.1.6.2 tls if test -d "${dir}/${file}" -o -x "${dir}/${file}"; then
68 1.1.1.1.6.2 tls echo "${file}"
69 1.1.1.1.6.2 tls fi
70 1.1.1.1.6.2 tls done
71 1.1.1.1.6.2 tls }
72 1.1.1.1.6.2 tls
73 1.1.1.1.6.2 tls
74 1.1.1.1.6.2 tls # Converts an Atffile to a Kyuafile.
75 1.1.1.1.6.2 tls #
76 1.1.1.1.6.2 tls # \param atffile The path to the Atfffile to convert.
77 1.1.1.1.6.2 tls # \param kyuafile The path to where the Kyuafile will be written.
78 1.1.1.1.6.2 tls convert_atffile() {
79 1.1.1.1.6.2 tls local atffile="${1}"; shift
80 1.1.1.1.6.2 tls local kyuafile="${1}"; shift
81 1.1.1.1.6.2 tls
82 1.1.1.1.6.2 tls lib_info "Converting ${atffile} -> ${kyuafile}"
83 1.1.1.1.6.2 tls
84 1.1.1.1.6.2 tls local test_suite="$(grep 'prop:.*test-suite.*' "${atffile}" \
85 1.1.1.1.6.2 tls | cut -d \" -f 2)"
86 1.1.1.1.6.2 tls
87 1.1.1.1.6.2 tls local dir="$(dirname "${atffile}")"
88 1.1.1.1.6.2 tls
89 1.1.1.1.6.2 tls local subdirs=
90 1.1.1.1.6.2 tls local test_programs=
91 1.1.1.1.6.2 tls for file in $(extract_files "${atffile}"); do
92 1.1.1.1.6.2 tls if test -f "${dir}/${file}/Atffile"; then
93 1.1.1.1.6.2 tls subdirs="${subdirs} ${file}"
94 1.1.1.1.6.2 tls elif test -x "${dir}/${file}"; then
95 1.1.1.1.6.2 tls test_programs="${test_programs} ${file}"
96 1.1.1.1.6.2 tls fi
97 1.1.1.1.6.2 tls done
98 1.1.1.1.6.2 tls
99 1.1.1.1.6.2 tls mkdir -p "$(dirname "${kyuafile}")"
100 1.1.1.1.6.2 tls
101 1.1.1.1.6.2 tls echo "syntax('kyuafile', 1)" >"${kyuafile}"
102 1.1.1.1.6.2 tls echo >>"${kyuafile}"
103 1.1.1.1.6.2 tls echo "test_suite('${test_suite}')" >>"${kyuafile}"
104 1.1.1.1.6.2 tls if [ -n "${subdirs}" ]; then
105 1.1.1.1.6.2 tls echo >>"${kyuafile}"
106 1.1.1.1.6.2 tls for dir in ${subdirs}; do
107 1.1.1.1.6.2 tls echo "include('${dir}/Kyuafile')" >>"${kyuafile}"
108 1.1.1.1.6.2 tls done
109 1.1.1.1.6.2 tls fi
110 1.1.1.1.6.2 tls if [ -n "${test_programs}" ]; then
111 1.1.1.1.6.2 tls echo >>"${kyuafile}"
112 1.1.1.1.6.2 tls for tp in ${test_programs}; do
113 1.1.1.1.6.2 tls echo "atf_test_program{name='${tp}'}" >>"${kyuafile}"
114 1.1.1.1.6.2 tls done
115 1.1.1.1.6.2 tls fi
116 1.1.1.1.6.2 tls }
117 1.1.1.1.6.2 tls
118 1.1.1.1.6.2 tls
119 1.1.1.1.6.2 tls # Adds Kyuafiles to a test suite by converting any existing Atffiles.
120 1.1.1.1.6.2 tls #
121 1.1.1.1.6.2 tls # \param source_root The path to the existing test suite root. Must contain
122 1.1.1.1.6.2 tls # an Atffile and the test programs.
123 1.1.1.1.6.2 tls # \param target_root The path to the directory where the Kyuafiles will be
124 1.1.1.1.6.2 tls # written. The layout will mimic that of source_root.
125 1.1.1.1.6.2 tls add_kyuafiles() {
126 1.1.1.1.6.2 tls local source_root="${1}"; shift
127 1.1.1.1.6.2 tls local target_root="${1}"; shift
128 1.1.1.1.6.2 tls
129 1.1.1.1.6.2 tls for atffile in $(cd "${source_root}" && find . -name Atffile); do
130 1.1.1.1.6.2 tls local subdir="$(echo "${atffile}" | sed 's,Atffile$,,;s,^\./,,')"
131 1.1.1.1.6.2 tls convert_atffile "${source_root}/${subdir}Atffile" \
132 1.1.1.1.6.2 tls "${target_root}/${subdir}Kyuafile"
133 1.1.1.1.6.2 tls done
134 1.1.1.1.6.2 tls }
135 1.1.1.1.6.2 tls
136 1.1.1.1.6.2 tls
137 1.1.1.1.6.2 tls # Prints program usage to stdout.
138 1.1.1.1.6.2 tls #
139 1.1.1.1.6.2 tls # \param progname The name of the program to use for the syntax help.
140 1.1.1.1.6.2 tls usage() {
141 1.1.1.1.6.2 tls local progname="${1}"; shift
142 1.1.1.1.6.2 tls echo "Usage: ${progname} [-s source_root] [-t target_root]"
143 1.1.1.1.6.2 tls }
144 1.1.1.1.6.2 tls
145 1.1.1.1.6.2 tls
146 1.1.1.1.6.2 tls # Entry point for the program.
147 1.1.1.1.6.2 tls #
148 1.1.1.1.6.2 tls # \param ... The user-provided arguments.
149 1.1.1.1.6.2 tls main() {
150 1.1.1.1.6.2 tls local source_root=
151 1.1.1.1.6.2 tls local target_root=
152 1.1.1.1.6.2 tls
153 1.1.1.1.6.2 tls while getopts ':s:t:' arg "${@}"; do
154 1.1.1.1.6.2 tls case "${arg}" in
155 1.1.1.1.6.2 tls s)
156 1.1.1.1.6.2 tls source_root="${OPTARG}"
157 1.1.1.1.6.2 tls ;;
158 1.1.1.1.6.2 tls t)
159 1.1.1.1.6.2 tls target_root="${OPTARG}"
160 1.1.1.1.6.2 tls ;;
161 1.1.1.1.6.2 tls \?)
162 1.1.1.1.6.2 tls lib_usage_error "Unknown option -${OPTARG}"
163 1.1.1.1.6.2 tls ;;
164 1.1.1.1.6.2 tls esac
165 1.1.1.1.6.2 tls done
166 1.1.1.1.6.2 tls shift $((${OPTIND} - 1))
167 1.1.1.1.6.2 tls
168 1.1.1.1.6.2 tls [ -n "${source_root}" ] || source_root=.
169 1.1.1.1.6.2 tls [ -n "${target_root}" ] || target_root="${source_root}"
170 1.1.1.1.6.2 tls
171 1.1.1.1.6.2 tls [ ${#} -eq 0 ] || lib_usage_error "No arguments allowed"
172 1.1.1.1.6.2 tls
173 1.1.1.1.6.2 tls [ -f "${source_root}/Atffile" ] || \
174 1.1.1.1.6.2 tls lib_error "${source_root} is not a test suite; missing Atffile"
175 1.1.1.1.6.2 tls
176 1.1.1.1.6.2 tls remove_kyuafiles "${target_root}"
177 1.1.1.1.6.2 tls add_kyuafiles "${source_root}" "${target_root}"
178 1.1.1.1.6.2 tls }
179 1.1.1.1.6.2 tls
180 1.1.1.1.6.2 tls
181 1.1.1.1.6.2 tls main "${@}"
182