< prev index next >

test/native/runtime/test_arguments.cpp

Print this page




 135  );
 136 }
 137 
 138 // A random value - used to verify the output when parsing is expected to fail.
 139 static const intx no_value = 4711;
 140 
 141 inline intx ArgumentsTest::parse_xss_inner_annotated(const char* str, jint expected_err, const char* file, int line_number) {
 142   intx value = no_value;
 143   jint err = parse_xss(NULL /* Silence error messages */, str, &value);
 144   EXPECT_EQ(err, expected_err) << "Failure from: " << file << ":" << line_number;
 145   return value;
 146 }
 147 
 148 // Wrapper around the help function - gives file and line number when a test failure occurs.
 149 #define parse_xss_inner(str, expected_err) ArgumentsTest::parse_xss_inner_annotated(str, expected_err, __FILE__, __LINE__)
 150 
 151 static intx calc_expected(julong small_xss_input) {
 152   assert(small_xss_input <= max_julong / 2, "Sanity");
 153 
 154   // Match code in arguments.cpp
 155   julong julong_ret = align_size_up_(small_xss_input, K) / K;
 156   assert(julong_ret <= (julong)max_intx, "Overflow: " JULONG_FORMAT, julong_ret);
 157   return (intx)julong_ret;
 158 }
 159 
 160 static char buff[100];
 161 static char* to_string(julong value) {
 162   jio_snprintf(buff, sizeof(buff), JULONG_FORMAT, value);
 163   return buff;
 164 }
 165 
 166 TEST_VM_F(ArgumentsTest, parse_xss) {
 167   // Test the maximum input value - should fail.
 168   {
 169     EXPECT_EQ(parse_xss_inner(to_string(max_julong), JNI_EINVAL), no_value);
 170     NOT_LP64(EXPECT_EQ(parse_xss_inner(to_string(max_uintx), JNI_EINVAL), no_value));
 171   }
 172 
 173   // Test values "far" away from the uintx boundary,
 174   // but still beyond the max limit.
 175   {
 176     LP64_ONLY(EXPECT_EQ(parse_xss_inner(to_string(max_julong / 2), JNI_EINVAL), no_value));
 177     EXPECT_EQ(parse_xss_inner(to_string(INT_MAX),     JNI_EINVAL), no_value);
 178   }
 179 
 180   // Test at and around the max limit.
 181   {
 182     EXPECT_EQ(parse_xss_inner(to_string(1 * M * K - 1), JNI_OK), calc_expected(1 * M * K - 1));
 183     EXPECT_EQ(parse_xss_inner(to_string(1 * M * K),     JNI_OK), calc_expected(1 * M * K));
 184     EXPECT_EQ(parse_xss_inner(to_string(1 * M * K + 1), JNI_EINVAL), no_value);
 185   }
 186 
 187   // Test value aligned both to K and vm_page_size.
 188   {
 189     EXPECT_TRUE(is_size_aligned(32 * M, K));
 190     EXPECT_TRUE(is_size_aligned(32 * M, (size_t)os::vm_page_size()));
 191     EXPECT_EQ(parse_xss_inner(to_string(32 * M), JNI_OK), (intx)(32 * M / K));
 192   }
 193 
 194   // Test around the min limit.
 195   {
 196     EXPECT_EQ(parse_xss_inner(to_string(0),     JNI_OK), calc_expected(0));
 197     EXPECT_EQ(parse_xss_inner(to_string(1),     JNI_OK), calc_expected(1));
 198     EXPECT_EQ(parse_xss_inner(to_string(K - 1), JNI_OK), calc_expected(K - 1));
 199     EXPECT_EQ(parse_xss_inner(to_string(K),     JNI_OK), calc_expected(K));
 200     EXPECT_EQ(parse_xss_inner(to_string(K + 1), JNI_OK), calc_expected(K + 1));
 201   }
 202 }


 135  );
 136 }
 137 
 138 // A random value - used to verify the output when parsing is expected to fail.
 139 static const intx no_value = 4711;
 140 
 141 inline intx ArgumentsTest::parse_xss_inner_annotated(const char* str, jint expected_err, const char* file, int line_number) {
 142   intx value = no_value;
 143   jint err = parse_xss(NULL /* Silence error messages */, str, &value);
 144   EXPECT_EQ(err, expected_err) << "Failure from: " << file << ":" << line_number;
 145   return value;
 146 }
 147 
 148 // Wrapper around the help function - gives file and line number when a test failure occurs.
 149 #define parse_xss_inner(str, expected_err) ArgumentsTest::parse_xss_inner_annotated(str, expected_err, __FILE__, __LINE__)
 150 
 151 static intx calc_expected(julong small_xss_input) {
 152   assert(small_xss_input <= max_julong / 2, "Sanity");
 153 
 154   // Match code in arguments.cpp
 155   julong julong_ret = align_up_(small_xss_input, K) / K;
 156   assert(julong_ret <= (julong)max_intx, "Overflow: " JULONG_FORMAT, julong_ret);
 157   return (intx)julong_ret;
 158 }
 159 
 160 static char buff[100];
 161 static char* to_string(julong value) {
 162   jio_snprintf(buff, sizeof(buff), JULONG_FORMAT, value);
 163   return buff;
 164 }
 165 
 166 TEST_VM_F(ArgumentsTest, parse_xss) {
 167   // Test the maximum input value - should fail.
 168   {
 169     EXPECT_EQ(parse_xss_inner(to_string(max_julong), JNI_EINVAL), no_value);
 170     NOT_LP64(EXPECT_EQ(parse_xss_inner(to_string(max_uintx), JNI_EINVAL), no_value));
 171   }
 172 
 173   // Test values "far" away from the uintx boundary,
 174   // but still beyond the max limit.
 175   {
 176     LP64_ONLY(EXPECT_EQ(parse_xss_inner(to_string(max_julong / 2), JNI_EINVAL), no_value));
 177     EXPECT_EQ(parse_xss_inner(to_string(INT_MAX),     JNI_EINVAL), no_value);
 178   }
 179 
 180   // Test at and around the max limit.
 181   {
 182     EXPECT_EQ(parse_xss_inner(to_string(1 * M * K - 1), JNI_OK), calc_expected(1 * M * K - 1));
 183     EXPECT_EQ(parse_xss_inner(to_string(1 * M * K),     JNI_OK), calc_expected(1 * M * K));
 184     EXPECT_EQ(parse_xss_inner(to_string(1 * M * K + 1), JNI_EINVAL), no_value);
 185   }
 186 
 187   // Test value aligned both to K and vm_page_size.
 188   {
 189     EXPECT_TRUE(is_aligned(32 * M, K));
 190     EXPECT_TRUE(is_aligned(32 * M, (size_t)os::vm_page_size()));
 191     EXPECT_EQ(parse_xss_inner(to_string(32 * M), JNI_OK), (intx)(32 * M / K));
 192   }
 193 
 194   // Test around the min limit.
 195   {
 196     EXPECT_EQ(parse_xss_inner(to_string(0),     JNI_OK), calc_expected(0));
 197     EXPECT_EQ(parse_xss_inner(to_string(1),     JNI_OK), calc_expected(1));
 198     EXPECT_EQ(parse_xss_inner(to_string(K - 1), JNI_OK), calc_expected(K - 1));
 199     EXPECT_EQ(parse_xss_inner(to_string(K),     JNI_OK), calc_expected(K));
 200     EXPECT_EQ(parse_xss_inner(to_string(K + 1), JNI_OK), calc_expected(K + 1));
 201   }
 202 }
< prev index next >