2
2
// Copyright 2019 The evmone Authors.
3
3
// SPDX-License-Identifier: Apache-2.0
4
4
5
+ #include " ../statetest/statetest.hpp"
5
6
#include " helpers.hpp"
6
7
#include " synthetic_benchmarks.hpp"
7
8
#include < benchmark/benchmark.h>
@@ -47,49 +48,17 @@ struct BenchmarkCase
47
48
{}
48
49
};
49
50
50
-
51
- constexpr auto runtime_code_extension = " .bin-runtime" ;
52
- constexpr auto inputs_extension = " .inputs" ;
53
-
54
51
// / Loads the benchmark case's inputs from the inputs file at the given path.
55
- std::vector<BenchmarkCase::Input> load_inputs (const fs::path& path )
52
+ std::vector<BenchmarkCase::Input> load_inputs (const StateTransitionTest& state_test )
56
53
{
57
- enum class state
58
- {
59
- name,
60
- input,
61
- expected_output
62
- };
63
-
64
- auto inputs_file = std::ifstream{path};
65
-
66
54
std::vector<BenchmarkCase::Input> inputs;
67
- auto st = state::name;
68
- std::string input_name;
69
- bytes input;
70
- for (std::string l; std::getline (inputs_file, l);)
55
+ for (size_t i = 0 ; i < state_test.multi_tx .inputs .size (); ++i)
71
56
{
72
- switch (st)
73
- {
74
- case state::name:
75
- if (l.empty ())
76
- continue ; // Skip any empty line.
77
- input_name = std::move (l);
78
- st = state::input;
79
- break ;
80
-
81
- case state::input:
82
- input = from_hexx (l);
83
- st = state::expected_output;
84
- break ;
85
-
86
- case state::expected_output:
87
- inputs.emplace_back (std::move (input_name), std::move (input), from_hexx (l));
88
- input_name = {};
89
- input = {};
90
- st = state::name;
91
- break ;
92
- }
57
+ const auto input_name = state_test.info .labels .at (i);
58
+ const auto input = state_test.multi_tx .inputs [i];
59
+ bytes expected_output;
60
+
61
+ inputs.emplace_back (std::move (input_name), std::move (input), std::move (expected_output));
93
62
}
94
63
95
64
return inputs;
@@ -98,16 +67,14 @@ std::vector<BenchmarkCase::Input> load_inputs(const fs::path& path)
98
67
// / Loads a benchmark case from a file at `path` and all its inputs from the matching inputs file.
99
68
BenchmarkCase load_benchmark (const fs::path& path, const std::string& name_prefix)
100
69
{
101
- const auto name = name_prefix + path. stem (). string ( );
70
+ auto state_test = evmone::test::load_state_test (path );
102
71
103
- std::ifstream file{ path} ;
104
- std::string code_hexx{std::istreambuf_iterator< char >{file}, std::istreambuf_iterator< char >{}} ;
105
- BenchmarkCase b{name, from_hexx (code_hexx)} ;
72
+ const auto name = name_prefix + path. stem (). string () ;
73
+ const auto code = state_test. pre_state . get (state_test. multi_tx . to . value ()). code ;
74
+ const auto inputs = load_inputs (state_test) ;
106
75
107
- auto inputs_path = path;
108
- inputs_path.replace_extension (inputs_extension);
109
- if (fs::exists (inputs_path))
110
- b.inputs = load_inputs (inputs_path);
76
+ BenchmarkCase b{name, code};
77
+ b.inputs = inputs;
111
78
112
79
return b;
113
80
}
@@ -123,7 +90,7 @@ std::vector<BenchmarkCase> load_benchmarks_from_dir( // NOLINT(misc-no-recursio
123
90
{
124
91
if (e.is_directory ())
125
92
subdirs.emplace_back (e);
126
- else if (e.path ().extension () == runtime_code_extension )
93
+ else if (e.path ().extension () == " .json " )
127
94
code_files.emplace_back (e);
128
95
}
129
96
0 commit comments