# Copyright 2011 The Kyua Authors. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of Google Inc. nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. utils_test_case one_test_program__all_pass one_test_program__all_pass_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < passed [S.UUUs] simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 0 failed, 1 skipped) EOF utils_cp_helper simple_all_pass . atf_check -s exit:0 -o file:expout -e empty kyua test } utils_test_case one_test_program__some_fail one_test_program__some_fail_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < failed: This fails on purpose [S.UUUs] simple_some_fail:pass -> passed [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 1 failed, 0 skipped) EOF utils_cp_helper simple_some_fail . atf_check -s exit:1 -o file:expout -e empty kyua test } utils_test_case many_test_programs__all_pass many_test_programs__all_pass_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < passed [S.UUUs] first:skip -> skipped: The reason for skipping is this [S.UUUs] fourth:main -> skipped: Required file '/non-existent/foo' not found [S.UUUs] second:pass -> passed [S.UUUs] second:skip -> skipped: The reason for skipping is this [S.UUUs] third:pass -> passed [S.UUUs] third:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 3/7 passed (0 broken, 0 failed, 4 skipped) EOF utils_cp_helper simple_all_pass first utils_cp_helper simple_all_pass second utils_cp_helper simple_all_pass third echo "not executed" >fourth; chmod +x fourth atf_check -s exit:0 -o file:expout -e empty kyua test } utils_test_case many_test_programs__some_fail many_test_programs__some_fail_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < failed: This fails on purpose [S.UUUs] first:pass -> passed [S.UUUs] fourth:main -> failed: Returned non-success exit status 76 [S.UUUs] second:fail -> failed: This fails on purpose [S.UUUs] second:pass -> passed [S.UUUs] third:pass -> passed [S.UUUs] third:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 3/7 passed (0 broken, 3 failed, 1 skipped) EOF utils_cp_helper simple_some_fail first utils_cp_helper simple_some_fail second utils_cp_helper simple_all_pass third echo '#! /bin/sh' >fourth echo 'exit 76' >>fourth chmod +x fourth atf_check -s exit:1 -o file:expout -e empty kyua test } utils_test_case expect__all_pass expect__all_pass_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < expected_failure: This is the reason for death [S.UUUs] expect_all_pass:exit -> expected_failure: Exiting with correct code [S.UUUs] expect_all_pass:failure -> expected_failure: Oh no: Forced failure [S.UUUs] expect_all_pass:signal -> expected_failure: Exiting with correct signal [S.UUUs] expect_all_pass:timeout -> expected_failure: This times out [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 5/5 passed (0 broken, 0 failed, 0 skipped) EOF # CHECK_STYLE_ENABLE utils_cp_helper expect_all_pass . atf_check -s exit:0 -o file:expout -e empty kyua test } utils_test_case expect__some_fail expect__some_fail_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < failed: Test case was expected to terminate abruptly but it continued execution [S.UUUs] expect_some_fail:exit -> failed: Test case expected to exit with code 12 but got code 34 [S.UUUs] expect_some_fail:failure -> failed: Test case was expecting a failure but none were raised [S.UUUs] expect_some_fail:pass -> passed [S.UUUs] expect_some_fail:signal -> failed: Test case expected to receive signal 15 but got 9 [S.UUUs] expect_some_fail:timeout -> failed: Test case was expected to hang but it continued execution [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/6 passed (0 broken, 5 failed, 0 skipped) EOF # CHECK_STYLE_ENABLE utils_cp_helper expect_some_fail . atf_check -s exit:1 -o file:expout -e empty kyua test } utils_test_case premature_exit premature_exit_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < broken: Premature exit; test case received signal 9 [S.UUUs] bogus_test_cases:exit -> broken: Premature exit; test case exited with code 0 [S.UUUs] bogus_test_cases:pass -> passed [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/3 passed (2 broken, 0 failed, 0 skipped) EOF # CHECK_STYLE_ENABLE utils_cp_helper bogus_test_cases . atf_check -s exit:1 -o file:expout -e empty kyua test } utils_test_case no_args no_args_body() { utils_install_stable_test_wrapper cat >Kyuafile <subdir/Kyuafile <expout < passed [S.UUUs] simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs] subdir/simple_some_fail:fail -> failed: This fails on purpose [S.UUUs] subdir/simple_some_fail:pass -> passed [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 2/4 passed (0 broken, 1 failed, 1 skipped) EOF atf_check -s exit:1 -o file:expout -e empty kyua test } utils_test_case one_arg__subdir one_arg__subdir_body() { utils_install_stable_test_wrapper cat >Kyuafile <subdir/Kyuafile <expout < passed [S.UUUs] subdir/simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 0 failed, 1 skipped) EOF # CHECK_STYLE_ENABLE atf_check -s exit:0 -o file:expout -e empty kyua test subdir } utils_test_case one_arg__test_case one_arg__test_case_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 0/1 passed (0 broken, 0 failed, 1 skipped) EOF atf_check -s exit:0 -o file:expout -e empty kyua test first:skip } utils_test_case one_arg__test_program one_arg__test_program_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < failed: This fails on purpose [S.UUUs] second:pass -> passed [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 1 failed, 0 skipped) EOF atf_check -s exit:1 -o file:expout -e empty kyua test second } utils_test_case one_arg__invalid one_arg__invalid_body() { cat >experr <experr <Kyuafile <subdir/Kyuafile <expout < passed [S.UUUs] subdir/second:fail -> failed: This fails on purpose [S.UUUs] subdir/second:pass -> passed [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 2/3 passed (0 broken, 1 failed, 0 skipped) EOF atf_check -s exit:1 -o file:expout -e empty kyua test subdir first:pass } utils_test_case many_args__invalid many_args__invalid_body() { cat >experr <experr <Kyuafile <expout <experr <Kyuafile <expout < passed [S.UUUs] first:skip -> skipped: The reason for skipping is this [S.UUUs] third:fail -> failed: This fails on purpose [S.UUUs] third:pass -> passed [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 2/4 passed (0 broken, 1 failed, 1 skipped) EOF cat >experr <root/Kyuafile <root/subdir/Kyuafile <expout < passed [S.UUUs] first:skip -> skipped: The reason for skipping is this [S.UUUs] subdir/fourth:fail -> failed: This fails on purpose [S.UUUs] Results file id is $(utils_results_id root) Results saved to $(utils_results_file root) 1/3 passed (0 broken, 1 failed, 1 skipped) EOF atf_check -s exit:1 -o file:expout -e empty kyua test \ -k "$(pwd)/root/Kyuafile" first subdir/fourth:fail } utils_test_case only_load_used_test_programs only_load_used_test_programs_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout < passed [S.UUUs] first:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 0 failed, 1 skipped) EOF CREATE_COOKIE="$(pwd)/cookie"; export CREATE_COOKIE atf_check -s exit:0 -o file:expout -e empty kyua test first if [ -f "${CREATE_COOKIE}" ]; then atf_fail "An unmatched test case has been executed, which harms" \ "performance" fi } utils_test_case config_behavior config_behavior_body() { cat >"my-config" <Kyuafile <Kyuafile <expout < failed: This fails on purpose [S.UUUs] some-program:pass -> passed [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 1 failed, 0 skipped) EOF atf_check -s exit:1 -o file:expout -e empty kyua test cat >expout <Kyuafile <Kyuafile <Kyuafile <Kyuafile <subdir/Kyuafile <expout < passed [S.UUUs] first:skip -> skipped: The reason for skipping is this [S.UUUs] subdir/second:pass -> passed [S.UUUs] subdir/second:skip -> skipped: The reason for skipping is this [S.UUUs] subdir/third:pass -> passed [S.UUUs] subdir/third:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 3/6 passed (0 broken, 0 failed, 3 skipped) EOF mkdir build mkdir build/subdir utils_cp_helper simple_all_pass build/first utils_cp_helper simple_all_pass build/subdir/second utils_cp_helper simple_all_pass build/subdir/third atf_check -s exit:0 -o file:expout -e empty kyua test --build-root=build } utils_test_case kyuafile_flag__no_args kyuafile_flag__no_args_body() { utils_install_stable_test_wrapper cat >Kyuafile <myfile <expout < passed [S.UUUs] sometest:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 0 failed, 1 skipped) EOF atf_check -s exit:0 -o file:expout -e empty kyua test -k myfile atf_check -s exit:0 -o file:expout -e empty kyua test --kyuafile=myfile } utils_test_case kyuafile_flag__some_args kyuafile_flag__some_args_body() { utils_install_stable_test_wrapper cat >Kyuafile <myfile <expout < passed [S.UUUs] sometest:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 0 failed, 1 skipped) EOF atf_check -s exit:0 -o file:expout -e empty kyua test -k myfile sometest cat >expout < passed [S.UUUs] sometest:skip -> skipped: The reason for skipping is this [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 1/2 passed (0 broken, 0 failed, 1 skipped) EOF atf_check -s exit:0 -o file:expout -e empty kyua test --kyuafile=myfile \ sometest } utils_test_case interrupt interrupt_body() { cat >Kyuafile <stdout 2>stderr & pid=${!} echo "Kyua subprocess is PID ${pid}" while [ ! -f body ]; do echo "Waiting for body to start" sleep 1 done echo "Body started" sleep 1 echo "Sending INT signal to ${pid}" kill -INT ${pid} echo "Waiting for process ${pid} to exit" wait ${pid} ret=${?} sed -e 's,^,kyua stdout:,' stdout sed -e 's,^,kyua stderr:,' stderr echo "Process ${pid} exited" [ ${ret} -ne 0 ] || atf_fail 'No error code reported' [ -f cleanup ] || atf_fail 'Cleanup part not executed after signal' atf_expect_pass atf_check -s exit:0 -o ignore -e empty grep 'Signal caught' stderr atf_check -s exit:0 -o ignore -e empty \ grep 'kyua: E: Interrupted by signal' stderr } utils_test_case exclusive_tests exclusive_tests_body() { cat >Kyuafile <>Kyuafile done utils_cp_helper race . atf_check \ -s exit:0 \ -o match:"100/100 passed" \ kyua \ -v parallelism=20 \ -v test_suites.integration.shared_file="$(pwd)/shared_file" \ test } utils_test_case no_test_program_match no_test_program_match_body() { utils_install_stable_test_wrapper cat >Kyuafile <expout <experr <Kyuafile <expout <experr <experr <subdir/Kyuafile <experr <subdir/Kyuafile <experr <"${HOME}/.kyua/kyua.conf" <Kyuafile <Kyuafile <non_executable # CHECK_STYLE_DISABLE cat >expout < broken: Invalid header for test case list; expecting Content-Type for application/X-atf-tp version 1, got '' [S.UUUs] non_executable:__test_cases_list__ -> broken: Permission denied to run test program [S.UUUs] Results file id is $(utils_results_id) Results saved to $(utils_results_file) 0/2 passed (2 broken, 0 failed, 0 skipped) EOF # CHECK_STYLE_ENABLE atf_check -s exit:1 -o file:expout -e empty kyua test } utils_test_case missing_test_program missing_test_program_body() { cat >Kyuafile <subdir/Kyuafile <subdir/ok # CHECK_STYLE_DISABLE cat >experr <