1 1.1 jmmv # 2 1.1 jmmv # Automated Testing Framework (atf) 3 1.1 jmmv # 4 1.2 martin # Copyright (c) 2007 The NetBSD Foundation, Inc. 5 1.1 jmmv # All rights reserved. 6 1.1 jmmv # 7 1.1 jmmv # Redistribution and use in source and binary forms, with or without 8 1.1 jmmv # modification, are permitted provided that the following conditions 9 1.1 jmmv # are met: 10 1.1 jmmv # 1. Redistributions of source code must retain the above copyright 11 1.1 jmmv # notice, this list of conditions and the following disclaimer. 12 1.1 jmmv # 2. Redistributions in binary form must reproduce the above copyright 13 1.1 jmmv # notice, this list of conditions and the following disclaimer in the 14 1.1 jmmv # documentation and/or other materials provided with the distribution. 15 1.1 jmmv # 16 1.1 jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17 1.1 jmmv # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 1.1 jmmv # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 1.1 jmmv # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 1.1 jmmv # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21 1.1 jmmv # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 1.1 jmmv # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 1.1 jmmv # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 1.1 jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 1.1 jmmv # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 1.1 jmmv # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 1.1 jmmv # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 1.1 jmmv # 29 1.1 jmmv 30 1.1 jmmv # TODO: Bring in the checks in the bootstrap testsuite for atf_check. 31 1.1 jmmv 32 1.1 jmmv atf_test_case info_ok 33 1.1 jmmv info_ok_head() 34 1.1 jmmv { 35 1.1 jmmv atf_set "descr" "Verifies that atf_check prints an informative" \ 36 1.1 jmmv "message even when the command is successful" 37 1.1 jmmv } 38 1.1 jmmv info_ok_body() 39 1.1 jmmv { 40 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 41 1.1 jmmv 42 1.1 jmmv atf_check -s eq:0 -o save:stdout -e save:stderr -x \ 43 1.1 jmmv "${h} atf_check_info_ok" 44 1.1 jmmv grep 'Executing command.*true' stdout >/dev/null || \ 45 1.1 jmmv atf_fail "atf_check does not print an informative message" 46 1.1 jmmv 47 1.1 jmmv atf_check -s eq:0 -o save:stdout -e save:stderr -x \ 48 1.1 jmmv "${h} atf_check_info_fail" 49 1.1 jmmv grep 'Executing command.*false' stdout >/dev/null || \ 50 1.1 jmmv atf_fail "atf_check does not print an informative message" 51 1.1 jmmv } 52 1.1 jmmv 53 1.1 jmmv atf_test_case expout_mismatch 54 1.1 jmmv expout_mismatch_head() 55 1.1 jmmv { 56 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a diff of the" \ 57 1.2 martin "stdout and the expected stdout if the two do not" \ 58 1.1 jmmv "match" 59 1.1 jmmv } 60 1.1 jmmv expout_mismatch_body() 61 1.1 jmmv { 62 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 63 1.1 jmmv 64 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 65 1.1 jmmv "${h} atf_check_expout_mismatch" 66 1.1 jmmv grep 'Executing command.*echo bar' stdout >/dev/null || \ 67 1.1 jmmv atf_fail "atf_check does not print an informative message" 68 1.1 jmmv grep 'stdout does not match golden output' stderr >/dev/null || \ 69 1.1 jmmv atf_fail "atf_check does not print the stdout header" 70 1.1 jmmv grep 'stderr' stderr >/dev/null && \ 71 1.1 jmmv atf_fail "atf_check prints the stderr header" 72 1.1 jmmv grep '^-foo' stderr >/dev/null || \ 73 1.1 jmmv atf_fail "atf_check does not print the stdout's diff" 74 1.1 jmmv grep '^+bar' stderr >/dev/null || \ 75 1.1 jmmv atf_fail "atf_check does not print the stdout's diff" 76 1.1 jmmv } 77 1.1 jmmv 78 1.1 jmmv atf_test_case experr_mismatch 79 1.1 jmmv experr_mismatch_head() 80 1.1 jmmv { 81 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a diff of the" \ 82 1.2 martin "stderr and the expected stderr if the two do not" \ 83 1.1 jmmv "match" 84 1.1 jmmv } 85 1.1 jmmv experr_mismatch_body() 86 1.1 jmmv { 87 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 88 1.1 jmmv 89 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 90 1.1 jmmv "${h} atf_check_experr_mismatch" 91 1.1 jmmv grep 'Executing command.*echo bar' stdout >/dev/null || \ 92 1.1 jmmv atf_fail "atf_check does not print an informative message" 93 1.1 jmmv grep 'stdout' stderr >/dev/null && \ 94 1.1 jmmv atf_fail "atf_check prints the stdout header" 95 1.1 jmmv grep 'stderr does not match golden output' stderr >/dev/null || \ 96 1.1 jmmv atf_fail "atf_check does not print the stderr header" 97 1.1 jmmv grep '^-foo' stderr >/dev/null || \ 98 1.1 jmmv atf_fail "atf_check does not print the stderr's diff" 99 1.1 jmmv grep '^+bar' stderr >/dev/null || \ 100 1.1 jmmv atf_fail "atf_check does not print the stderr's diff" 101 1.1 jmmv } 102 1.1 jmmv 103 1.1 jmmv atf_test_case null_stdout 104 1.1 jmmv null_stdout_head() 105 1.1 jmmv { 106 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a the stdout it got" \ 107 1.1 jmmv "when it was supposed to be null" 108 1.1 jmmv } 109 1.1 jmmv null_stdout_body() 110 1.1 jmmv { 111 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 112 1.1 jmmv 113 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 114 1.1 jmmv "${h} atf_check_null_stdout" 115 1.1 jmmv grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \ 116 1.1 jmmv atf_fail "atf_check does not print an informative message" 117 1.1 jmmv grep 'stdout not empty' stderr >/dev/null || \ 118 1.1 jmmv atf_fail "atf_check does not print the stdout header" 119 1.1 jmmv grep 'stderr' stderr >/dev/null && \ 120 1.1 jmmv atf_fail "atf_check prints the stderr header" 121 1.1 jmmv grep 'These are the contents' stderr >/dev/null || \ 122 1.1 jmmv atf_fail "atf_check does not print stdout's contents" 123 1.1 jmmv } 124 1.1 jmmv 125 1.1 jmmv atf_test_case null_stderr 126 1.1 jmmv null_stderr_head() 127 1.1 jmmv { 128 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a the stderr it got" \ 129 1.1 jmmv "when it was supposed to be null" 130 1.1 jmmv } 131 1.1 jmmv null_stderr_body() 132 1.1 jmmv { 133 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 134 1.1 jmmv 135 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 136 1.1 jmmv "${h} atf_check_null_stderr" 137 1.1 jmmv grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \ 138 1.1 jmmv atf_fail "atf_check does not print an informative message" 139 1.1 jmmv grep 'stdout' stderr >/dev/null && \ 140 1.1 jmmv atf_fail "atf_check prints the stdout header" 141 1.1 jmmv grep 'stderr not empty' stderr >/dev/null || \ 142 1.1 jmmv atf_fail "atf_check does not print the stderr header" 143 1.1 jmmv grep 'These are the contents' stderr >/dev/null || \ 144 1.1 jmmv atf_fail "atf_check does not print stderr's contents" 145 1.1 jmmv } 146 1.1 jmmv 147 1.1 jmmv atf_test_case equal 148 1.1 jmmv equal_head() 149 1.1 jmmv { 150 1.1 jmmv atf_set "descr" "Verifies that atf_check_equal works" 151 1.1 jmmv } 152 1.1 jmmv equal_body() 153 1.1 jmmv { 154 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 155 1.1 jmmv 156 1.1 jmmv atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_ok" 157 1.1 jmmv 158 1.1 jmmv atf_check -s eq:1 -o ignore -e ignore -x \ 159 1.1 jmmv "${h} -r resfile atf_check_equal_fail" 160 1.1 jmmv atf_check -s eq:0 -o ignore -e empty grep '^failed: a != b (a != b)$' \ 161 1.1 jmmv resfile 162 1.1 jmmv 163 1.1 jmmv atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_eval_ok" 164 1.1 jmmv 165 1.1 jmmv atf_check -s eq:1 -o ignore -e ignore -x \ 166 1.1 jmmv "${h} -r resfile atf_check_equal_eval_fail" 167 1.1 jmmv atf_check -s eq:0 -o ignore -e empty \ 168 1.1 jmmv grep '^failed: \${x} != \${y} (a != b)$' resfile 169 1.1 jmmv } 170 1.1 jmmv 171 1.2 martin atf_test_case flush_stdout_on_timeout 172 1.2 martin flush_stdout_on_timeout_body() 173 1.2 martin { 174 1.2 martin "$(atf_get_srcdir)/misc_helpers" -s "$(atf_get_srcdir)" atf_check_timeout \ 175 1.2 martin >out 2>err & 176 1.2 martin pid="${!}" 177 1.2 martin sleep 10 178 1.2 martin kill "${pid}" 179 1.2 martin 180 1.2 martin grep 'Executing command.*true' out \ 181 1.2 martin || atf_fail 'First command not in output' 182 1.2 martin grep 'Executing command.*sleep 42' out \ 183 1.2 martin || atf_fail 'Second command not in output' 184 1.2 martin } 185 1.2 martin 186 1.1 jmmv atf_init_test_cases() 187 1.1 jmmv { 188 1.1 jmmv atf_add_test_case info_ok 189 1.1 jmmv atf_add_test_case expout_mismatch 190 1.1 jmmv atf_add_test_case experr_mismatch 191 1.1 jmmv atf_add_test_case null_stdout 192 1.1 jmmv atf_add_test_case null_stderr 193 1.1 jmmv atf_add_test_case equal 194 1.2 martin atf_add_test_case flush_stdout_on_timeout 195 1.1 jmmv } 196 1.1 jmmv 197 1.1 jmmv # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 198