def runDecompilerTest(target, testcases):
    print 'Running decompiler test {}...'.format(target)
    tdir = tempfile.mkdtemp()

    cpath = [decompile.findJRE(), dec_class_location]
    if cpath[0] is None:
        raise RuntimeError('Unable to locate rt.jar')

    decompile.decompileClass(cpath, targets=[target], outpath=tdir, add_throws=True)
    new_fname = compileJava(target, os.path.join(tdir, target + '.java'))

    # testcases = map(tuple, tests.decompiler.registry[target])
    good_fname = os.path.join(dec_class_location, target + '.class')
    runJavaAndCompare(target, testcases, good_fname, new_fname)
    shutil.rmtree(tdir)
Beispiel #2
0
def performTest(target, expected_results, tempbase=tempfile.gettempdir()):
    temppath = os.path.join(tempbase, target)

    cpath = [decompile.findJRE(), class_location]
    if None in cpath:
        raise RuntimeError('Unable to locate rt.jar')

    # Clear any pre-existing files and create directory if necessary
    # try:
    #     shutil.rmtree(temppath)
    # except OSError as e:
    #     print e
    try:
        os.mkdir(temppath)
    except OSError as e:
        print e
    assert(os.path.isdir(temppath))

    decompile.decompileClass(cpath, targets=[target], outpath=temppath, add_throws=True)
    # out, err = execute(['java',  '-jar', 'procyon-decompiler-0.5.25.jar', os.path.join(class_location, target+'.class')], '.')
    # if err:
    #     print 'Decompile errors:', err
    #     return False
    # with open(os.path.join(temppath, target+'.java'), 'wb') as f:
    #     f.write(out)

    print 'Attempting to compile'
    _, stderr = execute(['javac', target+'.java', '-g:none'], cwd=temppath)
    if stderr:
        print 'Compile failed:'
        print stderr
        return False

    cases = tests.registry[target]
    for args, expected in zip(cases, expected_results):
        print 'Executing {} w/ args {}'.format(target, args)
        result = execute(['java', target] + list(args), cwd=temppath)
        if result != expected:
            print 'Failed test {} w/ args {}:'.format(target, args)
            if result[0] != expected[0]:
                print '  expected stdout:', repr(expected[0])
                print '  actual stdout  :', repr(result[0])
            if result[1] != expected[1]:
                print '  expected stderr:', repr(expected[1])
                print '  actual stderr  :', repr(result[1])
            return False
    return True
Beispiel #3
0
def runDecompilerTest(target, testcases):
    print('Running decompiler test {}...'.format(target))
    tdir = tempfile.mkdtemp()

    cpath = [decompile.findJRE(), dec_class_location]
    if cpath[0] is None:
        raise RuntimeError('Unable to locate rt.jar')

    decompile.decompileClass(cpath,
                             targets=[target],
                             outpath=tdir,
                             add_throws=True)
    new_fname = compileJava(target, os.path.join(tdir, target + '.java'))

    # testcases = map(tuple, tests.decompiler.registry[target])
    good_fname = os.path.join(dec_class_location, target + '.class')
    runJavaAndCompare(target, testcases, good_fname, new_fname)
    shutil.rmtree(tdir)
Beispiel #4
0
def performTest(temppath, testdata, cpath=class_location):
    target, cases = testdata

    clearFolder(temppath)
    cpath = [decompile.findJRE(), cpath]
    decompile.decompileClass(cpath, targets=[target], outpath=temppath)

    print 'Attempting to compile'
    out, err = execute(['javac', target+'.java'] + '-g:none -target 1.5'.split(), cwd=temppath)
    if err:
        print out, err
        return False

    for args, expected in cases:
        result = execute(['java', target] + list(args), cwd=temppath)
        if result != expected:
            print 'expected', expected
            print 'actual', result
            return False
    return True
Beispiel #5
0
def performTest(temppath, testdata, cpath=class_location):
    target, cases = testdata

    clearFolder(temppath)
    cpath = [decompile.findJRE(), cpath]
    if None in cpath:
        raise RuntimeError('Unable to locate rt.jar')
    decompile.decompileClass(cpath, targets=[target], outpath=temppath)

    print 'Attempting to compile'
    out, err = execute(['javac', target+'.java'] + '-g:none'.split(), cwd=temppath)
    if err:
        print out, err
        return False

    for args, expected in cases:
        result = execute(['java', target] + list(args), cwd=temppath)
        if result != expected:
            print 'input', args
            print 'expected', expected
            print 'actual', result
            return False
    return True