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