Skip to content

Commit 8a45df2

Browse files
committed
[test] Add support for --enforce-compile-to-ewasm.
1 parent 8194cbb commit 8a45df2

File tree

7 files changed

+66
-12
lines changed

7 files changed

+66
-12
lines changed

test/Common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ CommonOptions::CommonOptions(std::string _caption):
104104
("optimize", po::bool_switch(&optimize), "enables optimization")
105105
("enforce-via-yul", po::bool_switch(&enforceViaYul), "Enforce compiling all tests via yul to see if additional tests can be activated.")
106106
("abiencoderv1", po::bool_switch(&useABIEncoderV1), "enables abi encoder v1")
107+
("enforce-compile-to-ewasm", po::bool_switch(&enforceCompileToEwasm), "Enforce compiling all tests to ewasm to see if additional tests can be activated.")
107108
("show-messages", po::bool_switch(&showMessages), "enables message output")
108109
("show-metadata", po::bool_switch(&showMetadata), "enables metadata output");
109110
}

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 useABIEncoderV1 = 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
);
@@ -188,6 +190,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
188190
options.testPath / ts.path,
189191
ts.subpath,
190192
options.enforceViaYul,
193+
options.enforceCompileToEwasm,
191194
ts.labels,
192195
ts.testCaseCreator
193196
) > 0, std::string("no ") + ts.title + " tests found");

test/libsolidity/SemanticTest.cpp

Lines changed: 53 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,26 @@ 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+
{
126+
if (!m_enforceCompileToEwasm)
127+
throw;
128+
}
129+
}
118130
return result;
119131
}
120132

@@ -139,6 +151,7 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
139151
}
140152

141153
m_compileViaYulCanBeSet = false;
154+
m_compileToEwasmCanBeSet = false;
142155

143156
if (_compileViaYul)
144157
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Running via Yul:" << endl;
@@ -236,8 +249,23 @@ TestCase::TestResult SemanticTest::runTest(ostream& _stream, string const& _line
236249
return TestResult::Failure;
237250
}
238251

252+
if (success && !m_runWithEwasm && _compileToEwasm)
253+
{
254+
if (m_revertStrings != RevertStrings::Default)
255+
return TestResult::Success;
256+
257+
m_compileToEwasmCanBeSet = true;
258+
AnsiColorized(_stream, _formatted, {BOLD, YELLOW}) <<
259+
_linePrefix << endl <<
260+
_linePrefix << "Test can pass via Yul (ewasm) and marked with compileToEwasm: false." << endl;
261+
return TestResult::Failure;
262+
}
263+
239264
if (!success && (m_runWithYul || !_compileViaYul))
240265
{
266+
if (!m_runWithEwasm && m_enforceCompileToEwasm)
267+
return TestResult::Success;
268+
241269
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
242270
for (auto const& test: m_tests)
243271
{
@@ -355,11 +383,28 @@ void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePre
355383
return;
356384

357385
_stream << _linePrefix << "// ====" << endl;
358-
if (m_compileViaYulCanBeSet)
386+
if (m_compileToEwasmCanBeSet)
387+
{
388+
// if test was already configured to run via yul,
389+
// we need to preserve the original settings.
390+
if (m_runWithYul)
391+
{
392+
// if test was also configured to run without yul.
393+
if (m_runWithoutYul)
394+
_stream << _linePrefix << "// compileViaYul: also\n";
395+
// if test was configured only to run with yul.
396+
else
397+
_stream << _linePrefix << "// compileViaYul: true\n";
398+
}
399+
400+
_stream << _linePrefix << "// compileToEwasm: also\n";
401+
}
402+
else if (m_compileViaYulCanBeSet)
359403
_stream << _linePrefix << "// compileViaYul: also\n";
404+
360405
for (auto const& setting: settings)
361-
if (!m_compileViaYulCanBeSet || setting.first != "compileViaYul")
362-
_stream << _linePrefix << "// " << setting.first << ": " << setting.second << endl;
406+
if (!(m_compileViaYulCanBeSet || m_compileToEwasmCanBeSet) || setting.first != "compileViaYul")
407+
_stream << _linePrefix << "// " << setting.first << ": " << setting.second << endl;
363408
}
364409

365410
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)