manticore/tests/test_manticore.py
Yan 45d5b9f6d2 New state serialization (#376)
* Fix naming

* Separate storage from workspace

* Begin removing output generation from manticore.py

* Split up workspace and output

* Create a separation between output and workspace

* Get it to a working (hacky) state

* Start bringing state serialization into workspace

* More mcore->workspace moves

* Remove unused imports

* Update serializers; add interface

* move state saving to workspace

* can now save/load states and testcases

* Add redis as backend

* Implement streams in terms of values and vice versa

* Implement `ls` and move workspace loading to Workspace

* Better workspace initialization

* Fix how --workspace is parsed for tests

* update tests to new workspace indexes

* Fix state storage and handling

* Doc updates and extra error checking

* pep8 style changes

* Add Executor's 'sync'

* Remove previous workspace artifacts from Executor

* Comment out constraints check assert

* Centralize locking to new testcase ids

* Fix testcase generation

* pep8 updates

* propagate descriptor instead of path

* Add an in-memory state store

* Make memory maps be sortable

* Allow to produce an empty state

* Add workspace tests

* Make Memory.__cmp__() more robust
2017-07-12 17:50:24 -04:00

56 lines
1.6 KiB
Python

import unittest
from manticore import Manticore
class ManticoreTest(unittest.TestCase):
_multiprocess_can_split_ = True
def setUp(self):
self.m = Manticore('tests/binaries/arguments_linux_amd64')
def test_add_hook(self):
def tmp(state):
pass
entry = 0x00400e40
self.m.add_hook(entry, tmp)
self.assertTrue(tmp in self.m._hooks[entry])
def test_hook_dec(self):
entry = 0x00400e40
@self.m.hook(entry)
def tmp(state):
pass
self.assertTrue(tmp in self.m._hooks[entry])
def test_hook(self):
self.m.context['x'] = 0
@self.m.hook(None)
def tmp(state):
self.m.context['x'] = 1
self.m.terminate()
self.m.run()
self.assertEqual(self.m.context['x'], 1)
def test_hook_dec_err(self):
with self.assertRaises(TypeError):
@self.m.hook('0x00400e40')
def tmp(state):
pass
def test_integration_basic_stdin(self):
import os, struct
self.m = Manticore('tests/binaries/basic_linux_amd64')
self.m.run()
workspace = self.m._output.uri# os.path.join(os.getcwd(), self.m.workspace)
with open(os.path.join(workspace, 'test_00000000.stdin')) as f:
a = struct.unpack('<I', f.read())[0]
with open(os.path.join(workspace, 'test_00000001.stdin')) as f:
b = struct.unpack('<I', f.read())[0]
if a > 0x41:
self.assertTrue(a > 0x41)
self.assertTrue(b <= 0x41)
else:
self.assertTrue(a <= 0x41)
self.assertTrue(b > 0x41)