Skip to content

Commit

Permalink
features: Add tests for limiting memory in retdec-decompiler.sh (--ma…
Browse files Browse the repository at this point in the history
…x-memory and --no-memory-limit).
  • Loading branch information
s3rvac committed Apr 10, 2018
1 parent 0861e57 commit aa15fce
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Binary file added features/max-memory/ack.ex
Binary file not shown.
86 changes: 86 additions & 0 deletions features/max-memory/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from regression_tests import *


class TestDefaultLimit(Test):
"""Checks that retdec-decompiler.sh correctly decompiles a binary file when
there is the default memory limit (half of system RAM).
Test for https://github.com/avast-tl/retdec/issues/270
"""

settings = TestSettings(
input='ack.ex',
)

def test_correctly_decompiled_file(self):
# The check whether the decompilation was successful is done
# automatically during setUp(), so we only check that the default
# memory limit has been set.
# For fileinfo:
self.assertIn('--max-memory-half-ram', self.decompiler.output)
# For bin2llvmir and llvmir2hll:
self.assertIn(' -max-memory-half-ram', self.decompiler.output)


class TestCustomSufficientLimit(Test):
"""Checks that retdec-decompiler.sh correctly decompiles a binary file when
there is a custom memory limit (but sufficient).
Test for https://github.com/avast-tl/retdec/issues/270
"""

settings = TestSettings(
input='ack.ex',
args='--max-memory 107374182400', # 1 GB
)

def test_correctly_decompiled_file(self):
# The check whether the decompilation was successful is done
# automatically during setUp(), so we only check that the memory limit
# has been set.
# For fileinfo:
self.assertIn('--max-memory 107374182400', self.decompiler.output)
# For bin2llvmir and llvmir2hll:
self.assertIn(' -max-memory 107374182400', self.decompiler.output)


class TestCustomInsufficientLimit(Test):
"""Checks that retdec-decompiler.sh fails to decompile a binary file when
the maximal memory limit is too low.
Test for https://github.com/avast-tl/retdec/issues/270
"""

settings = TestSettings(
input='ack.ex',
args='--max-memory 100', # 100 bytes
)

def setUp(self):
# Fail expected.
pass

def test_failed_to_decompile_file(self):
self.assertNotEqual(self.decompiler.return_code, 0)


class TestNoLimit(Test):
"""Checks that retdec-decompiler.sh correctly decompiles a binary file when
there is no memory limit.
Test for https://github.com/avast-tl/retdec/issues/270
"""

settings = TestSettings(
input='ack.ex',
args='--no-memory-limit',
)

def test_correctly_decompiled_file(self):
# The check whether the decompilation was successful is done
# automatically during setUp(), so we only check that no memory limit
# has been set.
# For fileinfo:
self.assertNotIn('--max-memory', self.decompiler.output)
# For bin2llvmir and llvmir2hll:
self.assertNotIn(' -max-memory', self.decompiler.output)

0 comments on commit aa15fce

Please sign in to comment.