diff --git a/contrib/kyua/.gitignore b/contrib/kyua/.gitignore new file mode 100644 index 0000000000..d7f1a180d6 --- /dev/null +++ b/contrib/kyua/.gitignore @@ -0,0 +1,23 @@ +*.a +*.o +*_helpers +*_inttest +*_test +*~ + +.deps +.dirstamp +Doxyfile +Makefile +Makefile.in +aclocal.m4 +api-docs +autom4te.cache +config.h +config.h.in +config.log +config.status +configure +kyua +local-kyua +stamp-h1 diff --git a/contrib/kyua/.travis.yml b/contrib/kyua/.travis.yml new file mode 100644 index 0000000000..619dceaf3d --- /dev/null +++ b/contrib/kyua/.travis.yml @@ -0,0 +1,49 @@ +language: cpp +sudo: required + +before_install: + - ./admin/travis-install-deps.sh + +matrix: + include: + - os: linux + dist: xenial + compiler: clang + env: ARCH=amd64 DO=distcheck AS_ROOT=no + - os: linux + dist: xenial + compiler: gcc + env: ARCH=amd64 DO=distcheck AS_ROOT=no + - os: linux + dist: xenial + compiler: clang + env: ARCH=amd64 DO=apidocs + - os: linux + dist: xenial + compiler: clang + env: ARCH=amd64 DO=style + - os: linux + dist: xenial + compiler: clang + env: ARCH=amd64 DO=distcheck AS_ROOT=yes UNPRIVILEGED_USER=no + - os: linux + dist: xenial + compiler: clang + env: ARCH=amd64 DO=distcheck AS_ROOT=yes UNPRIVILEGED_USER=yes + # TODO(ngie): reenable i386; the libraries were not available in the + # Ubuntu Xenial x86_64 docker image. + #- os: linux + # dist: xenial + # compiler: clang + # env: ARCH=i386 DO=distcheck AS_ROOT=no + #- os: linux + # dist: xenial + # compiler: gcc + # env: ARCH=i386 DO=distcheck AS_ROOT=no + +script: + - ./admin/travis-build.sh + +notifications: + email: + - kyua-log@googlegroups.com diff --git a/contrib/kyua/AUTHORS b/contrib/kyua/AUTHORS index c7bd72ce77..ac0998fb93 100644 --- a/contrib/kyua/AUTHORS +++ b/contrib/kyua/AUTHORS @@ -8,5 +8,4 @@ # * Name # * Organization -* The FreeBSD Foundation * Google Inc. diff --git a/contrib/kyua/admin/travis-build.sh b/contrib/kyua/admin/travis-build.sh index 0ccf1cc41e..e69f271c13 100755 --- a/contrib/kyua/admin/travis-build.sh +++ b/contrib/kyua/admin/travis-build.sh @@ -61,7 +61,7 @@ syntax(2) parallelism = 4 EOF [ "${UNPRIVILEGED_USER:-no}" = no ] || \ - echo "unprivileged_user = 'nobody'" >>kyua.conf + echo "unprivileged_user = 'travis'" >>kyua.conf local f= f="${f} CFLAGS='${archflags}'" diff --git a/contrib/kyua/cli/cmd_report_html.cpp b/contrib/kyua/cli/cmd_report_html.cpp index 9c99e43482..b2133a8de0 100644 --- a/contrib/kyua/cli/cmd_report_html.cpp +++ b/contrib/kyua/cli/cmd_report_html.cpp @@ -54,7 +54,6 @@ #include "utils/fs/operations.hpp" #include "utils/fs/path.hpp" #include "utils/optional.ipp" -#include "utils/text/operations.hpp" #include "utils/text/templates.hpp" namespace cmdline = utils::cmdline; @@ -366,12 +365,12 @@ class html_hooks : public drivers::scan_results::base_hooks { { const std::string stdout_text = iter.stdout_contents(); if (!stdout_text.empty()) - templates.add_variable("stdout", text::escape_xml(stdout_text)); + templates.add_variable("stdout", stdout_text); } { const std::string stderr_text = iter.stderr_contents(); if (!stderr_text.empty()) - templates.add_variable("stderr", text::escape_xml(stderr_text)); + templates.add_variable("stderr", stderr_text); } generate(templates, "test_result.html", diff --git a/contrib/kyua/doc/kyua.1.in b/contrib/kyua/doc/kyua.1.in index 4a3ab7852b..2fca5eb09f 100644 --- a/contrib/kyua/doc/kyua.1.in +++ b/contrib/kyua/doc/kyua.1.in @@ -392,11 +392,6 @@ codes above 1 can be returned. .Xr atf 7 , .Xr tests 7 .Sh AUTHORS -The original author of -.Nm -was -.An Julio Merino . -.Pp For more details on the people that made .Nm possible and the license terms, run: diff --git a/contrib/kyua/doc/manbuild_test.sh b/contrib/kyua/doc/manbuild_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_about_test.sh b/contrib/kyua/integration/cmd_about_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_config_test.sh b/contrib/kyua/integration/cmd_config_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_db_exec_test.sh b/contrib/kyua/integration/cmd_db_exec_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_db_migrate_test.sh b/contrib/kyua/integration/cmd_db_migrate_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_debug_test.sh b/contrib/kyua/integration/cmd_debug_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_help_test.sh b/contrib/kyua/integration/cmd_help_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_list_test.sh b/contrib/kyua/integration/cmd_list_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_report_html_test.sh b/contrib/kyua/integration/cmd_report_html_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_report_junit_test.sh b/contrib/kyua/integration/cmd_report_junit_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_report_test.sh b/contrib/kyua/integration/cmd_report_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/cmd_test_test.sh b/contrib/kyua/integration/cmd_test_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/global_test.sh b/contrib/kyua/integration/global_test.sh old mode 100644 new mode 100755 diff --git a/contrib/kyua/integration/utils.sh b/contrib/kyua/integration/utils.sh old mode 100644 new mode 100755 index d1462a5a9b..99565a1c98 --- a/contrib/kyua/integration/utils.sh +++ b/contrib/kyua/integration/utils.sh @@ -42,7 +42,7 @@ # script that automatically does this. # CHECK_STYLE_DISABLE utils_strip_times='sed -E \ - -e "s,( |\[|\")[0-9][0-9]*\.[0-9][0-9][0-9](s]|s|\"),\1S.UUU\2,g" \ + -e "s,( |\[|\")[0-9][0-9]*.[0-9][0-9][0-9](s]|s|\"),\1S.UUU\2,g" \ -e "s,[0-9]{8}-[0-9]{6}-[0-9]{6},YYYYMMDD-HHMMSS-ssssss,g" \ -e "s,[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}Z,YYYY-MM-DDTHH:MM:SS.ssssssZ,g"' # CHECK_STYLE_ENABLE @@ -55,7 +55,7 @@ utils_strip_times='sed -E \ # replaced by the fixed string YYYY-MM-DDTHH:MM:SS.ssssssZ. # CHECK_STYLE_DISABLE utils_strip_times_but_not_ids='sed -E \ - -e "s,( |\[|\")[0-9][0-9]*\.[0-9][0-9][0-9](s]|s|\"),\1S.UUU\2,g" \ + -e "s,( |\[|\")[0-9][0-9]*.[0-9][0-9][0-9](s]|s|\"),\1S.UUU\2,g" \ -e "s,[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}Z,YYYY-MM-DDTHH:MM:SS.ssssssZ,g"' # CHECK_STYLE_ENABLE diff --git a/contrib/kyua/utils/datetime.cpp b/contrib/kyua/utils/datetime.cpp index 174d830031..ae3fdb62fe 100644 --- a/contrib/kyua/utils/datetime.cpp +++ b/contrib/kyua/utils/datetime.cpp @@ -590,12 +590,11 @@ datetime::timestamp::operator-=(const datetime::delta& other) datetime::delta datetime::timestamp::operator-(const datetime::timestamp& other) const { - /* - * XXX-BD: gettimeofday isn't necessarily monotonic so return the - * smallest non-zero delta if time went backwards. - */ - if ((*this) < other) - return datetime::delta::from_microseconds(1); + if ((*this) < other) { + throw std::runtime_error( + F("Cannot subtract %s from %s as it would result in a negative " + "datetime::delta, which are not supported") % other % (*this)); + } return datetime::delta::from_microseconds(to_microseconds() - other.to_microseconds()); } diff --git a/contrib/kyua/utils/datetime_test.cpp b/contrib/kyua/utils/datetime_test.cpp index a2d3a3c0cd..9f8ff50cd0 100644 --- a/contrib/kyua/utils/datetime_test.cpp +++ b/contrib/kyua/utils/datetime_test.cpp @@ -532,11 +532,11 @@ ATF_TEST_CASE_BODY(timestamp__subtraction) ATF_REQUIRE_EQ(datetime::delta(100, 0), ts3 - ts1); ATF_REQUIRE_EQ(datetime::delta(99, 999988), ts3 - ts2); - /* - * NOTE (ngie): behavior change for - * https://github.com/jmmv/kyua/issues/155 . - */ - ATF_REQUIRE_EQ(datetime::delta::from_microseconds(1), ts2 - ts3); + ATF_REQUIRE_THROW_RE( + std::runtime_error, + "Cannot subtract 1291970850123456us from 1291970750123468us " + ".*negative datetime::delta.*not supported", + ts2 - ts3); } diff --git a/contrib/kyua/utils/process/Kyuafile b/contrib/kyua/utils/process/Kyuafile index 37ab662982..92e62cfac6 100644 --- a/contrib/kyua/utils/process/Kyuafile +++ b/contrib/kyua/utils/process/Kyuafile @@ -6,7 +6,6 @@ atf_test_program{name="child_test"} atf_test_program{name="deadline_killer_test"} atf_test_program{name="exceptions_test"} atf_test_program{name="executor_test"} -atf_test_program{name="executor_pid_test"} atf_test_program{name="fdstream_test"} atf_test_program{name="isolation_test"} atf_test_program{name="operations_test"} diff --git a/contrib/kyua/utils/process/Makefile.am.inc b/contrib/kyua/utils/process/Makefile.am.inc index 5ce894091a..3cff02e7e4 100644 --- a/contrib/kyua/utils/process/Makefile.am.inc +++ b/contrib/kyua/utils/process/Makefile.am.inc @@ -83,11 +83,6 @@ utils_process_executor_test_SOURCES = utils/process/executor_test.cpp utils_process_executor_test_CXXFLAGS = $(UTILS_CFLAGS) $(ATF_CXX_CFLAGS) utils_process_executor_test_LDADD = $(UTILS_LIBS) $(ATF_CXX_LIBS) -tests_utils_process_PROGRAMS += utils/process/executor_pid_test -utils_process_executor_pid_test_SOURCES = utils/process/executor_pid_test.cpp -utils_process_executor_pid_test_CXXFLAGS = $(UTILS_CFLAGS) $(ATF_CXX_CFLAGS) -utils_process_executor_pid_test_LDADD = $(UTILS_LIBS) $(ATF_CXX_LIBS) - tests_utils_process_PROGRAMS += utils/process/fdstream_test utils_process_fdstream_test_SOURCES = utils/process/fdstream_test.cpp utils_process_fdstream_test_CXXFLAGS = $(UTILS_CFLAGS) $(ATF_CXX_CFLAGS) diff --git a/contrib/kyua/utils/process/executor.cpp b/contrib/kyua/utils/process/executor.cpp index a006326147..dbdf31268f 100644 --- a/contrib/kyua/utils/process/executor.cpp +++ b/contrib/kyua/utils/process/executor.cpp @@ -39,12 +39,10 @@ extern "C" { #include } -#include #include #include #include #include -#include #include "utils/datetime.hpp" #include "utils/format/macros.hpp" @@ -125,7 +123,7 @@ utils::process::executor::detail::setup_child( } -/// Internal implementation for the exec_handle class. +/// Internal implementation for the exit_handle class. struct utils::process::executor::exec_handle::impl : utils::noncopyable { /// PID of the process being run. int pid; @@ -549,9 +547,6 @@ struct utils::process::executor::executor_handle::impl : utils::noncopyable { /// Mapping of PIDs to the data required at run time. exec_handles_map all_exec_handles; - /// Former members of all_exec_handles removed due to PID reuse. - std::forward_list stale_exec_handles; - /// Whether the executor state has been cleaned yet or not. /// /// Used to keep track of explicit calls to the public cleanup(). @@ -563,8 +558,6 @@ struct utils::process::executor::executor_handle::impl : utils::noncopyable { interrupts_handler(new signals::interrupts_handler()), root_work_directory(new fs::auto_directory( fs::auto_directory::mkdtemp_public(work_directory_template))), - all_exec_handles(), - stale_exec_handles(), cleaned(false) { } @@ -610,17 +603,6 @@ struct utils::process::executor::executor_handle::impl : utils::noncopyable { } all_exec_handles.clear(); - for (auto iter : stale_exec_handles) { - // The process already exited, so no need to kill and wait. - try { - fs::rm_r(iter.control_directory()); - } catch (const fs::error& e) { - LE(F("Failed to clean up stale subprocess work directory " - "%s: %s") % iter.control_directory() % e.what()); - } - } - stale_exec_handles.clear(); - try { // The following only causes the work directory to be deleted, not // any of its contents, so we expect this to always succeed. This @@ -629,9 +611,9 @@ struct utils::process::executor::executor_handle::impl : utils::noncopyable { // subprocesses. root_work_directory->cleanup(); } catch (const fs::error& e) { - LE(F("Failed to clean up executor work directory %s: %s; " - "this could be an internal error or a buggy test") % - root_work_directory->directory() % e.what()); + LE(F("Failed to clean up executor work directory %s: %s; this is " + "an internal error") % root_work_directory->directory() + % e.what()); } root_work_directory.reset(NULL); @@ -791,16 +773,12 @@ executor::executor_handle::spawn_post( timeout, unprivileged_user, detail::refcnt_t(new detail::refcnt_t::element_type(0))))); - const auto value = exec_handles_map::value_type(handle.pid(), handle); - auto insert_pair = _pimpl->all_exec_handles.insert(value); - if (!insert_pair.second) { - LI(F("PID %s already in all_exec_handles") % handle.pid()); - _pimpl->stale_exec_handles.push_front(insert_pair.first->second); - _pimpl->all_exec_handles.erase(insert_pair.first); - insert_pair = _pimpl->all_exec_handles.insert(value); - INV_MSG(insert_pair.second, F("PID %s still in all_exec_handles") % - handle.pid()); - } + INV_MSG(_pimpl->all_exec_handles.find(handle.pid()) == + _pimpl->all_exec_handles.end(), + F("PID %s already in all_exec_handles; not properly cleaned " + "up or reused too fast") % handle.pid());; + _pimpl->all_exec_handles.insert(exec_handles_map::value_type( + handle.pid(), handle)); LI(F("Spawned subprocess with exec_handle %s") % handle.pid()); return handle; } @@ -838,16 +816,12 @@ executor::executor_handle::spawn_followup_post( timeout, base.unprivileged_user(), base.state_owners()))); - const auto value = exec_handles_map::value_type(handle.pid(), handle); - auto insert_pair = _pimpl->all_exec_handles.insert(value); - if (!insert_pair.second) { - LI(F("PID %s already in all_exec_handles") % handle.pid()); - _pimpl->stale_exec_handles.push_front(insert_pair.first->second); - _pimpl->all_exec_handles.erase(insert_pair.first); - insert_pair = _pimpl->all_exec_handles.insert(value); - INV_MSG(insert_pair.second, F("PID %s still in all_exec_handles") % - handle.pid()); - } + INV_MSG(_pimpl->all_exec_handles.find(handle.pid()) == + _pimpl->all_exec_handles.end(), + F("PID %s already in all_exec_handles; not properly cleaned " + "up or reused too fast") % handle.pid());; + _pimpl->all_exec_handles.insert(exec_handles_map::value_type( + handle.pid(), handle)); LI(F("Spawned subprocess with exec_handle %s") % handle.pid()); return handle; }