# Copyright (c) Meta Platforms, Inc. and affiliates.

# @noautodeps

load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest")
load("@fbcode_macros//build_defs:thrift_library.bzl", "thrift_library")
load("//data_compression/experimental/zstrong:defs.bzl", "zs_fuzzers")

oncall("data_compression")

thrift_library(
    name = "fuzz_data",
    languages = [
        "cpp2",
    ],
    thrift_cpp2_options = "reflection",
    thrift_srcs = {"fuzz_data.thrift": []},
)

cpp_library(
    name = "thrift_kernel_test_utils",
    headers = ["thrift_kernel_test_utils.h"],
    exported_deps = [
        ":fuzz_data-cpp2-reflection",
        ":fuzz_data-cpp2-types",
        ":fuzz_data-cpp2-visitation",
        "//data_compression/experimental/zstrong:zstronglib",
        "//data_compression/experimental/zstrong/tests/datagen:datagen",
        "//folly:overload",
        "//folly:range",
        "//folly/io:iobuf",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
)

cpp_unittest(
    name = "test_thrift_kernel",
    srcs = ["test_thrift_kernel.cpp"],
    deps = [
        "//data_compression/experimental/zstrong:common",
        "//data_compression/experimental/zstrong/custom_transforms/thrift/kernels:decode_thrift_kernel",
        "//data_compression/experimental/zstrong/custom_transforms/thrift/kernels:encode_thrift_kernel",
        "//data_compression/experimental/zstrong/custom_transforms/thrift/kernels:thrift_kernel_utils",
        "//folly:range",
        "//folly/io:iobuf",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
)

zs_fuzzers(
    srcs = ["fuzz_thrift_kernel.cpp"],
    ftest_names = [
        ("ThriftKernelTest", "FuzzRoundTrip"),
        ("ThriftKernelTest", "FuzzCompress"),
        ("ThriftKernelTest", "FuzzDecompress"),
    ],
    deps = [
        "fbsource//xplat/security/lionhead/utils/lib_ftest:lib",
        ":thrift_kernel_test_utils",
        "//data_compression/experimental/zstrong:common",
        "//data_compression/experimental/zstrong/custom_transforms/thrift/kernels:decode_thrift_binding",
        "//data_compression/experimental/zstrong/custom_transforms/thrift/kernels:encode_thrift_binding",
        "//data_compression/experimental/zstrong/tests:fuzz_utils",
        "//data_compression/experimental/zstrong/tests:test_zstrong_fixtures",
        "//folly:range",
        "//folly/io:iobuf",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
)
