Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / unit / atf-src / atf-run / integration_test.sh
blobafd013efbf06251f3d95782e06dea968aaf27eae
2 # Automated Testing Framework (atf)
4 # Copyright (c) 2007 The NetBSD Foundation, Inc.
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 create_atffile()
32 ATF_CONFDIR="$(pwd)"; export ATF_CONFDIR
34 cat >Atffile <<EOF
35 Content-Type: application/X-atf-atffile; version="1"
37 prop: test-suite = atf
39 EOF
40 for f in "${@}"; do
41 echo "tp: ${f}" >>Atffile
42 done
45 create_helper()
47 cp $(atf_get_srcdir)/misc_helpers helper
48 create_atffile helper
49 TESTCASE=${1}; export TESTCASE
52 create_helper_stdin()
54 # TODO: This really, really, really must use real test programs.
55 cat >${1} <<EOF
56 #! $(atf-config -t atf_shell)
57 while [ \${#} -gt 0 ]; do
58 case \${1} in
59 -l)
60 echo 'Content-Type: application/X-atf-tp; version="1"'
61 echo
62 EOF
63 cnt=1
64 while [ ${cnt} -le ${2} ]; do
65 echo "echo 'ident: tc${cnt}'" >>${1}
66 [ ${cnt} -lt ${2} ] && echo "echo" >>${1}
67 cnt=$((${cnt} + 1))
68 done
69 cat >>${1} <<EOF
70 exit 0
72 -r*)
73 resfile=\$(echo \${1} | cut -d r -f 2-)
75 esac
76 testcase=\$(echo \${1} | cut -d : -f 1)
77 shift
78 done
79 EOF
80 cat >>${1}
83 create_mount_helper()
85 cat >${1} <<EOF
86 #! /usr/bin/env atf-sh
88 do_mount() {
89 platform=\$(uname)
90 case \${platform} in
91 Linux|NetBSD)
92 mount -t tmpfs tmpfs \${1} || atf_fail "Mount failed"
94 FreeBSD)
95 mdmfs -s 16m md \${1} || atf_fail "Mount failed"
97 SunOS)
98 mount -F tmpfs tmpfs \$(pwd)/\${1} || atf_fail "Mount failed"
101 atf_fail "create_mount_helper called for an unsupported platform."
103 esac
106 atf_test_case main
107 main_head() {
108 atf_set "require.user" "root"
110 main_body() {
112 cat >>${1}
113 cat >>${1} <<EOF
116 atf_init_test_cases()
118 atf_add_test_case main
123 atf_test_case no_warnings
124 no_warnings_head()
126 atf_set "descr" "Tests that atf-run suppresses warnings about not running" \
127 "within atf-run"
129 no_warnings_body()
131 create_helper pass
132 atf_check -s eq:0 -o ignore -e not-match:'WARNING.*atf-run' atf-run helper
135 atf_test_case config
136 config_head()
138 atf_set "descr" "Tests that the config files are read in the correct" \
139 "order"
141 config_body()
143 create_helper config
145 mkdir etc
146 mkdir .atf
148 echo "First: read system-wide common.conf."
149 cat >etc/common.conf <<EOF
150 Content-Type: application/X-atf-config; version="1"
152 1st = "sw common"
153 2nd = "sw common"
154 3rd = "sw common"
155 4th = "sw common"
157 atf_check -s eq:0 \
158 -o match:'1st: sw common' \
159 -o match:'2nd: sw common' \
160 -o match:'3rd: sw common' \
161 -o match:'4th: sw common' \
162 -e ignore -x \
163 "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
165 echo "Second: read system-wide <test-suite>.conf."
166 cat >etc/atf.conf <<EOF
167 Content-Type: application/X-atf-config; version="1"
169 1st = "sw atf"
171 atf_check -s eq:0 \
172 -o match:'1st: sw atf' \
173 -o match:'2nd: sw common' \
174 -o match:'3rd: sw common' \
175 -o match:'4th: sw common' \
176 -e ignore -x \
177 "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
179 echo "Third: read user-specific common.conf."
180 cat >.atf/common.conf <<EOF
181 Content-Type: application/X-atf-config; version="1"
183 2nd = "us common"
185 atf_check -s eq:0 \
186 -o match:'1st: sw atf' \
187 -o match:'2nd: us common' \
188 -o match:'3rd: sw common' \
189 -o match:'4th: sw common' \
190 -e ignore -x \
191 "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
193 echo "Fourth: read user-specific <test-suite>.conf."
194 cat >.atf/atf.conf <<EOF
195 Content-Type: application/X-atf-config; version="1"
197 3rd = "us atf"
199 atf_check -s eq:0 \
200 -o match:'1st: sw atf' \
201 -o match:'2nd: us common' \
202 -o match:'3rd: us atf' \
203 -o match:'4th: sw common' \
204 -e ignore -x \
205 "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
208 atf_test_case vflag
209 vflag_head()
211 atf_set "descr" "Tests that the -v flag works and that it properly" \
212 "overrides the values in configuration files"
214 vflag_body()
216 create_helper testvar
218 echo "Checking that 'testvar' is not defined."
219 atf_check -s eq:1 -o ignore -e ignore -x \
220 "ATF_CONFDIR=$(pwd)/etc atf-run helper"
222 echo "Checking that defining 'testvar' trough '-v' works."
223 atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
224 "ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='a value' helper"
226 echo "Checking that defining 'testvar' trough the configuration" \
227 "file works."
228 mkdir etc
229 cat >etc/common.conf <<EOF
230 Content-Type: application/X-atf-config; version="1"
232 testvar = "value in conf file"
234 atf_check -s eq:0 -o match:'testvar: value in conf file' -e ignore -x \
235 "ATF_CONFDIR=$(pwd)/etc atf-run helper"
237 echo "Checking that defining 'testvar' trough -v overrides the" \
238 "configuration file."
239 atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
240 "ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='a value' helper"
243 atf_test_case atffile
244 atffile_head()
246 atf_set "descr" "Tests that the variables defined by the Atffile" \
247 "are recognized and that they take the lowest priority"
249 atffile_body()
251 create_helper testvar
253 echo "Checking that 'testvar' is not defined."
254 atf_check -s eq:1 -o ignore -e ignore -x \
255 "ATF_CONFDIR=$(pwd)/etc atf-run helper"
257 echo "Checking that defining 'testvar' trough the Atffile works."
258 echo 'conf: testvar = "a value"' >>Atffile
259 atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
260 "ATF_CONFDIR=$(pwd)/etc atf-run helper"
262 echo "Checking that defining 'testvar' trough the configuration" \
263 "file overrides the one in the Atffile."
264 mkdir etc
265 cat >etc/common.conf <<EOF
266 Content-Type: application/X-atf-config; version="1"
268 testvar = "value in conf file"
270 atf_check -s eq:0 -o match:'testvar: value in conf file' -e ignore -x \
271 "ATF_CONFDIR=$(pwd)/etc atf-run helper"
272 rm -rf etc
274 echo "Checking that defining 'testvar' trough -v overrides the" \
275 "one in the Atffile."
276 atf_check -s eq:0 -o match:'testvar: new value' -e ignore -x \
277 "ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='new value' helper"
280 atf_test_case atffile_recursive
281 atffile_recursive_head()
283 atf_set "descr" "Tests that variables defined by an Atffile are not" \
284 "inherited by other Atffiles."
286 atffile_recursive_body()
288 create_helper testvar
290 mkdir dir
291 mv Atffile helper dir
293 echo "Checking that 'testvar' is not inherited."
294 create_atffile dir
295 echo 'conf: testvar = "a value"' >> Atffile
296 atf_check -s eq:1 -o ignore -e ignore -x "ATF_CONFDIR=$(pwd)/etc atf-run"
298 echo "Checking that defining 'testvar' in the correct Atffile works."
299 echo 'conf: testvar = "a value"' >>dir/Atffile
300 atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
301 "ATF_CONFDIR=$(pwd)/etc atf-run"
304 atf_test_case fds
305 fds_head()
307 atf_set "descr" "Tests that all streams are properly captured"
309 fds_body()
311 create_helper fds
313 atf_check -s eq:0 \
314 -o match:'^tc-so:msg1 to stdout$' \
315 -o match:'^tc-so:msg2 to stdout$' \
316 -o match:'^tc-se:msg1 to stderr$' \
317 -o match:'^tc-se:msg2 to stderr$' \
318 -e empty atf-run
321 atf_test_case mux_streams
322 mux_streams_head()
324 atf_set "descr" "Tests for a race condition in stream multiplexing"
326 mux_streams_body()
328 create_helper mux_streams
330 for i in 1 2 3 4 5; do
331 echo "Attempt ${i}"
332 atf_check -s eq:0 -o match:'stdout 9999' -o match:'stderr 9999' atf-run
333 done
336 atf_test_case expect
337 expect_head()
339 atf_set "descr" "Tests the processing of test case results and the" \
340 "expect features"
342 expect_body()
344 ln -s "$(atf_get_srcdir)/expect_helpers" .
345 create_atffile expect_helpers
347 atf_check -s eq:1 \
348 -o match:'death_and_exit, expected_death' \
349 -o match:'death_and_signal, expected_death' \
350 -o match:'death_but_pass, failed' \
351 -o match:'exit_any_and_exit, expected_exit' \
352 -o match:'exit_but_pass, failed' \
353 -o match:'exit_code_and_exit, expected_exit' \
354 -o match:'fail_and_fail_check, expected_failure' \
355 -o match:'fail_and_fail_requirement, expected_failure' \
356 -o match:'fail_but_pass, failed' \
357 -o match:'pass_and_pass, passed' \
358 -o match:'pass_but_fail_check, failed' \
359 -o match:'pass_but_fail_requirement, failed' \
360 -o match:'signal_any_and_signal, expected_signal' \
361 -o match:'signal_but_pass, failed' \
362 -o match:'signal_no_and_signal, expected_signal' \
363 -o match:'timeout_and_hang, expected_timeout' \
364 -o match:'timeout_but_pass, failed' \
365 -e empty atf-run
368 atf_test_case missing_results
369 missing_results_head()
371 atf_set "descr" "Ensures that atf-run correctly handles test cases that " \
372 "do not create the results file"
374 missing_results_body()
376 create_helper_stdin helper 1 <<EOF
377 test -f \${resfile} && echo "resfile found"
378 exit 0
380 chmod +x helper
382 create_atffile helper
384 re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
385 atf_check -s eq:1 \
386 -o match:"${re} failed,.*failed to create" \
387 -o not-match:'resfile found' \
388 -e empty atf-run
391 atf_test_case broken_results
392 broken_results_head()
394 atf_set "descr" "Ensures that atf-run reports test programs that" \
395 "provide a bogus results output as broken programs"
397 broken_results_body()
399 # We produce two errors from the header to ensure that the parse
400 # errors are printed on a single line on the output file. Printing
401 # them on separate lines would be incorrect.
402 create_helper_stdin helper 1 <<EOF
403 echo 'line 1' >\${resfile}
404 echo 'line 2' >>\${resfile}
405 exit 0
407 chmod +x helper
409 create_atffile helper
411 re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
412 atf_check -s eq:1 -o match:"${re} .*line 1.*line 2" -e empty atf-run
415 atf_test_case broken_tp_list
416 broken_tp_list_head()
418 atf_set "descr" "Ensures that atf-run reports test programs that" \
419 "provide a bogus test case list"
421 broken_tp_list_body()
423 cat >helper <<EOF
424 #! $(atf-config -t atf_shell)
425 while [ \${#} -gt 0 ]; do
426 if [ \${1} = -l ]; then
427 echo 'Content-Type: application/X-atf-tp; version="1"'
428 echo
429 echo 'foo: bar'
430 exit 0
431 else
432 shift
434 done
435 exit 0
437 chmod +x helper
439 create_atffile helper
441 re='^tp-end: [0-9][0-9]*\.[0-9]*, helper,'
442 re="${re} Invalid format for test case list:.*First property.*ident"
443 atf_check -s eq:1 -o match:"${re}" -e empty atf-run
446 atf_test_case zero_tcs
447 zero_tcs_head()
449 atf_set "descr" "Ensures that atf-run reports test programs without" \
450 "test cases as errors"
452 zero_tcs_body()
454 create_helper_stdin helper 0 <<EOF
455 echo 'Content-Type: application/X-atf-tp; version="1"'
456 echo
457 exit 1
459 chmod +x helper
461 create_atffile helper
463 re='^tp-end: [0-9][0-9]*\.[0-9]*, helper,'
464 atf_check -s eq:1 \
465 -o match:"${re} .*Invalid format for test case list" \
466 -e empty atf-run
469 atf_test_case exit_codes
470 exit_codes_head()
472 atf_set "descr" "Ensures that atf-run reports bogus exit codes for" \
473 "programs correctly"
475 exit_codes_body()
477 create_helper_stdin helper 1 <<EOF
478 echo "failed: Yes, it failed" >\${resfile}
479 exit 0
481 chmod +x helper
483 create_atffile helper
485 re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
486 atf_check -s eq:1 \
487 -o match:"${re} .*exited successfully.*reported failure" \
488 -e empty atf-run
491 atf_test_case signaled
492 signaled_head()
494 atf_set "descr" "Ensures that atf-run reports test program's crashes" \
495 "correctly regardless of their actual results"
497 signaled_body()
499 create_helper_stdin helper 2 <<EOF
500 echo "passed" >\${resfile}
501 case \${testcase} in
502 tc1) ;;
503 tc2) echo "Killing myself!" ; kill -9 \$\$ ;;
504 esac
506 chmod +x helper
508 create_atffile helper
510 re='^tc-end: [0-9][0-9]*\.[0-9]*, tc2,'
511 atf_check -s eq:1 -o match:"${re} .*received signal 9" \
512 -e empty atf-run
515 atf_test_case hooks
516 hooks_head()
518 atf_set "descr" "Checks that the default hooks work and that they" \
519 "can be overriden by the user"
521 hooks_body()
523 cp $(atf_get_srcdir)/pass_helper helper
524 create_atffile helper
526 mkdir atf
527 mkdir .atf
529 echo "Checking default hooks"
530 atf_check -s eq:0 -o match:'^info: time.start, ' \
531 -o match:'^info: time.end, ' -e empty -x \
532 "ATF_CONFDIR=$(pwd)/atf atf-run"
534 echo "Checking the system-wide info_start hook"
535 cat >atf/atf-run.hooks <<EOF
536 info_start_hook()
538 atf_tps_writer_info "test" "sw value"
541 atf_check -s eq:0 \
542 -o match:'^info: test, sw value' \
543 -o not-match:'^info: time.start, ' \
544 -o match:'^info: time.end, ' \
545 -e empty -x \
546 "ATF_CONFDIR=$(pwd)/atf atf-run"
548 echo "Checking the user-specific info_start hook"
549 cat >.atf/atf-run.hooks <<EOF
550 info_start_hook()
552 atf_tps_writer_info "test" "user value"
555 atf_check -s eq:0 \
556 -o match:'^info: test, user value' \
557 -o not-match:'^info: time.start, ' \
558 -o match:'^info: time.end, ' \
559 -e empty -x \
560 "ATF_CONFDIR=$(pwd)/atf atf-run"
562 rm atf/atf-run.hooks
563 rm .atf/atf-run.hooks
565 echo "Checking the system-wide info_end hook"
566 cat >atf/atf-run.hooks <<EOF
567 info_end_hook()
569 atf_tps_writer_info "test" "sw value"
572 atf_check -s eq:0 \
573 -o match:'^info: time.start, ' \
574 -o not-match:'^info: time.end, ' \
575 -o match:'^info: test, sw value' \
576 -e empty -x \
577 "ATF_CONFDIR=$(pwd)/atf atf-run"
579 echo "Checking the user-specific info_end hook"
580 cat >.atf/atf-run.hooks <<EOF
581 info_end_hook()
583 atf_tps_writer_info "test" "user value"
586 atf_check -s eq:0 \
587 -o match:'^info: time.start, ' \
588 -o not-match:'^info: time.end, ' \
589 -o match:'^info: test, user value' \
590 -e empty -x \
591 "ATF_CONFDIR=$(pwd)/atf atf-run"
594 atf_test_case isolation_env
595 isolation_env_head()
597 atf_set "descr" "Tests that atf-run sets a set of environment variables" \
598 "to known sane values"
600 isolation_env_body()
602 undef_vars="LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY \
603 LC_NUMERIC LC_TIME"
604 def_vars="HOME TZ"
606 mangleenv="env"
607 for v in ${undef_vars} ${def_vars}; do
608 mangleenv="${mangleenv} ${v}=bogus-value"
609 done
611 create_helper env_list
612 create_atffile helper
614 # We must ignore stderr in this call (instead of specifying -e empty)
615 # because, when atf-run invokes the shell to run the hooks, we may get
616 # error messages about an invalid locale. This happens, at least, when
617 # the shell is bash 4.x.
618 atf_check -s eq:0 -o save:stdout -e ignore ${mangleenv} atf-run helper
620 for v in ${undef_vars}; do
621 atf_check -s eq:1 -o empty -e empty grep "^tc-so:${v}=" stdout
622 done
624 for v in ${def_vars}; do
625 atf_check -s eq:0 -o ignore -e empty grep "^tc-so:${v}=" stdout
626 done
628 atf_check -s eq:0 -o ignore -e empty grep "^tc-so:TZ=UTC" stdout
631 atf_test_case isolation_home
632 isolation_home_head()
634 atf_set "descr" "Tests that atf-run sets HOME to a sane and valid value"
636 isolation_home_body()
638 create_helper env_home
639 create_atffile helper
640 atf_check -s eq:0 -o ignore -e ignore env HOME=foo atf-run helper
643 atf_test_case isolation_stdin
644 isolation_stdin_head()
646 atf_set "descr" "Tests that atf-run nullifies the stdin of test cases"
648 isolation_stdin_body()
650 create_helper read_stdin
651 create_atffile helper
652 atf_check -s eq:0 -o ignore -e ignore -x 'echo hello world | atf-run helper'
655 atf_test_case isolation_umask
656 isolation_umask_head()
658 atf_set "descr" "Tests that atf-run sets the umask to a known value"
660 isolation_umask_body()
662 create_helper umask
663 create_atffile helper
665 atf_check -s eq:0 -o match:'umask: 0022' -e ignore -x \
666 "umask 0000 && atf-run helper"
669 atf_test_case cleanup_pass
670 cleanup_pass_head()
672 atf_set "descr" "Tests that atf-run calls the cleanup routine of the test" \
673 "case when the test case result is passed"
675 cleanup_pass_body()
677 create_helper cleanup_states
678 create_atffile helper
680 atf_check -s eq:0 -o match:'cleanup_states, passed' -e ignore atf-run \
681 -v state=pass -v statedir=$(pwd) helper
682 test -f to-stay || atf_fail "Test case body did not run correctly"
683 if [ -f to-delete ]; then
684 atf_fail "Test case cleanup did not run correctly"
688 atf_test_case cleanup_fail
689 cleanup_fail_head()
691 atf_set "descr" "Tests that atf-run calls the cleanup routine of the test" \
692 "case when the test case result is failed"
694 cleanup_fail_body()
696 create_helper cleanup_states
697 create_atffile helper
699 atf_check -s eq:1 -o match:'cleanup_states, failed' -e ignore atf-run \
700 -v state=fail -v statedir=$(pwd) helper
701 test -f to-stay || atf_fail "Test case body did not run correctly"
702 if [ -f to-delete ]; then
703 atf_fail "Test case cleanup did not run correctly"
707 atf_test_case cleanup_skip
708 cleanup_skip_head()
710 atf_set "descr" "Tests that atf-run calls the cleanup routine of the test" \
711 "case when the test case result is skipped"
713 cleanup_skip_body()
715 create_helper cleanup_states
716 create_atffile helper
718 atf_check -s eq:0 -o match:'cleanup_states, skipped' -e ignore atf-run \
719 -v state=skip -v statedir=$(pwd) helper
720 test -f to-stay || atf_fail "Test case body did not run correctly"
721 if [ -f to-delete ]; then
722 atf_fail "Test case cleanup did not run correctly"
726 atf_test_case cleanup_curdir
727 cleanup_curdir_head()
729 atf_set "descr" "Tests that atf-run calls the cleanup routine in the same" \
730 "work directory as the body so that they can share data"
732 cleanup_curdir_body()
734 create_helper cleanup_curdir
735 create_atffile helper
737 atf_check -s eq:0 -o match:'cleanup_curdir, passed' \
738 -o match:'Old value: 1234' -e ignore atf-run helper
741 atf_test_case cleanup_signal
742 cleanup_signal_head()
744 atf_set "descr" "Tests that atf-run calls the cleanup routine if it gets" \
745 "a termination signal while running the body"
747 cleanup_signal_body()
749 : # TODO: Write this.
752 atf_test_case cleanup_mount
753 cleanup_mount_head()
755 atf_set "descr" "Tests that the removal algorithm does not cross" \
756 "mount points"
757 atf_set "require.user" "root"
759 cleanup_mount_body()
761 ROOT="$(pwd)/root"; export ROOT
763 create_mount_helper helper <<EOF
764 echo \$(pwd) >\${ROOT}
765 mkdir foo
766 mkdir foo/bar
767 mkdir foo/bar/mnt
768 do_mount foo/bar/mnt
769 mkdir foo/baz
770 do_mount foo/baz
771 mkdir foo/baz/foo
772 mkdir foo/baz/foo/bar
773 do_mount foo/baz/foo/bar
775 create_atffile helper
776 chmod +x helper
778 platform=$(uname)
779 case ${platform} in
780 Linux|FreeBSD|NetBSD|SunOS)
783 # XXX Possibly specify in meta-data too.
784 atf_skip "Test unimplemented in this platform (${platform})"
786 esac
788 atf_check -s eq:0 -o match:"main, passed" -e ignore atf-run helper
789 mount | grep $(cat root) && atf_fail "Some file systems remain mounted"
790 atf_check -s eq:1 -o empty -e empty test -d $(cat root)/foo
793 atf_test_case cleanup_symlink
794 cleanup_symlink_head()
796 atf_set "descr" "Tests that the removal algorithm does not follow" \
797 "symlinks, which may live in another device and thus" \
798 "be treated as mount points"
799 atf_set "require.user" "root"
801 cleanup_symlink_body()
803 ROOT="$(pwd)/root"; export ROOT
805 create_mount_helper helper <<EOF
806 echo \$(pwd) >\${ROOT}
807 atf_check -s eq:0 -o empty -e empty mkdir foo
808 atf_check -s eq:0 -o empty -e empty mkdir foo/bar
809 do_mount foo/bar
810 atf_check -s eq:0 -o empty -e empty touch a
811 atf_check -s eq:0 -o empty -e empty ln -s "\$(pwd)/a" foo/bar
813 create_atffile helper
814 chmod +x helper
816 platform=$(uname)
817 case ${platform} in
818 Linux|FreeBSD|NetBSD|SunOS)
821 # XXX Possibly specify in meta-data too.
822 atf_skip "Test unimplemented in this platform (${platform})"
824 esac
826 atf_check -s eq:0 -o match:"main, passed" -e ignore atf-run helper
827 mount | grep $(cat root) && atf_fail "Some file systems remain mounted"
828 atf_check -s eq:1 -o empty -e empty test -d $(cat root)/foo
831 atf_test_case require_arch
832 require_arch_head()
834 atf_set "descr" "Tests that atf-run validates the require.arch property"
836 require_arch_body()
838 create_helper require_arch
839 create_atffile helper
841 echo "Checking for the real architecture"
842 arch=$(atf-config -t atf_arch)
843 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
844 -v arch="${arch}" helper
845 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
846 -v arch="foo ${arch}" helper
847 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
848 -v arch="${arch} foo" helper
850 echo "Checking for a fictitious architecture"
851 arch=fictitious
852 export ATF_ARCH=fictitious
853 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
854 -v arch="${arch}" helper
855 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
856 -v arch="foo ${arch}" helper
857 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
858 -v arch="${arch} foo" helper
860 echo "Triggering some failures"
861 atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*foo.*architecture" \
862 -e ignore atf-run -v arch="foo" helper
863 atf_check -s eq:0 \
864 -o match:"${TESTCASE}, skipped, .*foo bar.*architectures" -e ignore \
865 atf-run -v arch="foo bar" helper
866 atf_check -s eq:0 \
867 -o match:"${TESTCASE}, skipped, .*fictitiousxxx.*architecture" \
868 -e ignore atf-run -v arch="${arch}xxx" helper
871 atf_test_case require_config
872 require_config_head()
874 atf_set "descr" "Tests that atf-run validates the require.config property"
876 require_config_body()
878 create_helper require_config
879 create_atffile helper
881 atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*var1.*not defined" \
882 -e ignore atf-run helper
883 atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*var2.*not defined" \
884 -e ignore atf-run -v var1=foo helper
885 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
886 -v var1=a -v var2=' ' helper
889 atf_test_case require_files
890 require_files_head()
892 atf_set "descr" "Tests that atf-run validates the require.files property"
894 require_files_body()
896 create_helper require_files
897 create_atffile helper
899 touch i-exist
901 echo "Checking absolute paths"
902 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
903 -v files='/bin/cp' helper
904 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
905 -v files="$(pwd)/i-exist" helper
906 atf_check -s eq:0 \
907 -o match:"${TESTCASE}, skipped, .*/dont-exist" \
908 -e ignore atf-run -v files="$(pwd)/i-exist $(pwd)/dont-exist" helper
910 echo "Checking that relative paths are not allowed"
911 atf_check -s eq:1 \
912 -o match:"${TESTCASE}, failed, Relative paths.*not allowed.*hello" \
913 -e ignore atf-run -v files='hello' helper
914 atf_check -s eq:1 \
915 -o match:"${TESTCASE}, failed, Relative paths.*not allowed.*a/b" \
916 -e ignore atf-run -v files='a/b' helper
919 atf_test_case require_machine
920 require_machine_head()
922 atf_set "descr" "Tests that atf-run validates the require.machine property"
924 require_machine_body()
926 create_helper require_machine
927 create_atffile helper
929 echo "Checking for the real machine type"
930 machine=$(atf-config -t atf_machine)
931 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
932 -v machine="${machine}" helper
933 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
934 -v machine="foo ${machine}" helper
935 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
936 -v machine="${machine} foo" helper
938 echo "Checking for a fictitious machine type"
939 machine=fictitious
940 export ATF_MACHINE=fictitious
941 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
942 -v machine="${machine}" helper
943 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
944 -v machine="foo ${machine}" helper
945 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
946 -v machine="${machine} foo" helper
948 echo "Triggering some failures"
949 atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*foo.*machine type" \
950 -e ignore atf-run -v machine="foo" helper
951 atf_check -s eq:0 \
952 -o match:"${TESTCASE}, skipped, .*foo bar.*machine types" -e ignore \
953 atf-run -v machine="foo bar" helper
954 atf_check -s eq:0 \
955 -o match:"${TESTCASE}, skipped, .*fictitiousxxx.*machine type" \
956 -e ignore atf-run -v machine="${machine}xxx" helper
959 atf_test_case require_progs
960 require_progs_head()
962 atf_set "descr" "Tests that atf-run validates the require.progs property"
964 require_progs_body()
966 create_helper require_progs
967 create_atffile helper
969 echo "Checking absolute paths"
970 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
971 -v progs='/bin/cp' helper
972 atf_check -s eq:0 \
973 -o match:"${TESTCASE}, skipped, .*/bin/__non-existent__.*PATH" \
974 -e ignore atf-run -v progs='/bin/__non-existent__' helper
976 echo "Checking that relative paths are not allowed"
977 atf_check -s eq:1 \
978 -o match:"${TESTCASE}, failed, Relative paths.*not allowed.*bin/cp" \
979 -e ignore atf-run -v progs='bin/cp' helper
981 echo "Check plain file names, searching them in the PATH."
982 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
983 -v progs='cp' helper
984 atf_check -s eq:0 \
985 -o match:"${TESTCASE}, skipped, .*__non-existent__.*PATH" -e ignore \
986 atf-run -v progs='__non-existent__' helper
989 atf_test_case require_user_root
990 require_user_root_head()
992 atf_set "descr" "Tests that atf-run validates the require.user property" \
993 "when it is set to 'root'"
995 require_user_root_body()
997 create_helper require_user
998 create_atffile helper
1000 if [ $(id -u) -eq 0 ]; then
1001 exp=passed
1002 else
1003 exp=skipped
1005 atf_check -s eq:0 -o match:"${TESTCASE}, ${exp}" -e ignore atf-run \
1006 -v user=root helper
1009 atf_test_case require_user_unprivileged
1010 require_user_unprivileged_head()
1012 atf_set "descr" "Tests that atf-run validates the require.user property" \
1013 "when it is set to 'root'"
1015 require_user_unprivileged_body()
1017 create_helper require_user
1018 create_atffile helper
1020 if [ $(id -u) -eq 0 ]; then
1021 exp=skipped
1022 else
1023 exp=passed
1025 atf_check -s eq:0 -o match:"${TESTCASE}, ${exp}" -e ignore atf-run \
1026 -v user=unprivileged helper
1029 atf_test_case require_user_bad
1030 require_user_bad_head()
1032 atf_set "descr" "Tests that atf-run validates the require.user property" \
1033 "when it is set to 'root'"
1035 require_user_bad_body()
1037 create_helper require_user
1038 create_atffile helper
1040 atf_check -s eq:1 -o match:"${TESTCASE}, failed, Invalid value.*foobar" \
1041 -e ignore atf-run -v user=foobar helper
1044 atf_test_case timeout
1045 timeout_head()
1047 atf_set "descr" "Tests that atf-run kills a test case that times out"
1049 timeout_body()
1051 create_helper timeout
1052 create_atffile helper
1054 atf_check -s eq:1 \
1055 -o match:"${TESTCASE}, failed, .*timed out after 1 second" -e ignore \
1056 atf-run -v statedir=$(pwd) helper
1057 if [ -f finished ]; then
1058 atf_fail "Test case was not killed after time out"
1062 atf_test_case timeout_forkexit
1063 timeout_forkexit_head()
1065 atf_set "descr" "Tests that atf-run deals gracefully with a test program" \
1066 "that forks, exits, but the child process hangs"
1068 timeout_forkexit_body()
1070 create_helper timeout_forkexit
1071 create_atffile helper
1073 atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
1074 -v statedir=$(pwd) helper
1075 test -f parent-finished || atf_fail "Parent did not exit as expected"
1076 test -f child-finished && atf_fail "Subprocess exited but it should have" \
1077 "been forcibly terminated" || true
1080 atf_test_case ignore_deprecated_use_fs
1081 ignore_deprecated_use_fs_head()
1083 atf_set "descr" "Tests that atf-run ignores the deprecated use.fs property"
1085 ignore_deprecated_use_fs_body()
1087 create_helper use_fs
1088 create_atffile helper
1090 atf_check -s eq:0 -o ignore -e ignore atf-run helper
1093 atf_init_test_cases()
1095 atf_add_test_case no_warnings
1096 atf_add_test_case config
1097 atf_add_test_case vflag
1098 atf_add_test_case atffile
1099 atf_add_test_case atffile_recursive
1100 atf_add_test_case expect
1101 atf_add_test_case fds
1102 atf_add_test_case mux_streams
1103 atf_add_test_case missing_results
1104 atf_add_test_case broken_results
1105 atf_add_test_case broken_tp_list
1106 atf_add_test_case zero_tcs
1107 atf_add_test_case exit_codes
1108 atf_add_test_case signaled
1109 atf_add_test_case hooks
1110 atf_add_test_case isolation_env
1111 atf_add_test_case isolation_home
1112 atf_add_test_case isolation_stdin
1113 atf_add_test_case isolation_umask
1114 atf_add_test_case cleanup_pass
1115 atf_add_test_case cleanup_fail
1116 atf_add_test_case cleanup_skip
1117 atf_add_test_case cleanup_curdir
1118 atf_add_test_case cleanup_signal
1119 atf_add_test_case cleanup_mount
1120 atf_add_test_case cleanup_symlink
1121 atf_add_test_case require_arch
1122 atf_add_test_case require_config
1123 atf_add_test_case require_files
1124 atf_add_test_case require_machine
1125 atf_add_test_case require_progs
1126 atf_add_test_case require_user_root
1127 atf_add_test_case require_user_unprivileged
1128 atf_add_test_case require_user_bad
1129 atf_add_test_case timeout
1130 atf_add_test_case timeout_forkexit
1131 atf_add_test_case ignore_deprecated_use_fs
1134 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4