Example #1
0
def run_spirv_opt_on_spirv_shader(
    input_spirv_file_path: pathlib.Path,
    output_dir_path: pathlib.Path,
    spirv_opt_args: List[str],
    spirv_opt_file_path: Optional[pathlib.Path] = None,
    spirv_opt_no_validate_after_all: bool = False,
    time_limit: int = SPIRV_OPT_DEFAULT_TIME_LIMIT,
) -> pathlib.Path:

    if not spirv_opt_file_path:
        spirv_opt_file_path = util.tool_on_path(binaries_util.SPIRV_OPT_NAME)

    output_spirv_file_path = output_dir_path / input_spirv_file_path.name

    util.file_mkdirs_parent(output_spirv_file_path)

    cmd = [
        str(spirv_opt_file_path),
        str(input_spirv_file_path),
        "-o",
        str(output_spirv_file_path),
    ]

    if not spirv_opt_no_validate_after_all:
        cmd.append("--validate-after-all")

    cmd += spirv_opt_args

    cmd = util.prepend_catchsegv_if_available(cmd)

    subprocess_util.run(cmd, timeout=time_limit)

    return output_spirv_file_path
Example #2
0
def run_spirv_val_on_shader(
    shader_path: Path, spirv_val_path: Path, extra_args: Optional[List[str]] = None,
) -> None:
    cmd = util.prepend_catchsegv_if_available([str(spirv_val_path), str(shader_path)])
    if extra_args:
        cmd.extend(extra_args)

    subprocess_util.run(cmd)
def run_shader(
    shader_compiler_device: DeviceShaderCompiler,
    shader_path: Path,
    output_dir: Path,
    compiler_path: Path,
    timeout: int = DEFAULT_TIMEOUT,
) -> Path:
    output_file_path = output_dir / (shader_path.name + ".out")

    cmd = [str(compiler_path)]
    cmd += list(shader_compiler_device.args)
    cmd += [str(shader_path), "-o", str(output_file_path)]
    cmd = util.prepend_catchsegv_if_available(cmd)
    subprocess_util.run(cmd, verbose=True, timeout=timeout)
    return output_file_path
Example #4
0
def get_driver_details(
    amber_path: Path,
    icd: Optional[Path] = None,
    custom_launcher: Optional[List[str]] = None,
) -> str:

    env: Optional[Dict[str, str]] = None

    if icd:
        env = {"VK_ICD_FILENAMES": str(icd)}

    cmd = [str(amber_path), "-d", "-V"]

    if custom_launcher:
        cmd = custom_launcher + cmd

    try:
        result = subprocess_util.run(
            cmd,
            timeout=fuzz.AMBER_RUN_TIME_LIMIT,
            verbose=True,
            env=env,
        )
    except subprocess.SubprocessError as ex:
        raise devices_util.GetDeviceDetailsError() from ex

    match = devices_util.AMBER_DEVICE_DETAILS_PATTERN.search(result.stdout)

    if not match:
        raise devices_util.GetDeviceDetailsError(
            "Could not find device details in stdout: " + result.stdout)

    return match.group(1)
def run_prepare_reference(
    graphicsfuzz_tool_path: Path,
    input_reference_shader_json: Path,
    output_reference_shader_json: Path,
) -> Path:
    util.file_mkdirs_parent(output_reference_shader_json)
    cmd = [
        str(graphicsfuzz_tool_path),
        "com.graphicsfuzz.generator.tool.PrepareReference",
        "--generate-uniform-bindings",
        "--max-uniforms",
        "10",
        str(input_reference_shader_json),
        str(output_reference_shader_json),
    ]

    subprocess_util.run(cmd)

    return output_reference_shader_json
Example #6
0
def run_spirv_dis_on_spirv_shader(
    input_spirv_file_path: pathlib.Path,
    output_dir_path: pathlib.Path,
    spirv_dis_file_path: Optional[pathlib.Path] = None,
) -> pathlib.Path:
    if not spirv_dis_file_path:
        spirv_dis_file_path = util.tool_on_path(binaries_util.SPIRV_DIS_NAME)

    output_spirv_file_path = output_dir_path / (
        util.remove_end(input_spirv_file_path.name, ".spv") + ".asm")

    util.file_mkdirs_parent(output_spirv_file_path)

    subprocess_util.run(
        util.prepend_catchsegv_if_available([
            str(spirv_dis_file_path),
            str(input_spirv_file_path),
            "-o",
            str(output_spirv_file_path),
            "--raw-id",
        ]))

    return output_spirv_file_path
def run_glslang_glsl_shader_to_spirv_shader(
    glsl_shader_path: pathlib.Path,
    output_dir_path: pathlib.Path,
    glslang_validator_file_path: Optional[pathlib.Path] = None,
    time_limit: int = GLSLANG_DEFAULT_TIME_LIMIT,
    preprocessor_cache: Optional[util.CommandCache] = None,
) -> pathlib.Path:

    if not glslang_validator_file_path:
        glslang_validator_file_path = util.tool_on_path(
            binaries_util.GLSLANG_VALIDATOR_NAME)

    output_spirv_file_path = output_dir_path / (glsl_shader_path.name + ".spv")

    util.file_mkdirs_parent(output_spirv_file_path)

    cmd = util.HashedCommand()
    cmd.append_program_path(glslang_validator_file_path)
    cmd.append_str("-V")
    cmd.append_str("-o")
    cmd.append_output_file(output_spirv_file_path)
    cmd.append_input_file(glsl_shader_path)

    if preprocessor_cache and preprocessor_cache.write_cached_output_file(
            cmd, output_spirv_file_path):
        return output_spirv_file_path

    cmd_str = util.prepend_catchsegv_if_available(cmd.cmd)
    subprocess_util.run(
        cmd_str,
        timeout=time_limit,
    )

    if preprocessor_cache:
        preprocessor_cache.add_output_to_cache(cmd, output_spirv_file_path)

    return output_spirv_file_path
Example #8
0
def run_spirv_opt_on_spirv_shader(
    input_spirv_file_path: pathlib.Path,
    output_dir_path: pathlib.Path,
    spirv_opt_args: List[str],
    spirv_opt_file_path: Optional[pathlib.Path] = None,
    spirv_opt_no_validate_after_all: bool = False,
    time_limit: int = SPIRV_OPT_DEFAULT_TIME_LIMIT,
    preprocessor_cache: Optional[util.CommandCache] = None,
) -> pathlib.Path:

    if not spirv_opt_file_path:
        spirv_opt_file_path = util.tool_on_path(binaries_util.SPIRV_OPT_NAME)

    output_spirv_file_path = output_dir_path / input_spirv_file_path.name

    util.file_mkdirs_parent(output_spirv_file_path)

    cmd = util.HashedCommand()
    cmd.append_program_path(spirv_opt_file_path)
    cmd.append_input_file(input_spirv_file_path)
    cmd.append_str("-o")
    cmd.append_output_file(output_spirv_file_path)
    if not spirv_opt_no_validate_after_all:
        cmd.append_str("--validate-after-all")
    cmd.extend_str(spirv_opt_args)

    if preprocessor_cache and preprocessor_cache.write_cached_output_file(
            cmd, output_spirv_file_path):
        return output_spirv_file_path

    cmd_str = util.prepend_catchsegv_if_available(cmd.cmd)
    subprocess_util.run(cmd_str, timeout=time_limit)

    if preprocessor_cache:
        preprocessor_cache.add_output_to_cache(cmd, output_spirv_file_path)

    return output_spirv_file_path
Example #9
0
def get_function_signature_from_address(module: Path, address: str) -> Optional[str]:
    try:
        address_tool = util.tool_on_path("addr2line")
        result = subprocess_util.run(
            [str(address_tool), "-e", str(module), address, "-f", "-C"],
            check_exit_code=False,
        )
        if result.returncode != 0:
            return None
        stdout: str = result.stdout
        lines = stdout.splitlines()
        if not lines:
            return None
        return lines[0]
    except util.ToolNotOnPathError:
        return None
Example #10
0
def adb_helper(
    serial: Optional[str],
    adb_args: List[str],
    check_exit_code: bool,
    verbose: bool = False,
    timeout: Optional[int] = ADB_DEFAULT_TIME_LIMIT,
) -> types.CompletedProcess:

    adb_cmd = [str(adb_path())]
    if serial:
        adb_cmd.append("-s")
        adb_cmd.append(serial)

    adb_cmd.extend(adb_args)

    return subprocess_util.run(
        adb_cmd, check_exit_code=check_exit_code, timeout=timeout, verbose=verbose
    )
Example #11
0
def run_amber_helper(
    amber_script_file: Path,
    output_dir: Path,
    dump_image: bool,
    dump_buffer: bool,
    amber_path: Path,
    skip_render: bool = False,
    debug_layers: bool = False,
    icd: Optional[Path] = None,
) -> Path:

    variant_image_file = output_dir / fuzz.VARIANT_IMAGE_FILE_NAME
    reference_image_file = output_dir / fuzz.REFERENCE_IMAGE_FILE_NAME
    buffer_file = output_dir / fuzz.BUFFER_FILE_NAME

    cmd = [
        str(amber_path),
        str(amber_script_file),
        "--log-graphics-calls-time",
        "--disable-spirv-val",
    ]

    if not debug_layers:
        cmd.append("-d")

    if skip_render:
        # -ps tells amber to stop after pipeline creation
        cmd.append("-ps")
    else:
        if dump_image:
            cmd.append("-I")
            cmd.append("variant_framebuffer")
            cmd.append("-i")
            cmd.append(str(variant_image_file))
            cmd.append("-I")
            cmd.append("reference_framebuffer")
            cmd.append("-i")
            cmd.append(str(reference_image_file))
        if dump_buffer:
            cmd.append("-b")
            cmd.append(str(buffer_file))
            cmd.append("-B")
            cmd.append("0")

    cmd = util.prepend_catchsegv_if_available(cmd)

    status = "UNEXPECTED_ERROR"

    result: Optional[types.CompletedProcess] = None
    env: Optional[Dict[str, str]] = None

    if icd:
        env = {"VK_ICD_FILENAMES": str(icd)}

    try:
        result = subprocess_util.run(
            cmd,
            check_exit_code=False,
            timeout=fuzz.AMBER_RUN_TIME_LIMIT,
            verbose=True,
            env=env,
        )
    except subprocess.TimeoutExpired:
        status = fuzz.STATUS_TIMEOUT

    if result:
        if result.returncode != 0:
            status = fuzz.STATUS_CRASH
        else:
            status = fuzz.STATUS_SUCCESS

    log("\nSTATUS " + status + "\n")

    util.file_write_text(result_util.get_status_path(output_dir), status)

    return output_dir
Example #12
0
def run_spirv_val_on_shader(shader_path: Path, spirv_val_path: Path) -> None:
    subprocess_util.run(
        util.prepend_catchsegv_if_available(
            [str(spirv_val_path), str(shader_path)]))
def download_cts_graphicsfuzz_tests(  # pylint: disable=too-many-locals;
    git_tool: Path,
    cookie: str,
    output_tests_dir: Path,
) -> Path:
    work_dir = Path() / "temp" / ("cts_" + fuzz.get_random_name())

    latest_change = gerrit_util.get_latest_deqp_change(cookie)
    latest_change_number = latest_change["_number"]
    latest_change_details = gerrit_util.get_gerrit_change_details(
        change_number=latest_change_number, cookie=cookie)
    current_revision = latest_change_details["current_revision"]
    cts_archive_path = gerrit_util.download_gerrit_revision(
        output_path=work_dir / "cts.tgz",
        change_number=latest_change_number,
        revision=current_revision,
        download_type=gerrit_util.DownloadType.Archive,
        cookie=cookie,
    )

    cts_dir_name = "cts_temp"
    cts_out = util.extract_archive(cts_archive_path, work_dir / cts_dir_name)

    pending_graphicsfuzz_changes = gerrit_util.get_deqp_graphicsfuzz_pending_changes(
        cookie)

    for pending_change in pending_graphicsfuzz_changes:
        change_number = pending_change["_number"]
        change_details = gerrit_util.get_gerrit_change_details(
            change_number=change_number, cookie=cookie)
        current_revision = change_details["current_revision"]
        patch_zip = gerrit_util.download_gerrit_revision(
            output_path=work_dir / f"{change_number}.zip",
            change_number=change_number,
            revision=current_revision,
            download_type=gerrit_util.DownloadType.Patch,
            cookie=cookie,
        )
        util.extract_archive(patch_zip, work_dir)

    # Create a dummy git repo in the work directory, otherwise "git apply" can fail silently.
    # --unsafe-paths is possibly supposed to address this, but it doesn't seem to work if we
    # are already in a git repo.
    subprocess_util.run([str(git_tool), "init", "."],
                        verbose=True,
                        working_dir=work_dir)

    cmd = [str(git_tool), "apply"]

    patch_names = [p.name for p in work_dir.glob("*.diff")]

    cmd += patch_names

    # Use unix-style path for git.
    cmd += [
        "--verbose",
        "--unsafe-paths",
        f"--directory={cts_dir_name}",
        f"--exclude={cts_dir_name}/external/vulkancts/data/vulkan/amber/graphicsfuzz/index.txt",
        f"--include={cts_dir_name}/external/vulkancts/data/vulkan/amber/graphicsfuzz/*",
    ]

    subprocess_util.run(cmd, verbose=True, working_dir=work_dir)

    util.copy_dir(
        cts_out / "external" / "vulkancts" / "data" / "vulkan" / "amber" /
        "graphicsfuzz",
        output_tests_dir,
    )

    # Sometimes dEQP contributors add non-GraphicsFuzz AmberScript files to the graphicsfuzz directory.
    # We remove these.
    bad_test_names = ["texel_offset.amber"]

    for bad_test_name in bad_test_names:
        bad_test = output_tests_dir / bad_test_name
        if bad_test.is_file():
            bad_test.unlink()

    return output_tests_dir