示例#1
0
文件: test.py 项目: dhh1128/sandman
def run_codescan_tests(sb, argv):
    '''
    Run all codescan tests
    '''
    errcode = 0
    start = time.time()
    global _timeout_monitor
    _timeout_monitor = None
    codescan_root = SBROOT + '/code/buildscripts/codescan/'
    codescan_tests = [ test for test in os.listdir(codescan_root) if test.startswith('check') and test.endswith('.py') ]
    skip_tests = [ 'check_keywords.py', 'check_ant_timeout.py', 'check_copyright.py', 'check_jsdebug.py' ]
    if os.name == 'nt':
        skip_tests.append('check_pep8.py')
    for test in codescan_tests:
        if test in skip_tests:
            continue
        if '--collect-only' in argv:
            print(test)
            continue
        cmd = ["python", os.path.join( codescan_root, test )]
        try:
            # start a thread that will force an exit if the test hangs
            pabrt = _ProcAbort()
            _timeout_monitor = timeout_monitor.start(sb.get_test_timeout_seconds(), killfunc=pabrt)
            test_errcode = _run_with_timeout(sb, pabrt, cmd)
            if test_errcode != 0:
                errcode += test_errcode
        finally:
            if _timeout_monitor:
                _timeout_monitor.stop()
        elapsed = time.time() - start
        sys.stdout.flush()
        print('\n'.ljust(71,'='))
        print('Ran %s test in %1.2f s\n' % (test, elapsed))
    return errcode
示例#2
0
 def executeTests(self, commandLine):
     log.debug("JUnitTestLoader.executeTests() with commandLine=%s", commandLine)
     # Initialize our state.
     start = time.time()
     sb = Sandbox(SBROOT)
     sb.set_last_test_date(start)
     global _timeout_monitor
     _timeout_monitor = None
     testOutput = ""
     err = 0
     try:
         # Start up a thread that will force us to exit if we hang.
         pabrt = _ProcAbort()
         _timeout_monitor = timeout_monitor.start(sb.get_test_timeout_seconds(), killfunc=pabrt)
         # Always run tests in alphabetical order, for predictability
         # and ease of explanation.
         proc = subprocess.Popen(commandLine,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
         _timeout_monitor.last_status = time.time()
         pabrt.proc = proc
         testOutput, stderr = proc.communicate()
         err = proc.returncode
     except Exception as e:
         log.debug("JUnitTestLoader.executeTests(): Got exception: %s", str(e))
         err = 1
     finally:
         if _timeout_monitor:
             _timeout_monitor.stop()
     if "[junit] '-classpath" in testOutput and 'BUILD FAILED' in testOutput:
         err = 0
         log.debug("JUnitTestLoader.executeTests(): Actually it's JUnit test failed, all is fine.")
     if err != 0:
         raise Exception("Building compiled test suite failed!")
     return testOutput
示例#3
0
def do_build(sb, args_options, args, builder, builder_options):
    err = 0
    try:
        build_date = time.time()
        # Start up a thread that will force us to exit if we hang.
        if builder_options.timeout is not None:
            sb.set_build_timeout_seconds(int(builder_options.timeout),
                                         persist=False)
        global _timeout_monitor
        _timeout_monitor = timeout_monitor.start(
            sb.get_build_timeout_seconds())
        try:
            err = 0
            configuring = 'config' in args
            building = bool([x for x in args if x.startswith('build')])
            if not configuring:
                # Always call the script builder, even for sandboxes that are driven
                # by ant, cmake, etc. This will allow us to build the buildscripts
                # component and any other components that just contain script, like
                # python components, php components, pure html+javascript, etc.
                if builder.get_name() not in [
                        'script', 'simulated'
                ] and not args_options.assemble_only:
                    err = _builders['script'].build(sb, builder_options, args)
            if not err:
                if not args_options.assemble_only:
                    copy_required_built_files(sb)
                    if 'clean' in args:
                        err = builder.clean(sb.get_built_root(),
                                            builder.get_clean_exclusions(sb))
                        args.remove('clean')
                    if not err and len(args) > 0:
                        if building:
                            sb.set_last_build_date(build_date)
                        err = builder.build(sb, builder_options, args)
                if not err and building:
                    # Always generate the runnable aspect for the sandbox. We do
                    # this outside of the main build tool because logic to create
                    # runnable aspects doesn't need to vary from code type to code
                    # type; it's always a bunch of file copies.
                    err = assemble_run(sb)
        finally:
            _timeout_monitor.stop()
        if not err:
            sb.set_last_successful_build_date(build_date)
    except:
        err = 1
        traceback.print_exc()
    return err
示例#4
0
文件: common.py 项目: dhh1128/sandman
def run_make_command(cmd, timeout, input=None, cwd=None):
    '''
    Run an arbitrary command to help with make responsibilities.
    @param timeout secs before cmd is considered hung
    @param input If provided, these bytes are stuffed into stdin on the
    child process.
    @param cwd If provided, use the specified working directory, and
    undo it after cmd runs.
    @return tuple (returncode, stdout)
    '''
    restore_dir = None
    if cwd:
        restore_dir = os.getcwd()
        os.chdir(cwd)
    monitor = None
    stdout = ''
    err = 0
    try:
        try:
            proc = subprocess.Popen(cmd,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,
                                    shell=True,
                                    bufsize=1)
            monitor = timeout_monitor.start(timeout,
                                            killfunc=_BuildKiller(proc))
            monitor.last_status = time.time()
            while True:
                line = proc.stdout.readline()
                monitor.last_status = time.time()
                if not line:
                    proc.wait()
                    break
                print(line.rstrip())
                stdout += line
            err = proc.returncode
            if err:
                print('Error: build command "%s" returned %s.' %
                      (cmd, str(err)))
        except:
            print(cmd)
            raise
    finally:
        if monitor:
            monitor.stop()
        if restore_dir:
            os.chdir(restore_dir)
    return err, stdout
示例#5
0
def do_build(sb, args_options, args, builder, builder_options):
    err = 0
    try:
        build_date = time.time()
        # Start up a thread that will force us to exit if we hang.
        if builder_options.timeout is not None:
            sb.set_build_timeout_seconds(int(builder_options.timeout), persist=False)
        global _timeout_monitor
        _timeout_monitor = timeout_monitor.start(sb.get_build_timeout_seconds())
        try:
            err = 0
            configuring = 'config' in args
            building = bool([x for x in args if x.startswith('build')])
            if not configuring:
                # Always call the script builder, even for sandboxes that are driven
                # by ant, cmake, etc. This will allow us to build the buildscripts
                # component and any other components that just contain script, like
                # python components, php components, pure html+javascript, etc.
                if builder.get_name() not in ['script', 'simulated'] and not args_options.assemble_only:
                    err = _builders['script'].build(sb, builder_options, args)
            if not err:
                if not args_options.assemble_only:
                    copy_required_built_files(sb)
                    if 'clean' in args:
                        err = builder.clean(sb.get_built_root(), builder.get_clean_exclusions(sb))
                        args.remove('clean')
                    if not err and len(args) > 0:
                        if building:
                            sb.set_last_build_date(build_date)
                        err = builder.build(sb, builder_options, args)
                if not err and building:
                    # Always generate the runnable aspect for the sandbox. We do
                    # this outside of the main build tool because logic to create
                    # runnable aspects doesn't need to vary from code type to code
                    # type; it's always a bunch of file copies.
                    err = assemble_run(sb)
        finally:
            _timeout_monitor.stop()
        if not err:
            sb.set_last_successful_build_date(build_date)
    except:
        err = 1
        traceback.print_exc()
    return err
示例#6
0
def run_make_command(cmd, timeout, input=None, cwd=None):
    '''
    Run an arbitrary command to help with make responsibilities.
    @param timeout secs before cmd is considered hung
    @param input If provided, these bytes are stuffed into stdin on the
    child process.
    @param cwd If provided, use the specified working directory, and
    undo it after cmd runs.
    @return tuple (returncode, stdout)
    '''
    restore_dir = None
    if cwd:
        restore_dir = os.getcwd()
        os.chdir(cwd)
    monitor = None
    stdout = ''
    err = 0
    try:
        try:
            proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT, shell=True, bufsize=1)
            monitor = timeout_monitor.start(timeout, killfunc=_BuildKiller(proc))
            monitor.last_status = time.time()
            while True:
                line = proc.stdout.readline()
                monitor.last_status = time.time()
                if not line:
                    proc.wait()
                    break
                print(line.rstrip())
                stdout += line
            err = proc.returncode
            if err:
                print('Error: build command "%s" returned %s.' % (cmd, str(err)))
        except:
            print(cmd)
            raise
    finally:
        if monitor:
            monitor.stop()
        if restore_dir:
            os.chdir(restore_dir)
    return err, stdout
示例#7
0
 def executeTests(self, commandLine):
     log.debug("JUnitTestLoader.executeTests() with commandLine=%s",
               commandLine)
     # Initialize our state.
     start = time.time()
     sb = Sandbox(SBROOT)
     sb.set_last_test_date(start)
     global _timeout_monitor
     _timeout_monitor = None
     testOutput = ""
     err = 0
     try:
         # Start up a thread that will force us to exit if we hang.
         pabrt = _ProcAbort()
         _timeout_monitor = timeout_monitor.start(
             sb.get_test_timeout_seconds(), killfunc=pabrt)
         # Always run tests in alphabetical order, for predictability
         # and ease of explanation.
         proc = subprocess.Popen(commandLine,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
         _timeout_monitor.last_status = time.time()
         pabrt.proc = proc
         testOutput, stderr = proc.communicate()
         err = proc.returncode
     except Exception as e:
         log.debug("JUnitTestLoader.executeTests(): Got exception: %s",
                   str(e))
         err = 1
     finally:
         if _timeout_monitor:
             _timeout_monitor.stop()
     if "[junit] '-classpath" in testOutput and 'BUILD FAILED' in testOutput:
         err = 0
         log.debug(
             "JUnitTestLoader.executeTests(): Actually it's JUnit test failed, all is fine."
         )
     if err != 0:
         raise Exception("Building compiled test suite failed!")
     return testOutput
示例#8
0
文件: test.py 项目: dhh1128/sandman
def run_compiled_tests(sb, argv):
    '''
    Run all compiled tests
    '''
    errcode = 0
    bld = build.select_builder(sb)
    if ('--collect-only' not in argv) and bld and bld.has_compiled_tests():
        print('Running compiled tests...')
        if not bld.get_name() in ('cmake', 'ant'):
            errcode = 1
            build_py = SBROOT + '/code/buildscripts/build.py'
            if os.name == 'nt':
                build_py = build_py.replace('/', '\\')
            cmd = ['python', build_py ,'test']
            ##TODO move next "if" statement to JUnitTestLoader
            if quick and bld.get_build_file() == 'build.xml' and sb.is_experimental():
                cmd.append('--quick')

            # Initialize our state.
            start = time.time()
            sb.set_last_test_date(start)
            global _timeout_monitor
            _timeout_monitor = None
            try:
                # Start up a thread that will force us to exit if we hang.
                pabrt = _ProcAbort()
                _timeout_monitor = timeout_monitor.start(sb.get_test_timeout_seconds(), killfunc=pabrt)
                # Always run tests in alphabetical order, for predictability
                # and ease of explanation.
                errcode = _run_with_timeout(sb, pabrt, cmd)
            finally:
                if _timeout_monitor:
                    _timeout_monitor.stop()
            elapsed = time.time() - start
            sys.stdout.flush()
            print('\n'.ljust(71, '='))
            print('Ran compiled tests in %1.2f s\n' % elapsed)
    return errcode