Module Name: src
Committed By: christos
Date: Wed Nov 16 17:46:16 UTC 2011
Modified Files:
src/external/bsd/atf/dist/atf-c++/detail: text.cpp text.hpp
src/external/bsd/atf/dist/atf-run: requirements.cpp test-program.cpp
Log Message:
PR/45619: jmmv: Allow atf tests to request a minimum amount of memory
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 \
src/external/bsd/atf/dist/atf-c++/detail/text.cpp \
src/external/bsd/atf/dist/atf-c++/detail/text.hpp
cvs rdiff -u -r1.1.1.4 -r1.2 \
src/external/bsd/atf/dist/atf-run/requirements.cpp
cvs rdiff -u -r1.10 -r1.11 src/external/bsd/atf/dist/atf-run/test-program.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/atf-c++/detail/text.cpp
diff -u src/external/bsd/atf/dist/atf-c++/detail/text.cpp:1.1.1.1 src/external/bsd/atf/dist/atf-c++/detail/text.cpp:1.2
--- src/external/bsd/atf/dist/atf-c++/detail/text.cpp:1.1.1.1 Wed Oct 20 05:14:21 2010
+++ src/external/bsd/atf/dist/atf-c++/detail/text.cpp Wed Nov 16 12:46:16 2011
@@ -33,6 +33,7 @@ extern "C" {
#include <cctype>
#include <cstring>
+#include <cstdlib>
extern "C" {
#include "../../atf-c/error.h"
@@ -133,3 +134,12 @@ impl::to_bool(const std::string& str)
return b;
}
+
+int64_t
+impl::to_number(const std::string& str)
+{
+ int64_t num;
+ ::dehumanize_number(str.c_str(), &num);
+ return num;
+}
+
Index: src/external/bsd/atf/dist/atf-c++/detail/text.hpp
diff -u src/external/bsd/atf/dist/atf-c++/detail/text.hpp:1.1.1.1 src/external/bsd/atf/dist/atf-c++/detail/text.hpp:1.2
--- src/external/bsd/atf/dist/atf-c++/detail/text.hpp:1.1.1.1 Wed Oct 20 05:14:21 2010
+++ src/external/bsd/atf/dist/atf-c++/detail/text.hpp Wed Nov 16 12:46:16 2011
@@ -106,6 +106,13 @@ bool to_bool(const std::string&);
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
Index: src/external/bsd/atf/dist/atf-run/requirements.cpp
diff -u src/external/bsd/atf/dist/atf-run/requirements.cpp:1.1.1.4 src/external/bsd/atf/dist/atf-run/requirements.cpp:1.2
--- src/external/bsd/atf/dist/atf-run/requirements.cpp:1.1.1.4 Tue Jun 14 11:23:24 2011
+++ src/external/bsd/atf/dist/atf-run/requirements.cpp Wed Nov 16 12:46:16 2011
@@ -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 @@ check_user(const std::string& user, cons
"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 @@ impl::check_requirements(const atf::test
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.
Index: src/external/bsd/atf/dist/atf-run/test-program.cpp
diff -u src/external/bsd/atf/dist/atf-run/test-program.cpp:1.10 src/external/bsd/atf/dist/atf-run/test-program.cpp:1.11
--- src/external/bsd/atf/dist/atf-run/test-program.cpp:1.10 Wed Jun 15 04:48:36 2011
+++ src/external/bsd/atf/dist/atf-run/test-program.cpp Wed Nov 16 12:46:16 2011
@@ -418,6 +418,7 @@ detail::atf_tp_reader::validate_and_inse
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 @@ detail::atf_tp_reader::validate_and_inse
} 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"