From nobody Sun Nov 22 21:38:31 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jXj9z57hQz70wvM for ; Sun, 22 Nov 2026 21:38:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jXj9z3z9xz3G0b for ; Sun, 22 Nov 2026 21:38:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795383511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RAw5U5T9pG4WC6+GAU0tLu0GMVOBICdn4zyL2GflFPs=; b=G/1envYeREtJ2g5w8rp/Do+0OkjC86/8e7hII5udUDl4necGzrq7I852bSw3w/CLZ1XFmv GbVj1FAq/DsPVp+a/YbWCXMdVSy/4UhL+MzBiB4U4terVYov0v8ZiABHS4he/HPtQZIbfn 3OgmdUPB168QpSTozUT0FKiB3UueQh2WAS5V4L7sca06lsCRosQBkDNmMTzRu8xgRUygZo lWr/asHFknaPSACw8uBmzeW+SuV1cuM1nehZd88B/wnRAdR+Ruq7SKrGM+hbitGq+YaU9A Otz18oQ8KCZkCh72L5fU7LPe9ypTmG5qWtJpfEM9I9L2FqyfBxmup+thJTzG/A== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795383511; b=BiC66pNFwGneTOSgeHxnKtUWe5V2Wtjyap19Unu9GMtdLzwhiGPb579bTf5Kh4/qRpWpgP oIc+SfO27WyaM+oLboLUozwe8O1Uzx2XtcFUDGg9ubJc1/ITRacrncfciDP4oqx4moM5RW RFB9/K2sawCjIaG9F9hxVlBFqSjvjZKVYJT9yN2QGmTATRPbAvjk8SBhgBCl9TcZ931OZ8 uZY4CDbtimUAVA9t4LY2se7PadD11gs9LfSVLYK+3QBmzN7b3+k8Je3uo99WPMqfJ+AFcK v9sC+Uloe18c774eQCNun1kpLN9N2Uirs507+Z/Q5X+Ap/cWyXKRNle05hZVnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795383511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RAw5U5T9pG4WC6+GAU0tLu0GMVOBICdn4zyL2GflFPs=; b=s3q8PYX1c6I9nKWGajGlPy3ghHYQveSs391ymfdhyiYiTMyMjZoqHnpCRpqQm2uO07eT9H BmdNpiu1q6c+XcbtSTSSq/K7eYxt5ZynJwzSn+Hlyl/ZBUHh2+5JTLXboK4GB2YcT7Pdxi rHcA0+qzY1mGtNLyKNb0YOrL3GQeLJ0KCOIgQKxBCsYI9XLJ0KPSQt8OhvRvE8OPE2zJEN yzWCF3mEyu6e0ApfsaDXyNaiZ7hVvD/tDLIIXuBIwAoT3gkbymacJSnuw1o/b50kEwMypi ds6sD2CrjIGQ4JR91e6fFu2zdC4PmLtVmy16FX+wC6lvDEDg5OGwssAaFH5lZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jXj9z3d44zLSq for ; Sun, 22 Nov 2026 21:38:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id d0ef by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 22 Nov 2026 21:38:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Igor Ostapenko From: Enji Cooper Subject: git: bc2e0acc8891 - stable/15 - kyua: Add "debug -x|--execute cmd" option List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ngie X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: bc2e0acc8891a598f36908a070102f3020c25a4e Auto-Submitted: auto-generated Date: Sun, 22 Nov 2026 21:38:31 +0000 Message-Id: <6b0360d7.d0ef.47c0d01b@gitrepo.freebsd.org> The branch stable/15 has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=bc2e0acc8891a598f36908a070102f3020c25a4e commit bc2e0acc8891a598f36908a070102f3020c25a4e Author: Igor Ostapenko AuthorDate: 2026-01-11 13:43:33 +0000 Commit: Enji Cooper CommitDate: 2026-11-22 21:37:01 +0000 kyua: Add "debug -x|--execute cmd" option With execenv=jail specified, the "cmd" runs inside the test's jail. Reviewed by: ngie, markj Differential Revision: https://reviews.freebsd.org/D52642 (cherry picked from commit 8a21c17ccfecf0ee54becd46d3e08ccab76ca3d6) --- contrib/kyua/cli/cmd_debug.cpp | 82 +++++++++++++++++++++++++++++++++- contrib/kyua/engine/debugger.hpp | 7 +++ contrib/kyua/engine/scheduler.cpp | 3 ++ contrib/kyua/utils/cmdline/options.cpp | 20 +++++++-- contrib/kyua/utils/cmdline/options.hpp | 8 +++- contrib/kyua/utils/cmdline/parser.cpp | 20 ++++++--- contrib/kyua/utils/process/child.cpp | 24 ++++++++++ contrib/kyua/utils/process/child.hpp | 5 +++ contrib/kyua/utils/process/child.ipp | 20 +++++++++ 9 files changed, 178 insertions(+), 11 deletions(-) diff --git a/contrib/kyua/cli/cmd_debug.cpp b/contrib/kyua/cli/cmd_debug.cpp index f04b28104bbf..8ad52afb73a6 100644 --- a/contrib/kyua/cli/cmd_debug.cpp +++ b/contrib/kyua/cli/cmd_debug.cpp @@ -28,6 +28,10 @@ #include "cli/cmd_debug.hpp" +extern "C" { +#include +} + #include #include @@ -39,13 +43,20 @@ #include "utils/cmdline/parser.ipp" #include "utils/cmdline/ui.hpp" #include "utils/format/macros.hpp" +#include "utils/fs/path.hpp" +#include "utils/process/child.ipp" #include "utils/process/executor.hpp" +#include "utils/process/operations.hpp" +#include "utils/process/status.hpp" namespace cmdline = utils::cmdline; namespace config = utils::config; namespace executor = utils::process::executor; +namespace process = utils::process; using cli::cmd_debug; +using utils::process::args_vector; +using utils::process::child; namespace { @@ -63,6 +74,57 @@ const cmdline::bool_option pause_before_cleanup_option( "Pauses right before the test cleanup"); +static const char* DEFAULT_CMD = "$SHELL"; +const cmdline::string_option execute_option( + 'x', "execute", + "A command to run within the given execenv upon test failure", + "cmd", DEFAULT_CMD, true); + + +/// Functor to execute a program. +class execute { + const std::string& _cmd; + executor::exit_handle& _eh; + +public: + /// Constructor. + /// + /// \param program Program binary absolute path. + /// \param args Program arguments. + execute( + const std::string& cmd_, + executor::exit_handle& eh_) : + _cmd(cmd_), + _eh(eh_) + { + } + + /// Body of the subprocess. + void + operator()(void) + { + if (::chdir(_eh.work_directory().c_str()) == -1) { + std::cerr << "execute: chdir() errors: " + << strerror(errno) << ".\n"; + std::exit(EXIT_FAILURE); + } + + std::string program_path = "/bin/sh"; + const char* shell = std::getenv("SHELL"); + if (shell) + program_path = shell; + + args_vector av; + if (!(_cmd.empty() || _cmd == DEFAULT_CMD)) { + av.push_back("-c"); + av.push_back(_cmd); + } + + process::exec(utils::fs::path(program_path), av); + } +}; + + /// The debugger interface implementation. class dbg : public engine::debugger { /// Object to interact with the I/O of the program. @@ -104,6 +166,21 @@ public: } }; + void upon_test_failure( + const model::test_program_ptr&, + const model::test_case&, + optional< model::test_result >&, + executor::exit_handle& eh) const + { + if (!_cmdline.has_option(execute_option.long_name())) + return; + const std::string& cmd = _cmdline.get_option( + execute_option.long_name()); + std::unique_ptr< process::child > child = child::fork_interactive( + execute(cmd, eh)); + (void) child->wait(); + }; + }; @@ -128,6 +205,8 @@ cmd_debug::cmd_debug(void) : cli_command( add_option(cmdline::path_option( "stderr", "Where to direct the standard error of the test case", "path", "/dev/stderr")); + + add_option(execute_option); } @@ -152,7 +231,8 @@ cmd_debug::run(cmdline::ui* ui, const cmdline::parsed_cmdline& cmdline, engine::debugger_ptr debugger = nullptr; if (cmdline.has_option(pause_before_cleanup_upon_fail_option.long_name()) - || cmdline.has_option(pause_before_cleanup_option.long_name())) { + || cmdline.has_option(pause_before_cleanup_option.long_name()) + || cmdline.has_option(execute_option.long_name())) { debugger = std::shared_ptr< engine::debugger >(new dbg(ui, cmdline)); } diff --git a/contrib/kyua/engine/debugger.hpp b/contrib/kyua/engine/debugger.hpp index 3c4d087f8ad0..ce87d41ed94d 100644 --- a/contrib/kyua/engine/debugger.hpp +++ b/contrib/kyua/engine/debugger.hpp @@ -58,6 +58,13 @@ public: const model::test_case&, optional< model::test_result >&, executor::exit_handle&) const = 0; + + /// Called upon test failure. + virtual void upon_test_failure( + const model::test_program_ptr&, + const model::test_case&, + optional< model::test_result >&, + executor::exit_handle&) const = 0; }; diff --git a/contrib/kyua/engine/scheduler.cpp b/contrib/kyua/engine/scheduler.cpp index a0719ec461ab..d04fc1dfbd3d 100644 --- a/contrib/kyua/engine/scheduler.cpp +++ b/contrib/kyua/engine/scheduler.cpp @@ -1403,6 +1403,9 @@ scheduler::scheduler_handle::wait_any(void) if (debugger) { debugger->before_cleanup(test_data->test_program, test_case, result, handle); + if (!result.get().good()) + debugger->upon_test_failure(test_data->test_program, test_case, + result, handle); } if (test_data->needs_cleanup) { diff --git a/contrib/kyua/utils/cmdline/options.cpp b/contrib/kyua/utils/cmdline/options.cpp index 61736e31c11e..9d448503e3f9 100644 --- a/contrib/kyua/utils/cmdline/options.cpp +++ b/contrib/kyua/utils/cmdline/options.cpp @@ -53,15 +53,18 @@ namespace text = utils::text; /// purposes. /// \param default_value_ If not NULL, specifies that the option has a default /// value for the mandatory argument. +/// \param arg_is_optional_ Specifies if a value must be provided or not. cmdline::base_option::base_option(const char short_name_, const char* long_name_, const char* description_, const char* arg_name_, - const char* default_value_) : + const char* default_value_, + bool arg_is_optional_) : _short_name(short_name_), _long_name(long_name_), _description(description_), _arg_name(arg_name_ == NULL ? "" : arg_name_), + _arg_is_optional(arg_is_optional_), _has_default_value(default_value_ != NULL), _default_value(default_value_ == NULL ? "" : default_value_) { @@ -164,6 +167,16 @@ cmdline::base_option::arg_name(void) const } +/// Returns optionality of the argument. +/// +/// \return The optionality. +bool +cmdline::base_option::arg_is_optional(void) const +{ + return _arg_is_optional; +} + + /// Checks whether the option has a default value for its argument. /// /// \pre needs_arg() must be true. @@ -558,9 +571,10 @@ cmdline::string_option::string_option(const char short_name_, const char* long_name_, const char* description_, const char* arg_name_, - const char* default_value_) : + const char* default_value_, + bool arg_is_optional_) : base_option(short_name_, long_name_, description_, arg_name_, - default_value_) + default_value_, arg_is_optional_) { } diff --git a/contrib/kyua/utils/cmdline/options.hpp b/contrib/kyua/utils/cmdline/options.hpp index f3a83889e491..d11de14af514 100644 --- a/contrib/kyua/utils/cmdline/options.hpp +++ b/contrib/kyua/utils/cmdline/options.hpp @@ -91,6 +91,9 @@ class base_option { /// Descriptive name of the required argument; empty if not allowed. std::string _arg_name; + /// If the option can be used without an explicit argument provided. + bool _arg_is_optional = false; + /// Whether the option has a default value or not. /// /// \todo We should probably be using the optional class here. @@ -101,7 +104,7 @@ class base_option { public: base_option(const char, const char*, const char*, const char* = NULL, - const char* = NULL); + const char* = NULL, bool = false); base_option(const char*, const char*, const char* = NULL, const char* = NULL); virtual ~base_option(void); @@ -113,6 +116,7 @@ public: bool needs_arg(void) const; const std::string& arg_name(void) const; + bool arg_is_optional(void) const; bool has_default_value(void) const; const std::string& default_value(void) const; @@ -219,7 +223,7 @@ public: class string_option : public base_option { public: string_option(const char, const char*, const char*, const char*, - const char* = NULL); + const char* = NULL, bool = false); string_option(const char*, const char*, const char*, const char* = NULL); virtual ~string_option(void) {} diff --git a/contrib/kyua/utils/cmdline/parser.cpp b/contrib/kyua/utils/cmdline/parser.cpp index 5c83f6d69cc4..29dd4612f6ad 100644 --- a/contrib/kyua/utils/cmdline/parser.cpp +++ b/contrib/kyua/utils/cmdline/parser.cpp @@ -88,7 +88,10 @@ options_to_getopt_data(const cmdline::options_vector& options, long_option.name = option->long_name().c_str(); if (option->needs_arg()) - long_option.has_arg = required_argument; + if (option->arg_is_optional()) + long_option.has_arg = optional_argument; + else + long_option.has_arg = required_argument; else long_option.has_arg = no_argument; @@ -96,7 +99,7 @@ options_to_getopt_data(const cmdline::options_vector& options, if (option->has_short_name()) { data.short_options += option->short_name(); if (option->needs_arg()) - data.short_options += ':'; + data.short_options += option->arg_is_optional() ? "::" : ":"; id = option->short_name(); } else { id = cur_id++; @@ -320,9 +323,11 @@ cmdline::parse(const int argc, const char* const* argv, for (cmdline::options_vector::const_iterator iter = options.begin(); iter != options.end(); iter++) { const cmdline::base_option* option = *iter; - if (option->needs_arg() && option->has_default_value()) + if (option->needs_arg() && option->has_default_value() && + !option->arg_is_optional()) { option_values[option->long_name()].push_back( option->default_value()); + } } args_vector args; @@ -357,8 +362,13 @@ cmdline::parse(const int argc, const char* const* argv, if (::optarg != NULL) { option->validate(::optarg); option_values[option->long_name()].push_back(::optarg); - } else - INV(option->has_default_value()); + } else { + if (option->arg_is_optional()) + option_values[option->long_name()].push_back( + option->default_value()); + else + INV(option->has_default_value()); + } } else { option_values[option->long_name()].push_back(""); } diff --git a/contrib/kyua/utils/process/child.cpp b/contrib/kyua/utils/process/child.cpp index 36b6b6b3e51f..c51c39e6d1ff 100644 --- a/contrib/kyua/utils/process/child.cpp +++ b/contrib/kyua/utils/process/child.cpp @@ -235,6 +235,30 @@ process::child::fork_capture_aux(void) } +std::unique_ptr< process::child > +process::child::fork_interactive(void) +{ + std::cout.flush(); + std::cerr.flush(); + + std::unique_ptr< signals::interrupts_inhibiter > inhibiter( + new signals::interrupts_inhibiter); + pid_t pid = detail::syscall_fork(); + if (pid == -1) { + inhibiter.reset(); // Unblock signals. + throw process::system_error("fork(2) failed", errno); + } else if (pid == 0) { + inhibiter.reset(); // Unblock signals. + return {}; + } else { + signals::add_pid_to_kill(pid); + inhibiter.reset(NULL); // Unblock signals. + return std::unique_ptr< process::child >( + new process::child(new impl(pid, NULL))); + } +} + + /// Helper function for fork(). /// /// Please note: if you update this function to change the return type or to diff --git a/contrib/kyua/utils/process/child.hpp b/contrib/kyua/utils/process/child.hpp index 3e00cea8752c..fbe32311a05b 100644 --- a/contrib/kyua/utils/process/child.hpp +++ b/contrib/kyua/utils/process/child.hpp @@ -80,6 +80,8 @@ class child : noncopyable { static std::unique_ptr< child > fork_capture_aux(void); + static std::unique_ptr< child > fork_interactive(void); + static std::unique_ptr< child > fork_files_aux(const fs::path&, const fs::path&); @@ -92,6 +94,9 @@ public: static std::unique_ptr< child > fork_capture(Hook); std::istream& output(void); + template< typename Hook > + static std::unique_ptr< child > fork_interactive(Hook); + template< typename Hook > static std::unique_ptr< child > fork_files(Hook, const fs::path&, const fs::path&); diff --git a/contrib/kyua/utils/process/child.ipp b/contrib/kyua/utils/process/child.ipp index beb2ea3b0b0a..86bc01fc0d6e 100644 --- a/contrib/kyua/utils/process/child.ipp +++ b/contrib/kyua/utils/process/child.ipp @@ -104,6 +104,26 @@ child::fork_capture(Hook hook) } +template< typename Hook > +std::unique_ptr< child > +child::fork_interactive(Hook hook) +{ + std::unique_ptr< child > child = fork_interactive(); + if (child.get() == NULL) { + try { + hook(); + std::abort(); + } catch (const std::runtime_error& e) { + detail::report_error_and_abort(e); + } catch (...) { + detail::report_error_and_abort(); + } + } + + return child; +} + + } // namespace process } // namespace utils