def test_dir(): ana.dl = ana.DirDataLayer(pickle_dir="/tmp/test_ana") one = A(1) nose.tools.assert_is(one, A.ana_load(one.ana_store())) nose.tools.assert_true(os.path.exists("/tmp/test_ana/%s.p" % one.ana_uuid)) uuid = one.ana_uuid old_id = id(one) del one gc.collect() ana.dl = ana.DirDataLayer(pickle_dir="/tmp/test_ana") two = A.ana_load(uuid) nose.tools.assert_equals(uuid, two.ana_uuid) nose.tools.assert_not_equals(old_id, id(two)) # reset the datalayer to make sure we handle it properly ana.set_dl(ana.DictDataLayer()) try: two = A.ana_load(uuid) assert False except KeyError: pass two.ana_store() del two three = A.ana_load(uuid) assert uuid, three.ana_uuid
def setup(): # clean up AST cache in claripy, because a cached AST might believe it has been stored in ana after we clean up the # ana storage import claripy claripy.ast.bv._bvv_cache.clear() claripy.ast.bv.BV._hash_cache.clear() ana.set_dl(ana.DictDataLayer())
def test_dict(): ana.set_dl(ana.DictDataLayer()) l.debug("Initializing 1") one = A(1) l.debug("Initializing 2") two = A(2) one.make_uuid() l.debug("Copying 1") one_p = pickle.dumps(one) one_copy = pickle.loads(one_p) l.debug("Copying 2") two_p = pickle.dumps(two) two_copy = pickle.loads(two_p) nose.tools.assert_is(one_copy, one) nose.tools.assert_is_not(two_copy, two) nose.tools.assert_equal(str(two_copy), str(two)) nose.tools.assert_is(one, A.ana_load(one.ana_store())) nose.tools.assert_is(two, A.ana_load(two.ana_store())) two_copy2 = pickle.loads(pickle.dumps(two)) nose.tools.assert_equal(str(two_copy2), str(two)) l.debug("Initializing 3") three = A(3) three_str = str(three) l.debug("Storing 3") three_uuid = three.ana_store() l.debug("Deleting 3") del three gc.collect() nose.tools.assert_false(three_uuid in ana.get_dl().uuid_cache) l.debug("Loading 3") three_copy = A.ana_load(three_uuid) nose.tools.assert_equal(three_copy.ana_uuid, three_uuid) #pylint:disable=no-member nose.tools.assert_equal(str(three_copy), three_str) known = set() first_json = three_copy.to_literal(known) nose.tools.assert_true(three_copy.ana_uuid in first_json['objects']) nose.tools.assert_equal( first_json['objects'][three_copy.ana_uuid]['object']['n'], three_copy.n) nose.tools.assert_equal(first_json['value']['ana_uuid'], three_copy.ana_uuid) second_json = three_copy.to_literal(known) nose.tools.assert_false(three_copy.ana_uuid in second_json['objects']) nose.tools.assert_equal(second_json['value']['ana_uuid'], three_copy.ana_uuid)
def test_basic(): ana.set_dl(ana.DictDataLayer()) def pickle_callback(path): path.globals['pickled'] = True def unpickle_callback(path): path.globals['unpickled'] = True project = angr.Project(_bin('tests/cgc/sc2_0b32aa01_01')) path = project.factory.entry_state() spiller = angr.exploration_techniques.Spiller(pickle_callback=pickle_callback, unpickle_callback=unpickle_callback) spiller._pickle([path]) del path gc.collect() path = spiller._unpickle(1)[0] assert path.globals['pickled'] assert path.globals['unpickled']
def test_palindrome2(): ana.set_dl(ana.DictDataLayer()) project = angr.Project(_bin('tests/cgc/sc2_0b32aa01_01')) pg = project.factory.simgr() limiter = angr.exploration_techniques.LengthLimiter(max_length=250) pg.use_technique(limiter) def pickle_callback(path): path.globals['pickled'] = True def unpickle_callback(path): path.globals['unpickled'] = True def priority_key(path): return hash(tuple(path.history.bbl_addrs)) # to help ensure determinism spiller = angr.exploration_techniques.Spiller( pickle_callback=pickle_callback, unpickle_callback=unpickle_callback, priority_key=priority_key ) pg.use_technique(spiller) #pg.step(until=lambda lpg: len(lpg.active) == 10) #pg.step(until=lambda lpg: len(lpg.spill_stage) > 15) #pg.step(until=lambda lpg: spiller._pickled_paths) pg.run() assert spiller._ever_pickled > 0 assert spiller._ever_unpickled == spiller._ever_pickled assert all(('pickled' not in path.globals and 'unpickled' not in path.globals) or (path.globals['pickled'] and path.globals['unpickled']) for path in pg.cut)
def setup(): ana.set_dl(ana.DictDataLayer())