1 # Copyright 2012 Google Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of Google Inc. nor the names of its contributors
14 # may be used to endorse or promote products derived from this software
15 # without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # \file tests_lib.subr
30 # Common routines for test programs.
33 # Creates an Atffile file.
35 # \param destfile The path to the file to be created.
36 # \param ... The lines to append to the Atffile.
38 local destfile="${1}"; shift
40 cat >"${destfile}" <<EOF
41 Content-type: application/X-atf-atffile, version="1"
44 for line in "${@}"; do
45 echo "${line}" >>"${destfile}"
50 # Creates an ATF configuration file.
52 # \param destfile The path to the file to be created.
53 # \param ... The lines to append to the configuration file.
55 local destfile="${1}"; shift
57 cat >"${destfile}" <<EOF
58 Content-type: application/X-atf-config, version="1"
60 # This is a comment that should be ignored.
61 # And this is another one.
64 for line in "${@}"; do
65 echo "${line}" >>"${destfile}"
70 # Creates a fake test program.
72 # \param destfile The path to the test program to be created.
73 # \param ... List of the test cases to include in the fake test program.
74 create_test_program() {
75 local destfile="${1}"; shift
77 sed -e "s,@CONTROL_DIR@,$(pwd),g" \
78 -e "s,@ENABLED_TESTS@,${*},g" \
79 <"$(atf_get_srcdir)/helpers" >"${destfile}"
80 chmod +x "${destfile}"
84 # Strips timestamps from the output of 'kyua test' or 'kyua report'.
86 # The timestamps are all replaced with X.XXXs so that they can later be compared
87 # against prerecorded golden output.
89 # \param file The file in which to replace the timestamps. The replacement is
90 # performed in place. The reason is that the calls to atf-run and
91 # atf-report should be validated on their own WITHOUT piping them through
92 # any manipulation function.
94 local file="${1}"; shift
96 sed -e 's,[0-9][0-9]*\.[0-9][0-9]*s,X.XXXs,g' <"${file}" >"${file}.new"
97 mv "${file}.new" "${file}"