예제 #1
0
def canonical_file(path,
                   diff_tool=None,
                   local=False,
                   universal_lines=False,
                   diff_file_name=None,
                   diff_tool_timeout=None):
    """
    Create canonical file that can be returned from a test
    :param path: path to the file
    :param diff_tool: custom diff tool to use for comparison with the canonical one, if None - default will be used
    :param local: save file locally, otherwise move to sandbox
    :param universal_lines: normalize EOL
    :param diff_tool_timeout: timeout for running diff tool
    :return: object that can be canonized
    """
    abs_path = os.path.abspath(path)
    assert os.path.exists(abs_path), "Canonical path {} does not exist".format(
        path)
    tempdir = tempfile.mkdtemp(prefix="canon_tmp", dir=runtime.build_path())
    safe_path = os.path.join(tempdir, os.path.basename(abs_path))
    # if the created file is in output_path, we copy it, so that it will be available when the tests finishes
    _copy(path, safe_path, universal_lines=universal_lines)
    return runtime._get_ya_plugin_instance().file(
        safe_path,
        diff_tool=diff_tool,
        local=local,
        diff_file_name=diff_file_name,
        diff_tool_timeout=diff_tool_timeout)
예제 #2
0
파일: process.py 프로젝트: blockspacer/xtok
 def verify_sanitize_errors(self):
     """
     Verify there are no sanitizer (ASAN, MSAN, TSAN, etc) errors for this binary. If there are any report them.
     """
     if self._std_err and self._check_sanitizer and runtime._get_ya_config().sanitizer_extra_checks:
         build_path = runtime.build_path()
         if self.command[0].startswith(build_path):
             match = re.search(SANITIZER_ERROR_PATTERN, self._std_err)
             if match:
                 yatest_logger.error("%s sanitizer found errors:\n\tstd_err:%s\n", match.group(1), truncate(self.std_err, MAX_OUT_LEN))
                 raise ExecutionError(self)
             else:
                 yatest_logger.debug("No sanitizer errors found")
         else:
             yatest_logger.debug("'%s' doesn't belong to '%s' - no check for sanitize errors", self.command[0], build_path)
예제 #3
0
def canonical_file(path, diff_tool=None, local=False, universal_lines=False, diff_file_name=None, diff_tool_timeout=None):
    """
    Create canonical file that can be returned from a test
    :param path: path to the file
    :param diff_tool: custom diff tool to use for comparison with the canonical one, if None - default will be used
    :param local: save file locally, otherwise move to sandbox
    :param universal_lines: normalize EOL
    :param diff_tool_timeout: timeout for running diff tool
    :return: object that can be canonized
    """
    abs_path = os.path.abspath(path)
    assert os.path.exists(abs_path), "Canonical path {} does not exist".format(path)
    tempdir = tempfile.mkdtemp(prefix="canon_tmp", dir=runtime.build_path())
    safe_path = os.path.join(tempdir, os.path.basename(abs_path))
    # if the created file is in output_path, we copy it, so that it will be available when the tests finishes
    _copy(path, safe_path, universal_lines=universal_lines)
    return runtime._get_ya_plugin_instance().file(safe_path, diff_tool=diff_tool, local=local, diff_file_name=diff_file_name, diff_tool_timeout=diff_tool_timeout)
예제 #4
0
    def wait(self, check_exit_code=True, timeout=None, on_timeout=None):
        def _wait():
            finished = None
            try:
                if hasattr(os, "wait4"):
                    try:
                        pid, sts, rusage = subprocess._eintr_retry_call(
                            os.wait4, self._process.pid, 0)
                        finished = time.time()
                        self._process._handle_exitstatus(sts)
                        for field in [
                                "ru_idrss",
                                "ru_inblock",
                                "ru_isrss",
                                "ru_ixrss",
                                "ru_majflt",
                                "ru_maxrss",
                                "ru_minflt",
                                "ru_msgrcv",
                                "ru_msgsnd",
                                "ru_nivcsw",
                                "ru_nsignals",
                                "ru_nswap",
                                "ru_nvcsw",
                                "ru_oublock",
                                "ru_stime",
                                "ru_utime",
                        ]:
                            if hasattr(rusage, field):
                                self._metrics[field.replace("ru_",
                                                            "")] = getattr(
                                                                rusage, field)
                    except OSError as exc:

                        if exc.errno == errno.ECHILD:
                            yatest_logger.debug(
                                "Process resource usage is not available as process finished before wait4 was called"
                            )
                        else:
                            raise
            finally:
                self._process.wait(
                )  # this has to be here unconditionally, so that all process properties are set

            if not finished:
                finished = time.time()
            self._metrics["wtime"] = round(finished - self._started, 3)

        try:
            if timeout:
                process_is_finished = lambda: not self.running
                fail_message = "Command '%s' stopped by %d seconds timeout" % (
                    self._command, timeout)
                try:
                    wait_for(
                        process_is_finished,
                        timeout,
                        fail_message,
                        sleep_time=0.1,
                        on_check_condition=self._process_progress_listener)
                except TimeoutError as e:
                    if on_timeout:
                        yatest_logger.debug(
                            "Calling user specified on_timeout function")
                        try:
                            on_timeout(self, timeout)
                        except Exception:
                            yatest_logger.exception(
                                "Exception while calling on_timeout")
                    raise ExecutionTimeoutError(self, str(e))
            # Wait should be always called here, it finalizes internal states of its process and sets up return code
            _wait()
        except BaseException as e:
            _kill_process_tree(self._process.pid)
            _wait()
            yatest_logger.debug("Command exception: %s", e)
            raise
        finally:
            self._elapsed = time.time() - self._start
            self._save_outputs()

            if self.exit_code < 0 and self._collect_cores:
                try:
                    self._recover_core()
                except Exception:
                    yatest_logger.exception("Exception while recovering core")

        # Set the signal (negative number) which caused the process to exit
        if check_exit_code and self.exit_code != 0:
            yatest_logger.error(
                "Execution failed with exit code: %s\n\t,std_out:%s\n\tstd_err:%s\n",
                self.exit_code, truncate(self.std_out, MAX_OUT_LEN),
                truncate(self.std_err, MAX_OUT_LEN))
            raise ExecutionError(self)

        # Don't search for sanitize errors if stderr was redirected
        if self._std_err and self._check_sanitizer and runtime._get_ya_config(
        ).sanitizer_extra_checks:
            build_path = runtime.build_path()
            if self.command[0].startswith(build_path):
                match = re.search(SANITIZER_ERROR_PATTERN, self._std_err)
                if match:
                    yatest_logger.error(
                        "%s sanitizer found errors:\n\tstd_err:%s\n",
                        match.group(1), truncate(self.std_err, MAX_OUT_LEN))
                    raise ExecutionError(self)
                    yatest_logger.debug("No sanitizer errors found")
            else:
                yatest_logger.debug(
                    "'%s' doesn't belong to '%s' - no check for sanitize errors",
                    self.command[0], build_path)