コード例 #1
0
def Test():
    __pychecker__ = 'unusednames=args'
    global check_release
    global check_range

    ParseOptions(['--testgen_opt=so_long,MyOpt=XYZ,goodbye'])
    if Generator.Run('AST') != 0:
        print 'Generate release: Failed.\n'
        return -1

    if check_release != 1 or check_range != 0:
        print 'Gererate release: Failed to run.\n'
        return -1

    check_release = 0
    ParseOptions(['--testgen_opt="HELLO"', '--range=M14,M16'])
    if Generator.Run('AST') != 0:
        print 'Generate range: Failed.\n'
        return -1

    if check_release != 0 or check_range != 1:
        print 'Gererate range: Failed to run.\n'
        return -1

    print 'Generator test: Pass'
    return 0
コード例 #2
0
ファイル: generator.py プロジェクト: Havok380/chromium-test
def Main(args):
    # If no arguments are provided, assume we are trying to rebuild the
    # C headers with warnings off.
    try:
        if not args:
            args = [
                '--wnone',
                '--cgen',
                '--range=start,end',
                '--pnacl',
                '--pnaclshim',
                '../native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c',
                '--tgen',
            ]
            current_dir = os.path.abspath(os.getcwd())
            script_dir = os.path.abspath(os.path.dirname(__file__))
            if current_dir != script_dir:
                print '\nIncorrect CWD, default run skipped.'
                print 'When running with no arguments set CWD to the scripts directory:'
                print '\t' + script_dir + '\n'
                print 'This ensures correct default paths and behavior.\n'
                return 1

        filenames = ParseOptions(args)
        ast = ParseFiles(filenames)
        if ast.errors:
            print 'Found %d errors.  Aborting build.\n' % ast.errors
            return 1
        return Generator.Run(ast)
    except SystemExit, ec:
        print 'Exiting with %d' % ec.code
        sys.exit(ec.code)
コード例 #3
0
def main(args):
    # Default invocation will verify the golden files are unchanged.
    failed = 0
    if not args:
        args = ['--wnone', '--diff', '--test', '--dstroot=.']

    ParseOptions(args)

    idldir = os.path.split(sys.argv[0])[0]
    idldir = os.path.join(idldir, 'test_cgen', '*.idl')
    filenames = glob.glob(idldir)
    ast = ParseFiles(filenames)
    if hgen.GenerateRelease(ast, 'M14', {}):
        print "Golden file for M14 failed."
        failed = 1
    else:
        print "Golden file for M14 passed."

    idldir = os.path.split(sys.argv[0])[0]
    idldir = os.path.join(idldir, 'test_cgen_range', '*.idl')
    filenames = glob.glob(idldir)

    ast = ParseFiles(filenames)
    if hgen.GenerateRange(ast, ['M13', 'M14', 'M15'], {}):
        print "Golden file for M13-M15 failed."
        failed = 1
    else:
        print "Golden file for M13-M15 passed."

    return failed
コード例 #4
0
def Main(args):
    if not args: return Test()

    filenames = ParseOptions(args)
    ast = ParseFiles(filenames)

    return Generator.Run(ast)
コード例 #5
0
def Main():
    args = sys.argv[1:]
    # If no arguments are provided, assume we are trying to rebuild the
    # C headers with warnings off.
    if not args:
        args = [
            '--wnone',
            '--cgen',
            '--range=start,end',
            '--pnacl',
            '--pnaclshim',
            '../native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c',
        ]
        current_dir = os.path.abspath(os.getcwd())
        script_dir = os.path.abspath(os.path.dirname(__file__))
        if current_dir != script_dir:
            print '\nIncorrect CWD, default run skipped.'
            print 'When running with no arguments set CWD to the scripts directory:'
            print '\t' + script_dir + '\n'
            print 'This ensures correct default paths and behavior.\n'
            return 1

    filenames = ParseOptions(args)
    ast = ParseFiles(filenames)
    return Generator.Run(ast)
コード例 #6
0
def Main(args):
    filenames = ParseOptions(args)
    if GetOption('test'):
        return TestFiles(filenames)
    ast = ParseFiles(filenames)
    for f in ast.GetListOf('File'):
        if f.GetProperty('ERRORS') > 0:
            print 'Skipping %s' % f.GetName()
            continue
        print DefineDepends(node)
        for node in f.GetChildren()[2:]:
            print Define(node, comment=True, prefix='tst_')
コード例 #7
0
def main(args):
    filenames = ParseOptions(args)
    if GetOption('test'):
        return TestFiles(filenames)
    ast = ParseFiles(filenames)
    cgen = CSGen()
    for f in ast.GetListOf('File'):
        if f.GetProperty('ERRORS') > 0:
            print 'Skipping %s' % f.GetName()
            continue
        for node in f.GetChildren()[2:]:
            print cgen.Define(node, ast.releases, comment=True, prefix='tst_')
コード例 #8
0
def Main(args):
    filenames = ParseOptions(args)
    test_releases = ['M13', 'M14', 'M15']
    if not filenames:
        idldir = os.path.split(sys.argv[0])[0]
        idldir = os.path.join(idldir, 'test_gen_pnacl', '*.idl')
        filenames = glob.glob(idldir)
    filenames = sorted(filenames)
    if GetOption('test'):
        # Run the tests.
        return TestFiles(filenames, test_releases)

    # Otherwise, generate the output file (for potential use as golden file).
    ast = ParseFiles(filenames)
    return pnaclgen.GenerateRange(ast, test_releases, filenames)
コード例 #9
0
ファイル: idl_gen_rpc.py プロジェクト: adeshkp/moebius
def main(args):
    filenames = ParseOptions(args)
    ast = ParseFiles(filenames)
    rpcgen = RPCGen()
    files = ast.GetListOf('File')
    outname = GetOption('out')
    if outname == '':
        outname = 'out.cc'
    outfile = IDLOutFile(outname)
    emitted = set()
    for f in files:
        if f.GetName() == 'pp_macros.idl':
            GenerateDep(outfile, emitted, f, ast.releases)
    for f in files:
        GenerateDep(outfile, emitted, f, ast.releases)
    out = ''
    out += '#include "host/rpc.h"\n'
    out += '#include "json/json.cpp"\n'
    out += 'using namespace std;\n'
    out += 'using namespace JSON;\n'
    for declareOnly in [True, False]:
        for f in files:
            if f.GetProperty('ERRORS') > 0:
                print 'Skipping %s' % f.GetName()
                continue
            for node in f.GetChildren()[2:]:
                out += rpcgen.Define(node, ast.releases, declareOnly)
    out += 'static map<string, void*> gInterfaces;\n'
    out += '\n'
    out += 'typedef char* (*InterfaceMemberCallFunc)(const void*, JSONIterator&);\n'
    out += 'static map<string, InterfaceMemberCallFunc> gInterfaceMemberCallers;\n'
    out += '\n'
    out += 'void InitializeInterfaceList() {\n'
    for (interfaceString, interfaceStruct) in rpcgen.interfaceStructs:
        if interfaceString == "PPB_Flash_File_FileRef;2.0":
            interfaceString = "PPB_Flash_File_FileRef;2"
        elif interfaceString == "PPB_Flash_File_ModuleLocal;3.0":
            interfaceString = "PPB_Flash_File_ModuleLocal;3"
        elif interfaceString == "PPB_PDF;0.1":
            interfaceString = "PPB_PDF;1"
        out += '  gInterfaces.insert(pair<string, void*>("' + interfaceString + '", &' + interfaceStruct + '));\n'
    for (interfaceString, caller) in rpcgen.pppInterfaceGetters:
        out += '  gInterfaceMemberCallers.insert(pair<string, InterfaceMemberCallFunc>("' + interfaceString + '", ' + caller + '));\n'
    out += '};\n'
    out += '\n'
    outfile.Write(out)
    outfile.Close()
コード例 #10
0
ファイル: idl_lexer.py プロジェクト: adeshkp/moebius
def Main(args):
  filenames = ParseOptions(args)

  try:
    tokens = FilesToTokens(filenames, GetOption('verbose'))
    values = [tok.value for tok in tokens]
    if GetOption('output'): sys.stdout.write(' <> '.join(values) + '\n')
    if GetOption('test'):
      if TestSame(values):
        return -1
      if TestExpect(tokens):
        return -1
    return 0

  except lex.LexError as le:
    sys.stderr.write('%s\n' % str(le))
  return -1
コード例 #11
0
ファイル: idl_diff.py プロジェクト: Havok380/chromium-test
def Main(args):
  filenames = ParseOptions(args)
  if not filenames:
    gendir = os.path.join(GetOption('gen'), '*.h')
    filenames = sorted(glob.glob(gendir))
    srcdir = os.path.join(GetOption('src'), '*.h')
    srcs = sorted(glob.glob(srcdir))
    for name in srcs:
      name = os.path.split(name)[1]
      name = os.path.join(GetOption('gen'), name)
      if name not in filenames:
        print 'Missing: %s' % name

  for filename in filenames:
    gen = filename
    filename = filename[len(GetOption('gen')) + 1:]
    src = os.path.join(GetOption('src'), filename)
    diff = os.path.join(GetOption('diff'), filename)
    p = subprocess.Popen(['diff', src, gen], stdout=subprocess.PIPE)
    output, errors = p.communicate()

    try:
      input = open(diff, 'rt').read()
    except:
      input = ''

    if input != output:
      changes = GetChanges(output)
    else:
      changes = []

    if changes:
      print "\n\nDelta between:\n  src=%s\n  gen=%s\n" % (src, gen)
      for change in changes:
        change.Dump()
      print 'Done with %s\n\n' % src
      if GetOption('ok'):
        open(diff, 'wt').write(output)
      if GetOption('halt'):
        return 1
    else:
      print "\nSAME:\n  src=%s\n  gen=%s" % (src, gen)
      if input: print '  ** Matched expected diff. **'
      print '\n'
コード例 #12
0
ファイル: idl_parser.py プロジェクト: Devic1573/Chromium
def Main(args):
    filenames = ParseOptions(args)

    # If testing...
    if GetOption('test'):
        errs = TestErrorFiles(filenames)
        errs = TestNamespaceFiles(filenames)
        if errs:
            ErrOut.Log("Parser failed with %d errors." % errs)
            return -1
        return 0

    # Otherwise, build the AST
    ast = ParseFiles(filenames)
    errs = ast.GetProperty('ERRORS')
    if errs:
        ErrOut.Log('Found %d error(s).' % errs)
    InfoOut.Log("%d files processed." % len(filenames))
    return errs
コード例 #13
0
def Main(args):
    global errors
    ParseOptions(args)

    InfoOut.SetConsole(True)

    namespace = IDLNamespace(None)

    FooXX = MockNode('foo', None, None)
    Foo1X = MockNode('foo', 1.0, None)
    Foo2X = MockNode('foo', 2.0, None)
    Foo3X = MockNode('foo', 3.0, None)

    # Verify we succeed with undeprecated adds
    AddOkay(namespace, FooXX)
    AddOkay(namespace, Foo1X)
    AddOkay(namespace, Foo3X)
    # Verify we fail to add a node between undeprecated releases
    AddError(namespace, Foo2X,
             'Overlap in releases: 3.0 vs 2.0 when adding foo (2.0 : None)')

    BarXX = MockNode('bar', None, None)
    Bar12 = MockNode('bar', 1.0, 2.0)
    Bar23 = MockNode('bar', 2.0, 3.0)
    Bar34 = MockNode('bar', 3.0, 4.0)

    # Verify we succeed with fully qualified releases
    namespace = IDLNamespace(namespace)
    AddOkay(namespace, BarXX)
    AddOkay(namespace, Bar12)
    # Verify we warn when detecting a gap
    AddWarn(namespace, Bar34, 'Gap in release numbers.')
    # Verify we fail when inserting into this gap
    # (NOTE: while this could be legal, it is sloppy so we disallow it)
    AddError(namespace, Bar23, 'Declarations out of order.')

    # Verify local namespace
    VerifyFindOne(namespace, 'bar', 0.0, BarXX)
    VerifyFindAll(namespace, 'bar', 0.5, 1.5, [BarXX, Bar12])

    # Verify the correct release of the object is found recursively
    VerifyFindOne(namespace, 'foo', 0.0, FooXX)
    VerifyFindOne(namespace, 'foo', 0.5, FooXX)
    VerifyFindOne(namespace, 'foo', 1.0, Foo1X)
    VerifyFindOne(namespace, 'foo', 1.5, Foo1X)
    VerifyFindOne(namespace, 'foo', 3.0, Foo3X)
    VerifyFindOne(namespace, 'foo', 100.0, Foo3X)

    # Verify the correct range of objects is found
    VerifyFindAll(namespace, 'foo', 0.0, 1.0, [FooXX])
    VerifyFindAll(namespace, 'foo', 0.5, 1.0, [FooXX])
    VerifyFindAll(namespace, 'foo', 1.0, 1.1, [Foo1X])
    VerifyFindAll(namespace, 'foo', 0.5, 1.5, [FooXX, Foo1X])
    VerifyFindAll(namespace, 'foo', 0.0, 3.0, [FooXX, Foo1X])
    VerifyFindAll(namespace, 'foo', 3.0, 100.0, [Foo3X])

    FooBar = MockNode('foobar', 1.0, 2.0)
    namespace = IDLNamespace(namespace)
    AddOkay(namespace, FooBar)

    if errors:
        print 'Test failed with %d errors.' % errors
    else:
        print 'Passed.'
    return errors
コード例 #14
0
def Main(args):
    filenames = ParseOptions(args)
    ast = ParseFiles(filenames)
    return Generator.Run(ast)