Skip to content

Commit e42df92

Browse files
committed
[test] Add support for --enforce-compile-to-ewasm.
1 parent ee657f5 commit e42df92

File tree

7 files changed

+61
-12
lines changed

7 files changed

+61
-12
lines changed

test/Common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ CommonOptions::CommonOptions(std::string _caption):
9898
("no-smt", po::bool_switch(&disableSMT), "disable SMT checker")
9999
("optimize", po::bool_switch(&optimize), "enables optimization")
100100
("enforce-via-yul", po::bool_switch(&enforceViaYul), "Enforce compiling all tests via yul to see if additional tests can be activated.")
101+
("enforce-compile-to-ewasm", po::bool_switch(&enforceCompileToEwasm), "Enforce compiling all tests to ewasm to see if additional tests can be activated.")
101102
("abiencoderv2", po::bool_switch(&useABIEncoderV2), "enables abi encoder v2")
102103
("show-messages", po::bool_switch(&showMessages), "enables message output")
103104
("show-metadata", po::bool_switch(&showMetadata), "enables metadata output");

test/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct CommonOptions: boost::noncopyable
5656
bool ewasm = false;
5757
bool optimize = false;
5858
bool enforceViaYul = false;
59+
bool enforceCompileToEwasm = false;
5960
bool disableSMT = false;
6061
bool useABIEncoderV2 = false;
6162
bool showMessages = false;

test/TestCase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TestCase
4141
langutil::EVMVersion evmVersion;
4242
std::vector<boost::filesystem::path> vmPaths;
4343
bool enforceCompileViaYul;
44+
bool enforceCompileToEwasm;
4445
};
4546

4647
enum class TestResult { Success, Failure, FatalError };

test/boostTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ int registerTests(
6565
boost::filesystem::path const& _basepath,
6666
boost::filesystem::path const& _path,
6767
bool _enforceViaYul,
68+
bool _enforceCompileToEwasm,
6869
vector<string> const& _labels,
6970
TestCase::TestCaseCreator _testCaseCreator
7071
)
7172
{
7273
int numTestsAdded = 0;
7374
fs::path fullpath = _basepath / _path;
74-
TestCase::Config config{fullpath.string(), solidity::test::CommonOptions::get().evmVersion(), solidity::test::CommonOptions::get().vmPaths, _enforceViaYul};
75+
TestCase::Config config{fullpath.string(), solidity::test::CommonOptions::get().evmVersion(), solidity::test::CommonOptions::get().vmPaths, _enforceViaYul, _enforceCompileToEwasm};
7576
if (fs::is_directory(fullpath))
7677
{
7778
test_suite* sub_suite = BOOST_TEST_SUITE(_path.filename().string());
@@ -84,6 +85,7 @@ int registerTests(
8485
*sub_suite,
8586
_basepath, _path / entry.path().filename(),
8687
_enforceViaYul,
88+
_enforceCompileToEwasm,
8789
_labels,
8890
_testCaseCreator
8991
);
@@ -184,6 +186,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
184186
options.testPath / ts.path,
185187
ts.subpath,
186188
options.enforceViaYul,
189+
options.enforceCompileToEwasm,
187190
ts.labels,
188191
ts.testCaseCreator
189192
) > 0, std::string("no ") + ts.title + " tests found");

test/libsolidity/SemanticTest.cpp

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ using namespace boost::unit_test;
3939
namespace fs = boost::filesystem;
4040

4141

42-
SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVersion, vector<boost::filesystem::path> const& _vmPaths, bool enforceViaYul):
42+
SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVersion, vector<boost::filesystem::path> const& _vmPaths, bool enforceViaYul, bool enforceCompileToEwasm):
4343
SolidityExecutionFramework(_evmVersion, _vmPaths),
4444
EVMVersionRestrictedTestCase(_filename),
4545
m_sources(m_reader.sources()),
4646
m_lineOffset(m_reader.lineNumber()),
47-
m_enforceViaYul(enforceViaYul)
47+
m_enforceViaYul(enforceViaYul),
48+
m_enforceCompileToEwasm(enforceCompileToEwasm)
4849
{
4950
string choice = m_reader.stringSetting("compileViaYul", "default");
5051
if (choice == "also")
@@ -63,6 +64,7 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer
6364
m_runWithoutYul = true;
6465
// Do not try to run via yul if explicitly denied.
6566
m_enforceViaYul = false;
67+
m_enforceCompileToEwasm = false;
6668
}
6769
else if (choice == "default")
6870
{
@@ -105,16 +107,25 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
105107
{
106108
TestResult result = TestResult::Success;
107109
bool compileViaYul = m_runWithYul || m_enforceViaYul;
110+
bool compileToEwasm = m_runWithEwasm || m_enforceCompileToEwasm;
108111

109112
if (m_runWithoutYul)
110113
result = runTest(_stream, _linePrefix, _formatted, false, false);
111114

112115
if (compileViaYul && result == TestResult::Success)
113116
result = runTest(_stream, _linePrefix, _formatted, true, false);
114117

115-
if (m_runWithEwasm && result == TestResult::Success)
116-
result = runTest(_stream, _linePrefix, _formatted, true, true);
117-
118+
if (compileToEwasm && result == TestResult::Success)
119+
{
120+
try
121+
{
122+
result = runTest(_stream, _linePrefix, _formatted, true, true);
123+
}
124+
catch (...) {
125+
if (!m_enforceCompileToEwasm || m_runWithEwasm)
126+
throw;
127+
}
128+
}
118129
return result;
119130
}
120131

@@ -139,6 +150,7 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
139150
}
140151

141152
m_compileViaYulCanBeSet = false;
153+
m_compileToEwasmCanBeSet = false;
142154

143155
if (_compileViaYul)
144156
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Running via Yul:" << endl;
@@ -234,8 +246,23 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
234246
return TestResult::Failure;
235247
}
236248

249+
if (success && !m_runWithEwasm && _compileToEwasm)
250+
{
251+
if (m_revertStrings != RevertStrings::Default)
252+
return TestResult::Success;
253+
254+
m_compileToEwasmCanBeSet = true;
255+
AnsiColorized(_stream, _formatted, {BOLD, YELLOW}) <<
256+
_linePrefix << endl <<
257+
_linePrefix << "Test can pass via Yul to ewasm and marked with compileToEwasm: false." << endl;
258+
return TestResult::Failure;
259+
}
260+
237261
if (!success && (m_runWithYul || !_compileViaYul))
238262
{
263+
if (!m_runWithEwasm && m_enforceCompileToEwasm)
264+
return TestResult::Success;
265+
239266
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
240267
for (auto const& test: m_tests)
241268
{
@@ -353,11 +380,24 @@ void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePre
353380
return;
354381

355382
_stream << _linePrefix << "// ====" << endl;
356-
if (m_compileViaYulCanBeSet)
383+
if (m_compileToEwasmCanBeSet)
384+
{
385+
if (m_runWithYul)
386+
{
387+
if (m_runWithoutYul)
388+
_stream << _linePrefix << "// compileViaYul: also\n";
389+
else
390+
_stream << _linePrefix << "// compileViaYul: true\n";
391+
}
392+
393+
_stream << _linePrefix << "// compileToEwasm: also\n";
394+
}
395+
else if (m_compileViaYulCanBeSet)
357396
_stream << _linePrefix << "// compileViaYul: also\n";
397+
358398
for (auto const& setting: settings)
359-
if (!m_compileViaYulCanBeSet || setting.first != "compileViaYul")
360-
_stream << _linePrefix << "// " << setting.first << ": " << setting.second << endl;
399+
if (!(m_compileViaYulCanBeSet || m_compileToEwasmCanBeSet) || setting.first != "compileViaYul")
400+
_stream << _linePrefix << "// " << setting.first << ": " << setting.second << endl;
361401
}
362402

363403
void SemanticTest::parseExpectations(istream& _stream)

test/libsolidity/SemanticTest.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class SemanticTest: public SolidityExecutionFramework, public EVMVersionRestrict
4040
{
4141
public:
4242
static std::unique_ptr<TestCase> create(Config const& _options)
43-
{ return std::make_unique<SemanticTest>(_options.filename, _options.evmVersion, _options.vmPaths, _options.enforceCompileViaYul); }
43+
{ return std::make_unique<SemanticTest>(_options.filename, _options.evmVersion, _options.vmPaths, _options.enforceCompileViaYul, _options.enforceCompileToEwasm); }
4444

45-
explicit SemanticTest(std::string const& _filename, langutil::EVMVersion _evmVersion, std::vector<boost::filesystem::path> const& _vmPaths, bool _enforceViaYul = false);
45+
explicit SemanticTest(std::string const& _filename, langutil::EVMVersion _evmVersion, std::vector<boost::filesystem::path> const& _vmPaths, bool _enforceViaYul = false, bool _enforceCompileToEwasm = false);
4646

4747
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
4848
void printSource(std::ostream &_stream, std::string const& _linePrefix = "", bool _formatted = false) const override;
@@ -67,9 +67,11 @@ class SemanticTest: public SolidityExecutionFramework, public EVMVersionRestrict
6767
bool m_runWithEwasm = false;
6868
bool m_runWithoutYul = true;
6969
bool m_enforceViaYul = false;
70+
bool m_enforceCompileToEwasm = false;
7071
bool m_runWithABIEncoderV1Only = false;
7172
bool m_allowNonExistingFunctions = false;
7273
bool m_compileViaYulCanBeSet = false;
74+
bool m_compileToEwasmCanBeSet = false;
7375
};
7476

7577
}

test/tools/isoltest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ TestTool::Result TestTool::process()
162162
m_path.string(),
163163
m_options.evmVersion(),
164164
m_options.vmPaths,
165-
m_options.enforceViaYul
165+
m_options.enforceViaYul,
166+
m_options.enforceCompileToEwasm,
166167
});
167168
if (m_test->shouldRun())
168169
switch (TestCase::TestResult result = m_test->run(outputMessages, " ", formatted))

0 commit comments

Comments
 (0)