1 1.1 jmmv #! __ATF_SH__ 2 1.1 jmmv # Copyright 2012 Google Inc. 3 1.1 jmmv # All rights reserved. 4 1.1 jmmv # 5 1.1 jmmv # Redistribution and use in source and binary forms, with or without 6 1.1 jmmv # modification, are permitted provided that the following conditions are 7 1.1 jmmv # met: 8 1.1 jmmv # 9 1.1 jmmv # * Redistributions of source code must retain the above copyright 10 1.1 jmmv # notice, this list of conditions and the following disclaimer. 11 1.1 jmmv # * Redistributions in binary form must reproduce the above copyright 12 1.1 jmmv # notice, this list of conditions and the following disclaimer in the 13 1.1 jmmv # documentation and/or other materials provided with the distribution. 14 1.1 jmmv # * Neither the name of Google Inc. nor the names of its contributors 15 1.1 jmmv # may be used to endorse or promote products derived from this software 16 1.1 jmmv # without specific prior written permission. 17 1.1 jmmv # 18 1.1 jmmv # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 1.1 jmmv # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 1.1 jmmv # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 1.1 jmmv # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 1.1 jmmv # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 1.1 jmmv # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 1.1 jmmv # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 1.1 jmmv # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 1.1 jmmv # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 1.1 jmmv # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 1.1 jmmv # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 1.1 jmmv 30 1.1 jmmv 31 1.1 jmmv . "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/tests_lib.subr" 32 1.1 jmmv 33 1.1 jmmv 34 1.1 jmmv atf_test_case all_pass 35 1.1 jmmv all_pass_body() { 36 1.1 jmmv create_test_program program1 pass skip 37 1.1 jmmv create_atffile Atffile 'prop: test-suite = "suite"' \ 38 1.1 jmmv 'tp: program1' 'tp: subdir' 39 1.1 jmmv 40 1.1 jmmv mkdir subdir 41 1.1 jmmv create_test_program subdir/program2 skip 42 1.1 jmmv create_atffile subdir/Atffile 'prop: test-suite = "suite"' \ 43 1.1 jmmv 'tp: program2' 44 1.1 jmmv 45 1.1 jmmv atf_check -s exit:0 -e ignore \ 46 1.1 jmmv -o match:'program1:pass -> passed' \ 47 1.1 jmmv -o match:'program1:skip -> skipped' \ 48 1.1 jmmv -o match:'subdir/program2:skip -> skipped' \ 49 1.1 jmmv -o match:'Committed action 1' \ 50 1.1 jmmv atf-run 51 1.1 jmmv } 52 1.1 jmmv 53 1.1 jmmv 54 1.1 jmmv atf_test_case some_fail 55 1.1 jmmv some_fail_body() { 56 1.1 jmmv create_test_program program1 pass skip 57 1.1 jmmv create_atffile Atffile 'prop: test-suite = "suite"' \ 58 1.1 jmmv 'tp: program1' 'tp: subdir' 59 1.1 jmmv 60 1.1 jmmv mkdir subdir 61 1.1 jmmv create_atffile subdir/Atffile 'tp-glob: *' 62 1.1 jmmv 63 1.1 jmmv mkdir subdir/nested 64 1.1 jmmv create_test_program subdir/nested/program2 skip fail 65 1.1 jmmv create_atffile subdir/nested/Atffile 'prop: test-suite = "suite"' \ 66 1.1 jmmv 'tp-glob: program2*' 67 1.1 jmmv 68 1.1 jmmv atf_check -s exit:1 -e ignore \ 69 1.1 jmmv -o match:'program1:pass -> passed' \ 70 1.1 jmmv -o match:'program1:skip -> skipped' \ 71 1.1 jmmv -o match:'subdir/nested/program2:fail -> failed' \ 72 1.1 jmmv -o match:'subdir/nested/program2:skip -> skipped' \ 73 1.1 jmmv -o match:'Committed action 1' \ 74 1.1 jmmv atf-run 75 1.1 jmmv } 76 1.1 jmmv 77 1.1 jmmv atf_test_case prefer_kyuafiles 78 1.1 jmmv prefer_kyuafiles_body() { 79 1.1 jmmv create_test_program program1 pass skip 80 1.1 jmmv cat >Kyuafile <<EOF 81 1.1 jmmv syntax('kyuafile', 1) 82 1.1 jmmv test_suite('foo') 83 1.1 jmmv atf_test_program{name='program1'} 84 1.1 jmmv EOF 85 1.1 jmmv echo "This file is invalid" >Atffile 86 1.1 jmmv 87 1.1 jmmv atf_check -s exit:0 -e ignore \ 88 1.1 jmmv -o match:'program1:pass -> passed' \ 89 1.1 jmmv -o match:'program1:skip -> skipped' \ 90 1.1 jmmv atf-run 91 1.1 jmmv } 92 1.1 jmmv 93 1.1 jmmv 94 1.1 jmmv atf_test_case selectors 95 1.1 jmmv selectors_body() { 96 1.1 jmmv create_test_program program1 pass skip 97 1.1 jmmv create_atffile Atffile 'prop: test-suite = "suite"' \ 98 1.1 jmmv 'tp: program1' 'tp: subdir' 99 1.1 jmmv 100 1.1 jmmv mkdir subdir 101 1.1 jmmv create_atffile subdir/Atffile 'tp-glob: *' 102 1.1 jmmv 103 1.1 jmmv mkdir subdir/nested 104 1.1 jmmv create_test_program subdir/nested/program2 skip fail 105 1.1 jmmv create_atffile subdir/nested/Atffile 'prop: test-suite = "suite"' \ 106 1.1 jmmv 'tp-glob: program2*' 107 1.1 jmmv 108 1.1 jmmv atf_check -s exit:1 -e ignore \ 109 1.1 jmmv -o match:'program1:pass -> passed' \ 110 1.1 jmmv -o match:'program1:skip -> skipped' \ 111 1.1 jmmv -o match:'subdir/nested/program2:fail -> failed' \ 112 1.1 jmmv -o match:'subdir/nested/program2:skip -> skipped' \ 113 1.1 jmmv -o match:'Committed action 1' \ 114 1.1 jmmv atf-run 115 1.1 jmmv 116 1.1 jmmv atf_check -s exit:0 -e ignore \ 117 1.1 jmmv -o match:'program1:pass -> passed' \ 118 1.1 jmmv -o not-match:'program1:skip -> skipped' \ 119 1.1 jmmv -o not-match:'subdir/nested/program2:fail -> failed' \ 120 1.1 jmmv -o match:'subdir/nested/program2:skip -> skipped' \ 121 1.1 jmmv -o match:'Committed action 2' \ 122 1.1 jmmv atf-run program1:pass subdir/nested/program2:skip 123 1.1 jmmv 124 1.1 jmmv atf_check -s exit:1 -e ignore \ 125 1.1 jmmv -o not-match:'program1:pass -> passed' \ 126 1.1 jmmv -o not-match:'program1:skip -> skipped' \ 127 1.1 jmmv -o match:'subdir/nested/program2:fail -> failed' \ 128 1.1 jmmv -o match:'subdir/nested/program2:skip -> skipped' \ 129 1.1 jmmv -o match:'Committed action 3' \ 130 1.1 jmmv atf-run subdir/nested/program2 131 1.1 jmmv } 132 1.1 jmmv 133 1.1 jmmv 134 1.1 jmmv atf_test_case config__priorities 135 1.1 jmmv config__priorities_body() 136 1.1 jmmv { 137 1.1 jmmv mkdir system 138 1.1 jmmv export ATF_CONFDIR="$(pwd)/system" 139 1.1 jmmv mkdir user 140 1.1 jmmv mkdir user/.atf 141 1.1 jmmv export HOME="$(pwd)/user" 142 1.1 jmmv 143 1.1 jmmv create_test_program helper config 144 1.1 jmmv create_atffile Atffile 'prop: test-suite = "irrelevant"' 'tp: helper' 145 1.1 jmmv 146 1.1 jmmv echo "Checking system-wide configuration only" 147 1.2 jmmv create_config system/common.conf ' unprivileged-user = "nobody"' 148 1.1 jmmv atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run 149 1.1 jmmv atf_check -s exit:0 -o 'inline:unprivileged-user = nobody\n' \ 150 1.1 jmmv cat config.out 151 1.1 jmmv 152 1.1 jmmv echo "Checking user-specific overrides" 153 1.2 jmmv create_config user/.atf/common.conf ' unprivileged-user = "root"' 154 1.1 jmmv atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run 155 1.1 jmmv atf_check -s exit:0 -o 'inline:unprivileged-user = root\n' \ 156 1.1 jmmv cat config.out 157 1.1 jmmv 158 1.1 jmmv echo "Checking command-line overrides" 159 1.1 jmmv atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run \ 160 1.1 jmmv -v"unprivileged-user=$(id -u -n)" 161 1.1 jmmv atf_check -s exit:0 -o "inline:unprivileged-user = $(id -u -n)\n" \ 162 1.1 jmmv cat config.out 163 1.1 jmmv } 164 1.1 jmmv 165 1.1 jmmv 166 1.1 jmmv atf_test_case config__test_suites__files 167 1.1 jmmv config__test_suites__files_body() 168 1.1 jmmv { 169 1.1 jmmv mkdir system 170 1.1 jmmv export ATF_CONFDIR="$(pwd)/system" 171 1.1 jmmv 172 1.1 jmmv create_config system/suite1.conf 'var1 = "var1-for-suite1"' \ 173 1.1 jmmv 'var2 = "var2-for-suite1"' 174 1.1 jmmv create_config system/suite2.conf 'var1 = "var1-for-suite2"' \ 175 1.1 jmmv 'var2 = "var2-for-suite2"' 176 1.1 jmmv 177 1.1 jmmv create_test_program helper1 config 178 1.1 jmmv create_atffile Atffile 'prop: test-suite = "suite1"' 'tp: helper1' \ 179 1.1 jmmv 'tp: subdir' 180 1.1 jmmv mkdir subdir 181 1.1 jmmv create_test_program subdir/helper2 config 182 1.1 jmmv create_atffile subdir/Atffile 'prop: test-suite = "suite2"' 'tp: helper2' 183 1.1 jmmv 184 1.1 jmmv atf_check -s exit:0 -o ignore -e ignore atf-run helper1 185 1.1 jmmv atf_check -s exit:0 -o 'match:var1 = var1-for-suite1' \ 186 1.1 jmmv -o 'match:var2 = var2-for-suite1' -o 'not-match:suite2' \ 187 1.1 jmmv cat config.out 188 1.1 jmmv 189 1.1 jmmv atf_check -s exit:0 -o ignore -e ignore atf-run subdir/helper2 190 1.1 jmmv atf_check -s exit:0 -o 'match:var1 = var1-for-suite2' \ 191 1.1 jmmv -o 'match:var2 = var2-for-suite2' -o 'not-match:suite1' \ 192 1.1 jmmv cat config.out 193 1.1 jmmv } 194 1.1 jmmv 195 1.1 jmmv 196 1.1 jmmv atf_test_case config__test_suites__vflags 197 1.1 jmmv config__test_suites__vflags_body() 198 1.1 jmmv { 199 1.1 jmmv create_test_program helper1 config 200 1.1 jmmv create_atffile Atffile 'prop: test-suite = "suite1"' 'tp: helper1' \ 201 1.1 jmmv 'tp: subdir' 202 1.1 jmmv mkdir subdir 203 1.1 jmmv create_test_program subdir/helper2 config 204 1.1 jmmv create_atffile subdir/Atffile 'prop: test-suite = "suite2"' 'tp: helper2' 205 1.1 jmmv 206 1.1 jmmv atf_check -s exit:0 -o ignore -e ignore atf-run -v var1=foo helper1 207 1.1 jmmv atf_check -s exit:0 -o 'match:var1 = foo' cat config.out 208 1.1 jmmv 209 1.1 jmmv atf_check -s exit:0 -o ignore -e ignore atf-run -v var1=bar helper1 210 1.1 jmmv atf_check -s exit:0 -o 'match:var1 = bar' cat config.out 211 1.1 jmmv } 212 1.1 jmmv 213 1.1 jmmv 214 1.1 jmmv atf_test_case unknown_option 215 1.1 jmmv unknown_option_body() { 216 1.1 jmmv atf_check -s exit:1 -o empty -e match:'E: Unknown option -Z' \ 217 1.1 jmmv atf-run -Z -A 218 1.1 jmmv } 219 1.1 jmmv 220 1.1 jmmv 221 1.1 jmmv atf_init_test_cases() { 222 1.1 jmmv atf_add_test_case all_pass 223 1.1 jmmv atf_add_test_case some_fail 224 1.1 jmmv atf_add_test_case selectors 225 1.1 jmmv 226 1.1 jmmv atf_add_test_case prefer_kyuafiles 227 1.1 jmmv 228 1.1 jmmv atf_add_test_case config__priorities 229 1.1 jmmv atf_add_test_case config__test_suites__files 230 1.1 jmmv atf_add_test_case config__test_suites__vflags 231 1.1 jmmv 232 1.1 jmmv atf_add_test_case unknown_option 233 1.1 jmmv } 234