Commit a9ca9f7d authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/test-flags to unittests/flags/

... flag-definitions-unittest.

Bug: v8:12781
Change-Id: I11cd6acc4d7c548773f013fcaf5a2de5b47d730b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3682879Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80889}
parent a11fac26
...@@ -194,7 +194,6 @@ v8_source_set("cctest_sources") { ...@@ -194,7 +194,6 @@ v8_source_set("cctest_sources") {
"test-feedback-vector.cc", "test-feedback-vector.cc",
"test-feedback-vector.h", "test-feedback-vector.h",
"test-field-type-tracking.cc", "test-field-type-tracking.cc",
"test-flags.cc",
"test-func-name-inference.cc", "test-func-name-inference.cc",
"test-global-handles.cc", "test-global-handles.cc",
"test-global-object.cc", "test-global-object.cc",
......
...@@ -334,6 +334,7 @@ v8_source_set("unittests_sources") { ...@@ -334,6 +334,7 @@ v8_source_set("unittests_sources") {
"diagnostics/gdb-jit-unittest.cc", "diagnostics/gdb-jit-unittest.cc",
"execution/microtask-queue-unittest.cc", "execution/microtask-queue-unittest.cc",
"execution/threads-unittest.cc", "execution/threads-unittest.cc",
"flags/flag-definitions-unittest.cc",
"gay-fixed.cc", "gay-fixed.cc",
"gay-fixed.h", "gay-fixed.h",
"gay-precision.cc", "gay-precision.cc",
......
...@@ -29,39 +29,43 @@ ...@@ -29,39 +29,43 @@
#include "src/flags/flags.h" #include "src/flags/flags.h"
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/cctest.h" #include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// This test must be executed first! using FlagsTest = ::testing::Test;
TEST(Default) {
void TestDefault() {
CHECK(FLAG_testing_bool_flag); CHECK(FLAG_testing_bool_flag);
CHECK_EQ(13, FLAG_testing_int_flag); CHECK_EQ(13, FLAG_testing_int_flag);
CHECK_EQ(2.5, FLAG_testing_float_flag); CHECK_EQ(2.5, FLAG_testing_float_flag);
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "Hello, world!")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "Hello, world!"));
} }
// This test must be executed first!
TEST_F(FlagsTest, Default) { TestDefault(); }
static void SetFlagsToDefault() { static void SetFlagsToDefault() {
FlagList::ResetAllFlags(); FlagList::ResetAllFlags();
TestDefault(); TestDefault();
} }
TEST_F(FlagsTest, Flags1) { FlagList::PrintHelp(); }
TEST(Flags1) { TEST_F(FlagsTest, Flags2) {
FlagList::PrintHelp();
}
TEST(Flags2) {
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 8; int argc = 8;
const char* argv[] = { "Test2", "-notesting-bool-flag", const char* argv[] = {"Test2",
"--notesting-maybe-bool-flag", "notaflag", "-notesting-bool-flag",
"--testing_int_flag=77", "-testing_float_flag=.25", "--notesting-maybe-bool-flag",
"--testing_string_flag", "no way!" }; "notaflag",
CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, "--testing_int_flag=77",
const_cast<char **>(argv), "-testing_float_flag=.25",
"--testing_string_flag",
"no way!"};
CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv),
false)); false));
CHECK_EQ(8, argc); CHECK_EQ(8, argc);
CHECK(!FLAG_testing_bool_flag); CHECK(!FLAG_testing_bool_flag);
...@@ -72,8 +76,7 @@ TEST(Flags2) { ...@@ -72,8 +76,7 @@ TEST(Flags2) {
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!"));
} }
TEST_F(FlagsTest, Flags2b) {
TEST(Flags2b) {
SetFlagsToDefault(); SetFlagsToDefault();
const char* str = const char* str =
" -notesting-bool-flag notaflag --testing_int_flag=77 " " -notesting-bool-flag notaflag --testing_int_flag=77 "
...@@ -89,16 +92,19 @@ TEST(Flags2b) { ...@@ -89,16 +92,19 @@ TEST(Flags2b) {
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!"));
} }
TEST_F(FlagsTest, Flags3) {
TEST(Flags3) {
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 9; int argc = 9;
const char* argv[] = const char* argv[] = {"Test3",
{ "Test3", "--testing_bool_flag", "--testing-maybe-bool-flag", "notaflag", "--testing_bool_flag",
"--testing_int_flag", "-666", "--testing-maybe-bool-flag",
"--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" }; "notaflag",
CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, "--testing_int_flag",
const_cast<char **>(argv), "-666",
"--testing_float_flag",
"-12E10",
"-testing-string-flag=foo-bar"};
CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv),
true)); true));
CHECK_EQ(2, argc); CHECK_EQ(2, argc);
CHECK(FLAG_testing_bool_flag); CHECK(FLAG_testing_bool_flag);
...@@ -109,8 +115,7 @@ TEST(Flags3) { ...@@ -109,8 +115,7 @@ TEST(Flags3) {
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
} }
TEST_F(FlagsTest, Flags3b) {
TEST(Flags3b) {
SetFlagsToDefault(); SetFlagsToDefault();
const char* str = const char* str =
"--testing_bool_flag --testing-maybe-bool-flag notaflag " "--testing_bool_flag --testing-maybe-bool-flag notaflag "
...@@ -126,77 +131,67 @@ TEST(Flags3b) { ...@@ -126,77 +131,67 @@ TEST(Flags3b) {
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
} }
TEST_F(FlagsTest, Flags4) {
TEST(Flags4) {
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 3; int argc = 3;
const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" }; const char* argv[] = {"Test4", "--testing_bool_flag", "--foo"};
CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv),
const_cast<char **>(argv),
true)); true));
CHECK_EQ(2, argc); CHECK_EQ(2, argc);
CHECK(!FLAG_testing_maybe_bool_flag.has_value); CHECK(!FLAG_testing_maybe_bool_flag.has_value);
} }
TEST_F(FlagsTest, Flags4b) {
TEST(Flags4b) {
SetFlagsToDefault(); SetFlagsToDefault();
const char* str = "--testing_bool_flag --foo"; const char* str = "--testing_bool_flag --foo";
CHECK_EQ(2, FlagList::SetFlagsFromString(str, strlen(str))); CHECK_EQ(2, FlagList::SetFlagsFromString(str, strlen(str)));
CHECK(!FLAG_testing_maybe_bool_flag.has_value); CHECK(!FLAG_testing_maybe_bool_flag.has_value);
} }
TEST_F(FlagsTest, Flags5) {
TEST(Flags5) {
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 2; int argc = 2;
const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" }; const char* argv[] = {"Test5", "--testing_int_flag=\"foobar\""};
CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc, CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv),
const_cast<char **>(argv),
true)); true));
CHECK_EQ(2, argc); CHECK_EQ(2, argc);
} }
TEST_F(FlagsTest, Flags5b) {
TEST(Flags5b) {
SetFlagsToDefault(); SetFlagsToDefault();
const char* str = " --testing_int_flag=\"foobar\""; const char* str = " --testing_int_flag=\"foobar\"";
CHECK_EQ(1, FlagList::SetFlagsFromString(str, strlen(str))); CHECK_EQ(1, FlagList::SetFlagsFromString(str, strlen(str)));
} }
TEST_F(FlagsTest, Flags6) {
TEST(Flags6) {
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 4; int argc = 4;
const char* argv[] = { "Test5", "--testing-int-flag", "0", const char* argv[] = {"Test5", "--testing-int-flag", "0",
"--testing_float_flag" }; "--testing_float_flag"};
CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc, CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv),
const_cast<char **>(argv),
true)); true));
CHECK_EQ(2, argc); CHECK_EQ(2, argc);
} }
TEST_F(FlagsTest, Flags6b) {
TEST(Flags6b) {
SetFlagsToDefault(); SetFlagsToDefault();
const char* str = " --testing-int-flag 0 --testing_float_flag "; const char* str = " --testing-int-flag 0 --testing_float_flag ";
CHECK_EQ(3, FlagList::SetFlagsFromString(str, strlen(str))); CHECK_EQ(3, FlagList::SetFlagsFromString(str, strlen(str)));
} }
TEST(FlagsRemoveIncomplete) { TEST_F(FlagsTest, FlagsRemoveIncomplete) {
// Test that processed command line arguments are removed, even // Test that processed command line arguments are removed, even
// if the list of arguments ends unexpectedly. // if the list of arguments ends unexpectedly.
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 3; int argc = 3;
const char* argv[] = {"", "--testing-bool-flag", "--expose-gc-as"}; const char* argv[] = {"", "--testing-bool-flag", "--expose-gc-as"};
CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc, CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv),
const_cast<char **>(argv),
true)); true));
CHECK(argv[1]); CHECK(argv[1]);
CHECK_EQ(2, argc); CHECK_EQ(2, argc);
} }
TEST(FlagsJitlessImplications) { TEST_F(FlagsTest, FlagsJitlessImplications) {
if (FLAG_jitless) { if (FLAG_jitless) {
// Double-check implications work as expected. Our implication system is // Double-check implications work as expected. Our implication system is
// fairly primitive and can break easily depending on the implication // fairly primitive and can break easily depending on the implication
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment