Skip to content

Commit

Permalink
Merge branch 'issue-270-limiting-overall-memory'.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rvac committed Apr 11, 2018
2 parents c3830e7 + aa15fce commit 0b9c04f
Show file tree
Hide file tree
Showing 4 changed files with 150 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)
Binary file added tools/fileinfo/features/max-memory/ack.ex
Binary file not shown.
64 changes: 64 additions & 0 deletions tools/fileinfo/features/max-memory/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from regression_tests import *


class TestAnalysisWhenNoLimit(Test):
"""Checks that fileinfo correctly analyzes file when there is no memory
limit.
Test for https://github.com/avast-tl/retdec/issues/270
"""

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

def test_correctly_analyzes_file(self):
assert self.fileinfo.succeeded

self.assertEqual(
self.fileinfo.output['SHA256'],
'35f7b82373b66579d782fa61732da86717631eff95876b799a9549661709fd8b'
)


class TestAnalysisWhenSufficient(Test):
"""Checks that fileinfo correctly analyzes file when there is a sufficient
memory limit.
Test for https://github.com/avast-tl/retdec/issues/270
"""

settings = TestSettings(
tool='fileinfo',
args=[
'--max-memory=104857600', # 100 MB
'--max-memory-half-ram',
],
input='ack.ex',
)

def test_correctly_analyzes_file(self):
assert self.fileinfo.succeeded

self.assertEqual(
self.fileinfo.output['SHA256'],
'35f7b82373b66579d782fa61732da86717631eff95876b799a9549661709fd8b'
)


class TestAnalysisWhenInsufficientLimit(Test):
"""Checks that fileinfo fails to analyze the file when the memory limit is
not sufficient.
Test for https://github.com/avast-tl/retdec/issues/270
"""

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

def test_fails_to_analyze_file(self):
assert not self.fileinfo.succeeded, 'fileinfo succeeded but should have failed'

0 comments on commit 0b9c04f

Please sign in to comment.