Home | History | Annotate | Line # | Download | only in integration
      1  1.1  jmmv # Copyright 2011 Google Inc.
      2  1.1  jmmv # All rights reserved.
      3  1.1  jmmv #
      4  1.1  jmmv # Redistribution and use in source and binary forms, with or without
      5  1.1  jmmv # modification, are permitted provided that the following conditions are
      6  1.1  jmmv # met:
      7  1.1  jmmv #
      8  1.1  jmmv # * Redistributions of source code must retain the above copyright
      9  1.1  jmmv #   notice, this list of conditions and the following disclaimer.
     10  1.1  jmmv # * Redistributions in binary form must reproduce the above copyright
     11  1.1  jmmv #   notice, this list of conditions and the following disclaimer in the
     12  1.1  jmmv #   documentation and/or other materials provided with the distribution.
     13  1.1  jmmv # * Neither the name of Google Inc. nor the names of its contributors
     14  1.1  jmmv #   may be used to endorse or promote products derived from this software
     15  1.1  jmmv #   without specific prior written permission.
     16  1.1  jmmv #
     17  1.1  jmmv # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18  1.1  jmmv # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19  1.1  jmmv # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     20  1.1  jmmv # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     21  1.1  jmmv # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     22  1.1  jmmv # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     23  1.1  jmmv # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  jmmv # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  jmmv # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  jmmv # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27  1.1  jmmv # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  jmmv 
     29  1.1  jmmv 
     30  1.1  jmmv # Subcommand to strip the timestamps of a report.
     31  1.1  jmmv #
     32  1.1  jmmv # This is to make the reports deterministic and thus easily testable.  The
     33  1.1  jmmv # timestamps are replaced by the fixed string S.UUUs.
     34  1.1  jmmv #
     35  1.1  jmmv # This variable should be used as shown here:
     36  1.1  jmmv #
     37  1.1  jmmv #     atf_check ... -x kyua report "| ${uilts_strip_timestamp}"
     38  1.1  jmmv utils_strip_timestamp='sed -e "s,[0-9][0-9]*.[0-9][0-9][0-9]s,S.UUUs,g"'
     39  1.1  jmmv 
     40  1.1  jmmv 
     41  1.1  jmmv # Copies a helper binary from the source directory to the work directory.
     42  1.1  jmmv #
     43  1.1  jmmv # \param name The name of the binary to copy.
     44  1.1  jmmv # \param destination The target location for the binary; can be either
     45  1.1  jmmv #     a directory name or a file name.
     46  1.1  jmmv utils_cp_helper() {
     47  1.1  jmmv     local name="${1}"; shift
     48  1.1  jmmv     local destination="${1}"; shift
     49  1.1  jmmv 
     50  1.1  jmmv     ln -s "$(atf_get_srcdir)"/helpers/"${name}" "${destination}"
     51  1.1  jmmv }
     52  1.1  jmmv 
     53  1.1  jmmv 
     54  1.1  jmmv # Creates a 'kyua' binary in the path that strips timestamps off the output.
     55  1.1  jmmv #
     56  1.1  jmmv # Call this on test cases that wish to replace timestamps in the *stdout* of
     57  1.1  jmmv # Kyua with the S.UUUs deterministic string.  This is usable for tests that
     58  1.1  jmmv # validate the 'test' subcommand, but also by a few specific tests for the
     59  1.1  jmmv # 'report' subcommand.
     60  1.1  jmmv utils_install_timestamp_wrapper() {
     61  1.1  jmmv     [ ! -x kyua ] || return
     62  1.1  jmmv     cat >kyua <<EOF
     63  1.1  jmmv #! /bin/sh
     64  1.1  jmmv 
     65  1.1  jmmv PATH=${PATH}
     66  1.1  jmmv 
     67  1.1  jmmv kyua "\${@}" >kyua.tmpout
     68  1.1  jmmv result=\${?}
     69  1.1  jmmv cat kyua.tmpout | ${utils_strip_timestamp}
     70  1.1  jmmv exit \${result}
     71  1.1  jmmv EOF
     72  1.1  jmmv     chmod +x kyua
     73  1.1  jmmv     PATH="$(pwd):${PATH}"
     74  1.1  jmmv }
     75  1.1  jmmv 
     76  1.1  jmmv 
     77  1.1  jmmv # Defines a test case with a default head.
     78  1.1  jmmv utils_test_case() {
     79  1.1  jmmv     local name="${1}"; shift
     80  1.1  jmmv 
     81  1.1  jmmv     atf_test_case "${name}"
     82  1.1  jmmv     eval "${name}_head() {
     83  1.1  jmmv         atf_set require.progs kyua
     84  1.1  jmmv     }"
     85  1.1  jmmv }
     86