LCOV - code coverage report
Current view: top level - test/cctest - test-flags.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 98 98 100.0 %
Date: 2019-04-17 Functions: 16 16 100.0 %

          Line data    Source code
       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 "src/flags.h"
      31             : #include "src/v8.h"
      32             : #include "test/cctest/cctest.h"
      33             : 
      34             : namespace v8 {
      35             : namespace internal {
      36             : 
      37             : // This test must be executed first!
      38       26699 : TEST(Default) {
      39          60 :   CHECK(FLAG_testing_bool_flag);
      40          60 :   CHECK_EQ(13, FLAG_testing_int_flag);
      41          60 :   CHECK_EQ(2.5, FLAG_testing_float_flag);
      42          60 :   CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "Hello, world!"));
      43          60 : }
      44             : 
      45             : static void SetFlagsToDefault() {
      46          55 :   FlagList::ResetAllFlags();
      47          55 :   TestDefault();
      48             : }
      49             : 
      50             : 
      51       26644 : TEST(Flags1) {
      52           5 :   FlagList::PrintHelp();
      53           5 : }
      54             : 
      55             : 
      56       26644 : TEST(Flags2) {
      57             :   SetFlagsToDefault();
      58           5 :   int argc = 8;
      59             :   const char* argv[] = { "Test2", "-notesting-bool-flag",
      60             :                          "--notesting-maybe-bool-flag", "notaflag",
      61             :                          "--testing_int_flag=77", "-testing_float_flag=.25",
      62           5 :                          "--testing_string_flag", "no way!" };
      63           5 :   CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
      64             :                                                 const_cast<char **>(argv),
      65             :                                                 false));
      66           5 :   CHECK_EQ(8, argc);
      67           5 :   CHECK(!FLAG_testing_bool_flag);
      68           5 :   CHECK(FLAG_testing_maybe_bool_flag.has_value);
      69           5 :   CHECK(!FLAG_testing_maybe_bool_flag.value);
      70           5 :   CHECK_EQ(77, FLAG_testing_int_flag);
      71           5 :   CHECK_EQ(.25, FLAG_testing_float_flag);
      72           5 :   CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!"));
      73           5 : }
      74             : 
      75             : 
      76       26644 : TEST(Flags2b) {
      77             :   SetFlagsToDefault();
      78             :   const char* str =
      79             :       " -notesting-bool-flag notaflag   --testing_int_flag=77 "
      80             :       "-notesting-maybe-bool-flag   "
      81             :       "-testing_float_flag=.25  "
      82             :       "--testing_string_flag   no_way!  ";
      83           5 :   CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
      84           5 :   CHECK(!FLAG_testing_bool_flag);
      85           5 :   CHECK(FLAG_testing_maybe_bool_flag.has_value);
      86           5 :   CHECK(!FLAG_testing_maybe_bool_flag.value);
      87           5 :   CHECK_EQ(77, FLAG_testing_int_flag);
      88           5 :   CHECK_EQ(.25, FLAG_testing_float_flag);
      89           5 :   CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!"));
      90           5 : }
      91             : 
      92             : 
      93       26644 : TEST(Flags3) {
      94             :   SetFlagsToDefault();
      95           5 :   int argc = 9;
      96             :   const char* argv[] =
      97             :       { "Test3", "--testing_bool_flag", "--testing-maybe-bool-flag", "notaflag",
      98             :         "--testing_int_flag", "-666",
      99           5 :         "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" };
     100           5 :   CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
     101             :                                                 const_cast<char **>(argv),
     102             :                                                 true));
     103           5 :   CHECK_EQ(2, argc);
     104           5 :   CHECK(FLAG_testing_bool_flag);
     105           5 :   CHECK(FLAG_testing_maybe_bool_flag.has_value);
     106           5 :   CHECK(FLAG_testing_maybe_bool_flag.value);
     107           5 :   CHECK_EQ(-666, FLAG_testing_int_flag);
     108           5 :   CHECK_EQ(-12E10, FLAG_testing_float_flag);
     109           5 :   CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
     110           5 : }
     111             : 
     112             : 
     113       26644 : TEST(Flags3b) {
     114             :   SetFlagsToDefault();
     115             :   const char* str =
     116             :       "--testing_bool_flag --testing-maybe-bool-flag notaflag "
     117             :       "--testing_int_flag -666 "
     118             :       "--testing_float_flag -12E10 "
     119             :       "-testing-string-flag=foo-bar";
     120           5 :   CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
     121           5 :   CHECK(FLAG_testing_bool_flag);
     122           5 :   CHECK(FLAG_testing_maybe_bool_flag.has_value);
     123           5 :   CHECK(FLAG_testing_maybe_bool_flag.value);
     124           5 :   CHECK_EQ(-666, FLAG_testing_int_flag);
     125           5 :   CHECK_EQ(-12E10, FLAG_testing_float_flag);
     126           5 :   CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
     127           5 : }
     128             : 
     129             : 
     130       26644 : TEST(Flags4) {
     131             :   SetFlagsToDefault();
     132           5 :   int argc = 3;
     133           5 :   const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" };
     134           5 :   CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
     135             :                                                 const_cast<char **>(argv),
     136             :                                                 true));
     137           5 :   CHECK_EQ(2, argc);
     138           5 :   CHECK(!FLAG_testing_maybe_bool_flag.has_value);
     139           5 : }
     140             : 
     141             : 
     142       26644 : TEST(Flags4b) {
     143             :   SetFlagsToDefault();
     144             :   const char* str = "--testing_bool_flag --foo";
     145           5 :   CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str)));
     146           5 :   CHECK(!FLAG_testing_maybe_bool_flag.has_value);
     147           5 : }
     148             : 
     149             : 
     150       26644 : TEST(Flags5) {
     151             :   SetFlagsToDefault();
     152           5 :   int argc = 2;
     153           5 :   const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" };
     154           5 :   CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc,
     155             :                                                 const_cast<char **>(argv),
     156             :                                                 true));
     157           5 :   CHECK_EQ(2, argc);
     158           5 : }
     159             : 
     160             : 
     161       26644 : TEST(Flags5b) {
     162             :   SetFlagsToDefault();
     163             :   const char* str = "                     --testing_int_flag=\"foobar\"";
     164           5 :   CHECK_EQ(1, FlagList::SetFlagsFromString(str, StrLength(str)));
     165           5 : }
     166             : 
     167             : 
     168       26644 : TEST(Flags6) {
     169             :   SetFlagsToDefault();
     170           5 :   int argc = 4;
     171             :   const char* argv[] = { "Test5", "--testing-int-flag", "0",
     172           5 :                          "--testing_float_flag" };
     173           5 :   CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc,
     174             :                                                 const_cast<char **>(argv),
     175             :                                                 true));
     176           5 :   CHECK_EQ(2, argc);
     177           5 : }
     178             : 
     179             : 
     180       26644 : TEST(Flags6b) {
     181             :   SetFlagsToDefault();
     182             :   const char* str = "       --testing-int-flag 0      --testing_float_flag    ";
     183           5 :   CHECK_EQ(3, FlagList::SetFlagsFromString(str, StrLength(str)));
     184           5 : }
     185             : 
     186       26644 : TEST(FlagsRemoveIncomplete) {
     187             :   // Test that processed command line arguments are removed, even
     188             :   // if the list of arguments ends unexpectedly.
     189             :   SetFlagsToDefault();
     190           5 :   int argc = 3;
     191           5 :   const char* argv[] = {"", "--testing-bool-flag", "--expose-gc-as"};
     192           5 :   CHECK_EQ(2, FlagList::SetFlagsFromCommandLine(&argc,
     193             :                                                 const_cast<char **>(argv),
     194             :                                                 true));
     195           5 :   CHECK(argv[1]);
     196           5 :   CHECK_EQ(2, argc);
     197           5 : }
     198             : 
     199       26644 : TEST(FlagsJitlessImplications) {
     200           5 :   if (FLAG_jitless) {
     201             :     // Double-check implications work as expected. Our implication system is
     202             :     // fairly primitive and can break easily depending on the implication
     203             :     // definition order in flag-definitions.h.
     204           1 :     CHECK(!FLAG_opt);
     205           1 :     CHECK(!FLAG_validate_asm);
     206           1 :     CHECK(FLAG_wasm_interpret_all);
     207           1 :     CHECK(!FLAG_asm_wasm_lazy_compilation);
     208           1 :     CHECK(!FLAG_wasm_lazy_compilation);
     209             :   }
     210           5 : }
     211             : 
     212             : }  // namespace internal
     213       79917 : }  // namespace v8

Generated by: LCOV version 1.10