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