예제 #1
0
 def check_select_builder(self, fil, typ):
     with ioutil.TempDir() as td:
         sb = sandbox.Sandbox(td.path + '/foo.trunk.dev')
         sb.layout()
         os.makedirs(sb.get_code_root() + 'foo')
         aux_folder = sb.get_iftop_folder_path()
         os.makedirs(aux_folder)
         f = os.path.join(aux_folder, fil)
         #print('writing %s' % f)
         open(f, 'w').close()
         bld = build.select_builder(sb)
         self.assertEqual(typ, bld.get_name())
예제 #2
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
예제 #3
0
파일: test.py 프로젝트: dhh1128/sandman
def run_all(sb, argv):
    class Waiter:
        def __init__(self):
            # We introduce some variation here so multiple test processes won't
            # be likely to retry at the same instant.
            self.delay = 3 + (random.random() * 5)
            self.reported = None
            self.elapsed = 0
            self.fpath = os.path.join(tempfile.gettempdir(), 'global-test-lock.txt')
        def __call__(self):
            if self.reported is None or (time.time() - self.reported) > 300:
                sys.stdout.write('\nAs of %s, global test lock is owned by another test process:\n  ' % time.strftime('%c'))
                sys.stdout.write('\n  '.join(read_file(self.fpath).strip().split('\n')) + '\n')
                sys.stdout.flush()
                self.reported = time.time()
            else:
                sys.stdout.write("~")
                sys.stdout.flush()
            time.sleep(self.delay)
    # We use a global test lock so that different test commands cannot be run
    # in parallel. In theory, this should not be necessary -- but practice shows
    # that parallel tests are a bad idea. Some tests use system resources that
    # cannot be shared (e.g., ports). Others simply slow down the CPU or use
    # a lot of disk or RAM, and thus influence timing or other behaviors unduly.
    # While such tests should be refactored, we value accuracy/reproducibility
    # of test results more than the (potential) benefits of parallel testing,
    # so we force serial testing (at least across invocations of "sb test") here.
    sys.stdout.flush()
    waiter = Waiter()
    with filelock.FileLock(waiter.fpath, timeout=3600, delay=waiter) as flock:
        if waiter.reported:
            sys.stdout.write('\n')
            sys.stdout.flush()
        os.write(flock.fd, 'pid = %d\nstart time=%s\nsb=%s\nargs=%s' % (
            os.getpid(), time.strftime('%c'), sb.get_name(), ' '.join(sys.argv[1:])))
        global SelectedTestLoader, SelectedCollectPlugin
        try:
            runcodescan = True
            runcompiled = True
            bld = build.select_builder(sb)
            dirsToAdd = [sb.get_test_root()]
            if '--skip-codescan' in argv:
                while '--skip-codescan' in argv:
                    argv.remove( '--skip-codescan' )
                runcodescan = False
                print("Skipping codescan tests")
            if '--skip-compiled' in argv:
                while '--skip-compiled' in argv:
                    argv.remove('--skip-compiled')
                runcompiled = False
                print("Skipping compiled tests")
            if bld and bld.get_name() == 'cmake':
                argv.append('--compiled-root=%s' % sb.get_built_root())
                argv.append('--build-config=%s' % sb.get_build_config())
                argv.append('--where=%s' % sb.get_built_root())
                SelectedTestLoader = CTestTestLoader
                runcompiled = False
            elif bld and bld.get_name() == 'ant':
                argv.append('--compiled-root=%s' % sb.get_built_root())
                argv.append('--build-config=%s' % sb.get_build_config())
                argv.append('--where=%s' % sb.get_built_root())
                SelectedTestLoader = JUnitTestLoader
                SelectedCollectPlugin = PSJUnit2NosePlugin
                runcompiled = False

            # Do a little system maintenance. See func for comment about why.
            clean_tmp_folders()
            if global_vars.ea:
                pass #TODO clean out the appliance before we start running tests (this is already done between tests)
            nosetests_succeeded = run_nose(argv)

            compiled_test_error_code = 0
            codescan_test_error_code = 0
            ## TODO validate logic of the following "if" statement after compiled tests migration completed
            if runcompiled and not SPECIFIC_TESTS_SELECTED:
                os.chdir(sb.get_built_root())
                compiled_test_error_code = run_compiled_tests(sb, argv)
            if runcodescan and not SPECIFIC_TESTS_SELECTED:
                os.chdir(sb.get_built_root())
                codescan_test_error_code = run_codescan_tests(sb, argv)

            if not nosetests_succeeded:
                print ('\nERROR: tests had errors')
            if compiled_test_error_code != 0:
                print('\nERROR: compiled tests had errors')
            if codescan_test_error_code != 0:
                print('\nERROR: codescan tests had errors')
            result = compiled_test_error_code == 0 and codescan_test_error_code == 0 and nosetests_succeeded
            print('\nOverall result for test group - %s' % ('success' if result else 'failure'))
            return result
        except Exception, KeyboardInterrupt:
            traceback.print_exc()
            return False