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 Import atf-0.14:



details:   https://anonhg.NetBSD.org/src/rev/12b58034e019
branches:  trunk
changeset: 766064:12b58034e019
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Tue Jun 14 15:23:20 2011 +0000

description:
Import atf-0.14:

Experimental version released on June 14th, 2011.

* Added a pkg-config file for atf-sh and an aclocal file to ease the
  detection of atf-sh from autoconf scripts.

* Made the default test case body defined by atf_sh fail.  This is to
  ensure that test cases are properly defined in test programs and helps
  in catching typos in the names of the body functions.

* PR bin/44882: Made atf-run connect the stdin of test cases to /dev/zero.
  This provides more consistent results with "normal" execution (in
  particular, when tests are executed detached from a terminal).

* Made atf-run hardcode TZ=UTC for test cases.  It used to undefine TZ, but
  that does not take into account that libc determines the current timezone
  from a configuration file.

* All test programs will now print a warning when they are not run through
  atf-run(1) stating that this is unsupported and may deliver incorrect
  results.

* Added support for the 'require.files' test-case property.  This allows
  test cases to specify installed files that must be present for the test
  case to run.

diffstat:

 external/bsd/atf/dist/NEWS                            |  29 +++++++++
 external/bsd/atf/dist/atf-c/detail/tp_main.c          |  16 +++++
 external/bsd/atf/dist/atf-c/detail/user_test.c        |  10 ++-
 external/bsd/atf/dist/atf-run/misc_helpers.cpp        |  47 +++++++++++++++-
 external/bsd/atf/dist/atf-run/requirements.cpp        |  21 ++++++-
 external/bsd/atf/dist/atf-run/requirements_test.cpp   |  58 ++++++++++++++++++-
 external/bsd/atf/dist/atf-run/user_test.cpp           |   8 ++
 external/bsd/atf/dist/atf-sh/atf-sh.pc.in             |   8 ++
 external/bsd/atf/dist/atf-sh/config_test.sh           |  12 +-
 external/bsd/atf/dist/atf-sh/libatf-sh.subr           |  21 ++++++-
 external/bsd/atf/dist/atf-sh/misc_helpers.sh          |   9 ++-
 external/bsd/atf/dist/atf-sh/tc_test.sh               |  15 ++++-
 external/bsd/atf/dist/atf-sh/tp_test.sh               |   4 +-
 external/bsd/atf/dist/test-programs/expect_test.sh    |  34 ++++++----
 external/bsd/atf/dist/test-programs/meta_data_test.sh |  10 +-
 external/bsd/atf/dist/test-programs/result_test.sh    |  32 ++++++++--
 external/bsd/atf/dist/test-programs/srcdir_test.sh    |   6 +-
 17 files changed, 295 insertions(+), 45 deletions(-)

diffs (truncated from 787 to 300 lines):

diff -r fe679b170a7d -r 12b58034e019 external/bsd/atf/dist/NEWS
--- a/external/bsd/atf/dist/NEWS        Tue Jun 14 15:23:19 2011 +0000
+++ b/external/bsd/atf/dist/NEWS        Tue Jun 14 15:23:20 2011 +0000
@@ -2,6 +2,35 @@
 ===========================================================================
 
 
+Changes in version 0.14
+***********************
+
+Experimental version released on June 14th, 2011.
+
+* Added a pkg-config file for atf-sh and an aclocal file to ease the
+  detection of atf-sh from autoconf scripts.
+
+* Made the default test case body defined by atf_sh fail.  This is to
+  ensure that test cases are properly defined in test programs and helps
+  in catching typos in the names of the body functions.
+
+* PR bin/44882: Made atf-run connect the stdin of test cases to /dev/zero.
+  This provides more consistent results with "normal" execution (in
+  particular, when tests are executed detached from a terminal).
+
+* Made atf-run hardcode TZ=UTC for test cases.  It used to undefine TZ, but
+  that does not take into account that libc determines the current timezone
+  from a configuration file.
+
+* All test programs will now print a warning when they are not run through
+  atf-run(1) stating that this is unsupported and may deliver incorrect
+  results.
+
+* Added support for the 'require.files' test-case property.  This allows
+  test cases to specify installed files that must be present for the test
+  case to run.
+
+
 Changes in version 0.13
 ***********************
 
diff -r fe679b170a7d -r 12b58034e019 external/bsd/atf/dist/atf-c/detail/tp_main.c
--- a/external/bsd/atf/dist/atf-c/detail/tp_main.c      Tue Jun 14 15:23:19 2011 +0000
+++ b/external/bsd/atf/dist/atf-c/detail/tp_main.c      Tue Jun 14 15:23:20 2011 +0000
@@ -44,6 +44,7 @@
 #include "atf-c/utils.h"
 
 #include "dynstr.h"
+#include "env.h"
 #include "fs.h"
 #include "map.h"
 #include "sanity.h"
@@ -127,6 +128,13 @@
                 progname);
 }
 
+static
+void
+print_warning(const char *message)
+{
+    fprintf(stderr, "%s: WARNING: %s\n", progname, message);
+}
+
 /* ---------------------------------------------------------------------
  * Options handling.
  * --------------------------------------------------------------------- */
@@ -488,6 +496,14 @@
         goto out;
     }
 
+    if (!atf_env_has("__RUNNING_INSIDE_ATF_RUN") || strcmp(atf_env_get(
+        "__RUNNING_INSIDE_ATF_RUN"), "internal-yes-value") != 0)
+    {
+        print_warning("Running test cases without atf-run(1) is unsupported");
+        print_warning("No isolation nor timeout control is being applied; you "
+                      "may get unexpected failures; see atf-test-case(4)");
+    }
+
     switch (p->m_tcpart) {
     case BODY:
         err = atf_tp_run(tp, p->m_tcname, atf_fs_path_cstring(&p->m_resfile));
diff -r fe679b170a7d -r 12b58034e019 external/bsd/atf/dist/atf-c/detail/user_test.c
--- a/external/bsd/atf/dist/atf-c/detail/user_test.c    Tue Jun 14 15:23:19 2011 +0000
+++ b/external/bsd/atf/dist/atf-c/detail/user_test.c    Tue Jun 14 15:23:20 2011 +0000
@@ -64,6 +64,7 @@
     gid_t gids[NGROUPS_MAX];
     gid_t g, maxgid;
     int ngids;
+    const gid_t maxgid_limit = 1 << 16;
 
     {
         int i;
@@ -73,11 +74,18 @@
             atf_tc_fail("Call to getgroups failed");
         maxgid = 0;
         for (i = 0; i < ngids; i++) {
+            printf("User group %d is %u\n", i, gids[i]);
             if (maxgid < gids[i])
                 maxgid = gids[i];
         }
         printf("User belongs to %d groups\n", ngids);
-        printf("Last GID is %d\n", maxgid);
+        printf("Last GID is %u\n", maxgid);
+    }
+
+    if (maxgid > maxgid_limit) {
+        printf("Test truncated from %u groups to %u to keep the run time "
+               "reasonable enough\n", maxgid, maxgid_limit);
+        maxgid = maxgid_limit;
     }
 
     for (g = 0; g < maxgid; g++) {
diff -r fe679b170a7d -r 12b58034e019 external/bsd/atf/dist/atf-run/misc_helpers.cpp
--- a/external/bsd/atf/dist/atf-run/misc_helpers.cpp    Tue Jun 14 15:23:19 2011 +0000
+++ b/external/bsd/atf/dist/atf-run/misc_helpers.cpp    Tue Jun 14 15:23:20 2011 +0000
@@ -1,7 +1,7 @@
 //
 // Automated Testing Framework (atf)
 //
-// Copyright (c) 2007, 2008, 2010 The NetBSD Foundation, Inc.
+// Copyright (c) 2007, 2008, 2010, 2011 The NetBSD Foundation, Inc.
 // All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
@@ -66,6 +66,15 @@
 // Helper tests for "t_integration".
 // ------------------------------------------------------------------------
 
+ATF_TEST_CASE(pass);
+ATF_TEST_CASE_HEAD(pass)
+{
+    set_md_var("descr", "Helper test case for the t_integration test program");
+}
+ATF_TEST_CASE_BODY(pass)
+{
+}
+
 ATF_TEST_CASE(config);
 ATF_TEST_CASE_HEAD(config)
 {
@@ -166,6 +175,26 @@
     ATF_REQUIRE_EQ(fi1.get_inode(), fi2.get_inode());
 }
 
+ATF_TEST_CASE(read_stdin);
+ATF_TEST_CASE_HEAD(read_stdin)
+{
+    set_md_var("descr", "Helper test case for the t_integration test program");
+}
+ATF_TEST_CASE_BODY(read_stdin)
+{
+    char buf[100];
+    ssize_t len = ::read(STDIN_FILENO, buf, sizeof(buf) - 1);
+    ATF_REQUIRE(len != -1);
+
+    buf[len + 1] = '\0';
+    for (ssize_t i = 0; i < len; i++) {
+        if (buf[i] != '\0') {
+            fail("The stdin of the test case does not seem to be /dev/zero; "
+                 "got '" + std::string(buf) + "'");
+        }
+    }
+}
+
 ATF_TEST_CASE(umask);
 ATF_TEST_CASE_HEAD(umask)
 {
@@ -245,6 +274,16 @@
     std::cout << "var2: " << get_config_var("var2") << "\n";
 }
 
+ATF_TEST_CASE(require_files);
+ATF_TEST_CASE_HEAD(require_files)
+{
+    set_md_var("descr", "Helper test case for the t_integration test program");
+    set_md_var("require.files", get_config_var("files", "not-set"));
+}
+ATF_TEST_CASE_BODY(require_files)
+{
+}
+
 ATF_TEST_CASE(require_machine);
 ATF_TEST_CASE_HEAD(require_machine)
 {
@@ -337,6 +376,8 @@
     std::string which = atf::env::get("TESTCASE");
 
     // Add helper tests for t_integration.
+    if (which == "pass")
+        ATF_ADD_TEST_CASE(tcs, pass);
     if (which == "config")
         ATF_ADD_TEST_CASE(tcs, config);
     if (which == "fds")
@@ -349,6 +390,8 @@
         ATF_ADD_TEST_CASE(tcs, env_list);
     if (which == "env_home")
         ATF_ADD_TEST_CASE(tcs, env_home);
+    if (which == "read_stdin")
+        ATF_ADD_TEST_CASE(tcs, read_stdin);
     if (which == "umask")
         ATF_ADD_TEST_CASE(tcs, umask);
     if (which == "cleanup_states")
@@ -359,6 +402,8 @@
         ATF_ADD_TEST_CASE(tcs, require_arch);
     if (which == "require_config")
         ATF_ADD_TEST_CASE(tcs, require_config);
+    if (which == "require_files")
+        ATF_ADD_TEST_CASE(tcs, require_files);
     if (which == "require_machine")
         ATF_ADD_TEST_CASE(tcs, require_machine);
     if (which == "require_progs")
diff -r fe679b170a7d -r 12b58034e019 external/bsd/atf/dist/atf-run/requirements.cpp
--- a/external/bsd/atf/dist/atf-run/requirements.cpp    Tue Jun 14 15:23:19 2011 +0000
+++ b/external/bsd/atf/dist/atf-run/requirements.cpp    Tue Jun 14 15:23:20 2011 +0000
@@ -1,7 +1,7 @@
 //
 // Automated Testing Framework (atf)
 //
-// Copyright (c) 2007, 2008, 2009, 2010 The NetBSD Foundation, Inc.
+// Copyright (c) 2007, 2008, 2009, 2010, 2011 The NetBSD Foundation, Inc.
 // All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
@@ -106,6 +106,23 @@
 
 static
 std::string
+check_files(const std::string& progs)
+{
+    const std::vector< std::string > v = atf::text::split(progs, " ");
+    for (std::vector< std::string >::const_iterator iter = v.begin();
+         iter != v.end(); iter++) {
+        const atf::fs::path file(*iter);
+        if (!file.is_absolute())
+            throw std::runtime_error("Relative paths are not allowed when "
+                "checking for a required file (" + file.str() + ")");
+        if (!atf::fs::exists(file))
+            return "Required file '" + file.str() + "' not found";
+    }
+    return "";
+}
+
+static
+std::string
 check_machine(const std::string& machines)
 {
     const std::vector< std::string > v = atf::text::split(machines, " ");
@@ -186,6 +203,8 @@
             failure_reason = check_arch(value);
         else if (name == "require.config")
             failure_reason = check_config(value, config);
+        else if (name == "require.files")
+            failure_reason = check_files(value);
         else if (name == "require.machine")
             failure_reason = check_machine(value);
         else if (name == "require.progs")
diff -r fe679b170a7d -r 12b58034e019 external/bsd/atf/dist/atf-run/requirements_test.cpp
--- a/external/bsd/atf/dist/atf-run/requirements_test.cpp       Tue Jun 14 15:23:19 2011 +0000
+++ b/external/bsd/atf/dist/atf-run/requirements_test.cpp       Tue Jun 14 15:23:20 2011 +0000
@@ -1,7 +1,7 @@
 //
 // Automated Testing Framework (atf)
 //
-// Copyright (c) 2010 The NetBSD Foundation, Inc.
+// Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
 // All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
@@ -138,6 +138,54 @@
 }
 
 // -------------------------------------------------------------------------
+// Tests for the require.files metadata property.
+// -------------------------------------------------------------------------
+
+ATF_TEST_CASE_WITHOUT_HEAD(require_files_one_ok);
+ATF_TEST_CASE_BODY(require_files_one_ok) {
+    atf::tests::vars_map metadata;
+    metadata["require.files"] = "/bin/ls";
+    do_check("", metadata);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(require_files_one_missing);
+ATF_TEST_CASE_BODY(require_files_one_missing) {
+    atf::tests::vars_map metadata;
+    metadata["require.files"] = "/non-existent/foo";
+    do_check("Required file '/non-existent/foo' not found", metadata);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(require_files_one_fail);
+ATF_TEST_CASE_BODY(require_files_one_fail) {
+    atf::tests::vars_map metadata;
+    metadata["require.files"] = "/bin/cp this-is-relative";
+    ATF_REQUIRE_THROW_RE(std::runtime_error, "Relative.*(this-is-relative)",
+                         impl::check_requirements(metadata, no_config));
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(require_files_many_ok);
+ATF_TEST_CASE_BODY(require_files_many_ok) {
+    atf::tests::vars_map metadata;
+    metadata["require.files"] = "/bin/ls /bin/cp";
+    do_check("", metadata);



Home | Main Index | Thread Index | Old Index