def __init__(
        self,
        binary_list: Optional[List[Binary]] = None,
        platform: Optional[str] = None,
        built_in_binary_recipes: Optional[Dict[str, Recipe]] = None,
    ):
        self._binary_list = binary_list or DEFAULT_BINARIES
        self._resolved_paths = {}
        self._platform = platform or util.get_platform()
        self._binary_artifacts = []
        self._built_in_binary_recipes = {}

        self._binary_artifacts.extend(
            artifact_util.binary_artifacts_find(BINARY_RECIPES_PREFIX))

        # When changing this constructor, check self.get_child_binary_manager().

        if built_in_binary_recipes:
            self._built_in_binary_recipes = built_in_binary_recipes
            # For each recipe, add a tuple (ArchiveSet, artifact_path) to self._binary_artifacts.
            for (artifact_path,
                 recipe) in self._built_in_binary_recipes.items():
                check(
                    recipe.HasField("download_and_extract_archive_set"),
                    AssertionError(f"Bad built-in recipe: {recipe}"),
                )
                archive_set: RecipeDownloadAndExtractArchiveSet = recipe.download_and_extract_archive_set
                self._binary_artifacts.append(
                    (archive_set.archive_set, artifact_path))
def get_platform_from_binary(binary: Binary) -> str:
    tags = list(binary.tags)
    platforms = [p for p in tags if p in PLATFORMS_SET]
    if platforms:
        check(
            len(platforms) == 1,
            AssertionError(f"More than one platform in: {binary}"))
        platform = platforms[0]
    else:
        platform = util.get_platform()
    return platform
def get_github_release_recipe(  # pylint: disable=too-many-branches,too-many-statements;
    binary: Binary, ) -> recipe_wrap.RecipeWrap:

    project_name = binary_name_to_project_name(binary.name)

    if project_name == "graphicsfuzz":
        # Special case:
        platform = util.get_platform()  # Not used.
        tags = PLATFORMS[:]  # All host platforms.
        repo_name = f"gfbuild-{project_name}"
        version = binary.version
        artifact_name = f"gfbuild-{project_name}-{version}"
    elif project_name == "amber" and binary.name in ("amber_apk",
                                                     "amber_apk_test"):
        # Special case:
        platform = util.get_platform()  # Not used.
        tags = PLATFORMS[:]  # All host platforms.
        tags.append("Debug")
        repo_name = f"gfbuild-{project_name}"
        version = binary.version
        artifact_name = f"gfbuild-{project_name}-{version}-android_apk"
    else:
        # Normal case:
        platform = get_platform_from_binary(binary)
        config = get_config_from_binary(binary)
        arch = "x64"

        tags = [platform, config, arch]

        repo_name = f"gfbuild-{project_name}"
        version = binary.version
        artifact_name = f"gfbuild-{project_name}-{version}-{platform}_{arch}_{config}"

    recipe = recipe_wrap.RecipeWrap(
        path=f"{BUILT_IN_BINARY_RECIPES_PATH_PREFIX}/{artifact_name}",
        recipe=Recipe(
            download_and_extract_archive_set=
            RecipeDownloadAndExtractArchiveSet(archive_set=ArchiveSet(
                archives=[
                    Archive(
                        url=
                        f"https://github.com/google/{repo_name}/releases/download/github/google/{repo_name}/{version}/{artifact_name}.zip",
                        output_file=f"{project_name}.zip",
                        output_directory=f"{project_name}",
                    )
                ],
                binaries=[],
            ))),
    )

    executable_suffix = ".exe" if platform == "Windows" else ""

    if project_name == "glslang":
        binaries = [
            Binary(
                name="glslangValidator",
                tags=tags,
                path=f"{project_name}/bin/glslangValidator{executable_suffix}",
                version=version,
            )
        ]
    elif project_name == "SPIRV-Tools":
        binaries = [
            Binary(
                name="spirv-opt",
                tags=tags,
                path=f"{project_name}/bin/spirv-opt{executable_suffix}",
                version=version,
            ),
            Binary(
                name="spirv-as",
                tags=tags,
                path=f"{project_name}/bin/spirv-as{executable_suffix}",
                version=version,
            ),
            Binary(
                name="spirv-dis",
                tags=tags,
                path=f"{project_name}/bin/spirv-dis{executable_suffix}",
                version=version,
            ),
            Binary(
                name="spirv-val",
                tags=tags,
                path=f"{project_name}/bin/spirv-val{executable_suffix}",
                version=version,
            ),
            Binary(
                name="spirv-fuzz",
                tags=tags,
                path=f"{project_name}/bin/spirv-fuzz{executable_suffix}",
                version=version,
            ),
            Binary(
                name="spirv-reduce",
                tags=tags,
                path=f"{project_name}/bin/spirv-reduce{executable_suffix}",
                version=version,
            ),
        ]
    elif project_name == "swiftshader":
        binaries = [
            Binary(
                name="swift_shader_icd",
                tags=tags,
                path=f"{project_name}/lib/vk_swiftshader_icd.json",
                version=version,
            )
        ]
    elif project_name == "amber":
        if binary.name in ("amber_apk", "amber_apk_test"):
            binaries = [
                Binary(
                    name="amber_apk",
                    tags=tags,
                    path=f"{project_name}/amber.apk",
                    version=version,
                ),
                Binary(
                    name="amber_apk_test",
                    tags=tags,
                    path=f"{project_name}/amber-test.apk",
                    version=version,
                ),
            ]
        else:
            if platform == "Linux":
                vulkan_loader_name = "libvulkan.so.1"
            elif platform == "Mac":
                vulkan_loader_name = "libvulkan.1.dylib"
            elif platform == "Windows":
                vulkan_loader_name = "vulkan-1.dll"
            else:
                raise AssertionError(
                    f"Unknown platform for Amber's Vulkan loader: {platform}")

            binaries = [
                Binary(
                    name="amber",
                    tags=tags,
                    path=f"{project_name}/bin/amber{executable_suffix}",
                    version=version,
                ),
                Binary(
                    name=AMBER_VULKAN_LOADER_NAME,
                    tags=tags,
                    path=f"{project_name}/lib/{vulkan_loader_name}",
                    version=version,
                ),
            ]
    elif project_name == "graphicsfuzz":
        binaries = [
            Binary(
                name="graphicsfuzz-tool",
                tags=tags,
                path=f"{project_name}/python/drivers/graphicsfuzz-tool",
                version=version,
            )
        ]
    elif project_name == "llpc":
        if platform != "Linux":
            raise AssertionError("amdllpc is only available on Linux")
        binaries = [
            Binary(
                name="amdllpc",
                tags=tags,
                path=f"{project_name}/bin/amdllpc{executable_suffix}",
                version=version,
            )
        ]
    else:
        raise AssertionError(f"Unknown project name: {project_name}")

    recipe.recipe.download_and_extract_archive_set.archive_set.binaries.extend(
        binaries)
    return recipe
Exemple #4
0
def fuzz_and_reduce_bug(
    active_device: str,
    seed: int,
    check_result: Callable[[], None],
    settings: Optional[Settings] = None,
    ignored_signatures: Optional[List[str]] = None,
) -> None:
    """
    Fuzz, find a bug, reduce it.

    Linux only.
    """
    # Test only works on Linux.
    if util.get_platform() != "Linux":
        return

    here = util.norm_path(Path(__file__).absolute()).parent
    temp_dir: Path = here.parent / "temp"

    assert temp_dir.is_dir()

    os.chdir(temp_dir)

    # Create ROOT file in temp/ if needed.
    fuzz.try_get_root_file()

    work_dir = temp_dir / fuzz.get_random_name()[:8]
    util.mkdir_p_new(work_dir)
    os.chdir(work_dir)

    log(f"Changed to {str(work_dir)}")

    if settings is None:
        settings = Settings()
        settings.CopyFrom(settings_util.DEFAULT_SETTINGS)

    settings.device_list.CopyFrom(
        DeviceList(
            active_device_names=[active_device],
            devices=[
                Device(
                    name="amdllpc",
                    shader_compiler=DeviceShaderCompiler(
                        binary="amdllpc",
                        args=[
                            "-gfxip=9.0.0", "-verify-ir", "-auto-layout-desc"
                        ],
                    ),
                    binaries=[
                        Binary(
                            name="amdllpc",
                            tags=["Release"],
                            version="c21d76dceaf26361f9b6b3838a955ec3301506b5",
                        ),
                    ],
                ),
                Device(
                    name="swift_shader",
                    swift_shader=DeviceSwiftShader(),
                    binaries=[
                        Binary(
                            name="swift_shader_icd",
                            tags=["Release"],
                            version="6d69aae0e1ab49190ea46cd1c999fd3d02e016b9",
                        ),
                    ],
                    ignored_crash_signatures=ignored_signatures,
                ),
            ],
        ))

    spirv_tools_version = "983b5b4fccea17cab053de24d51403efb4829158"

    settings.latest_binary_versions.extend([
        Binary(
            name="glslangValidator",
            tags=["Release"],
            version="1afa2b8cc57b92c6b769eb44a6854510b6921a0b",
        ),
        Binary(name="spirv-opt", tags=["Release"],
               version=spirv_tools_version),
        Binary(name="spirv-dis", tags=["Release"],
               version=spirv_tools_version),
        Binary(name="spirv-as", tags=["Release"], version=spirv_tools_version),
        Binary(name="spirv-val", tags=["Release"],
               version=spirv_tools_version),
        Binary(name="spirv-fuzz",
               tags=["Release"],
               version=spirv_tools_version),
        Binary(name="spirv-reduce",
               tags=["Release"],
               version=spirv_tools_version),
        Binary(
            name="graphicsfuzz-tool",
            tags=[],
            version="7b143bcb3ad38b64ddc17d132886636b229b6684",
        ),
    ])
    # Add default binaries; the ones above have priority.
    settings.latest_binary_versions.extend(binaries_util.DEFAULT_BINARIES)

    settings.extra_graphics_fuzz_generate_args.append("--small")
    settings.extra_graphics_fuzz_generate_args.append("--single-pass")

    settings.extra_graphics_fuzz_reduce_args.append("--max-steps")
    settings.extra_graphics_fuzz_reduce_args.append("2")

    settings_util.write(settings, settings_util.DEFAULT_SETTINGS_FILE_PATH)

    # Add shaders.
    binary_manager = binaries_util.get_default_binary_manager(settings)
    graphicsfuzz_tool = binary_manager.get_binary_path_by_name(
        "graphicsfuzz-tool")
    sample_shaders_path: Path = graphicsfuzz_tool.path.parent.parent.parent / "shaders" / "samples" / "310es"
    util.copy_dir(sample_shaders_path, Path() / fuzz.REFERENCES_DIR)
    util.copy_dir(sample_shaders_path, Path() / fuzz.DONORS_DIR)

    fuzz.main_helper(
        settings_path=settings_util.DEFAULT_SETTINGS_FILE_PATH,
        iteration_seed_override=seed,
        override_sigint=False,
        use_amber_vulkan_loader=True,
    )

    check_result()

    os.chdir(here)
    shutil.rmtree(work_dir)