load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_test.bzl", "cc_test") licenses(["notice"]) ############################################################################### # Common settings for unit tests ############################################################################### UNIT_TEST_COPTS = select({ "@rules_cc//cc/compiler:msvc-cl": ["/w"], "//conditions:default": [ "-std=gnu99", "-w", ], }) UNIT_TEST_DEFINES = [ "CMAKE", 'VERSION=\\"2.1.2\\"', ] TEST_SUPPORT_DEPS = [ "//:config_header", "//:test_support_hdrs", "//:test_textual_srcs", ] ############################################################################### # Unit tests -- CUnit-based (test/unit/) ############################################################################### cc_test( name = "unit_libcommon_test", srcs = [ "path_helper.h", "unit/libcommon/base64_test.c", "unit/libcommon/file_test.c", "unit/libcommon/property_add.c", "unit/libcommon/property_value.c", "unit/libcommon/strings_test.c", "unit/libcommon/test.c", "unit/libcommon/topic_test.c", "unit/libcommon/trim_test.c", "unit/libcommon/utf8.c", ], copts = UNIT_TEST_COPTS, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_TLS", ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto_common", "@cunit", "@openssl//:ssl", ], ) cc_test( name = "unit_lib_test", srcs = [ "path_helper.h", "unit/lib/datatype_read.c", "unit/lib/datatype_write.c", "unit/lib/property_read.c", "unit/lib/property_user_read.c", "unit/lib/property_write.c", "unit/lib/stubs.c", "unit/lib/test.c", "//:lib_packet_srcs", ], copts = UNIT_TEST_COPTS, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_TLS", ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto_common", "@cunit", "@openssl//:ssl", ], ) cc_test( name = "unit_bridge_topic_test", srcs = [ "path_helper.h", "unit/broker/bridge_topic_test.c", "unit/broker/stubs.c", "//:broker_bridge_src", ], copts = UNIT_TEST_COPTS, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_BRIDGE", "WITH_BROKER", "WITH_TLS", ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto_common", "@cunit", "@openssl//:ssl", ], ) cc_test( name = "unit_keepalive_test", srcs = [ "path_helper.h", "unit/broker/keepalive_stubs.c", "unit/broker/keepalive_test.c", ], copts = UNIT_TEST_COPTS, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_BROKER", "WITH_TLS", ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto_common", "@cunit", "@openssl//:ssl", ], ) cc_test( name = "unit_persist_read_test", srcs = [ "path_helper.h", "unit/broker/persist_read_stubs.c", "unit/broker/persist_read_test.c", "//:broker_core_test_srcs", "//:broker_persist_read_srcs", "//:lib_data_util_srcs", ], copts = UNIT_TEST_COPTS, data = glob(["unit/broker/files/persist_read/*.test-db"]), env = {"MOSQUITTO_UNSAFE_ALLOW_SYMLINKS": "1"}, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_BROKER", "WITH_PERSISTENCE", "WITH_TLS", 'TEST_SOURCE_DIR=\\"test/unit/broker\\"', ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto_common", "@cunit", "@openssl//:ssl", ], ) cc_test( name = "unit_persist_write_test", srcs = [ "path_helper.h", "unit/broker/persist_write_stubs.c", "unit/broker/persist_write_test.c", "//:broker_core_test_srcs", "//:broker_persist_read_srcs", "//:broker_persist_write_srcs", "//:broker_subs_src", "//:lib_packet_srcs", ], copts = UNIT_TEST_COPTS, data = glob([ "unit/broker/files/persist_read/*.test-db", "unit/broker/files/persist_write/*.test-db", ]), env = {"MOSQUITTO_UNSAFE_ALLOW_SYMLINKS": "1"}, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_BROKER", "WITH_PERSISTENCE", "WITH_SYS_TREE", "WITH_TLS", 'TEST_SOURCE_DIR=\\"test/unit/broker\\"', ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto_common", "@cunit", "@openssl//:ssl", ], ) cc_test( name = "unit_subs_test", srcs = [ "path_helper.h", "unit/broker/subs_stubs.c", "unit/broker/subs_test.c", "//:broker_core_test_srcs", "//:broker_subs_src", "//:lib_data_srcs", ], copts = UNIT_TEST_COPTS, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_BROKER", "WITH_PERSISTENCE", "WITH_SYS_TREE", "WITH_TLS", ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto_common", "@cunit", "@openssl//:ssl", ], ) ############################################################################### # Integration test binaries -- test/lib/c/ # # Standalone C executables run by Python test scripts. Each is a single .c # file linking against libmosquitto. ############################################################################### LIB_C_TESTS = [ "01-con-discon-success", "01-con-discon-success-v5", "01-con-discon-will", "01-con-discon-will-clear", "01-con-discon-will-v5", "01-extended-auth-continue", "01-extended-auth-failure", "01-keepalive-pingreq", "01-no-clean-session", "01-pre-connect-callback", "01-server-keepalive-pingreq", "01-unpwd-set", "01-will-set", "01-will-unpwd-set", "02-subscribe-helper-callback-qos2", "02-subscribe-helper-simple-qos2", "02-subscribe-qos0", "02-subscribe-qos1", "02-subscribe-qos1-async1", "02-subscribe-qos1-async2", "02-subscribe-qos2", "02-unsubscribe", "02-unsubscribe-multiple-v5", "02-unsubscribe-v5", "02-unsubscribe2-v5", "03-publish-b2c-qos1", "03-publish-b2c-qos1-unexpected-puback", "03-publish-b2c-qos2", "03-publish-b2c-qos2-len", "03-publish-b2c-qos2-unexpected-pubcomp", "03-publish-b2c-qos2-unexpected-pubrel", "03-publish-c2b-qos1-disconnect", "03-publish-c2b-qos1-len", "03-publish-c2b-qos1-receive-maximum", "03-publish-c2b-qos2", "03-publish-c2b-qos2-disconnect", "03-publish-c2b-qos2-len", "03-publish-c2b-qos2-maximum-qos-0", "03-publish-c2b-qos2-maximum-qos-1", "03-publish-c2b-qos2-pubrec-error", "03-publish-c2b-qos2-receive-maximum", "03-publish-loop", "03-publish-loop-forever", "03-publish-loop-manual", "03-publish-loop-start", "03-publish-qos0", "03-publish-qos0-no-payload", "03-request-response-1", "03-request-response-2", "03-request-response-correlation-1", "04-retain-qos0", "08-ssl-bad-cacert", "08-ssl-connect-cert-auth", "08-ssl-connect-cert-auth-custom-ssl-ctx", "08-ssl-connect-cert-auth-custom-ssl-ctx-default", "08-ssl-connect-cert-auth-enc", "08-ssl-connect-no-auth", "08-ssl-connect-san", "08-ssl-fake-cacert", "09-util-topic-tokenise", "11-prop-oversize-packet", "11-prop-recv", "11-prop-send-content-type", "11-prop-send-payload-format", "fuzzish", ] [ cc_binary( name = t, srcs = [ "lib/c/" + t + ".c", "path_helper.h", ], copts = UNIT_TEST_COPTS, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_TLS", "WITH_TLS_PSK", 'TEST_SOURCE_DIR=\\"test/lib/c\\"', ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto", "@openssl//:ssl", ], ) for t in LIB_C_TESTS ] ############################################################################### # Integration test binaries -- test/broker/c/ (binaries) ############################################################################### BROKER_C_TEST_BINARIES = [ "08-tls-psk-bridge", "08-tls-psk-pub", ] [ cc_binary( name = t, srcs = ["broker/c/" + t + ".c"], copts = UNIT_TEST_COPTS, includes = ["."], local_defines = UNIT_TEST_DEFINES + [ "WITH_TLS", "WITH_TLS_PSK", ], deps = TEST_SUPPORT_DEPS + [ "//:mosquitto", "@openssl//:ssl", ], ) for t in BROKER_C_TEST_BINARIES ] ############################################################################### # Test plugins -- test/broker/c/ (shared libraries) # # Broker plugins dlopen'd at runtime; reference broker symbols resolved at # load time. Built with -undefined dynamic_lookup on macOS. ############################################################################### TEST_PLUGINS = [ "auth_plugin_acl", "auth_plugin_acl_change", "auth_plugin_acl_sub_denied", "auth_plugin_context_params", "auth_plugin_delayed", "auth_plugin_extended_multiple", "auth_plugin_extended_reauth", "auth_plugin_extended_single", "auth_plugin_extended_single2", "auth_plugin_id_change", "auth_plugin_msg_params", "auth_plugin_publish", "auth_plugin_pwd", "auth_plugin_v2", "auth_plugin_v3", "auth_plugin_v4", "auth_plugin_v5", "auth_plugin_v5_control", "bad_v1", "bad_v2_1", "bad_v2_2", "bad_v2_3", "bad_v2_4", "bad_v2_5", "bad_v2_6", "bad_v2_7", "bad_v3_1", "bad_v3_2", "bad_v3_3", "bad_v3_4", "bad_v3_5", "bad_v3_6", "bad_v3_7", "bad_v4_1", "bad_v4_2", "bad_v4_3", "bad_v4_4", "bad_v5_1", "bad_v6", "bad_vnone_1", "kick_last_client", "plugin_control", "plugin_evt_client_offline", "plugin_evt_message_in", "plugin_evt_message_out", "plugin_evt_persist_client_update", "plugin_evt_psk_key", "plugin_evt_reload", "plugin_evt_subscribe", "plugin_evt_tick", "plugin_evt_unsubscribe", "plugin_load_acl", "plugin_load_extended_auth", ] TEST_PLUGIN_HDRS = glob(["broker/c/*.h"]) PLUGIN_LINKOPTS = select({ "@platforms//os:macos": [ "-undefined", "dynamic_lookup", ], "//conditions:default": [], }) [ cc_binary( name = p, srcs = [ "broker/c/" + p + ".c", ] + TEST_PLUGIN_HDRS, copts = UNIT_TEST_COPTS, linkopts = PLUGIN_LINKOPTS, linkshared = True, local_defines = UNIT_TEST_DEFINES, target_compatible_with = select({ "@platforms//os:windows": ["@platforms//:incompatible"], "//conditions:default": [], }), deps = TEST_SUPPORT_DEPS + [ "//:cjson_compat", ], ) for p in TEST_PLUGINS ] ############################################################################### # GTest ctrl shell tests -- test/apps/ctrl/ # # Require WITH_CTRL_SHELL + readline (BCR dep @readline//:readline). # These are only buildable when --//:with_ctrl_shell=True is set. ############################################################################### # ctrl_shell object library sources provided by //:ctrl_shell_srcs filegroup CTRL_SHELL_MOCK_SRCS = [ "mock/apps/mosquitto_ctrl/ctrl_shell_mock.cpp", ] LIBMOSQUITTO_MOCK_SRCS = glob(["mock/lib/*.cpp"]) EDITLINE_MOCK_SRCS = [ "mock/editline_mock.cpp", ] PTHREAD_MOCK_SRCS = [ "mock/pthread_mock.cpp", ] CTRL_SHELL_MOCK_HDRS = glob( ["mock/**/*.hpp"], allow_empty = True, ) CTRL_SHELL_TEST_INCLUDES = [ "mock", "mock/apps/mosquitto_ctrl", "mock/lib", ] CTRL_SHELL_TESTS_MOCK_EDITLINE = [ "ctrl_shell_test", "ctrl_shell_broker_test", "ctrl_shell_dynsec_test", "ctrl_shell_help_test", "ctrl_shell_options_test", "ctrl_shell_pre_connect_test", ] CTRL_SHELL_TESTS_REAL_EDITLINE = [ "ctrl_shell_completion_test", ] [ cc_test( name = t, srcs = [ "apps/ctrl/" + t + ".cpp", "//:common_json_srcs", "//:ctrl_shell_srcs", ] + CTRL_SHELL_MOCK_SRCS + LIBMOSQUITTO_MOCK_SRCS + EDITLINE_MOCK_SRCS + PTHREAD_MOCK_SRCS + CTRL_SHELL_MOCK_HDRS, copts = ["-w"], includes = CTRL_SHELL_TEST_INCLUDES, local_defines = UNIT_TEST_DEFINES + [ "WITH_CTRL_SHELL", "WITH_EDITLINE", "WITH_TLS", ], target_compatible_with = select({ "//:ctrl_shell_enabled": [], "//conditions:default": ["@platforms//:incompatible"], }), deps = TEST_SUPPORT_DEPS + [ "//:cjson_compat", "//:editline_compat", "//:mosquitto_common", "@googletest//:gtest_main", ], ) for t in CTRL_SHELL_TESTS_MOCK_EDITLINE ] [ cc_test( name = t, srcs = [ "apps/ctrl/" + t + ".cpp", "//:common_json_srcs", "//:ctrl_shell_srcs", ] + CTRL_SHELL_MOCK_SRCS + LIBMOSQUITTO_MOCK_SRCS + PTHREAD_MOCK_SRCS + CTRL_SHELL_MOCK_HDRS, copts = ["-w"], includes = CTRL_SHELL_TEST_INCLUDES, local_defines = UNIT_TEST_DEFINES + [ "WITH_CTRL_SHELL", "WITH_EDITLINE", "WITH_TLS", ], target_compatible_with = select({ "//:ctrl_shell_enabled": [], "//conditions:default": ["@platforms//:incompatible"], }), deps = TEST_SUPPORT_DEPS + [ "//:cjson_compat", "//:editline_compat", "//:mosquitto_common", "@googletest//:gtest_main", ], ) for t in CTRL_SHELL_TESTS_REAL_EDITLINE ]