Fabcoin Core  0.16.2
P2P Digital Currency
Options.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
21 #include <libevm/VMFactory.h>
23 
24 using namespace std;
25 using namespace dev::test;
26 using namespace dev::eth;
27 
28 void printHelp()
29 {
30  cout << "Usage: " << std::endl;
31  cout << std::left;
32  cout << std::endl << "Setting test suite" << std::endl;
33  cout << setw(30) << "-t <TestSuite>" << setw(25) << "Execute test operations" << std::endl;
34  cout << setw(30) << "-t <TestSuite>/<TestCase>" << std::endl;
35 
36  cout << std::endl << "Debugging" << std::endl;
37  cout << setw(30) << "-d <index>" << setw(25) << "Set the transaction data array index when running GeneralStateTests" << std::endl;
38  cout << setw(30) << "-g <index>" << setw(25) << "Set the transaction gas array index when running GeneralStateTests" << std::endl;
39  cout << setw(30) << "-v <index>" << setw(25) << "Set the transaction value array index when running GeneralStateTests" << std::endl;
40  cout << setw(30) << "--singletest <TestName>" << setw(25) << "Run on a single test" << std::endl;
41  cout << setw(30) << "--singletest <TestFile> <TestName>" << std::endl;
42  cout << setw(30) << "--verbosity <level>" << setw(25) << "Set logs verbosity. 0 - silent, 1 - only errors, 2 - informative, >2 - detailed" << std::endl;
43  cout << setw(30) << "--vm <interpreter|jit|smart>" << setw(25) << "Set VM type for VMTests suite" << std::endl;
44  cout << setw(30) << "--vmtrace" << setw(25) << "Enable VM trace for the test. (Require build with VMTRACE=1)" << std::endl;
45  cout << setw(30) << "--stats <OutFile>" << setw(25) << "Output debug stats to the file" << std::endl;
46  cout << setw(30) << "--exectimelog" << setw(25) << "Output execution time for each test suite" << std::endl;
47  cout << setw(30) << "--filltest <FileData>" << setw(25) << "Try fill tests from the given json stream" << std::endl;
48  cout << setw(30) << "--checktest <FileData>" << setw(25) << "Try run tests from the given json stream" << std::endl;
49 
50  cout << std::endl << "Additional Tests" << std::endl;
51  cout << setw(30) << "--performance" << setw(25) << "Enable perfomance tests" << std::endl;
52  cout << setw(30) << "--quadratic" << setw(25) << "Enable quadratic complexity tests" << std::endl;
53  cout << setw(30) << "--memory" << setw(25) << "Enable memory consuming tests" << std::endl;
54  cout << setw(30) << "--inputLimits" << setw(25) << "Enable inputLimits tests" << std::endl;
55  cout << setw(30) << "--bigdata" << setw(25) << "Enable bigdata tests" << std::endl;
56  cout << setw(30) << "--wallet" << setw(25) << "Enable wallet tests" << std::endl;
57  cout << setw(30) << "--all" << setw(25) << "Enable all tests" << std::endl;
58 
59  cout << std::endl << "Test Generation" << std::endl;
60  cout << setw(30) << "--filltests" << setw(25) << "Run test fillers" << std::endl;
61  cout << setw(30) << "--checkstate" << setw(25) << "Enable expect section state checks" << std::endl;
62  cout << setw(30) << "--fillchain" << setw(25) << "When filling the state tests, fill tests as blockchain instead" << std::endl;
63  cout << setw(30) << "--createRandomTest" << setw(25) << "Create random test and output it to the console" << std::endl;
64  //cout << setw(30) << "--fulloutput" << setw(25) << "Disable address compression in the output field" << std::endl;
65 
66  cout << setw(30) << "--help" << setw(25) << "Display list of command arguments" << std::endl;
67 }
68 
69 Options::Options(int argc, char** argv)
70 {
71  trDataIndex = -1;
72  trGasIndex = -1;
73  trValueIndex = -1;
74  for (auto i = 0; i < argc; ++i)
75  {
76  auto arg = std::string{argv[i]};
77  if (arg == "--help")
78  {
79  printHelp();
80  exit(0);
81  }
82  else
83  if (arg == "--vm" && i + 1 < argc)
84  {
85  string vmKind = argv[++i];
86  if (vmKind == "interpreter")
87  VMFactory::setKind(VMKind::Interpreter);
88  else if (vmKind == "jit")
89  VMFactory::setKind(VMKind::JIT);
90  else if (vmKind == "smart")
91  VMFactory::setKind(VMKind::Smart);
92  else
93  cerr << "Unknown VM kind: " << vmKind << endl;
94  }
95  else if (arg == "--jit") // TODO: Remove deprecated option "--jit"
96  VMFactory::setKind(VMKind::JIT);
97  else if (arg == "--vmtrace")
98  {
99  vmtrace = true;
100  g_logVerbosity = 13;
101  }
102  else if (arg == "--filltests")
103  filltests = true;
104  else if (arg == "--fillchain")
105  fillchain = true;
106  else if (arg == "--stats" && i + 1 < argc)
107  {
108  stats = true;
109  statsOutFile = argv[i + 1];
110  }
111  else if (arg == "--exectimelog")
112  exectimelog = true;
113  else if (arg == "--performance")
114  performance = true;
115  else if (arg == "--quadratic")
116  quadratic = true;
117  else if (arg == "--memory")
118  memory = true;
119  else if (arg == "--inputlimits")
120  inputLimits = true;
121  else if (arg == "--bigdata")
122  bigData = true;
123  else if (arg == "--checkstate")
124  checkstate = true;
125  else if (arg == "--wallet")
126  wallet = true;
127  else if (arg == "--all")
128  {
129  performance = true;
130  quadratic = true;
131  memory = true;
132  inputLimits = true;
133  bigData = true;
134  wallet = true;
135  }
136  else if (arg == "--singletest" && i + 1 < argc)
137  {
138  singleTest = true;
139  auto name1 = std::string{argv[i + 1]};
140  if (i + 2 < argc) // two params
141  {
142  auto name2 = std::string{argv[i + 2]};
143  if (name2[0] == '-') // not param, another option
144  singleTestName = std::move(name1);
145  else
146  {
147  singleTestFile = std::move(name1);
148  singleTestName = std::move(name2);
149  }
150  }
151  else
152  singleTestName = std::move(name1);
153  }
154  else if (arg == "--singlenet" && i + 1 < argc)
155  singleTestNet = std::string{argv[i + 1]};
156  else if (arg == "--fulloutput")
157  fulloutput = true;
158  else if (arg == "--verbosity" && i + 1 < argc)
159  {
160  static std::ostringstream strCout; //static string to redirect logs to
161  std::string indentLevel = std::string{argv[i + 1]};
162  if (indentLevel == "0")
163  {
164  logVerbosity = Verbosity::None;
165  std::cout.rdbuf(strCout.rdbuf());
166  std::cerr.rdbuf(strCout.rdbuf());
167  }
168  else if (indentLevel == "1")
169  logVerbosity = Verbosity::NiceReport;
170  else
171  logVerbosity = Verbosity::Full;
172 
173  int indentLevelInt = atoi(argv[i + 1]);
174  if (indentLevelInt > g_logVerbosity)
175  g_logVerbosity = indentLevelInt;
176  }
177  else if (arg == "--createRandomTest")
178  createRandomTest = true;
179  else if (arg == "-t" && i + 1 < argc)
180  rCurrentTestSuite = std::string{argv[i + 1]};
181  else if (arg == "--checktest" || arg == "--filltest")
182  {
183  //read all line to the end
184  for (int j = i+1; j < argc; ++j)
185  rCheckTest += argv[j];
186  break;
187  }
188  else if (arg == "--nonetwork")
189  nonetwork = true;
190  else if (arg == "-d" && i + 1 < argc)
191  trDataIndex = atoi(argv[i + 1]);
192  else if (arg == "-g" && i + 1 < argc)
193  trGasIndex = atoi(argv[i + 1]);
194  else if (arg == "-v" && i + 1 < argc)
195  trValueIndex = atoi(argv[i + 1]);
196  }
197 
198  //Default option
199  if (logVerbosity == Verbosity::NiceReport)
200  g_logVerbosity = -1; //disable cnote but leave cerr and cout
201 }
202 
203 Options const& Options::get(int argc, char** argv)
204 {
205  static Options instance(argc, argv);
206  return instance;
207 }
208 
std::hash for asio::adress
Definition: Common.h:323
void createRandomTest()
Definition: boostTest.cpp:60
Class for handling testeth custom options.
int g_logVerbosity
The logging system&#39;s current verbosity.
Definition: Log.cpp:37
void printHelp()
Definition: Options.cpp:28
int atoi(const std::string &str)