Add flags to force or prevent setting of isolate.is_memory_constrained.

Enables MAYBE_BOOL flags for when you want to only do something if the flag
was explicitly set to true or false. Also cleans up JSArguments struct.

BUG=None
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/23513062

Patch from Ross McIlroy <rmcilroy@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16774 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a5e0f768
...@@ -624,7 +624,8 @@ bool SetResourceConstraints(ResourceConstraints* constraints) { ...@@ -624,7 +624,8 @@ bool SetResourceConstraints(ResourceConstraints* constraints) {
uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
isolate->stack_guard()->SetStackLimit(limit); isolate->stack_guard()->SetStackLimit(limit);
} }
if (constraints->is_memory_constrained().has_value) { if (constraints->is_memory_constrained().has_value &&
!i::FLAG_force_memory_constrained.has_value) {
isolate->set_is_memory_constrained( isolate->set_is_memory_constrained(
constraints->is_memory_constrained().value); constraints->is_memory_constrained().value);
} }
......
...@@ -939,8 +939,8 @@ Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { ...@@ -939,8 +939,8 @@ Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory(); i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory();
i::JSArguments js_args = i::FLAG_js_arguments; i::JSArguments js_args = i::FLAG_js_arguments;
i::Handle<i::FixedArray> arguments_array = i::Handle<i::FixedArray> arguments_array =
factory->NewFixedArray(js_args.argc()); factory->NewFixedArray(js_args.argc);
for (int j = 0; j < js_args.argc(); j++) { for (int j = 0; j < js_args.argc; j++) {
i::Handle<i::String> arg = i::Handle<i::String> arg =
factory->NewStringFromUtf8(i::CStrVector(js_args[j])); factory->NewStringFromUtf8(i::CStrVector(js_args[j]));
arguments_array->set(j, *arg); arguments_array->set(j, *arg);
......
...@@ -90,44 +90,34 @@ ...@@ -90,44 +90,34 @@
#define DEFINE_implication(whenflag, thenflag) #define DEFINE_implication(whenflag, thenflag)
#endif #endif
#define COMMA ,
#ifdef FLAG_MODE_DECLARE #ifdef FLAG_MODE_DECLARE
// Structure used to hold a collection of arguments to the JavaScript code. // Structure used to hold a collection of arguments to the JavaScript code.
#define JSARGUMENTS_INIT {{}}
struct JSArguments { struct JSArguments {
public: public:
inline int argc() const {
return static_cast<int>(storage_[0]);
}
inline const char** argv() const {
return reinterpret_cast<const char**>(storage_[1]);
}
inline const char*& operator[] (int idx) const { inline const char*& operator[] (int idx) const {
return argv()[idx]; return argv[idx];
}
inline JSArguments& operator=(JSArguments args) {
set_argc(args.argc());
set_argv(args.argv());
return *this;
} }
static JSArguments Create(int argc, const char** argv) { static JSArguments Create(int argc, const char** argv) {
JSArguments args; JSArguments args;
args.set_argc(argc); args.argc = argc;
args.set_argv(argv); args.argv = argv;
return args; return args;
} }
private: int argc;
void set_argc(int argc) { const char** argv;
storage_[0] = argc; };
}
void set_argv(const char** argv) { struct MaybeBoolFlag {
storage_[1] = reinterpret_cast<AtomicWord>(argv); static MaybeBoolFlag Create(bool has_value, bool value) {
MaybeBoolFlag flag;
flag.has_value = has_value;
flag.value = value;
return flag;
} }
public: bool has_value;
// Contains argc and argv. Unfortunately we have to store these two fields bool value;
// into a single one to avoid making the initialization macro (which would be
// "{ 0, NULL }") contain a coma.
AtomicWord storage_[2];
}; };
#endif #endif
...@@ -148,10 +138,13 @@ public: ...@@ -148,10 +138,13 @@ public:
#endif #endif
#define DEFINE_bool(nam, def, cmt) FLAG(BOOL, bool, nam, def, cmt) #define DEFINE_bool(nam, def, cmt) FLAG(BOOL, bool, nam, def, cmt)
#define DEFINE_maybe_bool(nam, cmt) FLAG(MAYBE_BOOL, MaybeBoolFlag, nam, \
{ false COMMA false }, cmt)
#define DEFINE_int(nam, def, cmt) FLAG(INT, int, nam, def, cmt) #define DEFINE_int(nam, def, cmt) FLAG(INT, int, nam, def, cmt)
#define DEFINE_float(nam, def, cmt) FLAG(FLOAT, double, nam, def, cmt) #define DEFINE_float(nam, def, cmt) FLAG(FLOAT, double, nam, def, cmt)
#define DEFINE_string(nam, def, cmt) FLAG(STRING, const char*, nam, def, cmt) #define DEFINE_string(nam, def, cmt) FLAG(STRING, const char*, nam, def, cmt)
#define DEFINE_args(nam, def, cmt) FLAG(ARGS, JSArguments, nam, def, cmt) #define DEFINE_args(nam, cmt) FLAG(ARGS, JSArguments, nam, \
{ 0 COMMA NULL }, cmt)
#define DEFINE_ALIAS_bool(alias, nam) FLAG_ALIAS(BOOL, bool, alias, nam) #define DEFINE_ALIAS_bool(alias, nam) FLAG_ALIAS(BOOL, bool, alias, nam)
#define DEFINE_ALIAS_int(alias, nam) FLAG_ALIAS(INT, int, alias, nam) #define DEFINE_ALIAS_int(alias, nam) FLAG_ALIAS(INT, int, alias, nam)
...@@ -599,6 +592,9 @@ DEFINE_int(hash_seed, ...@@ -599,6 +592,9 @@ DEFINE_int(hash_seed,
0, 0,
"Fixed seed to use to hash property keys (0 means random)" "Fixed seed to use to hash property keys (0 means random)"
"(with snapshots this option cannot override the baked-in seed)") "(with snapshots this option cannot override the baked-in seed)")
DEFINE_maybe_bool(force_memory_constrained,
"force (if true) or prevent (if false) the runtime from treating "
"the device as being memory constrained.")
// v8.cc // v8.cc
DEFINE_bool(preemption, false, DEFINE_bool(preemption, false,
...@@ -609,6 +605,7 @@ DEFINE_bool(regexp_optimization, true, "generate optimized regexp code") ...@@ -609,6 +605,7 @@ DEFINE_bool(regexp_optimization, true, "generate optimized regexp code")
// Testing flags test/cctest/test-{flags,api,serialization}.cc // Testing flags test/cctest/test-{flags,api,serialization}.cc
DEFINE_bool(testing_bool_flag, true, "testing_bool_flag") DEFINE_bool(testing_bool_flag, true, "testing_bool_flag")
DEFINE_maybe_bool(testing_maybe_bool_flag, "testing_maybe_bool_flag")
DEFINE_int(testing_int_flag, 13, "testing_int_flag") DEFINE_int(testing_int_flag, 13, "testing_int_flag")
DEFINE_float(testing_float_flag, 2.5, "float-flag") DEFINE_float(testing_float_flag, 2.5, "float-flag")
DEFINE_string(testing_string_flag, "Hello, world!", "string-flag") DEFINE_string(testing_string_flag, "Hello, world!", "string-flag")
...@@ -641,7 +638,7 @@ DEFINE_int(debugger_port, 5858, "Port to use for remote debugging") ...@@ -641,7 +638,7 @@ DEFINE_int(debugger_port, 5858, "Port to use for remote debugging")
#endif // ENABLE_DEBUGGER_SUPPORT #endif // ENABLE_DEBUGGER_SUPPORT
DEFINE_string(map_counters, "", "Map counters to a file") DEFINE_string(map_counters, "", "Map counters to a file")
DEFINE_args(js_arguments, JSARGUMENTS_INIT, DEFINE_args(js_arguments,
"Pass all remaining arguments to the script. Alias for \"--\".") "Pass all remaining arguments to the script. Alias for \"--\".")
#if defined(WEBOS__) #if defined(WEBOS__)
...@@ -833,6 +830,7 @@ DEFINE_implication(print_all_code, trace_codegen) ...@@ -833,6 +830,7 @@ DEFINE_implication(print_all_code, trace_codegen)
#undef FLAG_ALIAS #undef FLAG_ALIAS
#undef DEFINE_bool #undef DEFINE_bool
#undef DEFINE_maybe_bool
#undef DEFINE_int #undef DEFINE_int
#undef DEFINE_string #undef DEFINE_string
#undef DEFINE_float #undef DEFINE_float
...@@ -849,3 +847,5 @@ DEFINE_implication(print_all_code, trace_codegen) ...@@ -849,3 +847,5 @@ DEFINE_implication(print_all_code, trace_codegen)
#undef FLAG_MODE_DEFINE_DEFAULTS #undef FLAG_MODE_DEFINE_DEFAULTS
#undef FLAG_MODE_META #undef FLAG_MODE_META
#undef FLAG_MODE_DEFINE_IMPLICATIONS #undef FLAG_MODE_DEFINE_IMPLICATIONS
#undef COMMA
...@@ -55,7 +55,8 @@ namespace { ...@@ -55,7 +55,8 @@ namespace {
// to the actual flag, default value, comment, etc. This is designed to be POD // to the actual flag, default value, comment, etc. This is designed to be POD
// initialized as to avoid requiring static constructors. // initialized as to avoid requiring static constructors.
struct Flag { struct Flag {
enum FlagType { TYPE_BOOL, TYPE_INT, TYPE_FLOAT, TYPE_STRING, TYPE_ARGS }; enum FlagType { TYPE_BOOL, TYPE_MAYBE_BOOL, TYPE_INT, TYPE_FLOAT,
TYPE_STRING, TYPE_ARGS };
FlagType type_; // What type of flag, bool, int, or string. FlagType type_; // What type of flag, bool, int, or string.
const char* name_; // Name of the flag, ex "my_flag". const char* name_; // Name of the flag, ex "my_flag".
...@@ -75,6 +76,11 @@ struct Flag { ...@@ -75,6 +76,11 @@ struct Flag {
return reinterpret_cast<bool*>(valptr_); return reinterpret_cast<bool*>(valptr_);
} }
MaybeBoolFlag* maybe_bool_variable() const {
ASSERT(type_ == TYPE_MAYBE_BOOL);
return reinterpret_cast<MaybeBoolFlag*>(valptr_);
}
int* int_variable() const { int* int_variable() const {
ASSERT(type_ == TYPE_INT); ASSERT(type_ == TYPE_INT);
return reinterpret_cast<int*>(valptr_); return reinterpret_cast<int*>(valptr_);
...@@ -133,6 +139,8 @@ struct Flag { ...@@ -133,6 +139,8 @@ struct Flag {
switch (type_) { switch (type_) {
case TYPE_BOOL: case TYPE_BOOL:
return *bool_variable() == bool_default(); return *bool_variable() == bool_default();
case TYPE_MAYBE_BOOL:
return maybe_bool_variable()->has_value == false;
case TYPE_INT: case TYPE_INT:
return *int_variable() == int_default(); return *int_variable() == int_default();
case TYPE_FLOAT: case TYPE_FLOAT:
...@@ -145,7 +153,7 @@ struct Flag { ...@@ -145,7 +153,7 @@ struct Flag {
return strcmp(str1, str2) == 0; return strcmp(str1, str2) == 0;
} }
case TYPE_ARGS: case TYPE_ARGS:
return args_variable()->argc() == 0; return args_variable()->argc == 0;
} }
UNREACHABLE(); UNREACHABLE();
return true; return true;
...@@ -157,6 +165,9 @@ struct Flag { ...@@ -157,6 +165,9 @@ struct Flag {
case TYPE_BOOL: case TYPE_BOOL:
*bool_variable() = bool_default(); *bool_variable() = bool_default();
break; break;
case TYPE_MAYBE_BOOL:
*maybe_bool_variable() = MaybeBoolFlag::Create(false, false);
break;
case TYPE_INT: case TYPE_INT:
*int_variable() = int_default(); *int_variable() = int_default();
break; break;
...@@ -186,6 +197,7 @@ const size_t num_flags = sizeof(flags) / sizeof(*flags); ...@@ -186,6 +197,7 @@ const size_t num_flags = sizeof(flags) / sizeof(*flags);
static const char* Type2String(Flag::FlagType type) { static const char* Type2String(Flag::FlagType type) {
switch (type) { switch (type) {
case Flag::TYPE_BOOL: return "bool"; case Flag::TYPE_BOOL: return "bool";
case Flag::TYPE_MAYBE_BOOL: return "maybe_bool";
case Flag::TYPE_INT: return "int"; case Flag::TYPE_INT: return "int";
case Flag::TYPE_FLOAT: return "float"; case Flag::TYPE_FLOAT: return "float";
case Flag::TYPE_STRING: return "string"; case Flag::TYPE_STRING: return "string";
...@@ -203,6 +215,11 @@ static SmartArrayPointer<const char> ToString(Flag* flag) { ...@@ -203,6 +215,11 @@ static SmartArrayPointer<const char> ToString(Flag* flag) {
case Flag::TYPE_BOOL: case Flag::TYPE_BOOL:
buffer.Add("%s", (*flag->bool_variable() ? "true" : "false")); buffer.Add("%s", (*flag->bool_variable() ? "true" : "false"));
break; break;
case Flag::TYPE_MAYBE_BOOL:
buffer.Add("%s", flag->maybe_bool_variable()->has_value
? (flag->maybe_bool_variable()->value ? "true" : "false")
: "unset");
break;
case Flag::TYPE_INT: case Flag::TYPE_INT:
buffer.Add("%d", *flag->int_variable()); buffer.Add("%d", *flag->int_variable());
break; break;
...@@ -216,9 +233,9 @@ static SmartArrayPointer<const char> ToString(Flag* flag) { ...@@ -216,9 +233,9 @@ static SmartArrayPointer<const char> ToString(Flag* flag) {
} }
case Flag::TYPE_ARGS: { case Flag::TYPE_ARGS: {
JSArguments args = *flag->args_variable(); JSArguments args = *flag->args_variable();
if (args.argc() > 0) { if (args.argc > 0) {
buffer.Add("%s", args[0]); buffer.Add("%s", args[0]);
for (int i = 1; i < args.argc(); i++) { for (int i = 1; i < args.argc; i++) {
buffer.Add(" %s", args[i]); buffer.Add(" %s", args[i]);
} }
} }
...@@ -260,7 +277,7 @@ List<const char*>* FlagList::argv() { ...@@ -260,7 +277,7 @@ List<const char*>* FlagList::argv() {
buffer.Add("--%s", args_flag->name()); buffer.Add("--%s", args_flag->name());
args->Add(buffer.ToCString().Detach()); args->Add(buffer.ToCString().Detach());
JSArguments jsargs = *args_flag->args_variable(); JSArguments jsargs = *args_flag->args_variable();
for (int j = 0; j < jsargs.argc(); j++) { for (int j = 0; j < jsargs.argc; j++) {
args->Add(StrDup(jsargs[j])); args->Add(StrDup(jsargs[j]));
} }
} }
...@@ -380,6 +397,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -380,6 +397,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
// if we still need a flag value, use the next argument if available // if we still need a flag value, use the next argument if available
if (flag->type() != Flag::TYPE_BOOL && if (flag->type() != Flag::TYPE_BOOL &&
flag->type() != Flag::TYPE_MAYBE_BOOL &&
flag->type() != Flag::TYPE_ARGS && flag->type() != Flag::TYPE_ARGS &&
value == NULL) { value == NULL) {
if (i < *argc) { if (i < *argc) {
...@@ -399,6 +417,9 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -399,6 +417,9 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
case Flag::TYPE_BOOL: case Flag::TYPE_BOOL:
*flag->bool_variable() = !is_bool; *flag->bool_variable() = !is_bool;
break; break;
case Flag::TYPE_MAYBE_BOOL:
*flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool);
break;
case Flag::TYPE_INT: case Flag::TYPE_INT:
*flag->int_variable() = strtol(value, &endp, 10); // NOLINT *flag->int_variable() = strtol(value, &endp, 10); // NOLINT
break; break;
...@@ -425,8 +446,9 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -425,8 +446,9 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
} }
// handle errors // handle errors
if ((flag->type() == Flag::TYPE_BOOL && value != NULL) || bool is_bool_type = flag->type() == Flag::TYPE_BOOL ||
(flag->type() != Flag::TYPE_BOOL && is_bool) || flag->type() == Flag::TYPE_MAYBE_BOOL;
if ((is_bool_type && value != NULL) || (!is_bool_type && is_bool) ||
*endp != '\0') { *endp != '\0') {
PrintF(stderr, "Error: illegal value for flag %s of type %s\n" PrintF(stderr, "Error: illegal value for flag %s of type %s\n"
"Try --help for options\n", "Try --help for options\n",
...@@ -549,6 +571,7 @@ void FlagList::PrintHelp() { ...@@ -549,6 +571,7 @@ void FlagList::PrintHelp() {
} }
// static
void FlagList::EnforceFlagImplications() { void FlagList::EnforceFlagImplications() {
#define FLAG_MODE_DEFINE_IMPLICATIONS #define FLAG_MODE_DEFINE_IMPLICATIONS
#include "flag-definitions.h" #include "flag-definitions.h"
......
...@@ -1776,6 +1776,9 @@ Isolate::Isolate() ...@@ -1776,6 +1776,9 @@ Isolate::Isolate()
// TODO(bmeurer) Initialized lazily because it depends on flags; can // TODO(bmeurer) Initialized lazily because it depends on flags; can
// be fixed once the default isolate cleanup is done. // be fixed once the default isolate cleanup is done.
random_number_generator_(NULL), random_number_generator_(NULL),
// TODO(rmcilroy) Currently setting this based on
// FLAG_force_memory_constrained in Isolate::Init; move to here when
// isolate cleanup is done
is_memory_constrained_(false), is_memory_constrained_(false),
has_fatal_error_(false), has_fatal_error_(false),
use_crankshaft_(true), use_crankshaft_(true),
...@@ -2135,6 +2138,8 @@ bool Isolate::Init(Deserializer* des) { ...@@ -2135,6 +2138,8 @@ bool Isolate::Init(Deserializer* des) {
TRACE_ISOLATE(init); TRACE_ISOLATE(init);
stress_deopt_count_ = FLAG_deopt_every_n_times; stress_deopt_count_ = FLAG_deopt_every_n_times;
if (FLAG_force_memory_constrained.has_value)
is_memory_constrained_ = FLAG_force_memory_constrained.value;
has_fatal_error_ = false; has_fatal_error_ = false;
......
...@@ -54,15 +54,18 @@ TEST(Flags1) { ...@@ -54,15 +54,18 @@ TEST(Flags1) {
TEST(Flags2) { TEST(Flags2) {
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 7; int argc = 8;
const char* argv[] = { "Test2", "-notesting-bool-flag", "notaflag", const char* argv[] = { "Test2", "-notesting-bool-flag",
"--notesting-maybe-bool-flag", "notaflag",
"--testing_int_flag=77", "-testing_float_flag=.25", "--testing_int_flag=77", "-testing_float_flag=.25",
"--testing_string_flag", "no way!" }; "--testing_string_flag", "no way!" };
CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
const_cast<char **>(argv), const_cast<char **>(argv),
false)); false));
CHECK_EQ(7, argc); CHECK_EQ(8, argc);
CHECK(!FLAG_testing_bool_flag); CHECK(!FLAG_testing_bool_flag);
CHECK(FLAG_testing_maybe_bool_flag.has_value);
CHECK(!FLAG_testing_maybe_bool_flag.value);
CHECK_EQ(77, FLAG_testing_int_flag); CHECK_EQ(77, FLAG_testing_int_flag);
CHECK_EQ(.25, FLAG_testing_float_flag); CHECK_EQ(.25, FLAG_testing_float_flag);
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!"));
...@@ -73,10 +76,13 @@ TEST(Flags2b) { ...@@ -73,10 +76,13 @@ 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 "
"-notesting-maybe-bool-flag "
"-testing_float_flag=.25 " "-testing_float_flag=.25 "
"--testing_string_flag no_way! "; "--testing_string_flag no_way! ";
CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
CHECK(!FLAG_testing_bool_flag); CHECK(!FLAG_testing_bool_flag);
CHECK(FLAG_testing_maybe_bool_flag.has_value);
CHECK(!FLAG_testing_maybe_bool_flag.value);
CHECK_EQ(77, FLAG_testing_int_flag); CHECK_EQ(77, FLAG_testing_int_flag);
CHECK_EQ(.25, FLAG_testing_float_flag); CHECK_EQ(.25, FLAG_testing_float_flag);
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!"));
...@@ -85,9 +91,9 @@ TEST(Flags2b) { ...@@ -85,9 +91,9 @@ TEST(Flags2b) {
TEST(Flags3) { TEST(Flags3) {
SetFlagsToDefault(); SetFlagsToDefault();
int argc = 8; int argc = 9;
const char* argv[] = const char* argv[] =
{ "Test3", "--testing_bool_flag", "notaflag", { "Test3", "--testing_bool_flag", "--testing-maybe-bool-flag", "notaflag",
"--testing_int_flag", "-666", "--testing_int_flag", "-666",
"--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" }; "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" };
CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
...@@ -95,6 +101,8 @@ TEST(Flags3) { ...@@ -95,6 +101,8 @@ TEST(Flags3) {
true)); true));
CHECK_EQ(2, argc); CHECK_EQ(2, argc);
CHECK(FLAG_testing_bool_flag); CHECK(FLAG_testing_bool_flag);
CHECK(FLAG_testing_maybe_bool_flag.has_value);
CHECK(FLAG_testing_maybe_bool_flag.value);
CHECK_EQ(-666, FLAG_testing_int_flag); CHECK_EQ(-666, FLAG_testing_int_flag);
CHECK_EQ(-12E10, FLAG_testing_float_flag); CHECK_EQ(-12E10, FLAG_testing_float_flag);
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
...@@ -104,11 +112,14 @@ TEST(Flags3) { ...@@ -104,11 +112,14 @@ TEST(Flags3) {
TEST(Flags3b) { TEST(Flags3b) {
SetFlagsToDefault(); SetFlagsToDefault();
const char* str = const char* str =
"--testing_bool_flag notaflag --testing_int_flag -666 " "--testing_bool_flag --testing-maybe-bool-flag notaflag "
"--testing_int_flag -666 "
"--testing_float_flag -12E10 " "--testing_float_flag -12E10 "
"-testing-string-flag=foo-bar"; "-testing-string-flag=foo-bar";
CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
CHECK(FLAG_testing_bool_flag); CHECK(FLAG_testing_bool_flag);
CHECK(FLAG_testing_maybe_bool_flag.has_value);
CHECK(FLAG_testing_maybe_bool_flag.value);
CHECK_EQ(-666, FLAG_testing_int_flag); CHECK_EQ(-666, FLAG_testing_int_flag);
CHECK_EQ(-12E10, FLAG_testing_float_flag); CHECK_EQ(-12E10, FLAG_testing_float_flag);
CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar")); CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
...@@ -123,6 +134,7 @@ TEST(Flags4) { ...@@ -123,6 +134,7 @@ TEST(Flags4) {
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);
} }
...@@ -130,6 +142,7 @@ TEST(Flags4b) { ...@@ -130,6 +142,7 @@ TEST(Flags4b) {
SetFlagsToDefault(); SetFlagsToDefault();
const char* str = "--testing_bool_flag --foo"; const char* str = "--testing_bool_flag --foo";
CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str))); CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str)));
CHECK(!FLAG_testing_maybe_bool_flag.has_value);
} }
...@@ -181,7 +194,7 @@ TEST(FlagsJSArguments1) { ...@@ -181,7 +194,7 @@ TEST(FlagsJSArguments1) {
true)); true));
CHECK_EQ(42, FLAG_testing_int_flag); CHECK_EQ(42, FLAG_testing_int_flag);
CHECK_EQ(2.5, FLAG_testing_float_flag); CHECK_EQ(2.5, FLAG_testing_float_flag);
CHECK_EQ(2, FLAG_js_arguments.argc()); CHECK_EQ(2, FLAG_js_arguments.argc);
CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
CHECK_EQ(1, argc); CHECK_EQ(1, argc);
...@@ -194,7 +207,7 @@ TEST(FlagsJSArguments1b) { ...@@ -194,7 +207,7 @@ TEST(FlagsJSArguments1b) {
CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
CHECK_EQ(42, FLAG_testing_int_flag); CHECK_EQ(42, FLAG_testing_int_flag);
CHECK_EQ(2.5, FLAG_testing_float_flag); CHECK_EQ(2.5, FLAG_testing_float_flag);
CHECK_EQ(2, FLAG_js_arguments.argc()); CHECK_EQ(2, FLAG_js_arguments.argc);
CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
} }
...@@ -206,7 +219,7 @@ TEST(FlagsJSArguments2) { ...@@ -206,7 +219,7 @@ TEST(FlagsJSArguments2) {
CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
CHECK_EQ(42, FLAG_testing_int_flag); CHECK_EQ(42, FLAG_testing_int_flag);
CHECK_EQ(2.5, FLAG_testing_float_flag); CHECK_EQ(2.5, FLAG_testing_float_flag);
CHECK_EQ(2, FLAG_js_arguments.argc()); CHECK_EQ(2, FLAG_js_arguments.argc);
CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
} }
...@@ -218,7 +231,7 @@ TEST(FlagsJSArguments3) { ...@@ -218,7 +231,7 @@ TEST(FlagsJSArguments3) {
CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
CHECK_EQ(42, FLAG_testing_int_flag); CHECK_EQ(42, FLAG_testing_int_flag);
CHECK_EQ(2.5, FLAG_testing_float_flag); CHECK_EQ(2.5, FLAG_testing_float_flag);
CHECK_EQ(2, FLAG_js_arguments.argc()); CHECK_EQ(2, FLAG_js_arguments.argc);
CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag")); CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7")); CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
} }
...@@ -229,7 +242,7 @@ TEST(FlagsJSArguments4) { ...@@ -229,7 +242,7 @@ TEST(FlagsJSArguments4) {
const char* str = "--testing-int-flag 42 --"; const char* str = "--testing-int-flag 42 --";
CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
CHECK_EQ(42, FLAG_testing_int_flag); CHECK_EQ(42, FLAG_testing_int_flag);
CHECK_EQ(0, FLAG_js_arguments.argc()); CHECK_EQ(0, FLAG_js_arguments.argc);
} }
......
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