Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/atf/dist/tools Add support for running individu...



details:   https://anonhg.NetBSD.org/src/rev/9ee59ca26651
branches:  trunk
changeset: 982326:9ee59ca26651
user:      gson <gson%NetBSD.org@localhost>
date:      Sat Apr 10 10:32:57 2021 +0000

description:
Add support for running individual test cases under isolation.

diffstat:

 external/bsd/atf/dist/tools/atf-run.1   |  21 +++++++++++-------
 external/bsd/atf/dist/tools/atf-run.cpp |  36 +++++++++++++++++++++++++++-----
 2 files changed, 43 insertions(+), 14 deletions(-)

diffs (162 lines):

diff -r 5514537d4c2f -r 9ee59ca26651 external/bsd/atf/dist/tools/atf-run.1
--- a/external/bsd/atf/dist/tools/atf-run.1     Sat Apr 10 08:01:21 2021 +0000
+++ b/external/bsd/atf/dist/tools/atf-run.1     Sat Apr 10 10:32:57 2021 +0000
@@ -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 @@
 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
diff -r 5514537d4c2f -r 9ee59ca26651 external/bsd/atf/dist/tools/atf-run.cpp
--- a/external/bsd/atf/dist/tools/atf-run.cpp   Sat Apr 10 08:01:21 2021 +0000
+++ b/external/bsd/atf/dist/tools/atf-run.cpp   Sat Apr 10 10:32:57 2021 +0000
@@ -81,11 +81,13 @@
 
     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 @@
 atf_run::specific_args(void)
     const
 {
-    return "[test-program1 .. test-programN]";
+    return "[test1 .. testN]";
 }
 
 atf_run::options_set
@@ -214,6 +216,7 @@
 
 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 @@
         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 @@
     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 @@
 
 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)
 {
@@ -394,6 +398,9 @@
             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 +471,19 @@
     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 +492,9 @@
 
     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 +562,9 @@
     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);
     }



Home | Main Index | Thread Index | Old Index