Skip to content

Commit

Permalink
bring in patchset from freebsd
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Nov 8, 2024
1 parent 17d76eb commit 9e32ff0
Show file tree
Hide file tree
Showing 25 changed files with 103 additions and 71 deletions.
23 changes: 23 additions & 0 deletions contrib/kyua/.gitignore
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions contrib/kyua/.travis.yml
Original file line number Diff line number Diff line change
@@ -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:
- [email protected]
1 change: 0 additions & 1 deletion contrib/kyua/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
# * Name <email address>
# * Organization <optional email address>

* The FreeBSD Foundation
* Google Inc.
2 changes: 1 addition & 1 deletion contrib/kyua/admin/travis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}'"
Expand Down
5 changes: 2 additions & 3 deletions contrib/kyua/cli/cmd_report_html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions contrib/kyua/doc/kyua.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Empty file modified contrib/kyua/doc/manbuild_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_about_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_config_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_db_exec_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_db_migrate_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_debug_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_help_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_list_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_report_html_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_report_junit_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_report_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/cmd_test_test.sh
100644 → 100755
Empty file.
Empty file modified contrib/kyua/integration/global_test.sh
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions contrib/kyua/integration/utils.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 5 additions & 6 deletions contrib/kyua/utils/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
10 changes: 5 additions & 5 deletions contrib/kyua/utils/datetime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
1 change: 0 additions & 1 deletion contrib/kyua/utils/process/Kyuafile
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
5 changes: 0 additions & 5 deletions contrib/kyua/utils/process/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 16 additions & 42 deletions contrib/kyua/utils/process/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ extern "C" {
#include <signal.h>
}

#include <forward_list>
#include <fstream>
#include <map>
#include <memory>
#include <stdexcept>
#include <utility>

#include "utils/datetime.hpp"
#include "utils/format/macros.hpp"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<exec_handle> stale_exec_handles;

/// Whether the executor state has been cleaned yet or not.
///
/// Used to keep track of explicit calls to the public cleanup().
Expand All @@ -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)
{
}
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9e32ff0

Please sign in to comment.