# -*- python -*-

load(
    "//tools:drake.bzl",
    "drake_cc_binary",
    "drake_cc_googletest",
    "drake_cc_library",
)
load("//tools/lint:lint.bzl", "add_lint_tests")

drake_cc_library(
    name = "kuka_pick_and_place_monolithic",
    srcs = [
        "monolithic_pick_and_place_system.cc",
    ],
    hdrs = [
        "monolithic_pick_and_place_system.h",
    ],
    deps = [
        "//attic/multibody/parsers",
        "//attic/multibody/rigid_body_plant:contact_results_to_lcm",
        "//examples/kuka_iiwa_arm:iiwa_common",
        "//examples/kuka_iiwa_arm:lcm_plan_interpolator",
        "//examples/kuka_iiwa_arm/dev/pick_and_place:lcm_planner",
        "//examples/kuka_iiwa_arm/dev/pick_and_place:lcm_plant",
        "//multibody:rigid_body_tree",
        "//systems/framework:leaf_system",
        "//systems/primitives",
    ],
)

drake_cc_binary(
    name = "monolithic_pick_and_place_demo",
    srcs = ["monolithic_pick_and_place_demo.cc"],
    add_test_rule = 1,
    data = [
        "//examples/kuka_iiwa_arm:models",
        "//examples/kuka_iiwa_arm/pick_and_place:configuration",
        "//manipulation/models/iiwa_description:models",
        "//manipulation/models/wsg_50_description:models",
    ],
    # TODO(m-chaturvedi) TSan fails with a data race in LCM for this test. See
    # #7524.
    tags = [
        "no_tsan",
    ],
    test_rule_args = ["--quick"],
    # Flaky because LCM self-test can fail (PR #7311)
    test_rule_flaky = 1,
    deps = [
        ":kuka_pick_and_place_monolithic",
        "//common:find_resource",
        "//common:text_logging_gflags",
        "//examples/kuka_iiwa_arm:iiwa_common",
        "//examples/kuka_iiwa_arm:iiwa_lcm",
        "//examples/kuka_iiwa_arm/pick_and_place:pick_and_place_configuration_parsing",  # noqa
        "//lcm",
        "//lcmtypes:iiwa",
        "//systems/analysis:simulator",
        "@gflags",
        "@lcmtypes_bot2_core",
    ],
)

drake_cc_googletest(
    name = "monolithic_pick_and_place_system_test",
    # TODO(avalenzu) The gtest_filter argument below is required because the
    # test currently times out when compiled in debug mode. We should try to
    # split this test up such that this exclusion is no longer necessary.
    args = select({
        "//tools/cc_toolchain:debug": ["--gtest_filter=-*"],
        "//conditions:default": [],
    }),
    # Setting shard_count allows the test runner to split up the test-points in
    # this test into shard_count separate pieces which will be exectuted in
    # parallel, subject to the availability of resources. There are 31 test
    # points in this test. To count the number of tests in the googletest
    # target "foo_test" run
    #   $ ./bazel-bin/path/to/foo_test --gtest_list_tests | grep "  \w" | wc -l
    shard_count = 31,
    # TODO(sam.creasey) The "snopt" tag is required because IPOPT doesn't find
    # a reasonable solution for one of the steps in this demo.  We should see
    # if this improves when #3128 is fixed.
    # TODO(avalenzu) The "no_*" tags are required because the test currently
    # times out in those configurations. We should try to split this test up
    # such that the exclusions are no longer necessary.
    tags = [
        "no_kcov",
        "no_lsan",
        "no_tsan",
        "no_ubsan",
        "snopt",
        # TODO(9039) This test should be re-enabled in CI; it was disabled
        # because it was timing out frequenutly.
        "manual",
    ],
    deps = [
        ":kuka_pick_and_place_monolithic",
        "//common/test_utilities:eigen_matrix_compare",
        "//systems/analysis:simulator",
        "//systems/framework",
    ],
)

add_lint_tests()
