/* * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// Wrapper around the help function - gives file and line number when a test failure occurs. #define parse_xss_inner(str, expected_err) ArgumentsTest::parse_xss_inner_annotated(str, expected_err, __FILE__, __LINE__)
TEST_VM_F(ArgumentsTest, parse_xss) { // Test the maximum input value - should fail.
{
EXPECT_EQ(parse_xss_inner(to_string(max_julong), JNI_EINVAL), no_value);
NOT_LP64(EXPECT_EQ(parse_xss_inner(to_string(max_uintx), JNI_EINVAL), no_value));
}
// Test values "far" away from the uintx boundary, // but still beyond the max limit.
{
LP64_ONLY(EXPECT_EQ(parse_xss_inner(to_string(max_julong / 2), JNI_EINVAL), no_value));
EXPECT_EQ(parse_xss_inner(to_string(INT_MAX), JNI_EINVAL), no_value);
}
// Test at and around the max limit.
{
EXPECT_EQ(parse_xss_inner(to_string(1 * M * K - 1), JNI_OK), calc_expected(1 * M * K - 1));
EXPECT_EQ(parse_xss_inner(to_string(1 * M * K), JNI_OK), calc_expected(1 * M * K));
EXPECT_EQ(parse_xss_inner(to_string(1 * M * K + 1), JNI_EINVAL), no_value);
}
// Test value aligned both to K and vm_page_size.
{
EXPECT_TRUE(is_aligned(32 * M, K));
EXPECT_TRUE(is_aligned(32 * M, (size_t)os::vm_page_size()));
EXPECT_EQ(parse_xss_inner(to_string(32 * M), JNI_OK), (intx)(32 * M / K));
}
// Test around the min limit.
{
EXPECT_EQ(parse_xss_inner(to_string(0), JNI_OK), calc_expected(0));
EXPECT_EQ(parse_xss_inner(to_string(1), JNI_OK), calc_expected(1));
EXPECT_EQ(parse_xss_inner(to_string(K - 1), JNI_OK), calc_expected(K - 1));
EXPECT_EQ(parse_xss_inner(to_string(K), JNI_OK), calc_expected(K));
EXPECT_EQ(parse_xss_inner(to_string(K + 1), JNI_OK), calc_expected(K + 1));
}
}
// signed 32-bit template <typename T, ENABLE_IF(std::is_signed<T>::value), ENABLE_IF(sizeof(T) == 4)> void check_flag(constchar* f, T getvalue(JVMFlag* flag)) {
JVMFlag* flag = JVMFlag::find_flag(f); if (flag == NULL) { // not available in product builds return;
}
T k = static_cast<T>(K);
T m = static_cast<T>(M);
T g = static_cast<T>(G);
NumericArgument<T> valid_strings[] = { INTEGER_TEST_TABLE(INTEGER_TEST_i32) };
check_numeric_flag(flag, getvalue, valid_strings, ARRAY_SIZE(valid_strings));
}
// unsigned 32-bit template <typename T, ENABLE_IF(!std::is_signed<T>::value), ENABLE_IF(sizeof(T) == 4)> void check_flag(constchar* f, T getvalue(JVMFlag* flag)) {
JVMFlag* flag = JVMFlag::find_flag(f); if (flag == NULL) { // not available in product builds return;
}
T k = static_cast<T>(K);
T m = static_cast<T>(M);
T g = static_cast<T>(G);
NumericArgument<T> valid_strings[] = { INTEGER_TEST_TABLE(INTEGER_TEST_u32) };
check_numeric_flag(flag, getvalue, valid_strings, ARRAY_SIZE(valid_strings));
}
// signed 64-bit template <typename T, ENABLE_IF(std::is_signed<T>::value), ENABLE_IF(sizeof(T) == 8)> void check_flag(constchar* f, T getvalue(JVMFlag* flag)) {
JVMFlag* flag = JVMFlag::find_flag(f); if (flag == NULL) { // not available in product builds return;
}
T k = static_cast<T>(K);
T m = static_cast<T>(M);
T g = static_cast<T>(G);
T t = static_cast<T>(G) * k;
NumericArgument<T> valid_strings[] = { INTEGER_TEST_TABLE(INTEGER_TEST_i64) };
check_numeric_flag(flag, getvalue, valid_strings, ARRAY_SIZE(valid_strings));
}
// unsigned 64-bit template <typename T, ENABLE_IF(!std::is_signed<T>::value), ENABLE_IF(sizeof(T) == 8)> void check_flag(constchar* f, T getvalue(JVMFlag* flag)) {
JVMFlag* flag = JVMFlag::find_flag(f); if (flag == NULL) { // not available in product builds return;
}
T k = static_cast<T>(K);
T m = static_cast<T>(M);
T g = static_cast<T>(G);
T t = static_cast<T>(G) * k;
NumericArgument<T> valid_strings[] = { INTEGER_TEST_TABLE(INTEGER_TEST_u64) };
check_numeric_flag(flag, getvalue, valid_strings, ARRAY_SIZE(valid_strings));
}
// Testing the parsing of -XX:<SomeFlag>=<an integer value> // // All of the integral types that can be used for command line options: // int, uint, intx, uintx, uint64_t, size_t // // In all supported platforms, these types can be mapped to only 4 native types: // {signed, unsigned} x {32-bit, 64-bit} // // We use SFINAE to pick the correct column in the INTEGER_TEST_TABLE for each type.
TEST_VM_F(ArgumentsTest, set_numeric_flag_double) {
JVMFlag* flag = JVMFlag::find_flag("TestFlagFor_double"); if (flag == NULL) { // not available in product builds return;
}
constchar* more_test_strings[] = { // These examples are from https://en.cppreference.com/w/cpp/language/floating_literal // (but with the L and F suffix removed). "1e10", "1e-5", "1.e-2", "3.14", ".1", "0.1e-1", "0x1ffp10", "0X0p-1", "0x1.p0", "0xf.p-1", "0x0.123p-1", "0xa.bp10", "0x1.4p3",
// More test cases "1.5", "6.02e23", "-6.02e+23", "1.7976931348623157E+308", // max double "-0", "0", "0x1.91eb85p+1", "999999999999999999999999999999",
}; for (uint i = 0; i < ARRAY_SIZE(more_test_strings); i++) { constchar* str = more_test_strings[i];
char* end;
errno = 0; double expected = strtod(str, &end); if (errno == 0 && end != NULL && *end == '\0') {
ASSERT_TRUE(ArgumentsTest::parse_argument(flag->name(), str))
<< "Test string '" <<
str << "' did not parse for type " << flag->type_string() << ". (Expected value = " << expected << ")"; double d = flag->get_double();
ASSERT_TRUE(d == expected)
<< "Parsed number " << d << " is not the same as expected " << expected;
} else { // Some of the strings like "1.e-2" are not valid in certain locales. // The decimal-point character is also locale dependent.
ASSERT_FALSE(ArgumentsTest::parse_argument(flag->name(), str))
<< "Invalid string '" << str << "' parsed without error.";
}
}
}
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.