2424
2525#include < liblangutil/Scanner.h>
2626#include < libsolutil/AnsiColorized.h>
27+ #include < libsolutil/StringUtils.h>
2728
2829using namespace solidity ::test;
2930using namespace solidity ::util;
@@ -136,10 +137,20 @@ bool StackShufflingTest::parse(std::string const& _source)
136137StackShufflingTest::StackShufflingTest (std::string const & _filename):
137138 TestCase(_filename)
138139{
140+ processSettings ();
139141 m_source = m_reader.source ();
140142 m_expectation = m_reader.simpleExpectations ();
141143}
142144
145+ void StackShufflingTest::processSettings ()
146+ {
147+ std::string depthString = m_reader.stringSetting (" maximumStackDepth" , " 16" );
148+ std::optional<unsigned > depth = toUnsignedInt (depthString);
149+ if (!depth.has_value ())
150+ BOOST_THROW_EXCEPTION (std::runtime_error{" Invalid maximum stack depth: \" " + depthString + " \" " });
151+ m_maximumStackDepth = *depth;
152+ }
153+
143154TestCase::TestResult StackShufflingTest::run (std::ostream& _stream, std::string const & _linePrefix, bool _formatted)
144155{
145156 auto const & dialect = CommonOptions::get ().evmDialect ();
@@ -150,16 +161,19 @@ TestCase::TestResult StackShufflingTest::run(std::ostream& _stream, std::string
150161 }
151162
152163 std::ostringstream output;
164+ size_t operations = 0 ;
153165 createStackLayout (
154166 m_sourceStack,
155167 m_targetStack,
156168 [&](unsigned _swapDepth) // swap
157169 {
170+ ++operations;
158171 output << stackToString (m_sourceStack, dialect) << std::endl;
159172 output << " SWAP" << _swapDepth << std::endl;
160173 },
161174 [&](StackSlot const & _slot) // dupOrPush
162175 {
176+ ++operations;
163177 output << stackToString (m_sourceStack, dialect) << std::endl;
164178 if (canBeFreelyGenerated (_slot))
165179 output << " PUSH " << stackSlotToString (_slot, dialect) << std::endl;
@@ -172,13 +186,15 @@ TestCase::TestResult StackShufflingTest::run(std::ostream& _stream, std::string
172186 }
173187 },
174188 [&](){ // pop
189+ ++operations;
175190 output << stackToString (m_sourceStack, dialect) << std::endl;
176191 output << " POP" << std::endl;
177192 },
178- 16u // TODO: make it a test setting
193+ m_maximumStackDepth
179194 );
180195
181196 output << stackToString (m_sourceStack, dialect) << std::endl;
197+ output << operations << " operations" << std::endl;
182198 m_obtainedResult = output.str ();
183199
184200 return checkResult (_stream, _linePrefix, _formatted);
0 commit comments