From a10b7bae29ac84e3ce2679a12393abd280a62cbe Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Wed, 10 May 2017 19:44:55 -0400 Subject: [PATCH] Update parallel processing api (#246) * Remove m.workers, add run(procs=), update docs * Update docs --- examples/linux/binaries/concrete_solve.py | 4 ++-- examples/linux/binaries/symbolic_solve.py | 4 ++-- examples/script/count_instructions.py | 3 +-- examples/script/google2016_unbreakable/win.py | 3 +-- manticore/__main__.py | 7 ++----- manticore/manticore.py | 17 +++++------------ 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/examples/linux/binaries/concrete_solve.py b/examples/linux/binaries/concrete_solve.py index aebd843..d518719 100644 --- a/examples/linux/binaries/concrete_solve.py +++ b/examples/linux/binaries/concrete_solve.py @@ -29,7 +29,7 @@ def solve(state): # play with these numbers! m.verbosity = 0 -m.workers = 1 +procs = 1 -m.run() +m.run(procs) print m.context['solution'] diff --git a/examples/linux/binaries/symbolic_solve.py b/examples/linux/binaries/symbolic_solve.py index 0c5fd46..04f0088 100644 --- a/examples/linux/binaries/symbolic_solve.py +++ b/examples/linux/binaries/symbolic_solve.py @@ -33,6 +33,6 @@ def solve(state): # play with these numbers! m.verbosity = 0 -m.workers = 1 +procs = 1 -m.run() +m.run(procs) diff --git a/examples/script/count_instructions.py b/examples/script/count_instructions.py index e188ba3..2412576 100755 --- a/examples/script/count_instructions.py +++ b/examples/script/count_instructions.py @@ -17,13 +17,12 @@ if __name__ == '__main__': sys.exit(2) m = Manticore(sys.argv[1]) - m.workers = 3 m.context['count'] = 0 @m.hook(None) def explore(state): m.context['count'] += 1 - m.run() + m.run(procs=3) print "Executed ", m.context['count'], " instructions." diff --git a/examples/script/google2016_unbreakable/win.py b/examples/script/google2016_unbreakable/win.py index 0c1d2d2..612b17c 100644 --- a/examples/script/google2016_unbreakable/win.py +++ b/examples/script/google2016_unbreakable/win.py @@ -58,5 +58,4 @@ def hook(state): # We found the flag, no need to continue execution m.terminate() -m.workers = 10 -m.run() +m.run(procs=10) diff --git a/manticore/__main__.py b/manticore/__main__.py index 9ed912c..b52a2bc 100644 --- a/manticore/__main__.py +++ b/manticore/__main__.py @@ -40,7 +40,7 @@ def parse_arguments(): parser.add_argument('--dumpafter', type=int, default=0, help='Dump state after every N instructions; 0 to disable') parser.add_argument('--maxstorage', type=int, default=0, help='Storage use cap in megabytes.') parser.add_argument('--maxstates', type=int, default=0, help='Maximun number of states to mantain at the same time') - parser.add_argument('--procs', type=int, default=1, help='Number of parallel workers to spawn') + parser.add_argument('--procs', type=int, default=1, help='Number of parallel processes to spawn') parser.add_argument('--timeout', type=int, default=0, help='Timeout. Abort exploration aftr TIMEOUT seconds') parser.add_argument('--replay', type=str, default=None, help='The trace filename to replay') @@ -95,9 +95,6 @@ def main(): if args.names is not None: m.apply_model_hooks(args.names) - if args.procs: - m.workers = args.procs - if args.env: for entry in args.env: name, val = entry[0].split('=') @@ -111,7 +108,7 @@ def main(): logger.info('Loading program: {}'.format(args.programs)) logger.info('Workspace: {}'.format(m.workspace)) - m.run(args.timeout) + m.run(args.procs, args.timeout) m.dump_stats() diff --git a/manticore/manticore.py b/manticore/manticore.py index ed3fd67..b35af6b 100644 --- a/manticore/manticore.py +++ b/manticore/manticore.py @@ -159,7 +159,6 @@ class Manticore(object): # XXX(yan) '_args' will be removed soon; exists currently to ease porting self._args = args self._time_started = 0 - self._num_processes = 1 self._begun_trace = False self._assertions = {} self._model_hooks = {} @@ -371,15 +370,6 @@ class Manticore(object): ''' Make working directory ''' return tempfile.mkdtemp(prefix="mcore_", dir='./') - @property - def workers(self): - return self._num_processes - - @workers.setter - def workers(self, n): - assert not self._running, "Can't set workers if Manticore is running." - self._num_processes = n - @property def policy(self): return self._policy @@ -518,9 +508,12 @@ class Manticore(object): self._assertions[pc] = ' '.join(line.split(' ')[1:]) - def run(self, timeout=0): + def run(self, procs=1, timeout=0): ''' Runs analysis. + + :param int procs: Number of parallel worker processes + :param timeout: Analysis timeout, in seconds ''' assert not self._running, "Manticore is already running." args = self._args @@ -560,7 +553,7 @@ class Manticore(object): t = Timer(timeout, self.terminate) t.start() try: - self._start_workers(self._num_processes) + self._start_workers(procs) self._join_workers() finally: