Module Name: src Committed By: martin Date: Tue Oct 8 11:29:30 UTC 2024
Modified Files: src/external/bsd/atf/dist/tools [netbsd-9]: atf-run.1 atf-run.cpp Log Message: Pull up following revision(s) (requested by rin in ticket #1895): external/bsd/atf/dist/tools/atf-run.1: revision 1.5 external/bsd/atf/dist/tools/atf-run.cpp: revision 1.6 external/bsd/atf/dist/tools/atf-run.cpp: revision 1.7 Add support for running individual test cases under isolation. When running an individual test case under isolation, make the test case count on the tp-start line of the output match the number of test cases actually executed (one) so that the atf-run output is valid input to atf-report. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.4.30.1 src/external/bsd/atf/dist/tools/atf-run.1 cvs rdiff -u -r1.5 -r1.5.30.1 src/external/bsd/atf/dist/tools/atf-run.cpp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/atf/dist/tools/atf-run.1 diff -u src/external/bsd/atf/dist/tools/atf-run.1:1.4 src/external/bsd/atf/dist/tools/atf-run.1:1.4.30.1 --- src/external/bsd/atf/dist/tools/atf-run.1:1.4 Sat Feb 8 19:13:44 2014 +++ src/external/bsd/atf/dist/tools/atf-run.1 Tue Oct 8 11:29:30 2024 @@ -26,23 +26,22 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 1, 2010 +.Dd April 10, 2021 .Dt ATF-RUN 1 .Os .Sh NAME .Nm atf-run -.Nd executes a collection of test programs +.Nd executes a collection of tests .Sh SYNOPSIS .Nm .Op Fl v Ar var1=value1 Op .. Fl v Ar varN=valueN -.Op Ar test_program1 Op Ar .. test_programN +.Op Ar test1 Op Ar .. testN .Nm .Fl h .Sh DESCRIPTION .Nm -executes a collection of test programs or, in other words, a complete -test suite. -The results of each test program are collected by the tool, and are then +executes a collection of test cases, test programs, or a complete test suite. +The results of each test are collected by the tool, and are then multiplexed into a single machine-parseable report; see .Xr atf-formats 5 for more details. @@ -70,8 +69,14 @@ In the first synopsis form, parses the .Pa Atffile in the current directory and runs all the test programs specified in it. -If any test program names are given as part of the command line, those are -the ones executed instead of the complete list. +If any +.Ar test +arguments are given as part of the command line, those tests are +executed instead of the complete list. Each +.Ar test +argument can be either the name of a test program, or a string of the form +.Ar test_program:test_case +to execute a single test case. .Pp In the second synopsis form, .Nm Index: src/external/bsd/atf/dist/tools/atf-run.cpp diff -u src/external/bsd/atf/dist/tools/atf-run.cpp:1.5 src/external/bsd/atf/dist/tools/atf-run.cpp:1.5.30.1 --- src/external/bsd/atf/dist/tools/atf-run.cpp:1.5 Tue Feb 11 18:13:45 2014 +++ src/external/bsd/atf/dist/tools/atf-run.cpp Tue Oct 8 11:29:30 2024 @@ -81,11 +81,13 @@ class atf_run : public tools::applicatio size_t count_tps(std::vector< std::string >) const; - int run_test(const tools::fs::path&, tools::test_program::atf_tps_writer&, + int run_test(const tools::fs::path&, const std::string &, + tools::test_program::atf_tps_writer&, const vars_map&); int run_test_directory(const tools::fs::path&, tools::test_program::atf_tps_writer&); int run_test_program(const tools::fs::path&, + const std::string tc, tools::test_program::atf_tps_writer&, const vars_map&); @@ -179,7 +181,7 @@ std::string atf_run::specific_args(void) const { - return "[test-program1 .. test-programN]"; + return "[test1 .. testN]"; } atf_run::options_set @@ -214,6 +216,7 @@ atf_run::parse_vflag(const std::string& int atf_run::run_test(const tools::fs::path& tp, + const std::string &tc, tools::test_program::atf_tps_writer& w, const vars_map& config) { @@ -226,7 +229,7 @@ atf_run::run_test(const tools::fs::path& const vars_map effective_config = tools::config_file::merge_configs(config, m_cmdline_vars); - errcode = run_test_program(tp, w, effective_config); + errcode = run_test_program(tp, tc, w, effective_config); } return errcode; } @@ -247,7 +250,7 @@ atf_run::run_test_directory(const tools: bool ok = true; for (std::vector< std::string >::const_iterator iter = af.tps().begin(); iter != af.tps().end(); iter++) { - const bool result = run_test(tp / *iter, w, + const bool result = run_test(tp / *iter, "", w, tools::config_file::merge_configs(af.conf(), test_suite_vars)); ok &= (result == EXIT_SUCCESS); } @@ -362,6 +365,7 @@ atf_run::get_test_case_result(const std: int atf_run::run_test_program(const tools::fs::path& tp, + const std::string tc, tools::test_program::atf_tps_writer& w, const vars_map& config) { @@ -384,7 +388,22 @@ atf_run::run_test_program(const tools::f tools::fs::temp_dir resdir( tools::fs::path(tools::config::get("atf_workdir")) / "atf-run.XXXXXX"); - w.start_tp(tp.str(), md.test_cases.size()); + size_t nseltcs; + if (tc.empty()) { + nseltcs = md.test_cases.size(); + } else { + nseltcs = 0; + for (std::map< std::string, vars_map >::const_iterator iter + = md.test_cases.begin(); iter != md.test_cases.end(); iter++) { + const std::string& tcname = (*iter).first; + if (tcname == tc) + nseltcs++; + } + if (nseltcs == 0) + throw std::runtime_error("No such test case"); + } + + w.start_tp(tp.str(), nseltcs); if (md.test_cases.empty()) { w.end_tp("Bogus test program: reported 0 test cases"); errcode = EXIT_FAILURE; @@ -394,6 +413,9 @@ atf_run::run_test_program(const tools::f const std::string& tcname = (*iter).first; const vars_map& tcmd = (*iter).second; + if (! tc.empty() && tcname != tc) + continue; + w.start_tc(tcname); try { @@ -464,6 +486,19 @@ atf_run::run_test_program(const tools::f return errcode; } +static void +colon_split(const std::string &s, std::string &tp, std::string &tc) +{ + size_t colon_pos = s.rfind(':'); + if (colon_pos != std::string::npos && colon_pos < s.size() - 1) { + tp = s.substr(0, colon_pos); + tc = s.substr(colon_pos + 1); + } else { + tp = s; + tc = ""; + } +} + size_t atf_run::count_tps(std::vector< std::string > tps) const @@ -472,7 +507,9 @@ atf_run::count_tps(std::vector< std::str for (std::vector< std::string >::const_iterator iter = tps.begin(); iter != tps.end(); iter++) { - tools::fs::path tp(*iter); + std::string tpname, tcname; + colon_split(*iter, tpname, tcname); + tools::fs::path tp(tpname); tools::fs::file_info fi(tp); if (fi.get_type() == tools::fs::file_info::dir_type) { @@ -540,7 +577,9 @@ atf_run::main(void) bool ok = true; for (std::vector< std::string >::const_iterator iter = tps.begin(); iter != tps.end(); iter++) { - const bool result = run_test(tools::fs::path(*iter), w, + std::string tp, tc; + colon_split(*iter, tp, tc); + const bool result = run_test(tools::fs::path(tp), tc, w, tools::config_file::merge_configs(af.conf(), test_suite_vars)); ok &= (result == EXIT_SUCCESS); }