v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-flags.cc
Go to the documentation of this file.
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include <stdlib.h>
29 
30 #include "v8.h"
31 #include "cctest.h"
32 
33 using namespace v8::internal;
34 
35 // This test must be executed first!
36 TEST(Default) {
37  CHECK(FLAG_testing_bool_flag);
38  CHECK_EQ(13, FLAG_testing_int_flag);
39  CHECK_EQ(2.5, FLAG_testing_float_flag);
40  CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "Hello, world!"));
41 }
42 
43 
44 static void SetFlagsToDefault() {
46  TestDefault();
47 }
48 
49 
50 TEST(Flags1) {
52 }
53 
54 
55 TEST(Flags2) {
56  SetFlagsToDefault();
57  int argc = 7;
58  const char* argv[] = { "Test2", "-notesting-bool-flag", "notaflag",
59  "--testing_int_flag=77", "-testing_float_flag=.25",
60  "--testing_string_flag", "no way!" };
62  const_cast<char **>(argv),
63  false));
64  CHECK_EQ(7, argc);
65  CHECK(!FLAG_testing_bool_flag);
66  CHECK_EQ(77, FLAG_testing_int_flag);
67  CHECK_EQ(.25, FLAG_testing_float_flag);
68  CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!"));
69 }
70 
71 
72 TEST(Flags2b) {
73  SetFlagsToDefault();
74  const char* str =
75  " -notesting-bool-flag notaflag --testing_int_flag=77 "
76  "-testing_float_flag=.25 "
77  "--testing_string_flag no_way! ";
79  CHECK(!FLAG_testing_bool_flag);
80  CHECK_EQ(77, FLAG_testing_int_flag);
81  CHECK_EQ(.25, FLAG_testing_float_flag);
82  CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!"));
83 }
84 
85 
86 TEST(Flags3) {
87  SetFlagsToDefault();
88  int argc = 8;
89  const char* argv[] =
90  { "Test3", "--testing_bool_flag", "notaflag",
91  "--testing_int_flag", "-666",
92  "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" };
94  const_cast<char **>(argv),
95  true));
96  CHECK_EQ(2, argc);
97  CHECK(FLAG_testing_bool_flag);
98  CHECK_EQ(-666, FLAG_testing_int_flag);
99  CHECK_EQ(-12E10, FLAG_testing_float_flag);
100  CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
101 }
102 
103 
104 TEST(Flags3b) {
105  SetFlagsToDefault();
106  const char* str =
107  "--testing_bool_flag notaflag --testing_int_flag -666 "
108  "--testing_float_flag -12E10 "
109  "-testing-string-flag=foo-bar";
111  CHECK(FLAG_testing_bool_flag);
112  CHECK_EQ(-666, FLAG_testing_int_flag);
113  CHECK_EQ(-12E10, FLAG_testing_float_flag);
114  CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
115 }
116 
117 
118 TEST(Flags4) {
119  SetFlagsToDefault();
120  int argc = 3;
121  const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" };
123  const_cast<char **>(argv),
124  true));
125  CHECK_EQ(2, argc);
126 }
127 
128 
129 TEST(Flags4b) {
130  SetFlagsToDefault();
131  const char* str = "--testing_bool_flag --foo";
133 }
134 
135 
136 TEST(Flags5) {
137  SetFlagsToDefault();
138  int argc = 2;
139  const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" };
141  const_cast<char **>(argv),
142  true));
143  CHECK_EQ(2, argc);
144 }
145 
146 
147 TEST(Flags5b) {
148  SetFlagsToDefault();
149  const char* str = " --testing_int_flag=\"foobar\"";
151 }
152 
153 
154 TEST(Flags6) {
155  SetFlagsToDefault();
156  int argc = 4;
157  const char* argv[] = { "Test5", "--testing-int-flag", "0",
158  "--testing_float_flag" };
160  const_cast<char **>(argv),
161  true));
162  CHECK_EQ(2, argc);
163 }
164 
165 
166 TEST(Flags6b) {
167  SetFlagsToDefault();
168  const char* str = " --testing-int-flag 0 --testing_float_flag ";
170 }
171 
172 
173 TEST(FlagsJSArguments1) {
174  SetFlagsToDefault();
175  int argc = 6;
176  const char* argv[] = {"TestJSArgs1",
177  "--testing-int-flag", "42",
178  "--", "testing-float-flag", "7"};
180  const_cast<char **>(argv),
181  true));
182  CHECK_EQ(42, FLAG_testing_int_flag);
183  CHECK_EQ(2.5, FLAG_testing_float_flag);
184  CHECK_EQ(2, FLAG_js_arguments.argc());
185  CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
186  CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
187  CHECK_EQ(1, argc);
188 }
189 
190 
191 TEST(FlagsJSArguments1b) {
192  SetFlagsToDefault();
193  const char* str = "--testing-int-flag 42 -- testing-float-flag 7";
195  CHECK_EQ(42, FLAG_testing_int_flag);
196  CHECK_EQ(2.5, FLAG_testing_float_flag);
197  CHECK_EQ(2, FLAG_js_arguments.argc());
198  CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
199  CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
200 }
201 
202 
203 TEST(FlagsJSArguments2) {
204  SetFlagsToDefault();
205  const char* str = "--testing-int-flag 42 --js-arguments testing-float-flag 7";
207  CHECK_EQ(42, FLAG_testing_int_flag);
208  CHECK_EQ(2.5, FLAG_testing_float_flag);
209  CHECK_EQ(2, FLAG_js_arguments.argc());
210  CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
211  CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
212 }
213 
214 
215 TEST(FlagsJSArguments3) {
216  SetFlagsToDefault();
217  const char* str = "--testing-int-flag 42 --js-arguments=testing-float-flag 7";
219  CHECK_EQ(42, FLAG_testing_int_flag);
220  CHECK_EQ(2.5, FLAG_testing_float_flag);
221  CHECK_EQ(2, FLAG_js_arguments.argc());
222  CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
223  CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
224 }
225 
226 
227 TEST(FlagsJSArguments4) {
228  SetFlagsToDefault();
229  const char* str = "--testing-int-flag 42 --";
231  CHECK_EQ(42, FLAG_testing_int_flag);
232  CHECK_EQ(0, FLAG_js_arguments.argc());
233 }
234 
235 
236 TEST(FlagsRemoveIncomplete) {
237  // Test that processed command line arguments are removed, even
238  // if the list of arguments ends unexpectedly.
239  SetFlagsToDefault();
240  int argc = 3;
241  const char* argv[] = { "", "--crankshaft", "--expose-debug-as" };
243  const_cast<char **>(argv),
244  true));
245  CHECK_NE(NULL, argv[1]);
246  CHECK_EQ(argc, 2);
247 }
#define CHECK_EQ(expected, value)
Definition: checks.h:219
static void PrintHelp()
Definition: flags.cc:519
static void ResetAllFlags()
Definition: flags.cc:511
#define CHECK(condition)
Definition: checks.h:56
#define CHECK_NE(unexpected, value)
Definition: checks.h:223
int StrLength(const char *string)
Definition: utils.h:234
static int SetFlagsFromString(const char *str, int len)
Definition: flags.cc:475
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
Definition: flags.cc:301
static int SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
Definition: flags.cc:343