Skip to content

Commit 9f4aacf

Browse files
committed
Migrate ethdebug CLI tests to isolest
1 parent 9cdc2bc commit 9f4aacf

18 files changed

Lines changed: 871 additions & 0 deletions

test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ set(libsolidity_sources
7979
libsolidity/ASTJSONTest.h
8080
libsolidity/ErrorCheck.cpp
8181
libsolidity/ErrorCheck.h
82+
libsolidity/EthdebugTest.cpp
83+
libsolidity/EthdebugTest.h
8284
libsolidity/FunctionDependencyGraphTest.cpp
8385
libsolidity/FunctionDependencyGraphTest.h
8486
libsolidity/GasCosts.cpp
@@ -100,6 +102,8 @@ set(libsolidity_sources
100102
libsolidity/SemVerMatcher.cpp
101103
libsolidity/SMTCheckerTest.cpp
102104
libsolidity/SMTCheckerTest.h
105+
libsolidity/StandardJSONTest.cpp
106+
libsolidity/StandardJSONTest.h
103107
libsolidity/SolidityCompiler.cpp
104108
libsolidity/SolidityEndToEndTest.cpp
105109
libsolidity/SolidityExecutionFramework.cpp

test/InteractiveTests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <test/TestCase.h>
2222
#include <test/libsolidity/ABIJsonTest.h>
23+
#include <test/libsolidity/EthdebugTest.h>
2324
#include <test/libsolidity/ASTJSONTest.h>
2425
#include <test/libsolidity/ASTPropertyTest.h>
2526
#include <libsolidity/FunctionDependencyGraphTest.h>
@@ -89,6 +90,7 @@ Testsuite const g_interactiveTestsuites[] = {
8990
{"JSON ABI", "libsolidity", "ABIJson", false, false, &ABIJsonTest::create},
9091
{"JSON Natspec", "libsolidity", "natspecJSON", false, false, &NatspecJSONTest::create},
9192
{"SMT Checker", "libsolidity", "smtCheckerTests", true, false, &SMTCheckerTest::create},
93+
{"Ethdebug", "libsolidity", "ethdebugTests", false, false, &EthdebugTest::create},
9294
{"Gas Estimates", "libsolidity", "gasTests", false, false, &GasTest::create},
9395
{"Memory Guard", "libsolidity", "memoryGuardTests", false, false, &MemoryGuardTest::create},
9496
{"AST Properties", "libsolidity", "astPropertyTests", false, false, &ASTPropertyTest::create},

test/libsolidity/EthdebugTest.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
This file is part of solidity.
3+
4+
solidity 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+
solidity 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 solidity. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
// SPDX-License-Identifier: GPL-3.0
18+
19+
#include <test/libsolidity/EthdebugTest.h>
20+
#include <test/Common.h>
21+
22+
#include <liblangutil/DebugInfoSelection.h>
23+
24+
#include <libsolidity/interface/OptimiserSettings.h>
25+
26+
#include <boost/throw_exception.hpp>
27+
28+
#include <stdexcept>
29+
30+
using namespace solidity;
31+
using namespace solidity::frontend;
32+
using namespace solidity::frontend::test;
33+
using namespace solidity::langutil;
34+
35+
EthdebugTest::EthdebugTest(std::string const& _filename):
36+
StandardJSONTest(_filename)
37+
{
38+
m_optimise = m_reader.boolSetting("optimize", false);
39+
m_optimiseYul = m_reader.boolSetting("optimize-yul", false);
40+
m_useSSACFG = m_reader.boolSetting("compileViaSSACFG", false);
41+
42+
auto revertStrings = revertStringsFromString(m_reader.stringSetting("revertStrings", "default"));
43+
if (!revertStrings)
44+
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid revertStrings setting."));
45+
m_revertStrings = *revertStrings;
46+
}
47+
48+
void EthdebugTest::setupCompiler(CompilerStack& _compiler)
49+
{
50+
AnalysisFramework::setupCompiler(_compiler);
51+
52+
_compiler.setViaIR(true);
53+
_compiler.setExperimental(true);
54+
if (m_useSSACFG)
55+
_compiler.setViaSSACFG(true);
56+
57+
DebugInfoSelection selection = DebugInfoSelection::Default();
58+
selection.enable("ethdebug");
59+
_compiler.selectDebugInfo(selection);
60+
61+
_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
62+
_compiler.setRevertStringBehaviour(m_revertStrings);
63+
64+
OptimiserSettings settings = m_optimise ? OptimiserSettings::standard() : OptimiserSettings::minimal();
65+
if (m_optimiseYul)
66+
settings.runYulOptimiser = true;
67+
_compiler.setOptimiserSettings(settings);
68+
}
69+
70+
std::map<std::string, Json> EthdebugTest::collectScopes() const
71+
{
72+
std::map<std::string, Json> result;
73+
74+
if (compiler().state() < CompilerStack::State::CompilationSuccessful)
75+
return result;
76+
77+
result[".resources"] = compiler().ethdebug();
78+
result[".compilation"] = compiler().ethdebugCompilation();
79+
80+
auto shortNameOf = [](std::string const& _qualified) {
81+
size_t colon = _qualified.rfind(':');
82+
return colon == std::string::npos ? _qualified : _qualified.substr(colon + 1);
83+
};
84+
85+
std::map<std::string, int> shortNameCount;
86+
for (std::string const& contractName: compiler().contractNames())
87+
++shortNameCount[shortNameOf(contractName)];
88+
89+
for (std::string const& contractName: compiler().contractNames())
90+
{
91+
std::string shortName = shortNameOf(contractName);
92+
Json creation = compiler().ethdebug(contractName);
93+
Json runtime = compiler().ethdebugRuntime(contractName);
94+
bool emitShortAlias = shortNameCount[shortName] == 1;
95+
96+
result[contractName + ".creation"] = creation;
97+
result[contractName + ".runtime"] = runtime;
98+
if (emitShortAlias)
99+
{
100+
result[shortName + ".creation"] = creation;
101+
result[shortName + ".runtime"] = runtime;
102+
}
103+
// Shortcut: "C.contract" -> the contract sub-object from creation
104+
if (!creation.is_null() && creation.contains("contract"))
105+
{
106+
result[contractName + ".contract"] = creation["contract"];
107+
if (emitShortAlias)
108+
result[shortName + ".contract"] = creation["contract"];
109+
}
110+
}
111+
112+
return result;
113+
}
114+
115+
std::pair<std::string, std::string> EthdebugTest::splitNonGlobalPath(std::string_view _path) const
116+
{
117+
// Qualified paths look like "source.sol:C.kind.subpath" — used to disambiguate
118+
// when the same short contract name appears in multisource tests.
119+
auto colonPos = _path.find(':');
120+
size_t contractStart = colonPos == std::string_view::npos ? 0 : colonPos + 1;
121+
122+
auto firstDot = _path.find('.', contractStart);
123+
if (firstDot == std::string_view::npos)
124+
return {std::string(_path), ""};
125+
126+
auto secondDot = _path.find('.', firstDot + 1);
127+
if (secondDot == std::string_view::npos)
128+
return {std::string(_path), ""};
129+
130+
solAssert(secondDot < _path.size());
131+
return {std::string(_path.substr(0, secondDot)), std::string(_path.substr(secondDot + 1))};
132+
}

test/libsolidity/EthdebugTest.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
This file is part of solidity.
3+
4+
solidity 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+
solidity 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 solidity. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
// SPDX-License-Identifier: GPL-3.0
18+
19+
#pragma once
20+
21+
#include <test/libsolidity/StandardJSONTest.h>
22+
23+
#include <libsolidity/interface/DebugSettings.h>
24+
25+
namespace solidity::frontend::test
26+
{
27+
28+
class EthdebugTest: public StandardJSONTest
29+
{
30+
public:
31+
static std::unique_ptr<TestCase> create(Config const& _config)
32+
{
33+
return std::make_unique<EthdebugTest>(_config.filename);
34+
}
35+
36+
EthdebugTest(std::string const& _filename);
37+
38+
protected:
39+
void setupCompiler(CompilerStack& _compiler) override;
40+
std::map<std::string, Json> collectScopes() const override;
41+
std::pair<std::string, std::string> splitNonGlobalPath(std::string_view _path) const override;
42+
43+
private:
44+
bool m_optimise = false;
45+
bool m_optimiseYul = false;
46+
bool m_useSSACFG = false;
47+
RevertStrings m_revertStrings = RevertStrings::Default;
48+
};
49+
50+
}

0 commit comments

Comments
 (0)