20 #include <gtest/gtest.h>
30 TEST(ParseMemSpecs, Basic) {
34 int64_t megabytes = 1024 * 1024;
35 int64_t gigabytes = 1024 * megabytes;
39 ASSERT_FALSE(is_percent);
42 ASSERT_EQ(100, bytes);
43 ASSERT_FALSE(is_percent);
46 ASSERT_EQ(4 * megabytes, bytes);
47 ASSERT_FALSE(is_percent);
50 ASSERT_EQ(4 * megabytes, bytes);
51 ASSERT_FALSE(is_percent);
54 ASSERT_EQ(8 * gigabytes, bytes);
55 ASSERT_FALSE(is_percent);
58 ASSERT_EQ(8 * gigabytes, bytes);
59 ASSERT_FALSE(is_percent);
62 ASSERT_EQ(12 * gigabytes, bytes);
63 ASSERT_FALSE(is_percent);
67 ASSERT_TRUE(is_percent);
71 ASSERT_TRUE(is_percent);
73 vector<string> bad_values;
74 bad_values.push_back(
"1gib");
75 bad_values.push_back(
"1%b");
76 bad_values.push_back(
"1b%");
77 bad_values.push_back(
"gb");
78 bad_values.push_back(
"1GMb");
79 bad_values.push_back(
"1b1Mb");
80 bad_values.push_back(
"1Bb");
81 bad_values.push_back(
"1%%");
82 bad_values.push_back(
"1.1");
85 bad_values.push_back(ss.str());
86 bad_values.push_back(
"%");
87 for (vector<string>::iterator it = bad_values.begin(); it != bad_values.end(); it++) {
107 int main(
int argc,
char **argv) {
109 ::testing::InitGoogleTest(&argc, argv);
110 return RUN_ALL_TESTS();
static int64_t physical_mem()
Get total physical memory in bytes (ignores cgroups memory limits).
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
static int64_t ParseMemSpec(const std::string &mem_spec_str, bool *is_percent, int64_t relative_reference)
int main(int argc, char **argv)