summaryrefslogtreecommitdiff
path: root/src/mongo/util/processinfo_test.cpp
diff options
context:
space:
mode:
authorAndrea Lattuada <andrea.lattuada@10gen.com>2012-11-13 16:34:57 -0500
committerAndrea Lattuada <andrea.lattuada@10gen.com>2012-11-13 16:34:57 -0500
commitfe38a5e9f8a06e0db57e89b97b9af1bfb789bff0 (patch)
tree50040a8c9e217f6389c4a170e3e3b6d43e2ef55e /src/mongo/util/processinfo_test.cpp
parent93fdafcb4c4883d401a0726b67f2141404daa9ee (diff)
downloadmongo-fe38a5e9f8a06e0db57e89b97b9af1bfb789bff0.tar.gz
SERVER-7570 changed ProcessInfo::blockInMemory to leverage getPageSize, added pagesInMemory
Diffstat (limited to 'src/mongo/util/processinfo_test.cpp')
-rw-r--r--src/mongo/util/processinfo_test.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/util/processinfo_test.cpp b/src/mongo/util/processinfo_test.cpp
index 2d13c1861fd..fbf20abdd0b 100644
--- a/src/mongo/util/processinfo_test.cpp
+++ b/src/mongo/util/processinfo_test.cpp
@@ -14,6 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <vector>
+
+#include "boost/scoped_array.hpp"
+
#include "mongo/unittest/unittest.h"
#include "mongo/util/processinfo.h"
@@ -26,4 +30,38 @@ namespace mongo_test {
ASSERT_FALSE(processInfo.getOsType().empty());
}
}
+
+ TEST(ProcessInfo, NonZeroPageSize) {
+ if (ProcessInfo::blockCheckSupported()) {
+ ASSERT_GREATER_THAN(ProcessInfo::getPageSize(), 0u);
+ }
+ }
+
+ const size_t PAGES = 10;
+
+ TEST(ProcessInfo, BlockInMemoryDoesNotThrowIfSupported) {
+ if (ProcessInfo::blockCheckSupported()) {
+ boost::scoped_array<char> ptr(new char[ProcessInfo::getPageSize() * PAGES]);
+ ProcessInfo::blockInMemory(ptr.get() + ProcessInfo::getPageSize() * 2);
+ }
+ }
+
+ TEST(ProcessInfo, PagesInMemoryIsSensible) {
+ if (ProcessInfo::blockCheckSupported()) {
+ static volatile char ptr[4096 * PAGES];
+ ptr[1] = 'a';
+ std::vector<char> result;
+ ASSERT_TRUE(ProcessInfo::pagesInMemory(const_cast<char*>(ptr), PAGES, &result));
+ ASSERT_TRUE(result[0]);
+ ASSERT_FALSE(result[1]);
+ ASSERT_FALSE(result[2]);
+ ASSERT_FALSE(result[3]);
+ ASSERT_FALSE(result[4]);
+ ASSERT_FALSE(result[5]);
+ ASSERT_FALSE(result[6]);
+ ASSERT_FALSE(result[7]);
+ ASSERT_FALSE(result[8]);
+ ASSERT_FALSE(result[9]);
+ }
+ }
}