| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef AWS_C_MQTT_MQTT311_TESTING_UTILS_H |
| 7 |
#define AWS_C_MQTT_MQTT311_TESTING_UTILS_H |
| 8 |
|
| 9 |
#include <aws/mqtt/mqtt.h> |
| 10 |
|
| 11 |
#include <aws/common/array_list.h> |
| 12 |
#include <aws/common/condition_variable.h> |
| 13 |
#include <aws/common/mutex.h> |
| 14 |
#include <aws/io/socket.h> |
| 15 |
#include <aws/mqtt/client.h> |
| 16 |
|
| 17 |
#include <inttypes.h> |
| 18 |
|
| 19 |
#define TEST_LOG_SUBJECT 60000 |
| 20 |
#define ONE_SEC 1000000000 |
| 21 |
|
| 22 |
#define AWS_RESET_RECONNECT_BACKOFF_DELAY_SECONDS 10 |
| 23 |
#define RECONNECT_BACKOFF_DELAY_ERROR_MARGIN_NANO_SECONDS 500000000 |
| 24 |
#define DEFAULT_MIN_RECONNECT_DELAY_SECONDS 1 |
| 25 |
|
| 26 |
#define DEFAULT_TEST_PING_TIMEOUT_MS 1000 |
| 27 |
#define DEFAULT_TEST_KEEP_ALIVE_S 2 |
| 28 |
|
| 29 |
struct received_publish_packet { |
| 30 |
struct aws_byte_buf topic; |
| 31 |
struct aws_byte_buf payload; |
| 32 |
bool dup; |
| 33 |
enum aws_mqtt_qos qos; |
| 34 |
bool retain; |
| 35 |
}; |
| 36 |
|
| 37 |
struct mqtt_connection_state_test { |
| 38 |
struct aws_allocator *allocator; |
| 39 |
struct aws_channel *server_channel; |
| 40 |
struct aws_channel_handler *mock_server; |
| 41 |
struct aws_client_bootstrap *client_bootstrap; |
| 42 |
struct aws_server_bootstrap *server_bootstrap; |
| 43 |
struct aws_event_loop_group *el_group; |
| 44 |
struct aws_host_resolver *host_resolver; |
| 45 |
struct aws_socket_endpoint endpoint; |
| 46 |
struct aws_socket *listener; |
| 47 |
struct aws_mqtt_client *mqtt_client; |
| 48 |
struct aws_mqtt_client_connection *mqtt_connection; |
| 49 |
struct aws_socket_options socket_options; |
| 50 |
|
| 51 |
bool session_present; |
| 52 |
bool connection_completed; |
| 53 |
bool connection_success; |
| 54 |
bool connection_failure; |
| 55 |
bool client_disconnect_completed; |
| 56 |
bool server_disconnect_completed; |
| 57 |
bool connection_interrupted; |
| 58 |
bool connection_resumed; |
| 59 |
bool subscribe_completed; |
| 60 |
bool listener_destroyed; |
| 61 |
bool connection_terminated; |
| 62 |
int interruption_error; |
| 63 |
int subscribe_complete_error; |
| 64 |
int op_complete_error; |
| 65 |
enum aws_mqtt_connect_return_code mqtt_return_code; |
| 66 |
int error; |
| 67 |
struct aws_condition_variable cvar; |
| 68 |
struct aws_mutex lock; |
| 69 |
|
| 70 |
struct aws_array_list any_published_messages; |
| 71 |
size_t any_publishes_received; |
| 72 |
size_t expected_any_publishes; |
| 73 |
|
| 74 |
struct aws_array_list published_messages; |
| 75 |
size_t publishes_received; |
| 76 |
size_t expected_publishes; |
| 77 |
|
| 78 |
struct aws_array_list qos_returned; |
| 79 |
size_t ops_completed; |
| 80 |
size_t expected_ops_completed; |
| 81 |
size_t connection_close_calls; |
| 82 |
int operation_set_result; |
| 83 |
|
| 84 |
size_t connection_termination_calls; |
| 85 |
}; |
| 86 |
|
| 87 |
AWS_EXTERN_C_BEGIN |
| 88 |
|
| 89 |
int aws_test311_setup_mqtt_server_fn(struct aws_allocator *allocator, void *ctx); |
| 90 |
|
| 91 |
int aws_test311_clean_up_mqtt_server_fn(struct aws_allocator *allocator, int setup_result, void *ctx); |
| 92 |
|
| 93 |
void aws_test311_wait_for_interrupt_to_complete(struct mqtt_connection_state_test *state_test_data); |
| 94 |
|
| 95 |
void aws_test311_wait_for_reconnect_to_complete(struct mqtt_connection_state_test *state_test_data); |
| 96 |
|
| 97 |
void aws_test311_wait_for_connection_to_succeed(struct mqtt_connection_state_test *state_test_data); |
| 98 |
|
| 99 |
void aws_test311_wait_for_connection_to_fail(struct mqtt_connection_state_test *state_test_data); |
| 100 |
|
| 101 |
void aws_test311_on_connection_complete_fn( |
| 102 |
struct aws_mqtt_client_connection *connection, |
| 103 |
int error_code, |
| 104 |
enum aws_mqtt_connect_return_code return_code, |
| 105 |
bool session_present, |
| 106 |
void *userdata); |
| 107 |
|
| 108 |
void aws_test311_wait_for_connection_to_complete(struct mqtt_connection_state_test *state_test_data); |
| 109 |
|
| 110 |
void aws_test311_on_disconnect_fn(struct aws_mqtt_client_connection *connection, void *userdata); |
| 111 |
|
| 112 |
void aws_test311_wait_for_disconnect_to_complete(struct mqtt_connection_state_test *state_test_data); |
| 113 |
|
| 114 |
void aws_test311_wait_for_any_publish(struct mqtt_connection_state_test *state_test_data); |
| 115 |
|
| 116 |
void aws_test311_on_publish_received( |
| 117 |
struct aws_mqtt_client_connection *connection, |
| 118 |
const struct aws_byte_cursor *topic, |
| 119 |
const struct aws_byte_cursor *payload, |
| 120 |
bool dup, |
| 121 |
enum aws_mqtt_qos qos, |
| 122 |
bool retain, |
| 123 |
void *userdata); |
| 124 |
|
| 125 |
void aws_test311_wait_for_publish(struct mqtt_connection_state_test *state_test_data); |
| 126 |
|
| 127 |
void aws_test311_on_suback( |
| 128 |
struct aws_mqtt_client_connection *connection, |
| 129 |
uint16_t packet_id, |
| 130 |
const struct aws_byte_cursor *topic, |
| 131 |
enum aws_mqtt_qos qos, |
| 132 |
int error_code, |
| 133 |
void *userdata); |
| 134 |
|
| 135 |
void aws_test311_wait_for_subscribe_to_complete(struct mqtt_connection_state_test *state_test_data); |
| 136 |
|
| 137 |
void aws_test311_on_multi_suback( |
| 138 |
struct aws_mqtt_client_connection *connection, |
| 139 |
uint16_t packet_id, |
| 140 |
const struct aws_array_list *topic_subacks, |
| 141 |
int error_code, |
| 142 |
void *userdata); |
| 143 |
|
| 144 |
void aws_test311_on_op_complete( |
| 145 |
struct aws_mqtt_client_connection *connection, |
| 146 |
uint16_t packet_id, |
| 147 |
int error_code, |
| 148 |
void *userdata); |
| 149 |
|
| 150 |
void aws_test311_wait_for_ops_completed(struct mqtt_connection_state_test *state_test_data); |
| 151 |
|
| 152 |
void aws_test311_on_connection_termination_fn(void *userdata); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
void aws_test_mqtt_build_expected_metrics( |
| 167 |
struct aws_allocator *allocator, |
| 168 |
const struct aws_byte_cursor *original_username, |
| 169 |
const struct aws_byte_cursor sdk, |
| 170 |
const struct aws_byte_cursor *platform, |
| 171 |
const struct aws_mqtt_metadata_entry *metadata_entries, |
| 172 |
size_t metadata_count, |
| 173 |
struct aws_byte_buf *expected_buf); |
| 174 |
|
| 175 |
AWS_EXTERN_C_END |
| 176 |
|
| 177 |
#endif |