view paraspace/tests/injection_test.py @ 92:1728795c29b7

Build dependencies for injection testcases
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 25 Jul 2011 10:01:14 +0800
parents fe7b3f111d57
children 2fa9b6f21344
line wrap: on
line source

from paraspace import dexfile
import os

def _install_dexfile_4_deptracker():
    global dexfile
    import imp
    from paraspace import dex_deptracker
    
    try:
        new_dexfile = imp.load_compiled('dexfile', dexfile.__file__)
    except ImportError:
        new_dexfile = imp.load_source('dexfile', dexfile.__file__)
        pass
    dex_deptracker.dexfile = new_dexfile
    dexfile = new_dexfile
    dex_deptracker._nest_types = (dexfile.array, dexfile.cond, dexfile.switch)
    pass


def inject_fakefile_to_helloworld_test():
    from paraspace.dex_deptracker import prepare_dep_decls
    from paraspace.dex_deptracker import build_dependencies
    
    _install_dexfile_4_deptracker()
    
    all_dep_decls = prepare_dep_decls()
    
    srcdir = os.path.dirname(__file__)
    srcroot = os.path.join(srcdir, '..', '..')
    
    helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex')
    helloworld_dex = dexfile.DEXFile.open(helloworld_fn)
    build_dependencies(helloworld_dex, all_dep_decls)

    fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex')
    fakefile_dex = dexfile.DEXFile.open(fakefile_fn)
    build_dependencies(fakefile_dex, all_dep_decls)
    pass