Exemplo n.º 1
0
    def _debugWithScript(self, builddir, program):
        child = None
        try:
            prog_path = self.findProgram(builddir, program)
            if prog_path is None:
                return

            env = os.environ.copy()
            env['YOTTA_PROGRAM'] = _encodePathForEnv(prog_path)

            cmd = [
                os.path.expandvars(string.Template(x).safe_substitute(program=prog_path))
                for x in self.getScript('debug')
            ]
            logger.debug('starting debugger: %s', cmd)
            child = subprocess.Popen(
                cmd, cwd = builddir, env = env
            )
            child.wait()
            if child.returncode:
                return "debug process exited with status %s" % child.returncode
            child = None
        except:
            # reset the terminal, in case the debugger has screwed it up
            os.system('reset')
            raise
        finally:
            if child is not None:
                _tryTerminate(child)
Exemplo n.º 2
0
    def _debugWithScript(self, builddir, program):
        child = None
        try:
            prog_path = self.findProgram(builddir, program)
            if prog_path is None:
                return

            debug_env, debug_vars = self.buildProgEnvAndVars(prog_path, builddir)

            cmd = [
                os.path.expandvars(string.Template(x).safe_substitute(**debug_vars))
                for x in self.getScript('debug')
            ]
            logger.debug('starting debugger: %s', cmd)
            child = subprocess.Popen(
                cmd, cwd = builddir, env = debug_env
            )
            child.wait()
            if child.returncode:
                return "debug process exited with status %s" % child.returncode
            child = None
        except:
            # reset the terminal, in case the debugger has screwed it up
            os.system('reset')
            raise
        finally:
            if child is not None:
                _tryTerminate(child)
Exemplo n.º 3
0
    def _debugWithScript(self, builddir, program):
        child = None
        try:
            prog_path = self.findProgram(builddir, program)
            if prog_path is None:
                return

            env = os.environ.copy()
            env['YOTTA_PROGRAM'] = _encodePathForEnv(prog_path)

            cmd = [
                os.path.expandvars(
                    string.Template(x).safe_substitute(program=prog_path))
                for x in self.getScript('debug')
            ]
            logger.debug('starting debugger: %s', cmd)
            child = subprocess.Popen(cmd, cwd=builddir, env=env)
            child.wait()
            if child.returncode:
                return "debug process exited with status %s" % child.returncode
            child = None
        except:
            # reset the terminal, in case the debugger has screwed it up
            os.system('reset')
            raise
        finally:
            if child is not None:
                _tryTerminate(child)
Exemplo n.º 4
0
    def start(self, builddir, program, forward_args):
        ''' Launch the specified program. Uses the `start` script if specified
            by the target, attempts to run it natively if that script is not
            defined.
        '''
        child = None
        try:
            prog_path = self.findProgram(builddir, program)
            if prog_path is None:
                return

            env = os.environ.copy()
            env['YOTTA_PROGRAM'] = _encodePathForEnv(prog_path)

            if self.getScript('start'):
                cmd = [
                    os.path.expandvars(string.Template(x).safe_substitute(program=prog_path))
                    for x in self.getScript('start')
                ] + forward_args
            else:
                cmd = shlex.split('./' + prog_path) + forward_args

            logger.debug('starting program: %s', cmd)
            child = subprocess.Popen(
                cmd, cwd = builddir, env = env
            )
            child.wait()
            if child.returncode:
                return "process exited with status %s" % child.returncode
            child = None
        except OSError as e:
            import errno
            if e.errno == errno.ENOEXEC:
                return ("the program %s cannot be run (perhaps your target "+
                        "needs to define a 'start' script to start it on its "
                        "intended execution target?)") % prog_path
        finally:
            if child is not None:
                _tryTerminate(child)
Exemplo n.º 5
0
    def start(self, builddir, program, forward_args):
        ''' Launch the specified program. Uses the `start` script if specified
            by the target, attempts to run it natively if that script is not
            defined.
        '''
        child = None
        try:
            prog_path = self.findProgram(builddir, program)
            if prog_path is None:
                return

            env = os.environ.copy()
            env['YOTTA_PROGRAM'] = _encodePathForEnv(prog_path)

            if self.getScript('start'):
                cmd = [
                    os.path.expandvars(
                        string.Template(x).safe_substitute(program=prog_path))
                    for x in self.getScript('start')
                ] + forward_args
            else:
                cmd = shlex.split('./' + prog_path) + forward_args

            logger.debug('starting program: %s', cmd)
            child = subprocess.Popen(cmd, cwd=builddir, env=env)
            child.wait()
            if child.returncode:
                return "process exited with status %s" % child.returncode
            child = None
        except OSError as e:
            import errno
            if e.errno == errno.ENOEXEC:
                return ("the program %s cannot be run (perhaps your target " +
                        "needs to define a 'start' script to start it on its "
                        "intended execution target?)") % prog_path
        finally:
            if child is not None:
                _tryTerminate(child)
Exemplo n.º 6
0
    def test(self, test_dir, module_dir, test_command, filter_command, forward_args):
        # we assume that test commands are relative to the current directory
        # (filter commands are relative to the module dir to make it possible
        # to use filter scripts shipped with the module)
        test_command = './' + test_command
        test_script = self.getScript('test')
        if test_script is None:
            cmd = shlex.split(test_command) + forward_args
        else:
            cmd = [
                os.path.expandvars(string.Template(x).safe_substitute(program=os.path.abspath(os.path.join(test_dir, test_command))))
                for x in test_script
            ] + forward_args

        # if the command is a python script, run it with the python interpreter
        # being used to run yotta:
        if test_command[0].lower().endswith('.py'):
            import sys
            python_interpreter = sys.executable
            cmd = [python_interpreter] + cmd
        if filter_command and filter_command[0].lower().endswith('.py'):
            import sys
            python_interpreter = sys.executable
            filter_command = [python_interpreter] + filter_command

        env = os.environ.copy()
        env['YOTTA_PROGRAM'] = _encodePathForEnv(test_command)

        test_child = None
        test_filter = None
        try:
            logger.debug('running test: %s', cmd)
            if filter_command:
                logger.debug('using output filter command: %s', filter_command)
                test_child = subprocess.Popen(
                    cmd, cwd = test_dir, stdout = subprocess.PIPE, env = env
                )
                try:
                    test_filter = subprocess.Popen(
                        filter_command, cwd = module_dir, stdin = test_child.stdout, env = env
                    )
                except OSError as e:
                    logger.error('error starting test output filter "%s": %s', filter_command, e)
                    _tryTerminate(test_child)
                    return 1
                logger.debug('waiting for filter process')
                test_filter.communicate()
                if test_child.poll() is None:
                    logger.warning('test child has not exited and will be terminated')
                    _tryTerminate(test_child)
                test_child.stdout.close()
                returncode = test_filter.returncode
                test_child = None
                test_filter = None
                if returncode:
                    logger.debug("test filter exited with status %s (=fail)", returncode)
                    return 1
            else:
                try:
                    test_child = subprocess.Popen(
                        cmd, cwd = test_dir, env = env
                    )
                    logger.debug('waiting for test child')
                except OSError as e:
                    if e.errno == errno.ENOENT:
                        logger.error('Error: no such file or directory: "%s"', cmd[0])
                        return 1
                    raise
                test_child.wait()
                returncode = test_child.returncode
                test_child = None
                if returncode:
                    logger.debug("test process exited with status %s (=fail)", returncode)
                    return 1
        finally:
            if test_child is not None:
                _tryTerminate(test_child)
            if test_filter is not None:
                _tryTerminate(test_filter)
        logger.debug("test %s passed", test_command)
        return 0
Exemplo n.º 7
0
    def test(self, test_dir, module_dir, test_command, filter_command, forward_args):
        # we assume that test commands are relative to the current directory
        # (filter commands are relative to the module dir to make it possible
        # to use filter scripts shipped with the module)
        test_command = './' + test_command
        test_script = self.getScript('test')

        test_env, test_vars = self.buildProgEnvAndVars(os.path.abspath(os.path.join(test_dir, test_command)), test_dir)

        if test_script is None:
            cmd = shlex.split(test_command) + forward_args
        else:
            cmd = [
                os.path.expandvars(string.Template(x).safe_substitute(**test_vars))
                for x in test_script
            ] + forward_args

        # if the command is a python script, run it with the python interpreter
        # being used to run yotta:
        if test_command[0].lower().endswith('.py'):
            import sys
            python_interpreter = sys.executable
            cmd = [python_interpreter] + cmd
        if filter_command and filter_command[0].lower().endswith('.py'):
            import sys
            python_interpreter = sys.executable
            filter_command = [python_interpreter] + filter_command

        test_child = None
        test_filter = None
        try:
            logger.debug('running test: %s', cmd)
            if filter_command:
                logger.debug('using output filter command: %s', filter_command)
                test_child = subprocess.Popen(
                    cmd, cwd = test_dir, stdout = subprocess.PIPE, env = test_env
                )
                try:
                    test_filter = subprocess.Popen(
                        filter_command, cwd = module_dir, stdin = test_child.stdout, env = test_env
                    )
                except OSError as e:
                    logger.error('error starting test output filter "%s": %s', filter_command, e)
                    _tryTerminate(test_child)
                    return 1
                logger.debug('waiting for filter process')
                test_filter.communicate()
                if test_child.poll() is None:
                    logger.warning('test child has not exited and will be terminated')
                    _tryTerminate(test_child)
                test_child.stdout.close()
                returncode = test_filter.returncode
                test_child = None
                test_filter = None
                if returncode:
                    logger.debug("test filter exited with status %s (=fail)", returncode)
                    return 1
            else:
                try:
                    test_child = subprocess.Popen(
                        cmd, cwd = test_dir, env = test_env
                    )
                    logger.debug('waiting for test child')
                except OSError as e:
                    if e.errno == errno.ENOENT:
                        logger.error('Error: no such file or directory: "%s"', cmd[0])
                        return 1
                    raise
                test_child.wait()
                returncode = test_child.returncode
                test_child = None
                if returncode:
                    logger.debug("test process exited with status %s (=fail)", returncode)
                    return 1
        finally:
            if test_child is not None:
                _tryTerminate(test_child)
            if test_filter is not None:
                _tryTerminate(test_filter)
        logger.debug("test %s passed", test_command)
        return 0