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