Пример #1
0
def run_executable(exe: str, cmdline: str,
                   workdir="", envmods=None, cappath=None,
                   opts=rd.GetDefaultCaptureOptions()):
    """
    Runs an executable with RenderDoc injected, and returns the control ident.

    Throws a RuntimeError if the execution failed for any reason.

    :param exe: The executable to run.
    :param cmdline: The command line to pass.
    :param workdir: The working directory.
    :param envmods: Environment modifications to apply.
    :param cappath: The directory to output captures in.
    :param opts: An instance of renderdoc.CaptureOptions.
    :return:
    """
    if envmods is None:
        envmods = []
    if cappath is None:
        cappath = util.get_tmp_path('capture')

    wait_for_exit = False

    log.print("Running exe:'{}' cmd:'{}' in dir:'{}' with env:'{}'".format(exe, cmdline, workdir, envmods))

    # Execute the test program
    res = rd.ExecuteAndInject(exe, workdir, cmdline, envmods, cappath, opts, wait_for_exit)

    if res.status != rd.ReplayStatus.Succeeded:
        raise RuntimeError("Couldn't launch program: {}".format(str(res.status)))

    return res.ident
Пример #2
0
def run_and_capture(exe: str,
                    cmdline: str,
                    frame: int,
                    *,
                    frame_count=1,
                    capture_name=None,
                    opts=rd.GetDefaultCaptureOptions(),
                    timeout=None,
                    logfile=None):
    """
    Helper function to run an executable with a command line, capture a particular frame, and exit.

    This will raise a RuntimeError if anything goes wrong, otherwise it will return the path of the
    capture that was generated.

    :param exe: The executable to run.
    :param cmdline: The command line to pass.
    :param frame: The frame to capture.
    :param frame_count: The number of frames to capture.
    :param capture_name: The name to use creating the captures
    :param opts: The capture options to use
    :param timeout: The timeout to wait before killing the process if no capture has happened.
    :param logfile: The log file output to include in the test log.
    :return: The path of the generated capture.
    :rtype: str
    """

    if capture_name is None:
        capture_name = 'capture'

    control = TargetControl(run_executable(
        exe, cmdline, cappath=util.get_tmp_path(capture_name), opts=opts),
                            timeout=timeout)

    log.print("Queuing capture of frame {}..{} with timeout of {}".format(
        frame, frame + frame_count, "default" if timeout is None else timeout))

    # Capture frame
    control.queue_capture(frame, frame_count)

    # By default, runs until the first capture is made
    control.run()

    captures = control.captures()

    if logfile is not None and os.path.exists(logfile):
        log.inline_file('Process output', logfile, with_stdout=True)

    if len(captures) == 0:
        raise RuntimeError("No capture made")

    return captures[0].path
Пример #3
0
def run_and_capture(exe: str,
                    cmdline: str,
                    frame: int,
                    capture_name=None,
                    opts=rd.GetDefaultCaptureOptions(),
                    timeout=None):
    """
    Helper function to run an executable with a command line, capture a particular frame, and exit.

    This will raise a RuntimeError if anything goes wrong, otherwise it will return the path of the
    capture that was generated.

    :param exe: The executable to run.
    :param cmdline: The command line to pass.
    :param frame: The frame to capture.
    :param capture_name: The name to use creating the captures
    :return: The path of the generated capture.
    :rtype: str
    """

    if capture_name is None:
        capture_name = 'capture'

    control = TargetControl(run_executable(
        exe, cmdline, cappath=util.get_tmp_path(capture_name), opts=opts),
                            timeout=timeout)

    log.print("Queuing capture of frame {} without timeout of {}".format(
        frame, "default" if timeout is None else timeout))

    # Capture frame
    control.queue_capture(frame)

    # By default, runs until the first capture is made
    control.run()

    captures = control.captures()

    if len(captures) == 0:
        raise RuntimeError("No capture made")

    return captures[0].path
Пример #4
0
def run_and_capture(exe: str, cmdline: str, frame: int, *, frame_count=1, captures_expected=None, capture_name=None, opts=rd.GetDefaultCaptureOptions(),
                    timeout=None, logfile=None):
    """
    Helper function to run an executable with a command line, capture a particular frame, and exit.

    This will raise a RuntimeError if anything goes wrong, otherwise it will return the path of the
    capture that was generated.

    :param exe: The executable to run.
    :param cmdline: The command line to pass.
    :param frame: The frame to capture.
    :param frame_count: The number of frames to capture.
    :param capture_name: The name to use creating the captures
    :param opts: The capture options to use
    :param timeout: The timeout to wait before killing the process if no capture has happened.
    :param logfile: The log file output to include in the test log.
    :return: The path of the generated capture.
    :rtype: str
    """

    if capture_name is None:
        capture_name = 'capture'

    if captures_expected is None:
        captures_expected = frame_count

    control = TargetControl(run_executable(exe, cmdline, cappath=util.get_tmp_path(capture_name), opts=opts), timeout=timeout)

    log.print("Queuing capture of frame {}..{} with timeout of {}".format(frame, frame+frame_count, "default" if timeout is None else timeout))

    # Capture frame
    control.queue_capture(frame, frame_count)

    # Run until we have all expected captures (probably just 1). If the program
    # exits or times out we will also stop, of course
    control.run(keep_running=lambda x: len(x.captures()) < captures_expected)

    captures = control.captures()

    if logfile is not None and os.path.exists(logfile):
        log.inline_file('Process output', logfile, with_stdout=True)

    if len(captures) != captures_expected:
        if len(captures) == 0:
            raise RuntimeError("No capture made in program")

        raise RuntimeError("Expected {} captures, but only got {}".format(frame_count, len(captures)))

    return captures[0].path