1414 *    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
1515 */  
1616
17+ #include  < vector> 
18+ 
19+ #include  " boost/scoped_array.hpp" 
20+ 
1721#include  " mongo/unittest/unittest.h" 
1822#include  " mongo/util/processinfo.h" 
1923
@@ -26,4 +30,38 @@ namespace mongo_test {
2630            ASSERT_FALSE (processInfo.getOsType ().empty ());
2731        }
2832    }
33+ 
34+     TEST (ProcessInfo, NonZeroPageSize) {
35+         if  (ProcessInfo::blockCheckSupported ()) {
36+             ASSERT_GREATER_THAN (ProcessInfo::getPageSize (), 0u );
37+         }
38+     }
39+ 
40+     const  size_t  PAGES = 10 ;
41+ 
42+     TEST (ProcessInfo, BlockInMemoryDoesNotThrowIfSupported) {
43+         if  (ProcessInfo::blockCheckSupported ()) {
44+             boost::scoped_array<char > ptr (new  char [ProcessInfo::getPageSize () * PAGES]);
45+             ProcessInfo::blockInMemory (ptr.get () + ProcessInfo::getPageSize () * 2 );
46+         }
47+     }
48+ 
49+     TEST (ProcessInfo, PagesInMemoryIsSensible) {
50+         if  (ProcessInfo::blockCheckSupported ()) {
51+             static  volatile  char  ptr[4096  * PAGES];
52+             ptr[1 ] = ' a'  ;
53+             std::vector<char > result;
54+             ASSERT_TRUE (ProcessInfo::pagesInMemory (const_cast <char *>(ptr), PAGES, &result));
55+             ASSERT_TRUE (result[0 ]);
56+             ASSERT_FALSE (result[1 ]);
57+             ASSERT_FALSE (result[2 ]);
58+             ASSERT_FALSE (result[3 ]);
59+             ASSERT_FALSE (result[4 ]);
60+             ASSERT_FALSE (result[5 ]);
61+             ASSERT_FALSE (result[6 ]);
62+             ASSERT_FALSE (result[7 ]);
63+             ASSERT_FALSE (result[8 ]);
64+             ASSERT_FALSE (result[9 ]);
65+         }
66+     }
2967}
0 commit comments