Skip to content

Commit 5937f16

Browse files
aarltaxic
authored andcommitted
[test] Add support for --enforce-compile-to-ewasm.
1 parent 1db3278 commit 5937f16

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

test/Common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ CommonOptions::CommonOptions(std::string _caption):
103103
("no-smt", po::bool_switch(&disableSMT), "disable SMT checker")
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.")
106+
("enforce-compile-to-ewasm", po::bool_switch(&enforceCompileToEwasm), "Enforce compiling all tests to Ewasm to see if additional tests can be activated.")
106107
("enforce-gas-cost", po::bool_switch(&enforceGasTest), "Enforce checking gas cost in semantic tests.")
107108
("enforce-gas-cost-min-value", po::value(&enforceGasTestMinValue), "Threshold value to enforce adding gas checks to a test.")
108109
("abiencoderv1", po::bool_switch(&useABIEncoderV1), "enables abi encoder v1")

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 enforceGasTest = false;
6061
u256 enforceGasTestMinValue = 100000;
6162
bool disableSMT = 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 = false;
44+
bool enforceCompileToEwasm = false;
4445
bool enforceGasCost = false;
4546
u256 enforceGasCostMinValue;
4647
};

test/boostTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ 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
)
@@ -76,6 +77,7 @@ int registerTests(
7677
solidity::test::CommonOptions::get().evmVersion(),
7778
solidity::test::CommonOptions::get().vmPaths,
7879
_enforceViaYul,
80+
_enforceCompileToEwasm,
7981
solidity::test::CommonOptions::get().enforceGasTest,
8082
solidity::test::CommonOptions::get().enforceGasTestMinValue
8183
};
@@ -91,6 +93,7 @@ int registerTests(
9193
*sub_suite,
9294
_basepath, _path / entry.path().filename(),
9395
_enforceViaYul,
96+
_enforceCompileToEwasm,
9497
_labels,
9598
_testCaseCreator
9699
);
@@ -195,6 +198,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
195198
options.testPath / ts.path,
196199
ts.subpath,
197200
options.enforceViaYul,
201+
options.enforceCompileToEwasm,
198202
ts.labels,
199203
ts.testCaseCreator
200204
) > 0, std::string("no ") + ts.title + " tests found");

test/libsolidity/SemanticTest.cpp

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ SemanticTest::SemanticTest(
5050
langutil::EVMVersion _evmVersion,
5151
vector<boost::filesystem::path> const& _vmPaths,
5252
bool _enforceViaYul,
53+
bool _enforceCompileToEwasm,
5354
bool _enforceGasCost,
5455
u256 _enforceGasCostMinValue
5556
):
@@ -58,6 +59,7 @@ SemanticTest::SemanticTest(
5859
m_sources(m_reader.sources()),
5960
m_lineOffset(m_reader.lineNumber()),
6061
m_enforceViaYul(_enforceViaYul),
62+
m_enforceCompileToEwasm(_enforceCompileToEwasm),
6163
m_enforceGasCost(_enforceGasCost),
6264
m_enforceGasCostMinValue(_enforceGasCostMinValue)
6365
{
@@ -78,6 +80,7 @@ SemanticTest::SemanticTest(
7880
m_runWithoutYul = true;
7981
// Do not try to run via yul if explicitly denied.
8082
m_enforceViaYul = false;
83+
m_enforceCompileToEwasm = false;
8184
}
8285
else if (choice == "default")
8386
{
@@ -126,16 +129,26 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
126129
{
127130
TestResult result = TestResult::Success;
128131
bool compileViaYul = m_runWithYul || m_enforceViaYul;
132+
bool compileToEwasm = m_runWithEwasm || m_enforceCompileToEwasm;
129133

130134
if (m_runWithoutYul)
131135
result = runTest(_stream, _linePrefix, _formatted, false, false);
132136

133137
if (compileViaYul && result == TestResult::Success)
134138
result = runTest(_stream, _linePrefix, _formatted, true, false);
135139

136-
if (m_runWithEwasm && result == TestResult::Success)
137-
result = runTest(_stream, _linePrefix, _formatted, true, true);
138-
140+
if (compileToEwasm && result == TestResult::Success)
141+
{
142+
try
143+
{
144+
result = runTest(_stream, _linePrefix, _formatted, true, true);
145+
}
146+
catch (...)
147+
{
148+
if (!m_enforceCompileToEwasm)
149+
throw;
150+
}
151+
}
139152
return result;
140153
}
141154

@@ -165,6 +178,7 @@ TestCase::TestResult SemanticTest::runTest(
165178
}
166179

167180
m_compileViaYulCanBeSet = false;
181+
m_compileToEwasmCanBeSet = false;
168182

169183
if (_compileViaYul)
170184
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Running via Yul:" << endl;
@@ -288,8 +302,23 @@ TestCase::TestResult SemanticTest::runTest(
288302
return TestResult::Failure;
289303
}
290304

305+
if (success && !m_runWithEwasm && _compileToEwasm)
306+
{
307+
if (m_revertStrings != RevertStrings::Default)
308+
return TestResult::Success;
309+
310+
m_compileToEwasmCanBeSet = true;
311+
AnsiColorized(_stream, _formatted, {BOLD, YELLOW})
312+
<< _linePrefix << endl
313+
<< _linePrefix << "Test can pass via Yul (ewasm), but marked with \"compileToEwasm: false.\"" << endl;
314+
return TestResult::Failure;
315+
}
316+
291317
if (!success && (m_runWithYul || !_compileViaYul))
292318
{
319+
if (!m_runWithEwasm && m_enforceCompileToEwasm)
320+
return TestResult::Success;
321+
293322
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
294323
for (TestFunctionCall const& test: m_tests)
295324
{
@@ -424,11 +453,28 @@ void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePre
424453
return;
425454

426455
_stream << _linePrefix << "// ====" << endl;
427-
if (m_compileViaYulCanBeSet)
456+
if (m_compileToEwasmCanBeSet)
457+
{
458+
// if test was already configured to run via yul,
459+
// we need to preserve the original settings.
460+
if (m_runWithYul)
461+
{
462+
// if test was also configured to run without yul.
463+
if (m_runWithoutYul)
464+
_stream << _linePrefix << "// compileViaYul: also\n";
465+
// if test was configured only to run with yul.
466+
else
467+
_stream << _linePrefix << "// compileViaYul: true\n";
468+
}
469+
470+
_stream << _linePrefix << "// compileToEwasm: also\n";
471+
}
472+
else if (m_compileViaYulCanBeSet)
428473
_stream << _linePrefix << "// compileViaYul: also\n";
474+
429475
for (auto const& setting: settings)
430-
if (!m_compileViaYulCanBeSet || setting.first != "compileViaYul")
431-
_stream << _linePrefix << "// " << setting.first << ": " << setting.second << endl;
476+
if (!(m_compileViaYulCanBeSet || m_compileToEwasmCanBeSet) || setting.first != "compileViaYul")
477+
_stream << _linePrefix << "// " << setting.first << ": " << setting.second << endl;
432478
}
433479

434480
void SemanticTest::parseExpectations(istream& _stream)

test/libsolidity/SemanticTest.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class SemanticTest: public SolidityExecutionFramework, public EVMVersionRestrict
4646
_options.evmVersion,
4747
_options.vmPaths,
4848
_options.enforceCompileViaYul,
49+
_options.enforceCompileToEwasm,
4950
_options.enforceGasCost,
5051
_options.enforceGasCostMinValue
5152
);
@@ -56,6 +57,7 @@ class SemanticTest: public SolidityExecutionFramework, public EVMVersionRestrict
5657
langutil::EVMVersion _evmVersion,
5758
std::vector<boost::filesystem::path> const& _vmPaths,
5859
bool _enforceViaYul = false,
60+
bool _enforceCompileToEwasm = false,
5961
bool _enforceGasCost = false,
6062
u256 _enforceGasCostMinValue = 100000
6163
);
@@ -85,9 +87,11 @@ class SemanticTest: public SolidityExecutionFramework, public EVMVersionRestrict
8587
bool m_runWithEwasm = false;
8688
bool m_runWithoutYul = true;
8789
bool m_enforceViaYul = false;
90+
bool m_enforceCompileToEwasm = false;
8891
bool m_runWithABIEncoderV1Only = false;
8992
bool m_allowNonExistingFunctions = false;
9093
bool m_compileViaYulCanBeSet = false;
94+
bool m_compileToEwasmCanBeSet = false;
9195
std::map<std::string, Builtin> m_builtins{};
9296

9397
bool m_gasCostFailure = false;

test/tools/isoltest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ TestTool::Result TestTool::process()
163163
m_options.evmVersion(),
164164
m_options.vmPaths,
165165
m_options.enforceViaYul,
166+
m_options.enforceCompileToEwasm,
166167
m_options.enforceGasTest,
167168
m_options.enforceGasTestMinValue
168169
});

0 commit comments

Comments
 (0)