//
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package {
    default_team: "trendy_team_android_kernel",
    default_applicable_licenses: ["Android-Apache-2.0"],
}

python_test_host {
    name: "fmq_test",
    main: "fmq_test.py",
    srcs: ["fmq_test.py"],
    test_config: "fmq_test.xml",
    data_device_bins_both: [
        "android.hardware.tests.msgq@1.0-service-test",
        "android.hardware.tests.msgq@1.0-rust-service-test",
        "fmq_test_client",
        "fmq_rust_test_client",
    ],
    test_suites: [
        "general-tests",
        "vts",
    ],
    test_options: {
        unit_test: false,
    },
}

rust_test {
    name: "fmq_rust_test_client",
    team: "trendy_team_android_kernel",
    srcs: ["msgq_rust_test_client.rs"],
    crate_name: "fmq_rust_test_client",
    rustlibs: [
        "android.fmq.test-rust",
        "android.hardware.common.fmq-V1-rust",
        "libbinder_rs",
        "libfmq_rust",
        "liblibc",
    ],
    shared_libs: [
        "libutils",
        "libcutils",
        "libbase",
        "libfmq",
    ],
    compile_multilib: "both",
    multilib: {
        lib32: {
            suffix: "32",
        },
        lib64: {
            suffix: "64",
        },
    },
    test_suites: [
        "general-tests",
        "vts",
    ],
    auto_gen_config: false,
}

cc_test {
    name: "fmq_test_client",
    tidy_timeout_srcs: ["msgq_test_client.cpp"],
    srcs: ["msgq_test_client.cpp"],
    // This cc_test is used through the python test and won't support isolated
    isolated: false,
    cflags: [
        "-Wall",
        "-Werror",
    ],
    sanitize: {
        misc_undefined: ["integer"],
    },

    shared_libs: [
        "libbase",
        "libcutils",
        "libfmq",
        "libhidlbase",
        "liblog",
        "libutils",
        "libbinder",
        "libbinder_ndk",
    ],

    // These are static libs only for testing purposes and portability. Shared
    // libs should be used on device.
    static_libs: [
        "android.hardware.common-V2-cpp",
        "android.hardware.common.fmq-V1-cpp",
        "android.hardware.common-V2-ndk",
        "android.hardware.common.fmq-V1-ndk",
        "android.hardware.tests.msgq@1.0",
        "android.fmq.test-cpp",
        "android.fmq.test-ndk",
    ],
    whole_static_libs: [
        "android.hardware.tests.msgq@1.0-impl",
        "android.fmq.test-impl",
    ],

    compile_multilib: "both",
    multilib: {
        lib32: {
            suffix: "32",
        },
        lib64: {
            suffix: "64",
        },
    },
    test_suites: [
        "general-tests",
        "vts",
    ],
    auto_gen_config: false,
}

// C++-usable FFI library so we can test the Rust wrapper against C++ clients
rust_ffi_static {
    name: "libfmq_rust_test",
    host_supported: true,
    crate_name: "fmq_rust_test",
    srcs: ["fmq_test.rs"],
    edition: "2021",
    shared_libs: [
        "libbase",
        "liblog",
        "libcutils",
        "libfmq",
        "android.hardware.common.fmq-V1-ndk",
    ],
    rustlibs: [
        "libfmq_rust",
        "android.hardware.common.fmq-V1-rust",
    ],
    proc_macros: [],
}

cc_test {
    name: "fmq_unit_tests",
    host_supported: true,

    tidy_timeout_srcs: ["fmq_unit_tests.cpp"],
    srcs: ["fmq_unit_tests.cpp"],
    shared_libs: [
        "libbase",
        "libcutils",
        "libfmq",
        "libhidlbase",
        "liblog",
        "libutils",
    ],
    static_libs: [
        "android.hardware.common.fmq-V1-ndk",
        "android.hardware.common.fmq-V1-cpp",
        "libfmq_rust_test",
    ],

    cflags: [
        "-Wall",
        "-Werror",
    ],
    sanitize: {
        misc_undefined: ["integer"],
    },
    test_suites: ["general-tests"],
    auto_gen_config: true,
}
