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 PR/45619: jmmv: Allow atf tests to req...



details:   https://anonhg.NetBSD.org/src/rev/ca2ac5ff7940
branches:  trunk
changeset: 771250:ca2ac5ff7940
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 16 17:46:16 2011 +0000

description:
PR/45619: jmmv: Allow atf tests to request a minimum amount of memory

diffstat:

 external/bsd/atf/dist/atf-c++/detail/text.cpp  |  10 ++++++
 external/bsd/atf/dist/atf-c++/detail/text.hpp  |   7 ++++
 external/bsd/atf/dist/atf-run/requirements.cpp |  40 ++++++++++++++++++++++++++
 external/bsd/atf/dist/atf-run/test-program.cpp |   7 ++++
 4 files changed, 64 insertions(+), 0 deletions(-)

diffs (129 lines):

diff -r 6eac7c088d55 -r ca2ac5ff7940 external/bsd/atf/dist/atf-c++/detail/text.cpp
--- a/external/bsd/atf/dist/atf-c++/detail/text.cpp     Wed Nov 16 17:28:10 2011 +0000
+++ b/external/bsd/atf/dist/atf-c++/detail/text.cpp     Wed Nov 16 17:46:16 2011 +0000
@@ -33,6 +33,7 @@
 
 #include <cctype>
 #include <cstring>
+#include <cstdlib>
 
 extern "C" {
 #include "../../atf-c/error.h"
@@ -133,3 +134,12 @@
 
     return b;
 }
+
+int64_t
+impl::to_number(const std::string& str)
+{
+       int64_t num;
+       ::dehumanize_number(str.c_str(), &num);
+       return num;
+}
+    
diff -r 6eac7c088d55 -r ca2ac5ff7940 external/bsd/atf/dist/atf-c++/detail/text.hpp
--- a/external/bsd/atf/dist/atf-c++/detail/text.hpp     Wed Nov 16 17:28:10 2011 +0000
+++ b/external/bsd/atf/dist/atf-c++/detail/text.hpp     Wed Nov 16 17:46:16 2011 +0000
@@ -106,6 +106,13 @@
 std::string to_lower(const std::string&);
 
 //!
+//! \brief Converts the given string to a number
+//!
+//! The string should be of the form ^[0-9]+[KMGT]$ or ^[0-9]$
+//!
+int64_t to_number(const std::string&);
+
+//!
 //! \brief Converts the given object to a string.
 //!
 //! Returns a string with the representation of the given object.  There
diff -r 6eac7c088d55 -r ca2ac5ff7940 external/bsd/atf/dist/atf-run/requirements.cpp
--- a/external/bsd/atf/dist/atf-run/requirements.cpp    Wed Nov 16 17:28:10 2011 +0000
+++ b/external/bsd/atf/dist/atf-run/requirements.cpp    Wed Nov 16 17:46:16 2011 +0000
@@ -29,6 +29,14 @@
 
 // TODO: We probably don't want to raise std::runtime_error for the errors
 // detected in this file.
+extern "C" {
+#include <sys/param.h>
+#include <sys/sysctl.h>
+};
+
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
 #include <stdexcept>
 
 #include "atf-c++/config.hpp"
@@ -185,6 +193,36 @@
                                  "require.user");
 }
 
+static
+std::string
+check_memory(const std::string& memory)
+{
+    // Make sure we have enough memory 
+    int64_t memneed = atf::text::to_number(memory);
+    int64_t memavail;
+    size_t len = sizeof(memavail);
+
+    if (::sysctlbyname("hw.usermem64", &memavail, &len, NULL, 0) == -1) {
+       const char *e = ::strerror(errno);
+       std::stringstream ss;
+       ss << "sysctl hw.usermem64 failed (" << e << ")";
+       return ss.str();
+    }
+
+    if (memavail < memneed) {
+       char avail[6], need[6];
+       ::humanize_number(avail, sizeof(avail), memavail, "", HN_AUTOSCALE,
+           HN_B | HN_NOSPACE);
+       ::humanize_number(need, sizeof(need), memneed, "", HN_AUTOSCALE,
+           HN_B | HN_NOSPACE);
+       std::stringstream ss;
+       ss << "available memory (" << avail <<
+           ") is less than required (" << need << ")";
+       return ss.str();
+    }
+    return "";
+}
+
 } // anonymous namespace
 
 std::string
@@ -211,6 +249,8 @@
             failure_reason = check_progs(value);
         else if (name == "require.user")
             failure_reason = check_user(value, config);
+       else if (name == "require.memory")
+            failure_reason = check_memory(value);
         else {
             // Unknown require.* properties are forbidden by the
             // application/X-atf-tp parser.
diff -r 6eac7c088d55 -r ca2ac5ff7940 external/bsd/atf/dist/atf-run/test-program.cpp
--- a/external/bsd/atf/dist/atf-run/test-program.cpp    Wed Nov 16 17:28:10 2011 +0000
+++ b/external/bsd/atf/dist/atf-run/test-program.cpp    Wed Nov 16 17:46:16 2011 +0000
@@ -418,6 +418,7 @@
 
     const std::string ident_regex = "^[_A-Za-z0-9]+$";
     const std::string integer_regex = "^[0-9]+$";
+    const std::string memory_regex = "^[0-9]+[KMGT]$";
 
     if (name == "descr") {
         // Any non-empty value is valid.
@@ -438,6 +439,12 @@
     } else if (name == "require.machine") {
     } else if (name == "require.progs") {
     } else if (name == "require.user") {
+    } else if (name == "require.memory") {
+        if (!atf::text::match(value, integer_regex) &&
+           !atf::text::match(value, memory_regex))
+            throw parse_error(lineno, "The require.memory property requires"
+                             " an integer value or a string of the form"
+                             " <number>[KMGT]");
     } else if (name == "timeout") {
         if (!atf::text::match(value, integer_regex))
             throw parse_error(lineno, "The timeout property requires an integer"



Home | Main Index | Thread Index | Old Index