From 2d38bcd7378c1237d95e9465f2b0dab74453f456 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 30 Jul 2021 00:00:34 +0200 Subject: [PATCH] Remove the blackbox test suite. --- configure.ac | 19 - test/Makefile.am | 4 - test/blackbox/.gitignore | 5 - test/blackbox/Makefile.am | 25 - test/blackbox/common/common_handlers.c | 189 --- test/blackbox/common/common_handlers.h | 53 - test/blackbox/common/common_types.h | 58 - test/blackbox/common/containers.c | 1134 ----------------- test/blackbox/common/containers.h | 84 -- test/blackbox/common/mesh_event_handler.c | 290 ----- test/blackbox/common/mesh_event_handler.h | 156 --- .../common/network_namespace_framework.c | 569 --------- .../common/network_namespace_framework.h | 123 -- test/blackbox/common/tcpdump.c | 68 - test/blackbox/common/tcpdump.h | 29 - test/blackbox/common/test_step.c | 140 -- test/blackbox/common/test_step.h | 33 - test/blackbox/run_blackbox_tests/.gitignore | 1 - test/blackbox/run_blackbox_tests/Makefile.am | 73 -- .../run_blackbox_tests/execute_tests.c | 130 -- .../run_blackbox_tests/execute_tests.h | 70 - .../run_blackbox_tests/run_blackbox_tests.c | 169 --- test/blackbox/run_blackbox_tests/test_cases.c | 551 -------- test/blackbox/run_blackbox_tests/test_cases.h | 29 - .../run_blackbox_tests/test_cases_add_addr.c | 172 --- .../run_blackbox_tests/test_cases_add_addr.h | 29 - .../test_cases_add_ex_addr.c | 134 -- .../test_cases_add_ex_addr.h | 29 - .../test_cases_autoconnect.c | 160 --- .../test_cases_autoconnect.h | 28 - .../run_blackbox_tests/test_cases_blacklist.c | 233 ---- .../run_blackbox_tests/test_cases_blacklist.h | 28 - .../test_cases_channel_blacklist.c | 210 --- .../test_cases_channel_blacklist.h | 43 - .../test_cases_channel_close.c | 147 --- .../test_cases_channel_close.h | 28 - .../test_cases_channel_conn.c | 802 ------------ .../test_cases_channel_conn.h | 29 - .../test_cases_channel_ex.c | 664 ---------- .../test_cases_channel_ex.h | 28 - .../test_cases_channel_get_flags.c | 202 --- .../test_cases_channel_get_flags.h | 28 - .../test_cases_channel_open.c | 259 ---- .../test_cases_channel_open.h | 28 - .../test_cases_channel_send.c | 365 ------ .../test_cases_channel_send.h | 31 - .../test_cases_channel_set_accept_cb.c | 271 ---- .../test_cases_channel_set_accept_cb.h | 28 - .../test_cases_channel_set_poll_cb.c | 519 -------- .../test_cases_channel_set_poll_cb.h | 28 - .../test_cases_channel_set_receive_cb.c | 261 ---- .../test_cases_channel_set_receive_cb.h | 28 - .../test_cases_channel_shutdown.c | 348 ----- .../test_cases_channel_shutdown.h | 28 - .../test_cases_default_blacklist.c | 207 --- .../test_cases_default_blacklist.h | 28 - .../run_blackbox_tests/test_cases_destroy.c | 154 --- .../run_blackbox_tests/test_cases_destroy.h | 28 - .../run_blackbox_tests/test_cases_export.c | 118 -- .../run_blackbox_tests/test_cases_export.h | 28 - .../test_cases_get_all_nodes.c | 182 --- .../test_cases_get_all_nodes.h | 28 - .../test_cases_get_all_nodes_by_dev_class.c | 344 ----- .../test_cases_get_all_nodes_by_dev_class.h | 29 - .../test_cases_get_ex_addr.c | 147 --- .../test_cases_get_ex_addr.h | 28 - .../test_cases_get_fingerprint.c | 180 --- .../test_cases_get_fingerprint.h | 28 - .../run_blackbox_tests/test_cases_get_node.c | 209 --- .../run_blackbox_tests/test_cases_get_node.h | 28 - .../test_cases_get_node_reachability.c | 960 -------------- .../test_cases_get_node_reachability.h | 26 - .../run_blackbox_tests/test_cases_get_port.c | 110 -- .../run_blackbox_tests/test_cases_get_port.h | 28 - .../run_blackbox_tests/test_cases_get_self.c | 115 -- .../run_blackbox_tests/test_cases_get_self.h | 28 - .../test_cases_hint_address.c | 142 --- .../test_cases_hint_address.h | 28 - .../run_blackbox_tests/test_cases_import.c | 317 ----- .../run_blackbox_tests/test_cases_import.h | 28 - .../run_blackbox_tests/test_cases_invite.c | 287 ----- .../run_blackbox_tests/test_cases_invite.h | 28 - .../run_blackbox_tests/test_cases_join.c | 788 ------------ .../run_blackbox_tests/test_cases_join.h | 29 - .../test_cases_key_rotation.c | 503 -------- .../test_cases_key_rotation.h | 26 - .../run_blackbox_tests/test_cases_open.c | 355 ------ .../run_blackbox_tests/test_cases_open.h | 28 - .../run_blackbox_tests/test_cases_pmtu.c | 159 --- .../run_blackbox_tests/test_cases_pmtu.h | 28 - .../test_cases_random_port_bindings01.c | 302 ----- .../test_cases_random_port_bindings01.h | 28 - .../test_cases_random_port_bindings02.c | 435 ------- .../test_cases_random_port_bindings02.h | 28 - .../run_blackbox_tests/test_cases_rec_cb.c | 212 --- .../run_blackbox_tests/test_cases_rec_cb.h | 28 - .../run_blackbox_tests/test_cases_send.c | 179 --- .../run_blackbox_tests/test_cases_send.h | 29 - .../test_cases_set_connection_try_cb.c | 152 --- .../test_cases_set_connection_try_cb.h | 26 - .../test_cases_set_log_cb.c | 147 --- .../test_cases_set_log_cb.h | 28 - .../run_blackbox_tests/test_cases_set_port.c | 305 ----- .../run_blackbox_tests/test_cases_set_port.h | 28 - .../run_blackbox_tests/test_cases_sign.c | 404 ------ .../run_blackbox_tests/test_cases_sign.h | 28 - .../run_blackbox_tests/test_cases_start.c | 131 -- .../run_blackbox_tests/test_cases_start.h | 30 - .../run_blackbox_tests/test_cases_status_cb.c | 179 --- .../run_blackbox_tests/test_cases_status_cb.h | 28 - .../test_cases_stop_close.c | 94 -- .../test_cases_stop_close.h | 29 - .../run_blackbox_tests/test_cases_submesh01.c | 186 --- .../run_blackbox_tests/test_cases_submesh01.h | 30 - .../run_blackbox_tests/test_cases_submesh02.c | 189 --- .../run_blackbox_tests/test_cases_submesh02.h | 30 - .../run_blackbox_tests/test_cases_submesh03.c | 184 --- .../run_blackbox_tests/test_cases_submesh03.h | 30 - .../run_blackbox_tests/test_cases_submesh04.c | 163 --- .../run_blackbox_tests/test_cases_submesh04.h | 30 - .../run_blackbox_tests/test_cases_verify.c | 384 ------ .../run_blackbox_tests/test_cases_verify.h | 29 - .../run_blackbox_tests/test_cases_whitelist.c | 332 ----- .../run_blackbox_tests/test_cases_whitelist.h | 28 - .../run_blackbox_tests/test_optimal_pmtu.c | 651 ---------- .../run_blackbox_tests/test_optimal_pmtu.h | 62 - .../node_sim_nut_01.c | 224 ---- .../node_sim_nut_01.h | 31 - .../node_sim_peer_01.c | 109 -- .../node_sim_relay_01.c | 49 - .../test_case_channel_conn_01/Makefile.am | 9 - .../test_case_channel_conn_01/node_sim_nut.c | 168 --- .../test_case_channel_conn_01/node_sim_peer.c | 127 -- .../test_case_channel_conn_02/Makefile.am | 9 - .../test_case_channel_conn_02/node_sim_nut.c | 170 --- .../test_case_channel_conn_02/node_sim_peer.c | 113 -- .../test_case_channel_conn_03/Makefile.am | 9 - .../test_case_channel_conn_03/node_sim_nut.c | 174 --- .../test_case_channel_conn_03/node_sim_peer.c | 115 -- .../test_case_channel_conn_04/Makefile.am | 9 - .../test_case_channel_conn_04/node_sim_nut.c | 167 --- .../test_case_channel_conn_04/node_sim_peer.c | 137 -- .../test_case_channel_conn_05/Makefile.am | 13 - .../test_case_channel_conn_05/node_sim_nut.c | 168 --- .../test_case_channel_conn_05/node_sim_peer.c | 127 -- .../node_sim_relay.c | 59 - .../test_case_channel_conn_06/Makefile.am | 13 - .../test_case_channel_conn_06/node_sim_nut.c | 174 --- .../test_case_channel_conn_06/node_sim_peer.c | 115 -- .../node_sim_relay.c | 59 - .../test_case_channel_conn_07/Makefile.am | 13 - .../test_case_channel_conn_07/node_sim_nut.c | 180 --- .../test_case_channel_conn_07/node_sim_peer.c | 115 -- .../node_sim_relay.c | 59 - .../test_case_channel_conn_08/Makefile.am | 13 - .../test_case_channel_conn_08/node_sim_nut.c | 167 --- .../test_case_channel_conn_08/node_sim_peer.c | 137 -- .../node_sim_relay.c | 59 - .../test_case_meta_conn_01/Makefile.am | 13 - .../test_case_meta_conn_01/node_sim_nut.c | 133 -- .../test_case_meta_conn_01/node_sim_peer.c | 64 - .../test_case_meta_conn_01/node_sim_relay.c | 60 - .../test_case_meta_conn_01/test/node_step.sh | 25 - .../test_case_meta_conn_02/Makefile.am | 13 - .../test_case_meta_conn_02/node_sim_nut.c | 118 -- .../test_case_meta_conn_02/node_sim_peer.c | 70 - .../test_case_meta_conn_02/node_sim_relay.c | 66 - .../test_case_meta_conn_03/Makefile.am | 13 - .../test_case_meta_conn_03/node_sim_nut.c | 131 -- .../test_case_meta_conn_03/node_sim_peer.c | 70 - .../test_case_meta_conn_03/node_sim_relay.c | 66 - .../test_case_meta_conn_04/Makefile.am | 13 - .../test_case_meta_conn_04/node_sim_nut.c | 130 -- .../test_case_meta_conn_04/node_sim_peer.c | 70 - .../test_case_meta_conn_04/node_sim_relay.c | 63 - .../test_case_meta_conn_05/Makefile.am | 13 - .../test_case_meta_conn_05/node_sim_nut.c | 147 --- .../test_case_meta_conn_05/node_sim_peer.c | 70 - .../test_case_meta_conn_05/node_sim_relay.c | 63 - .../test_case_optimal_pmtu_01/node_sim_nut.c | 304 ----- .../test_case_optimal_pmtu_01/node_sim_peer.c | 133 -- .../node_sim_relay.c | 64 - .../test_case_optimal_pmtu.h | 22 - .../test_case_optimal_pmtu_02/Makefile.am | 13 - .../test_case_optimal_pmtu_03/Makefile.am | 13 - .../test_case_optimal_pmtu_04/Makefile.am | 13 - .../test_case_optimal_pmtu_05/Makefile.am | 13 - .../test_case_optimal_pmtu_06/Makefile.am | 13 - .../test_case_optimal_pmtu_07/Makefile.am | 13 - .../test_case_optimal_pmtu_07/node_sim_nut.c | 330 ----- .../test_case_optimal_pmtu_07/node_sim_peer.c | 168 --- .../node_sim_relay.c | 59 - .../blackbox/test_cases_submesh01/Makefile.am | 25 - .../test_cases_submesh01/node_sim_app1node1.c | 231 ---- .../test_cases_submesh01/node_sim_app1node2.c | 255 ---- .../test_cases_submesh01/node_sim_app2node1.c | 230 ---- .../test_cases_submesh01/node_sim_app2node2.c | 255 ---- .../test_cases_submesh01/node_sim_corenode1.c | 190 --- .../test_cases_submesh01/node_sim_corenode2.c | 212 --- .../blackbox/test_cases_submesh02/Makefile.am | 25 - .../test_cases_submesh02/node_sim_app1node1.c | 231 ---- .../test_cases_submesh02/node_sim_app1node2.c | 298 ----- .../test_cases_submesh02/node_sim_app2node1.c | 230 ---- .../test_cases_submesh02/node_sim_app2node2.c | 301 ----- .../test_cases_submesh02/node_sim_corenode1.c | 190 --- .../test_cases_submesh02/node_sim_corenode2.c | 212 --- .../blackbox/test_cases_submesh03/Makefile.am | 13 - .../test_cases_submesh03/node_sim_app1node1.c | 231 ---- .../test_cases_submesh03/node_sim_app1node2.c | 267 ---- .../test_cases_submesh03/node_sim_corenode1.c | 190 --- .../blackbox/test_cases_submesh04/Makefile.am | 13 - .../test_cases_submesh04/node_sim_app1node1.c | 231 ---- .../test_cases_submesh04/node_sim_app1node2.c | 299 ----- .../test_cases_submesh04/node_sim_corenode1.c | 190 --- test/blackbox/util/build_container.sh | 97 -- test/blackbox/util/gen_invite.c | 51 - test/blackbox/util/install_node_sim_copy.sh | 3 - test/blackbox/util/install_packages.sh | 55 - test/blackbox/util/lxc_copy_dir.sh | 27 - test/blackbox/util/lxc_copy_file.sh | 25 - test/blackbox/util/lxc_rename.sh | 29 - test/blackbox/util/lxc_run.sh | 26 - test/blackbox/util/nat.sh | 130 -- test/blackbox/util/nat_destroy.sh | 16 - test/blackbox/util/node_step.sh | 25 - 225 files changed, 30610 deletions(-) delete mode 100644 test/blackbox/.gitignore delete mode 100644 test/blackbox/Makefile.am delete mode 100644 test/blackbox/common/common_handlers.c delete mode 100644 test/blackbox/common/common_handlers.h delete mode 100644 test/blackbox/common/common_types.h delete mode 100644 test/blackbox/common/containers.c delete mode 100644 test/blackbox/common/containers.h delete mode 100644 test/blackbox/common/mesh_event_handler.c delete mode 100644 test/blackbox/common/mesh_event_handler.h delete mode 100644 test/blackbox/common/network_namespace_framework.c delete mode 100644 test/blackbox/common/network_namespace_framework.h delete mode 100644 test/blackbox/common/tcpdump.c delete mode 100644 test/blackbox/common/tcpdump.h delete mode 100644 test/blackbox/common/test_step.c delete mode 100644 test/blackbox/common/test_step.h delete mode 100644 test/blackbox/run_blackbox_tests/.gitignore delete mode 100644 test/blackbox/run_blackbox_tests/Makefile.am delete mode 100644 test/blackbox/run_blackbox_tests/execute_tests.c delete mode 100644 test/blackbox/run_blackbox_tests/execute_tests.h delete mode 100644 test/blackbox/run_blackbox_tests/run_blackbox_tests.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_add_addr.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_add_addr.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_autoconnect.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_autoconnect.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_blacklist.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_blacklist.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_close.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_close.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_conn.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_conn.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_ex.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_ex.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_open.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_open.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_send.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_send.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_default_blacklist.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_destroy.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_destroy.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_export.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_export.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_node.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_node.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_port.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_port.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_self.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_get_self.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_hint_address.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_hint_address.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_import.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_import.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_invite.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_invite.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_join.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_join.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_key_rotation.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_key_rotation.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_open.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_open.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_pmtu.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_pmtu.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_rec_cb.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_rec_cb.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_send.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_send.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_set_log_cb.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_set_port.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_set_port.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_sign.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_sign.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_start.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_start.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_status_cb.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_status_cb.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_stop_close.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_stop_close.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh01.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh01.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh02.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh02.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh03.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh03.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh04.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_submesh04.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_verify.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_verify.h delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_whitelist.c delete mode 100644 test/blackbox/run_blackbox_tests/test_cases_whitelist.h delete mode 100644 test/blackbox/run_blackbox_tests/test_optimal_pmtu.c delete mode 100644 test/blackbox/run_blackbox_tests/test_optimal_pmtu.h delete mode 100644 test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c delete mode 100644 test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.h delete mode 100644 test/blackbox/test_case_channel_blacklist_01/node_sim_peer_01.c delete mode 100644 test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c delete mode 100644 test/blackbox/test_case_channel_conn_01/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_01/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_01/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_02/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_02/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_02/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_03/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_03/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_03/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_04/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_04/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_04/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_05/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_05/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_05/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_05/node_sim_relay.c delete mode 100644 test/blackbox/test_case_channel_conn_06/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_06/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_06/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_06/node_sim_relay.c delete mode 100644 test/blackbox/test_case_channel_conn_07/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_07/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_07/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_07/node_sim_relay.c delete mode 100644 test/blackbox/test_case_channel_conn_08/Makefile.am delete mode 100644 test/blackbox/test_case_channel_conn_08/node_sim_nut.c delete mode 100644 test/blackbox/test_case_channel_conn_08/node_sim_peer.c delete mode 100644 test/blackbox/test_case_channel_conn_08/node_sim_relay.c delete mode 100644 test/blackbox/test_case_meta_conn_01/Makefile.am delete mode 100644 test/blackbox/test_case_meta_conn_01/node_sim_nut.c delete mode 100644 test/blackbox/test_case_meta_conn_01/node_sim_peer.c delete mode 100644 test/blackbox/test_case_meta_conn_01/node_sim_relay.c delete mode 100755 test/blackbox/test_case_meta_conn_01/test/node_step.sh delete mode 100644 test/blackbox/test_case_meta_conn_02/Makefile.am delete mode 100644 test/blackbox/test_case_meta_conn_02/node_sim_nut.c delete mode 100644 test/blackbox/test_case_meta_conn_02/node_sim_peer.c delete mode 100644 test/blackbox/test_case_meta_conn_02/node_sim_relay.c delete mode 100644 test/blackbox/test_case_meta_conn_03/Makefile.am delete mode 100644 test/blackbox/test_case_meta_conn_03/node_sim_nut.c delete mode 100644 test/blackbox/test_case_meta_conn_03/node_sim_peer.c delete mode 100644 test/blackbox/test_case_meta_conn_03/node_sim_relay.c delete mode 100644 test/blackbox/test_case_meta_conn_04/Makefile.am delete mode 100644 test/blackbox/test_case_meta_conn_04/node_sim_nut.c delete mode 100644 test/blackbox/test_case_meta_conn_04/node_sim_peer.c delete mode 100644 test/blackbox/test_case_meta_conn_04/node_sim_relay.c delete mode 100644 test/blackbox/test_case_meta_conn_05/Makefile.am delete mode 100644 test/blackbox/test_case_meta_conn_05/node_sim_nut.c delete mode 100644 test/blackbox/test_case_meta_conn_05/node_sim_peer.c delete mode 100644 test/blackbox/test_case_meta_conn_05/node_sim_relay.c delete mode 100644 test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c delete mode 100644 test/blackbox/test_case_optimal_pmtu_01/node_sim_peer.c delete mode 100644 test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c delete mode 100644 test/blackbox/test_case_optimal_pmtu_01/test_case_optimal_pmtu.h delete mode 100644 test/blackbox/test_case_optimal_pmtu_02/Makefile.am delete mode 100644 test/blackbox/test_case_optimal_pmtu_03/Makefile.am delete mode 100644 test/blackbox/test_case_optimal_pmtu_04/Makefile.am delete mode 100644 test/blackbox/test_case_optimal_pmtu_05/Makefile.am delete mode 100644 test/blackbox/test_case_optimal_pmtu_06/Makefile.am delete mode 100644 test/blackbox/test_case_optimal_pmtu_07/Makefile.am delete mode 100644 test/blackbox/test_case_optimal_pmtu_07/node_sim_nut.c delete mode 100644 test/blackbox/test_case_optimal_pmtu_07/node_sim_peer.c delete mode 100644 test/blackbox/test_case_optimal_pmtu_07/node_sim_relay.c delete mode 100644 test/blackbox/test_cases_submesh01/Makefile.am delete mode 100644 test/blackbox/test_cases_submesh01/node_sim_app1node1.c delete mode 100644 test/blackbox/test_cases_submesh01/node_sim_app1node2.c delete mode 100644 test/blackbox/test_cases_submesh01/node_sim_app2node1.c delete mode 100644 test/blackbox/test_cases_submesh01/node_sim_app2node2.c delete mode 100644 test/blackbox/test_cases_submesh01/node_sim_corenode1.c delete mode 100644 test/blackbox/test_cases_submesh01/node_sim_corenode2.c delete mode 100644 test/blackbox/test_cases_submesh02/Makefile.am delete mode 100644 test/blackbox/test_cases_submesh02/node_sim_app1node1.c delete mode 100644 test/blackbox/test_cases_submesh02/node_sim_app1node2.c delete mode 100644 test/blackbox/test_cases_submesh02/node_sim_app2node1.c delete mode 100644 test/blackbox/test_cases_submesh02/node_sim_app2node2.c delete mode 100644 test/blackbox/test_cases_submesh02/node_sim_corenode1.c delete mode 100644 test/blackbox/test_cases_submesh02/node_sim_corenode2.c delete mode 100644 test/blackbox/test_cases_submesh03/Makefile.am delete mode 100644 test/blackbox/test_cases_submesh03/node_sim_app1node1.c delete mode 100644 test/blackbox/test_cases_submesh03/node_sim_app1node2.c delete mode 100644 test/blackbox/test_cases_submesh03/node_sim_corenode1.c delete mode 100644 test/blackbox/test_cases_submesh04/Makefile.am delete mode 100644 test/blackbox/test_cases_submesh04/node_sim_app1node1.c delete mode 100644 test/blackbox/test_cases_submesh04/node_sim_app1node2.c delete mode 100644 test/blackbox/test_cases_submesh04/node_sim_corenode1.c delete mode 100755 test/blackbox/util/build_container.sh delete mode 100644 test/blackbox/util/gen_invite.c delete mode 100755 test/blackbox/util/install_node_sim_copy.sh delete mode 100755 test/blackbox/util/install_packages.sh delete mode 100755 test/blackbox/util/lxc_copy_dir.sh delete mode 100755 test/blackbox/util/lxc_copy_file.sh delete mode 100755 test/blackbox/util/lxc_rename.sh delete mode 100755 test/blackbox/util/lxc_run.sh delete mode 100755 test/blackbox/util/nat.sh delete mode 100755 test/blackbox/util/nat_destroy.sh delete mode 100755 test/blackbox/util/node_step.sh diff --git a/configure.ac b/configure.ac index f349de1..253f26d 100644 --- a/configure.ac +++ b/configure.ac @@ -144,25 +144,6 @@ AC_CONFIG_FILES([ Makefile src/Makefile test/Makefile - test/blackbox/Makefile - test/blackbox/run_blackbox_tests/Makefile - test/blackbox/test_case_channel_conn_01/Makefile - test/blackbox/test_case_channel_conn_02/Makefile - test/blackbox/test_case_channel_conn_03/Makefile - test/blackbox/test_case_channel_conn_04/Makefile - test/blackbox/test_case_channel_conn_05/Makefile - test/blackbox/test_case_channel_conn_06/Makefile - test/blackbox/test_case_channel_conn_07/Makefile - test/blackbox/test_case_channel_conn_08/Makefile - test/blackbox/test_case_meta_conn_01/Makefile - test/blackbox/test_case_meta_conn_02/Makefile - test/blackbox/test_case_meta_conn_03/Makefile - test/blackbox/test_case_meta_conn_04/Makefile - test/blackbox/test_case_meta_conn_05/Makefile - test/blackbox/test_cases_submesh01/Makefile - test/blackbox/test_cases_submesh02/Makefile - test/blackbox/test_cases_submesh03/Makefile - test/blackbox/test_cases_submesh04/Makefile examples/Makefile ]) diff --git a/test/Makefile.am b/test/Makefile.am index d9703dd..57d7eb8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -29,10 +29,6 @@ TESTS = \ TESTS += \ api_set_node_status_cb -#if BLACKBOX_TESTS -#SUBDIRS = blackbox -#endif - dist_check_SCRIPTS = $(TESTS) AM_CPPFLAGS = $(PTHREAD_CFLAGS) -I${top_srcdir}/src -iquote. -Wall diff --git a/test/blackbox/.gitignore b/test/blackbox/.gitignore deleted file mode 100644 index 4190b42..0000000 --- a/test/blackbox/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -gen_invite -node_sim_peer -node_sim_nut -node_sim_relay -interfaces diff --git a/test/blackbox/Makefile.am b/test/blackbox/Makefile.am deleted file mode 100644 index df5792b..0000000 --- a/test/blackbox/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -check_PROGRAMS = gen_invite -SUBDIRS = \ - run_blackbox_tests \ - test_case_channel_conn_01 \ - test_case_channel_conn_02 \ - test_case_channel_conn_03 \ - test_case_channel_conn_04 \ - test_case_channel_conn_05 \ - test_case_channel_conn_06 \ - test_case_channel_conn_07 \ - test_case_channel_conn_08 \ - test_case_meta_conn_01 \ - test_case_meta_conn_02 \ - test_case_meta_conn_03 \ - test_case_meta_conn_04 \ - test_case_meta_conn_05 \ - test_cases_submesh01 \ - test_cases_submesh02 \ - test_cases_submesh03 \ - test_cases_submesh04 - - -gen_invite_SOURCES = util/gen_invite.c common/common_handlers.c common/test_step.c common/mesh_event_handler.c -gen_invite_LDADD = ../../src/libmeshlink.la -gen_invite_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/common/common_handlers.c b/test/blackbox/common/common_handlers.c deleted file mode 100644 index e728f43..0000000 --- a/test/blackbox/common/common_handlers.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - common_handlers.c -- Implementation of common callback handling and signal handling - functions for black box tests - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "test_step.h" -#include "common_handlers.h" - -char *lxc_bridge = NULL; -black_box_state_t *state_ptr = NULL; - -bool meta_conn_status[10]; - -bool test_running; - -static int meshlink_get_node_in_container(const char *name) { - int i; - - for(i = 0; i < state_ptr->num_nodes; i++) { - if(!strcasecmp(state_ptr->node_names[i], name)) { - return i; - break; - } - } - - return -1; -} - -void mesh_close_signal_handler(int signum) { - (void)signum; - test_running = false; - - exit(EXIT_SUCCESS); -} - -void setup_signals(void) { - test_running = true; - signal(SIGTERM, mesh_close_signal_handler); -} - -/* Return the IP Address of the Interface 'if_name' - The caller is responsible for freeing the dynamically allocated string that is returned */ -char *get_ip(const char *if_name) { - struct ifaddrs *ifaddr, *ifa; - char *ip; - int family; - - ip = malloc(NI_MAXHOST); - assert(ip); - assert(getifaddrs(&ifaddr) != -1); - - for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if(ifa->ifa_addr == NULL) { - continue; - } - - family = ifa->ifa_addr->sa_family; - - if(family == AF_INET && !strcmp(ifa->ifa_name, if_name)) { - assert(!getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)); - break; - } - } - - return ip; -} - -/* Return the IP Address of the Interface 'if_name' - The caller is responsible for freeing the dynamically allocated string that is returned */ -char *get_netmask(const char *if_name) { - struct ifaddrs *ifaddr, *ifa; - char *ip; - int family; - - ip = malloc(NI_MAXHOST); - assert(ip); - assert(getifaddrs(&ifaddr) != -1); - - for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if(ifa->ifa_addr == NULL) { - continue; - } - - family = ifa->ifa_addr->sa_family; - - if(family == AF_INET && !strcmp(ifa->ifa_name, if_name)) { - assert(!getnameinfo(ifa->ifa_netmask, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)); - break; - } - } - - return ip; -} - -/* Change the IP Address of an interface */ -void set_ip(const char *if_name, const char *new_ip) { - char set_ip_cmd[100]; - assert(snprintf(set_ip_cmd, sizeof(set_ip_cmd), "ifconfig %s %s", if_name, new_ip) >= 0); - assert(system(set_ip_cmd) == 0); -} - -/* Change the Netmask of an interface */ -void set_netmask(const char *if_name, const char *new_netmask) { - char set_mask_cmd[100]; - assert(snprintf(set_mask_cmd, sizeof(set_mask_cmd), "ifconfig %s netmask %s", if_name, new_netmask) >= 0); - assert(system(set_mask_cmd) == 0); -} - -/* Bring a network interface down (before making changes such as the IP Address) */ -void stop_nw_intf(const char *if_name) { - char nw_down_cmd[100]; - assert(snprintf(nw_down_cmd, sizeof(nw_down_cmd), "ifconfig %s down", if_name) >= 0); - assert(system(nw_down_cmd) == 0); -} - -/* Bring a network interface up (after bringing it down and making changes such as - the IP Address) */ -void start_nw_intf(const char *if_name) { - char nw_up_cmd[100]; - assert(snprintf(nw_up_cmd, sizeof(nw_up_cmd), "ifconfig %s up", if_name) >= 0); - assert(system(nw_up_cmd) == 0); -} - -void meshlink_callback_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable) { - (void)mesh; - fprintf(stderr, "Node %s became %s\n", node->name, (reachable) ? "reachable" : "unreachable"); -} - -void meshlink_callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, - const char *text) { - (void)mesh; - (void)level; - - fprintf(stderr, "meshlink>> %s\n", text); - - if(state_ptr) { - bool status; - char name[100]; - - if(sscanf(text, "Connection with %s activated", name) == 1) { - status = true; - } else if(sscanf(text, "Already connected to %s", name) == 1) { - status = true; - } else if(sscanf(text, "Connection closed by %s", name) == 1) { - status = false; - } else if(sscanf(text, "Closing connection with %s", name) == 1) { - status = false; - } else { - return; - } - - int i = meshlink_get_node_in_container(name); - assert(i != -1); - meta_conn_status[i] = status; - } -} diff --git a/test/blackbox/common/common_handlers.h b/test/blackbox/common/common_handlers.h deleted file mode 100644 index 7c5fbd2..0000000 --- a/test/blackbox/common/common_handlers.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - common_handlers.h -- Declarations of common callback handlers and signal handlers for - black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef COMMON_HANDLERS_H -#define COMMON_HANDLERS_H - -#include "common_types.h" - -#define PRINT_TEST_CASE_HEADER() if(state_ptr) \ - fprintf(stderr, "[ %s ]\n", state_ptr->test_case_name) -#define PRINT_TEST_CASE_MSG(...) if(state_ptr) \ - do { \ - fprintf(stderr, "[ %s ] ", \ - state_ptr->test_case_name); \ - fprintf(stderr, __VA_ARGS__); \ - } while(0) - -extern bool meta_conn_status[]; -extern bool node_reachable_status[]; -extern bool test_running; - -char *get_ip(const char *if_name); -char *get_netmask(const char *if_name); -void stop_nw_intf(const char *if_name); -void start_nw_intf(const char *if_name); -void set_ip(const char *if_name, const char *new_ip); -void set_netmask(const char *if_name, const char *new_ip); -void mesh_close_signal_handler(int a); -void mesh_stop_start_signal_handler(int a); -void setup_signals(void); -void meshlink_callback_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable); -void meshlink_callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, - const char *text); - -#endif // COMMON_HANDLERS_H diff --git a/test/blackbox/common/common_types.h b/test/blackbox/common/common_types.h deleted file mode 100644 index 75dd686..0000000 --- a/test/blackbox/common/common_types.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - common_types.h -- Declarations of common types used in Black Box Testing - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef COMMON_TYPES_H -#define COMMON_TYPES_H - -#include -#include "../../../src/meshlink-tiny.h" - -#define NUT_NODE_NAME "nut" - -#define LXC_UTIL_REL_PATH "test/blackbox/util" -#define LXC_RENAME_SCRIPT "lxc_rename.sh" -#define LXC_RUN_SCRIPT "lxc_run.sh" -#define LXC_COPY_SCRIPT "lxc_copy_file.sh" -#define LXC_BUILD_SCRIPT "build_container.sh" -#define LXC_NAT_BUILD "nat.sh" -#define LXC_NAT_FULL_CONE "full_cone.sh" -#define LXC_NAT_DESTROY "nat_destroy.sh" - -typedef struct black_box_state { - char *test_case_name; - char **node_names; - int num_nodes; - bool test_result; -} black_box_state_t; - -extern char *lxc_bridge; - -extern char *eth_if_name; - -extern black_box_state_t *state_ptr; - -extern char *meshlink_root_path; - -/* Meshlink Mesh Handle */ -extern meshlink_handle_t *mesh_handle; - -/* Flag to indicate if Mesh is running */ -extern bool mesh_started; - -#endif // COMMON_TYPES_H diff --git a/test/blackbox/common/containers.c b/test/blackbox/common/containers.c deleted file mode 100644 index 4f3f881..0000000 --- a/test/blackbox/common/containers.c +++ /dev/null @@ -1,1134 +0,0 @@ -/* - containers.h -- Container Management API - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "containers.h" -#include "common_handlers.h" - -char *lxc_path = NULL; -extern char *choose_arch; -static char container_ips[10][100]; - -/* Return the handle to an existing container after finding it by container name */ -struct lxc_container *find_container(const char *name) { - struct lxc_container **test_containers; - char **container_names; - int num_containers, i; - - assert((num_containers = list_all_containers(lxc_path, &container_names, - &test_containers)) != -1); - - for(i = 0; i < num_containers; i++) { - if(strcmp(container_names[i], name) == 0) { - return test_containers[i]; - } - } - - return NULL; -} - -/* Rename a Container */ -void rename_container(const char *old_name, const char *new_name) { - char rename_command[200]; - int rename_status; - struct lxc_container *old_container; - - /* Stop the old container if its still running */ - assert((old_container = find_container(old_name))); - old_container->shutdown(old_container, CONTAINER_SHUTDOWN_TIMEOUT); - /* Call stop() in case shutdown() fails - one of these two will always succeed */ - old_container->stop(old_container); - /* Rename the Container */ - /* TO DO: Perform this operation using the LXC API - currently does not work via the API, - need to investigate and determine why it doesn't work, and make it work */ - assert(snprintf(rename_command, sizeof(rename_command), - "%s/" LXC_UTIL_REL_PATH "/" LXC_RENAME_SCRIPT " %s %s %s", meshlink_root_path, lxc_path, - old_name, new_name) >= 0); - rename_status = system(rename_command); - PRINT_TEST_CASE_MSG("Container '%s' rename status: %d\n", old_name, rename_status); - assert(rename_status == 0); -} - -char *run_in_container(const char *cmd, const char *container_name, bool daemonize) { - char container_find_name[1000]; - struct lxc_container *container; - - assert(cmd); - assert(container_name); - assert(snprintf(container_find_name, sizeof(container_find_name), "%s_%s", - state_ptr->test_case_name, container_name) >= 0); - assert((container = find_container(container_find_name))); - - return run_in_container_ex(cmd, container, daemonize); -} - -char *execute_in_container(const char *cmd, const char *container_name, bool daemonize) { - struct lxc_container *container; - - assert(cmd); - assert(container_name); - assert((container = find_container(container_name))); - - return run_in_container_ex(cmd, container, daemonize); -} - -/* Run 'cmd' inside the Container created for 'node' and return the first line of the output - or NULL if there is no output - useful when, for example, a meshlink invite is generated - by a node running inside a Container - 'cmd' is run as a daemon if 'daemonize' is true - this mode is useful for running node - simulations in Containers - The caller is responsible for freeing the returned string */ -char *run_in_container_ex(const char *cmd, struct lxc_container *container, bool daemonize) { - char *output = NULL; - size_t output_len = 0; - - /* Run the command within the Container, either as a daemon or foreground process */ - /* TO DO: Perform this operation using the LXC API - currently does not work using the API - Need to determine why it doesn't work, and make it work */ - if(daemonize) { - char run_script_path[100]; - char *attach_argv[4]; - - assert(snprintf(run_script_path, sizeof(run_script_path), "%s/" LXC_UTIL_REL_PATH "/" LXC_RUN_SCRIPT, - meshlink_root_path) >= 0); - attach_argv[0] = run_script_path; - attach_argv[1] = (char *)cmd; - attach_argv[2] = container->name; - attach_argv[3] = NULL; - - /* To daemonize, create a child process and detach it from its parent (this program) */ - if(fork() == 0) { - assert(daemon(1, 0) != -1); // Detach from the parent process - assert(execv(attach_argv[0], attach_argv) != -1); // Run exec() in the child process - } - } else { - char *attach_command; - size_t attach_command_len; - int i; - attach_command_len = strlen(meshlink_root_path) + strlen(LXC_UTIL_REL_PATH) + strlen(LXC_RUN_SCRIPT) + strlen(cmd) + strlen(container->name) + 10; - attach_command = malloc(attach_command_len); - assert(attach_command); - - assert(snprintf(attach_command, attach_command_len, - "%s/" LXC_UTIL_REL_PATH "/" LXC_RUN_SCRIPT " \"%s\" %s", meshlink_root_path, cmd, - container->name) >= 0); - FILE *attach_fp; - assert((attach_fp = popen(attach_command, "r"))); - free(attach_command); - /* If the command has an output, strip out any trailing carriage returns or newlines and - return it, otherwise return NULL */ - output = NULL; - output_len = 0; - - if(getline(&output, &output_len, attach_fp) != -1) { - i = strlen(output) - 1; - - while(output[i] == '\n' || output[i] == '\r') { - i--; - } - - output[i + 1] = '\0'; - } else { - free(output); - output = NULL; - } - - assert(pclose(attach_fp) != -1); - } - - return output; -} - -/* Wait for a starting Container to obtain an IP Address, then save that IP for future use */ -void container_wait_ip(int node) { - char container_name[100]; - char *ip; - - assert(snprintf(container_name, sizeof(container_name), "%s_%s", state_ptr->test_case_name, - state_ptr->node_names[node]) >= 0); - ip = container_wait_ip_ex(container_name); - - strncpy(container_ips[node], ip, sizeof(container_ips[node])); // Save the IP for future use - PRINT_TEST_CASE_MSG("Node '%s' has IP Address %s\n", state_ptr->node_names[node], - container_ips[node]); - free(ip); -} - -char *container_wait_ip_ex(const char *container_name) { - struct lxc_container *test_container; - char lxcls_command[200]; - char *ip; - size_t ip_len; - bool ip_found; - int i; - int timeout; - FILE *lxcls_fp; - - assert((test_container = find_container(container_name))); - assert(snprintf(lxcls_command, sizeof(lxcls_command), - "lxc-ls -f | grep %s | tr -s ' ' | cut -d ' ' -f 5", test_container->name) >= 0); - PRINT_TEST_CASE_MSG("Waiting for Container '%s' to acquire IP\n", test_container->name); - assert((ip = malloc(20))); - ip_len = sizeof(ip); - ip_found = false; - timeout = 60; - - while(!ip_found && timeout) { - assert((lxcls_fp = popen(lxcls_command, "r"))); // Run command - assert(getline((char **)&ip, &ip_len, lxcls_fp) != -1); // Read its output - /* Strip newlines and carriage returns from output */ - i = strlen(ip) - 1; - - while(ip[i] == '\n' || ip[i] == '\r') { - i--; - } - - ip[i + 1] = '\0'; - ip_found = (strcmp(ip, "-") != 0); // If the output is not "-", IP has been acquired - assert(pclose(lxcls_fp) != -1); - sleep(1); - timeout--; - } - - // Fail if IP cannot be read - assert(timeout); - - return ip; -} - -/* Create all required test containers */ -void create_containers(const char *node_names[], int num_nodes) { - int i; - char container_name[100]; - int create_status, snapshot_status, snap_restore_status; - struct lxc_container *first_container = NULL; - - for(i = 0; i < num_nodes; i++) { - assert(snprintf(container_name, sizeof(container_name), "run_%s", node_names[i]) >= 0); - - /* If this is the first Container, create it otherwise restore the snapshot saved - for the first Container to create an additional Container */ - if(i == 0) { - assert((first_container = lxc_container_new(container_name, NULL))); - assert(!first_container->is_defined(first_container)); - create_status = first_container->createl(first_container, "download", NULL, NULL, - LXC_CREATE_QUIET, "-d", "ubuntu", "-r", "trusty", "-a", choose_arch, NULL); - fprintf(stderr, "Container '%s' create status: %d - %s\n", container_name, - first_container->error_num, first_container->error_string); - assert(create_status); - snapshot_status = first_container->snapshot(first_container, NULL); - fprintf(stderr, "Container '%s' snapshot status: %d - %s\n", container_name, - first_container->error_num, first_container->error_string); - assert(snapshot_status != -1); - } else { - assert(first_container); - snap_restore_status = first_container->snapshot_restore(first_container, "snap0", - container_name); - fprintf(stderr, "Snapshot restore to Container '%s' status: %d - %s\n", container_name, - first_container->error_num, first_container->error_string); - assert(snap_restore_status); - } - } -} - -/* Setup Containers required for a test - This function should always be invoked in a CMocka context - after setting the state of the test case to an instance of black_box_state_t */ -void setup_containers(void **state) { - black_box_state_t *test_state = (black_box_state_t *)(*state); - int i; - char build_command[200]; - struct lxc_container *test_container, *new_container; - char container_find_name[100]; - char container_new_name[100]; - int create_status, build_status; - - PRINT_TEST_CASE_HEADER(); - - for(i = 0; i < test_state->num_nodes; i++) { - /* Find the run_ Container or create it if it doesn't exist */ - assert(snprintf(container_find_name, sizeof(container_find_name), "run_%s", - test_state->node_names[i]) >= 0); - - if(!(test_container = find_container(container_find_name))) { - assert((test_container = lxc_container_new(container_find_name, NULL))); - assert(!test_container->is_defined(test_container)); - create_status = test_container->createl(test_container, "download", NULL, NULL, - LXC_CREATE_QUIET, "-d", "ubuntu", "-r", "trusty", "-a", choose_arch, NULL); - PRINT_TEST_CASE_MSG("Container '%s' create status: %d - %s\n", container_find_name, - test_container->error_num, test_container->error_string); - assert(create_status); - } - - /* Stop the Container if it's running */ - test_container->shutdown(test_container, CONTAINER_SHUTDOWN_TIMEOUT); - /* Call stop() in case shutdown() fails - One of these two calls will always succeed */ - test_container->stop(test_container); - /* Rename the Container to make it specific to this test case, - if a Container with the target name already exists, skip this step */ - assert(snprintf(container_new_name, sizeof(container_new_name), "%s_%s", - test_state->test_case_name, test_state->node_names[i]) >= 0); - - if(!(new_container = find_container(container_new_name))) { - rename_container(test_container->name, container_new_name); - assert((new_container = find_container(container_new_name))); - } - - /* Start the Container */ - assert(new_container->start(new_container, 0, NULL)); - /* Build the Container by copying required files into it */ - assert(snprintf(build_command, sizeof(build_command), - "%s/" LXC_UTIL_REL_PATH "/" LXC_BUILD_SCRIPT " %s %s %s +x >/dev/null", - meshlink_root_path, test_state->test_case_name, test_state->node_names[i], - meshlink_root_path) >= 0); - build_status = system(build_command); - PRINT_TEST_CASE_MSG("Container '%s' build Status: %d\n", new_container->name, - build_status); - assert(build_status == 0); - /* Restart the Container after building it and wait for it to acquire an IP */ - new_container->shutdown(new_container, CONTAINER_SHUTDOWN_TIMEOUT); - new_container->stop(new_container); - new_container->start(new_container, 0, NULL); - container_wait_ip(i); - } -} - -/* Destroy all Containers with names containing 'run_' - Containers saved for debugging will - have names beginning with test_case_ ; 'run_' is reserved for temporary Containers - intended to be re-used for the next test */ -void destroy_containers(void) { - struct lxc_container **test_containers; - char **container_names; - int num_containers, i; - - assert((num_containers = list_all_containers(lxc_path, &container_names, - &test_containers)) != -1); - - for(i = 0; i < num_containers; i++) { - if(strstr(container_names[i], "run_")) { - fprintf(stderr, "Destroying Container '%s'\n", container_names[i]); - /* Stop the Container - it cannot be destroyed till it is stopped */ - test_containers[i]->shutdown(test_containers[i], CONTAINER_SHUTDOWN_TIMEOUT); - /* Call stop() in case shutdown() fails - One of these two calls will always succeed */ - test_containers[i]->stop(test_containers[i]); - /* Destroy the Container */ - test_containers[i]->destroy(test_containers[i]); - /* Call destroy_with_snapshots() in case destroy() fails - one of these two calls will always succeed */ - test_containers[i]->destroy_with_snapshots(test_containers[i]); - } - } -} - -/* Restart all the Containers being used in the current test case i.e. Containers with - names beginning with _ */ -void restart_all_containers(void) { - char container_name[100]; - struct lxc_container *test_container; - int i; - - for(i = 0; i < state_ptr->num_nodes; i++) { - /* Shutdown, then start the Container, then wait for it to acquire an IP Address */ - assert(snprintf(container_name, sizeof(container_name), "%s_%s", state_ptr->test_case_name, - state_ptr->node_names[i]) >= 0); - assert((test_container = find_container(container_name))); - test_container->shutdown(test_container, CONTAINER_SHUTDOWN_TIMEOUT); - test_container->stop(test_container); - test_container->start(test_container, 0, NULL); - container_wait_ip(i); - } -} - -/* Run the gen_invite command inside the 'inviter' container to generate an invite - for 'invitee', and return the generated invite which is output on the terminal */ -char *invite_in_container(const char *inviter, const char *invitee) { - char invite_command[200]; - char *invite_url; - - assert(snprintf(invite_command, sizeof(invite_command), - "LD_LIBRARY_PATH=/home/ubuntu/test/.libs /home/ubuntu/test/gen_invite %s %s " - "2> gen_invite.log", inviter, invitee) >= 0); - assert((invite_url = run_in_container(invite_command, inviter, false))); - PRINT_TEST_CASE_MSG("Invite Generated from '%s' to '%s': %s\n", inviter, - invitee, invite_url); - - return invite_url; -} - -/* Run the gen_invite command inside the 'inviter' container to generate an invite - for 'invitee' belonging to pparticular submesh, and return the generated invite - which is output on the terminal */ -char *submesh_invite_in_container(const char *inviter, const char *invitee, const char *submesh) { - char invite_command[200]; - char *invite_url; - - assert(snprintf(invite_command, sizeof(invite_command), - "LD_LIBRARY_PATH=/home/ubuntu/test/.libs /home/ubuntu/test/gen_invite %s %s %s " - "2> gen_invite.log", inviter, invitee, submesh) >= 0); - assert((invite_url = run_in_container(invite_command, inviter, false))); - PRINT_TEST_CASE_MSG("Invite Generated from '%s' to '%s': %s\n", inviter, - invitee, invite_url); - - return invite_url; -} - -/* Run the node_sim_ program inside the 'node''s container */ -void node_sim_in_container(const char *node, const char *device_class, const char *invite_url) { - char *node_sim_command; - size_t node_sim_command_len; - - node_sim_command_len = 500 + (invite_url ? strlen(invite_url) : 0); - node_sim_command = calloc(1, node_sim_command_len); - assert(node_sim_command); - assert(snprintf(node_sim_command, node_sim_command_len, - "LD_LIBRARY_PATH=/home/ubuntu/test/.libs /home/ubuntu/test/node_sim_%s %s %s %s " - "1>&2 2>> node_sim_%s.log", node, node, device_class, - (invite_url) ? invite_url : "", node) >= 0); - run_in_container(node_sim_command, node, true); - PRINT_TEST_CASE_MSG("node_sim_%s started in Container\n", node); - - free(node_sim_command); -} - -/* Run the node_sim_ program inside the 'node''s container with event handling capable */ -void node_sim_in_container_event(const char *node, const char *device_class, - const char *invite_url, const char *clientId, const char *import) { - char *node_sim_command; - size_t node_sim_command_len; - - assert(node && device_class && clientId && import); - node_sim_command_len = 500 + (invite_url ? strlen(invite_url) : 0); - node_sim_command = calloc(1, node_sim_command_len); - assert(node_sim_command); - assert(snprintf(node_sim_command, node_sim_command_len, - "LD_LIBRARY_PATH=/home/ubuntu/test/.libs /home/ubuntu/test/node_sim_%s %s %s %s %s %s " - "1>&2 2>> node_sim_%s.log", node, node, device_class, - clientId, import, (invite_url) ? invite_url : "", node) >= 0); - run_in_container(node_sim_command, node, true); - PRINT_TEST_CASE_MSG("node_sim_%s(Client Id :%s) started in Container with event handling\n%s\n", - node, clientId, node_sim_command); - - free(node_sim_command); -} - -/* Run the node_step.sh script inside the 'node''s container to send the 'sig' signal to the - node_sim program in the container */ -void node_step_in_container(const char *node, const char *sig) { - char node_step_command[1000]; - - assert(snprintf(node_step_command, sizeof(node_step_command), - "/home/ubuntu/test/node_step.sh lt-node_sim_%s %s 1>&2 2> node_step.log", - node, sig) >= 0); - run_in_container(node_step_command, node, false); - PRINT_TEST_CASE_MSG("Signal %s sent to node_sim_%s\n", sig, node); -} - -/* Change the IP Address of the Container running 'node' - Changes begin from X.X.X.254 and continue iteratively till an available address is found */ -void change_ip(int node) { - char *gateway_addr; - char new_ip[20] = ""; - char *netmask; - char *last_dot_in_ip; - int last_ip_byte = 254; - FILE *if_fp; - char copy_command[200]; - char container_name[100]; - struct lxc_container *container; - int copy_file_stat; - - /* Get IP Address of LXC Bridge Interface - this will be set up as the Gateway Address - of the Static IP assigned to the Container */ - assert((gateway_addr = get_ip(lxc_bridge))); - /* Get Netmask of LXC Brdige Interface */ - assert((netmask = get_netmask(lxc_bridge))); - - /* Replace last byte of Container's IP with 254 to form the new Container IP */ - assert(container_ips[node]); - strncpy(new_ip, container_ips[node], sizeof(new_ip) - 1); - assert((last_dot_in_ip = strrchr(new_ip, '.'))); - assert(snprintf(last_dot_in_ip + 1, 4, "%d", last_ip_byte) >= 0); - - /* Check that the new IP does not match the Container's existing IP - if it does, iterate till it doesn't */ - /* TO DO: Make sure the IP does not conflict with any other running Container */ - while(strcmp(new_ip, container_ips[node]) == 0) { - last_ip_byte--; - assert(snprintf(last_dot_in_ip + 1, 4, "%d", last_ip_byte) >= 0); - } - - /* Create new 'interfaces' file for Container */ - assert((if_fp = fopen("interfaces", "w"))); - fprintf(if_fp, "auto lo\n"); - fprintf(if_fp, "iface lo inet loopback\n"); - fprintf(if_fp, "\n"); - fprintf(if_fp, "auto eth0\n"); - fprintf(if_fp, "iface eth0 inet static\n"); - fprintf(if_fp, "\taddress %s\n", new_ip); - fprintf(if_fp, "\tnetmask %s\n", netmask); - fprintf(if_fp, "\tgateway %s\n", gateway_addr); - assert(fclose(if_fp) != EOF); - - /* Copy 'interfaces' file into Container's /etc/network path */ - assert(snprintf(copy_command, sizeof(copy_command), - "%s/" LXC_UTIL_REL_PATH "/" LXC_COPY_SCRIPT " interfaces %s_%s /etc/network/interfaces", - meshlink_root_path, state_ptr->test_case_name, state_ptr->node_names[node]) >= 0); - copy_file_stat = system(copy_command); - PRINT_TEST_CASE_MSG("Container '%s_%s' 'interfaces' file copy status: %d\n", - state_ptr->test_case_name, state_ptr->node_names[node], copy_file_stat); - assert(copy_file_stat == 0); - - /* Restart Container to apply new IP Address */ - assert(snprintf(container_name, sizeof(container_name), "%s_%s", state_ptr->test_case_name, - state_ptr->node_names[node]) >= 0); - assert((container = find_container(container_name))); - container->shutdown(container, CONTAINER_SHUTDOWN_TIMEOUT); - /* Call stop() in case shutdown() fails - One of these two calls with always succeed */ - container->stop(container); - assert(container->start(container, 0, NULL)); - - strncpy(container_ips[node], new_ip, sizeof(container_ips[node])); // Save the new IP Address - PRINT_TEST_CASE_MSG("Node '%s' IP Address changed to %s\n", state_ptr->node_names[node], - container_ips[node]); -} - -char **get_container_interface_ips(const char *container_name, const char *interface_name) { - char **ips; - struct lxc_container *container = find_container(container_name); - assert(container); - - char **interfaces = container->get_interfaces(container); - assert(interfaces); - - int i; - ips = NULL; - - for(i = 0; interfaces[i]; i++) { - if(!strcasecmp(interfaces[i], interface_name)) { - ips = container->get_ips(container, interface_name, "inet", 0); - assert(ips); - break; - } - } - - free(interfaces); - - return ips; -} - -/* Install an app in a container */ -void install_in_container(const char *node, const char *app) { - char install_cmd[100]; - - assert(snprintf(install_cmd, sizeof(install_cmd), - "apt-get install %s -y >> /dev/null", app) >= 0); - run_in_container(install_cmd, node, false); - // TODO: Check in container whether app has installed or not with a timeout - sleep(10); -} - -/* Return container's IP address */ -char *get_container_ip(const char *node_name) { - int node = -1, i; - - for(i = 0; i < state_ptr->num_nodes; i++) { - if(!strcasecmp(state_ptr->node_names[i], node_name)) { - node = i; - break; - } - } - - if(i == state_ptr->num_nodes) { - return NULL; - } - - char *ip = strdup(container_ips[node]); - assert(ip); - - return ip; -} - -/* Simulate a network failure by adding NAT rule in the container with it's IP address */ -void block_node_ip(const char *node) { - char block_cmd[100]; - char *node_ip; - - node_ip = get_container_ip(node); - assert(node_ip); - assert(snprintf(block_cmd, sizeof(block_cmd), "iptables -A OUTPUT -p all -s %s -j DROP", node_ip) >= 0); - run_in_container(block_cmd, node, false); - - assert(snprintf(block_cmd, sizeof(block_cmd), "iptables -A INPUT -p all -s %s -j DROP", node_ip) >= 0); - run_in_container(block_cmd, node, false); - - assert(snprintf(block_cmd, sizeof(block_cmd), "iptables -A FORWARD -p all -s %s -j DROP", node_ip) >= 0); - run_in_container(block_cmd, node, false); - - free(node_ip); -} - -void accept_port_rule(const char *node, const char *chain, const char *protocol, int port) { - char block_cmd[100]; - - assert(port >= 0 && port < 65536); - assert(!strcmp(chain, "INPUT") || !strcmp(chain, "FORWARD") || !strcmp(chain, "OUTPUT")); - assert(!strcmp(protocol, "all") || !strcmp(protocol, "tcp") || !strcmp(protocol, "udp") || !strcmp(protocol, "icmp")); - assert(snprintf(block_cmd, sizeof(block_cmd), "iptables -A %s -p %s --dport %d -j ACCEPT", chain, protocol, port) >= 0); - run_in_container(block_cmd, node, false); -} - -/* Restore the network that was blocked before by the NAT rule with it's own IP address */ -void unblock_node_ip(const char *node) { - char unblock_cmd[100]; - char *node_ip; - - node_ip = get_container_ip(node); - assert(node_ip); - assert(snprintf(unblock_cmd, sizeof(unblock_cmd), "iptables -D OUTPUT -p all -s %s -j DROP", node_ip) >= 0); - run_in_container(unblock_cmd, node, false); - - assert(snprintf(unblock_cmd, sizeof(unblock_cmd), "iptables -D INPUT -p all -s %s -j DROP", node_ip) >= 0); - run_in_container(unblock_cmd, node, false); - - assert(snprintf(unblock_cmd, sizeof(unblock_cmd), "iptables -D FORWARD -p all -s %s -j DROP", node_ip) >= 0); - run_in_container(unblock_cmd, node, false); -} - -char *block_icmp(const char *container_name) { - char block_cmd[500]; - assert(container_name); - assert(snprintf(block_cmd, sizeof(block_cmd), "iptables -A FORWARD -p icmp -j DROP") >= 0); - return execute_in_container(block_cmd, container_name, false); -} - -char *unblock_icmp(const char *container_name) { - char block_cmd[500]; - assert(container_name); - assert(snprintf(block_cmd, sizeof(block_cmd), "iptables -D FORWARD -p icmp -j DROP") >= 0); - return execute_in_container(block_cmd, container_name, false); -} - -char *change_container_mtu(const char *container_name, const char *interface_name, int mtu) { - char cmd[500]; - assert(container_name); - assert(snprintf(cmd, sizeof(cmd), "ifconfig %s mtu %d", interface_name, mtu) >= 0); - return execute_in_container(cmd, container_name, false); -} - -char *flush_conntrack(const char *container_name) { - assert(container_name); - - return execute_in_container("conntrack -F", container_name, false); -} - -void flush_nat_rules(const char *container_name, const char *chain) { - char *ret; - char flush_cmd[500]; - - assert(container_name); - assert(snprintf(flush_cmd, sizeof(flush_cmd), "iptables -F %s", chain ? chain : "") >= 0); - ret = execute_in_container("iptables -F", container_name, false); - assert(ret == NULL); -} - -void add_full_cone_nat_rules(const char *container_name, const char *pub_interface, const char *priv_interface_listen_address) { - char nat_cmd[500]; - - char **pub_interface_ips = get_container_interface_ips(container_name, pub_interface); - assert(pub_interface_ips[0]); - char *pub_interface_ip = pub_interface_ips[0]; - - assert(snprintf(nat_cmd, sizeof(nat_cmd), - "%s/" LXC_UTIL_REL_PATH "/" LXC_NAT_FULL_CONE " %s %s %s %s >/dev/null", - meshlink_root_path, container_name, pub_interface, pub_interface_ip, priv_interface_listen_address) >= 0); - assert(system(nat_cmd) == 0); - free(pub_interface_ips); -} - -/* Create a NAT and a bridge, bridge connected to NAT and containers to be NATed can be switched - to the NAT bridge from lxcbr0 */ -void nat_create(const char *nat_name, const char *nat_bridge, int nat_type) { - (void)nat_type; - - char build_command[200]; - assert(snprintf(build_command, sizeof(build_command), - "%s/" LXC_UTIL_REL_PATH "/" LXC_NAT_BUILD " %s %s %s >/dev/stderr", - meshlink_root_path, nat_name, nat_bridge, meshlink_root_path) >= 0); - assert(system(build_command) == 0); -} - -void nat_destroy(const char *nat_name) { - char build_command[200]; - assert(snprintf(build_command, sizeof(build_command), - "%s/" LXC_UTIL_REL_PATH "/" LXC_NAT_DESTROY " %s +x >/dev/null", - meshlink_root_path, nat_name) >= 0); - assert(system(build_command) == 0); -} - -/* Switches a container from current bridge to a new bridge */ -void container_switch_bridge(const char *container_name, char *lxc_conf_path, const char *current_bridge, const char *new_bridge) { - char config_path[500]; - char buffer[500]; - struct lxc_container *container; - char *lxc_path_temp; - char *ip; - - PRINT_TEST_CASE_MSG("Switiching container %s from bridge '%s' to bridge '%s'", container_name, current_bridge, new_bridge); - lxc_path_temp = lxc_path; - lxc_path = lxc_conf_path; - container = find_container(container_name); - assert(container); - lxc_path = lxc_path_temp; - assert(snprintf(config_path, sizeof(config_path), "%s/%s/config", lxc_conf_path, container_name) >= 0); - FILE *fp = fopen(config_path, "r"); - assert(fp); - FILE *fp_temp = fopen(".temp_file", "w"); - assert(fp_temp); - - int net_no; - - while((fgets(buffer, sizeof(buffer), fp)) != NULL) { - if(sscanf(buffer, "lxc.net.%d.link", &net_no) == 1) { - char *ptr; - int len; - - if((ptr = strstr(buffer, current_bridge)) != NULL) { - len = strlen(current_bridge); - - if(((*(ptr - 1) == ' ') || (*(ptr - 1) == '\t') || (*(ptr - 1) == '=')) && ((ptr[len] == '\n') || (ptr[len] == '\t') || (ptr[len] == '\0') || (ptr[len] == ' '))) { - sprintf(buffer, "lxc.net.%d.link = %s\n", net_no, new_bridge); - } - } - } - - fputs(buffer, fp_temp); - } - - fclose(fp_temp); - fclose(fp); - remove(config_path); - rename(".temp_file", config_path); - - /* Restart the Container after building it and wait for it to acquire an IP */ - char cmd[200]; - int sys_ret; - assert(snprintf(cmd, sizeof(cmd), "lxc-stop %s", container_name) >= 0); - sys_ret = system(cmd); - assert(snprintf(cmd, sizeof(cmd), "lxc-start %s", container_name) >= 0); - sys_ret = system(cmd); - assert(sys_ret == 0); - ip = container_wait_ip_ex(container_name); - PRINT_TEST_CASE_MSG("Obtained IP address: %s for container %s after switching bridge", ip, container_name); - free(ip); -} - -/* Takes bridgeName as input parameter and creates a bridge */ -void create_bridge(const char *bridgeName) { - char command[100] = "brctl addbr "; - strcat(command, bridgeName); - int create_bridge_status = system(command); - assert(create_bridge_status == 0); - PRINT_TEST_CASE_MSG("%s bridge created\n", bridgeName); -} - -/* Add interface for the bridge created */ -void add_interface(const char *bridgeName, const char *interfaceName) { - char command[100] = "brctl addif "; - char cmd[100] = "dhclient "; - - strcat(command, bridgeName); - strcat(command, " "); - strcat(command, interfaceName); - int addif_status = system(command); - assert(addif_status == 0); - strcat(cmd, bridgeName); - int dhclient_status = system(cmd); - assert(dhclient_status == 0); - PRINT_TEST_CASE_MSG("Added interface for %s\n", bridgeName); -} - -/* Create a veth pair and bring them up */ -void add_veth_pair(const char *vethName1, const char *vethName2) { - char command[100] = "ip link add "; - char upCommand1[100] = "ip link set "; - char upCommand2[100] = "ip link set "; - - strcat(command, vethName1); - strcat(command, " type veth peer name "); - strcat(command, vethName2); - int link_add_status = system(command); - assert(link_add_status == 0); - strcat(upCommand1, vethName1); - strcat(upCommand1, " up"); - int link_set_veth1_status = system(upCommand1); - assert(link_set_veth1_status == 0); - strcat(upCommand2, vethName2); - strcat(upCommand2, " up"); - int link_set_veth2_status = system(upCommand2); - assert(link_set_veth2_status == 0); - PRINT_TEST_CASE_MSG("Added veth pairs %s and %s\n", vethName1, vethName2); -} - -/* Bring the interface up for the bridge created */ -void bring_if_up(const char *bridgeName) { - char command[300] = "ifconfig "; - strcat(command, bridgeName); - strcat(command, " up"); - int if_up_status = system(command); - assert(if_up_status == 0); - sleep(2); - PRINT_TEST_CASE_MSG("Interface brought up for %s created\n", bridgeName); -} - -/** - * Replace all occurrences of a given a word in string. - */ -void replaceAll(char *str, const char *oldWord, const char *newWord) { - char *pos, temp[BUFSIZ]; - int index = 0; - int owlen; - owlen = strlen(oldWord); - - while((pos = strstr(str, oldWord)) != NULL) { - strcpy(temp, str); - index = pos - str; - str[index] = '\0'; - strcat(str, newWord); - strcat(str, temp + index + owlen); - } -} - -/* Switches the bridge for a given container */ -void switch_bridge(const char *containerName, const char *currentBridge, const char *newBridge) { - char command[100] = "lxc-stop -n "; - char command_start[100] = "lxc-start -n "; - PRINT_TEST_CASE_MSG("Switching %s container to %s\n", containerName, newBridge); - strcat(command, containerName); - strcat(command_start, containerName); - int container_stop_status = system(command); - assert(container_stop_status == 0); - sleep(2); - FILE *fPtr; - FILE *fTemp; - char path[300] = "/var/lib/lxc/"; - strcat(path, containerName); - strcat(path, "/config"); - - char buffer[BUFSIZ]; - /* Open all required files */ - fPtr = fopen(path, "r"); - fTemp = fopen("replace.tmp", "w"); - - if(fPtr == NULL || fTemp == NULL) { - PRINT_TEST_CASE_MSG("\nUnable to open file.\n"); - PRINT_TEST_CASE_MSG("Please check whether file exists and you have read/write privilege.\n"); - exit(EXIT_SUCCESS); - } - - while((fgets(buffer, BUFSIZ, fPtr)) != NULL) { - replaceAll(buffer, currentBridge, newBridge); - fputs(buffer, fTemp); - } - - fclose(fPtr); - fclose(fTemp); - remove(path); - rename("replace.tmp", path); - PRINT_TEST_CASE_MSG("Switching procedure done successfully\n"); - int container_start_status = system(command_start); - assert(container_start_status == 0); - sleep(2); -} - -/* Bring the interface down for the bridge created */ -void bring_if_down(const char *bridgeName) { - char command[300] = "ip link set dev "; - strcat(command, bridgeName); - strcat(command, " down"); - int if_down_status = system(command); - assert(if_down_status == 0); - PRINT_TEST_CASE_MSG("Interface brought down for %s created\n", bridgeName); -} - -/* Delete interface for the bridge created */ -void del_interface(const char *bridgeName, const char *interfaceName) { - char command[300] = "brctl delif "; - strcat(command, bridgeName); - strcat(command, interfaceName); - int if_delete_status = system(command); - assert(if_delete_status == 0); - PRINT_TEST_CASE_MSG("Deleted interface for %s\n", bridgeName); -} - -/* Takes bridgeName as input parameter and deletes a bridge */ -void delete_bridge(const char *bridgeName) { - bring_if_down(bridgeName); - char command[300] = "brctl delbr "; - strcat(command, bridgeName); - int bridge_delete = system(command); - assert(bridge_delete == 0); - PRINT_TEST_CASE_MSG("%s bridge deleted\n", bridgeName); - sleep(2); -} - -/* Creates container on a specified bridge with added interface */ -void create_container_on_bridge(const char *containerName, const char *bridgeName, const char *ifName) { - char command[100] = "lxc-create -t download -n "; - char cmd[100] = " -- -d ubuntu -r trusty -a "; - char start[100] = "lxc-start -n "; - FILE *fPtr; - char path[300] = "/var/lib/lxc/"; - strcat(path, containerName); - strcat(path, "/config"); - strcat(command, containerName); - strcat(command, cmd); - strcat(command, choose_arch); - int container_create_status = system(command); - assert(container_create_status == 0); - sleep(3); - assert((fPtr = fopen(path, "a+"))); - fprintf(fPtr, "lxc.net.0.name = eth0\n"); - fprintf(fPtr, "\n"); - fprintf(fPtr, "lxc.net.1.type = veth\n"); - fprintf(fPtr, "lxc.net.1.flags = up\n"); - fprintf(fPtr, "lxc.net.1.link = %s\n", bridgeName); - fprintf(fPtr, "lxc.net.1.name = %s\n", ifName); - fprintf(fPtr, "lxc.net.1.hwaddr = 00:16:3e:ab:xx:xx\n"); - fclose(fPtr); - strcat(start, containerName); - int container_start_status = system(start); - assert(container_start_status == 0); - sleep(3); - PRINT_TEST_CASE_MSG("Created %s on %s with interface name %s\n", containerName, bridgeName, ifName); -} - -/* Configures dnsmasq and iptables for the specified container with inputs of listen address and dhcp range */ -void config_dnsmasq(const char *containerName, const char *ifName, const char *listenAddress, const char *dhcpRange) { - char command[500] = "echo \"apt-get install dnsmasq iptables -y\" | lxc-attach -n "; - strcat(command, containerName); - strcat(command, " --"); - int iptables_install_status = system(command); - assert(iptables_install_status == 0); - sleep(5); - char com1[300] = "echo \"echo \"interface=eth1\" >> /etc/dnsmasq.conf\" | lxc-attach -n "; - strcat(com1, containerName); - strcat(com1, " --"); - int dnsmasq_status = system(com1); - assert(dnsmasq_status == 0); - sleep(5); - char com2[300] = "echo \"echo \"bind-interfaces\" >> /etc/dnsmasq.conf\" | lxc-attach -n "; - strcat(com2, containerName); - strcat(com2, " --"); - dnsmasq_status = system(com2); - assert(dnsmasq_status == 0); - sleep(5); - char com3[300] = "echo \"echo \"listen-address="; - strcat(com3, listenAddress); - strcat(com3, "\" >> /etc/dnsmasq.conf\" | lxc-attach -n "); - strcat(com3, containerName); - strcat(com3, " --"); - dnsmasq_status = system(com3); - assert(dnsmasq_status == 0); - sleep(5); - char com4[300] = "echo \"echo \"dhcp-range="; - strcat(com4, dhcpRange); - strcat(com4, "\" >> /etc/dnsmasq.conf\" | lxc-attach -n "); - strcat(com4, containerName); - strcat(com4, " --"); - dnsmasq_status = system(com4); - assert(dnsmasq_status == 0); - sleep(5); - char cmd[300] = "echo \"ifconfig "; - strcat(cmd, ifName); - strcat(cmd, " "); - strcat(cmd, listenAddress); - strcat(cmd, " netmask 255.255.255.0 up\" | lxc-attach -n "); - strcat(cmd, containerName); - strcat(cmd, " --"); - dnsmasq_status = system(cmd); - assert(dnsmasq_status == 0); - sleep(2); - char com[500] = "echo \"service dnsmasq restart >> /dev/null\" | lxc-attach -n "; - strcat(com, containerName); - strcat(com, " --"); - dnsmasq_status = system(com); - assert(dnsmasq_status == 0); - sleep(2); - PRINT_TEST_CASE_MSG("Configured dnsmasq in %s with interface name %s, listen-address = %s, dhcp-range = %s\n", containerName, ifName, listenAddress, dhcpRange); -} - -/* Configure the NAT rules inside the container */ -void config_nat(const char *containerName, const char *listenAddress) { - char *last_dot_in_ip; - int last_ip_byte = 0; - char new_ip[300] = {0}; - strncpy(new_ip, listenAddress, sizeof(new_ip) - 1); - assert((last_dot_in_ip = strrchr(new_ip, '.'))); - assert(snprintf(last_dot_in_ip + 1, 4, "%d", last_ip_byte) >= 0); - char comd[300] = "echo \"iptables -t nat -A POSTROUTING -s "; - strcat(comd, new_ip); - strcat(comd, "/24 ! -d "); - strcat(comd, new_ip); - strcat(comd, "/24 -j MASQUERADE\" | lxc-attach -n "); - strcat(comd, containerName); - strcat(comd, " --"); - int conf_nat_status = system(comd); - assert(conf_nat_status == 0); - sleep(2); - PRINT_TEST_CASE_MSG("Configured NAT on %s\n", containerName); -} - -/* Creates a NAT layer on a specified bridge with certain dhcp range to allocate ips for nodes */ -void create_nat_layer(const char *containerName, const char *bridgeName, const char *ifName, const char *listenAddress, char *dhcpRange) { - create_bridge(bridgeName); - bring_if_up(bridgeName); - create_container_on_bridge(containerName, bridgeName, ifName); - config_dnsmasq(containerName, ifName, listenAddress, dhcpRange); - config_nat(containerName, listenAddress); - PRINT_TEST_CASE_MSG("NAT layer created with %s\n", containerName); -} - -/* Destroys the NAT layer created */ -void destroy_nat_layer(const char *containerName, const char *bridgeName) { - bring_if_down(bridgeName); - delete_bridge(bridgeName); - char command[100] = "lxc-stop -n "; - strcat(command, containerName); - int container_stop_status = system(command); - assert(container_stop_status == 0); - char destroy[100] = "lxc-destroy -n "; - strcat(destroy, containerName); - strcat(destroy, " -s"); - int container_destroy_status = system(destroy); - assert(container_destroy_status == 0); - PRINT_TEST_CASE_MSG("NAT layer destroyed with %s\n", containerName); -} - -/* Add incoming firewall rules for ipv4 addresses with packet type and port number */ -void incoming_firewall_ipv4(const char *packetType, int portNumber) { - char buf[5]; - snprintf(buf, sizeof(buf), "%d", portNumber); - assert(system("iptables -F") == 0); - assert(system("iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT") == 0); - assert(system("iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT") == 0); - char command[100] = "iptables -A INPUT -p "; - strcat(command, packetType); - strcat(command, " --dport "); - strcat(command, buf); - strcat(command, " -j ACCEPT"); - assert(system(command) == 0); - sleep(2); - assert(system("iptables -A INPUT -j DROP") == 0); - PRINT_TEST_CASE_MSG("Firewall for incoming requests added on IPv4"); - assert(system("iptables -L") == 0); -} - -/* Add incoming firewall rules for ipv6 addresses with packet type and port number */ -void incoming_firewall_ipv6(const char *packetType, int portNumber) { - char buf[5]; - snprintf(buf, sizeof(buf), "%d", portNumber); - assert(system("ip6tables -F") == 0); - assert(system("ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT") == 0); - assert(system("ip6tables -A INPUT -s ::1 -d ::1 -j ACCEPT") == 0); - char command[100] = "ip6tables -A INPUT -p "; - strcat(command, packetType); - strcat(command, " --dport "); - strcat(command, buf); - strcat(command, " -j ACCEPT"); - assert(system(command) == 0); - sleep(2); - assert(system("ip6tables -A INPUT -j DROP") == 0); - PRINT_TEST_CASE_MSG("Firewall for incoming requests added on IPv6"); - assert(system("ip6tables -L") == 0); -} - -/* Add outgoing firewall rules for ipv4 addresses with packet type and port number */ -void outgoing_firewall_ipv4(const char *packetType, int portNumber) { - char buf[5]; - snprintf(buf, sizeof(buf), "%d", portNumber); - assert(system("iptables -F") == 0); - assert(system("iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT") == 0); - assert(system("iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT") == 0); - char command[100] = "iptables -A OUTPUT -p "; - strcat(command, packetType); - strcat(command, " --dport "); - strcat(command, buf); - strcat(command, " -j ACCEPT"); - assert(system(command) == 0); - sleep(2); - assert(system("iptables -A OUTPUT -j DROP") == 0); - PRINT_TEST_CASE_MSG("Firewall for outgoing requests added on IPv4"); - assert(system("iptables -L") == 0); -} - -/* Add outgoing firewall rules for ipv6 addresses with packet type and port number */ -void outgoing_firewall_ipv6(const char *packetType, int portNumber) { - char buf[5]; - snprintf(buf, sizeof(buf), "%d", portNumber); - assert(system("ip6tables -F") == 0); - assert(system("ip6tables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT") == 0); - assert(system("ip6tables -A OUTPUT -s ::1 -d ::1 -j ACCEPT") == 0); - char command[100] = "ip6tables -A OUTPUT -p "; - strcat(command, packetType); - strcat(command, " --dport "); - strcat(command, buf); - strcat(command, " -j ACCEPT"); - assert(system(command) == 0); - sleep(2); - assert(system("ip6tables -A OUTPUT -j DROP") == 0); - PRINT_TEST_CASE_MSG("Firewall for outgoing requests added on IPv6"); - assert(system("ip6tables -L") == 0); -} - -void bridge_add(const char *bridge_name) { - char cmd[500]; - - assert(bridge_name); - assert(snprintf(cmd, sizeof(cmd), "brctl addbr %s", bridge_name) >= 0); - assert(system(cmd) == 0); - assert(snprintf(cmd, sizeof(cmd), "ifconfig %s up", bridge_name) >= 0); - assert(system(cmd) == 0); -} - -void bridge_delete(const char *bridge_name) { - char cmd[500]; - - assert(bridge_name); - assert(snprintf(cmd, sizeof(cmd), "brctl delbr %s", bridge_name) >= 0); - assert(system(cmd) == 0); -} - -void bridge_add_interface(const char *bridge_name, const char *interface_name) { - char cmd[500]; - - assert(bridge_name || interface_name); - assert(snprintf(cmd, sizeof(cmd), "brctl addif %s %s", bridge_name, interface_name) >= 0); - assert(system(cmd) == 0); -} diff --git a/test/blackbox/common/containers.h b/test/blackbox/common/containers.h deleted file mode 100644 index c807bbf..0000000 --- a/test/blackbox/common/containers.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - containers.h -- Declarations for Container Management API - Copyright (C) 2018 Guus Sliepen - Manav Kumar Mehta - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef CONTAINERS_H -#define CONTAINERS_H - -#include - -#define DAEMON_ARGV_LEN 2000 -#define CONTAINER_SHUTDOWN_TIMEOUT 5 - -#define DHCP_RANGE "172.16.0.2,172.16.255.254,12h" -#define PUB_INTERFACE "eth0" -#define PRIV_INTERFACE "eth1" -#define LISTEN_ADDRESS "172.16.0.1" -#define NET_MASK "255.255.255.0" -#define SUBNET_MASK "172.16.0.0/24" - -#define FULLCONE_NAT 1 -#define ADDRESS_RESTRICTED_NAT 2 -#define PORT_RESTRICTED_NAT 3 -#define SYMMERTIC_NAT 4 - -extern char *lxc_path; - -extern struct lxc_container *find_container(const char *name); -extern void rename_container(const char *old_name, const char *new_name); -extern char *run_in_container(const char *cmd, const char *node, bool daemonize); -extern void container_wait_ip(int node); -extern void create_containers(const char *node_names[], int num_nodes); -extern void setup_containers(void **state); -extern void destroy_containers(void); -extern void restart_all_containers(void); -extern char *invite_in_container(const char *inviter, const char *invitee); -extern char *submesh_invite_in_container(const char *inviter, const char *invitee, const char *submesh); -extern void node_sim_in_container(const char *node, const char *device_class, const char *invite_url); -extern void node_sim_in_container_event(const char *node, const char *device_class, - const char *invite_url, const char *clientId, const char *import); -extern void node_step_in_container(const char *node, const char *sig); -extern void change_ip(int node); - -extern char *get_container_ip(const char *node_name); -extern void install_in_container(const char *node, const char *app); -extern void unblock_node_ip(const char *node); -extern void block_node_ip(const char *node); -extern void accept_port_rule(const char *node, const char *chain, const char *protocol, int port); -extern void nat_create(const char *nat_name, const char *nat_bridge, int nat_type); -extern void container_switch_bridge(const char *container_name, char *lxc_conf_path, const char *current_bridge, const char *new_bridge); -extern void bridge_add(const char *bridge_name); -extern void bridge_delete(const char *bridge_name); -extern void bridge_add_interface(const char *bridge_name, const char *interface_name); - -extern void nat_destroy(const char *nat_name); -extern char *run_in_container_ex(const char *cmd, struct lxc_container *container, bool daemonize); -extern char *execute_in_container(const char *cmd, const char *container_name, bool daemonize); -extern char *block_icmp(const char *container_name); -extern char *unblock_icmp(const char *container_name); -extern char *change_container_mtu(const char *container_name, const char *interface_name, int mtu); -extern char *flush_conntrack(const char *container_name); - -extern char **get_container_interface_ips(const char *container_name, const char *interface_name); -extern void flush_nat_rules(const char *container_name, const char *chain); -extern void add_full_cone_nat_rules(const char *container_name, const char *pub_interface, const char *priv_interface_listen_address); -extern void add_port_rest_nat_rules(const char *container_name, const char *pub_interface); -extern char *container_wait_ip_ex(const char *container_name); - -#endif // CONTAINERS_H diff --git a/test/blackbox/common/mesh_event_handler.c b/test/blackbox/common/mesh_event_handler.c deleted file mode 100644 index e00f7d3..0000000 --- a/test/blackbox/common/mesh_event_handler.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - mesh_event_handler.c -- handling of mesh events API - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#define _POSIX_C_SOURCE 200809L - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../../../src/meshlink_queue.h" -#include "../../utils.h" -#include "mesh_event_handler.h" - -#define SERVER_LISTEN_PORT "9000" /* Port number that is binded with mesh event server socket */ -#define UDP_BUFF_MAX 2000 - -const char *event_status[] = { - [NODE_STARTED] = "Node Started", - [NODE_JOINED] = "Node Joined", - [ERR_NETWORK] = "Network Error", - [CHANNEL_OPENED] = "Channel Opened", - [CHANNEL_DATA_RECIEVED] = "Channel Data Received", - [SIG_ABORT] = "SIG_ABORT Received", - [MESH_EVENT_COMPLETED] = "MESH_EVENT_COMPLETED Received" -}; - -// TODO: Implement mesh event handling with reentrancy . -static struct sockaddr_in server_addr; -static int client_fd = -1; -static int server_fd = -1; -static pthread_t event_receive_thread, event_handle_thread; -static meshlink_queue_t event_queue; -static bool event_receive_thread_running, event_handle_thread_running; -static struct cond_flag sync_event = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void set_cond_flag(struct cond_flag *s, bool flag) { - pthread_mutex_lock(&s->mutex); - s->flag = flag; - pthread_cond_broadcast(&s->cond); - pthread_mutex_unlock(&s->mutex); -} - -static bool wait_cond_flag(struct cond_flag *s, int seconds) { - struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); - timeout.tv_sec += seconds; - - pthread_mutex_lock(&s->mutex); - - while(!s->flag) - if(!pthread_cond_timedwait(&s->cond, &s->mutex, &timeout) || errno != EINTR) { - break; - } - - pthread_mutex_unlock(&s->mutex); - - return s->flag; -} - -// event_receive_handler running in a separate thread queues all the events received from the UDP port -static void *event_receive_handler(void *arg) { - (void)arg; - size_t recv_ret; - char udp_buff[UDP_BUFF_MAX]; - struct sockaddr client; - socklen_t soc_len; - - while(event_receive_thread_running) { - recv_ret = recvfrom(server_fd, udp_buff, sizeof(udp_buff), 0, &client, &soc_len); - assert(recv_ret >= sizeof(mesh_event_payload_t)); - - // Push received mesh event data into the event_queue - mesh_event_payload_t *data = malloc(sizeof(mesh_event_payload_t)); - assert(data); - memcpy(data, udp_buff, sizeof(mesh_event_payload_t)); - - // Also receive if there is any payload - if(data->payload_length) { - void *payload_data = malloc(data->payload_length); - assert(payload_data); - memcpy(payload_data, udp_buff + (int)sizeof(mesh_event_payload_t), data->payload_length); - data->payload = payload_data; - } else { - data->payload = NULL; - } - - // Push the event into the event queue - assert(meshlink_queue_push(&event_queue, data)); - } - - return NULL; -} - -// `event_handler' runs in a separate thread which invokes the event handle callback with -// event packet as argument returns from the thread when the callback returns `true' or timeout -static void *event_handler(void *argv) { - bool callback_return = false; - void *data; - mesh_event_payload_t mesh_event_rec_packet; - mesh_event_callback_t callback = *(mesh_event_callback_t *)argv; - - while(event_handle_thread_running) { - - // Pops the event if found in the event queue - while((data = meshlink_queue_pop(&event_queue)) != NULL) { - memcpy(&mesh_event_rec_packet, data, sizeof(mesh_event_payload_t)); - free(data); - - // Invokes the callback with the popped event packet - callback_return = callback(mesh_event_rec_packet); - - if(mesh_event_rec_packet.payload_length) { - free(mesh_event_rec_packet.payload); - } - - // Return or Close the event handle thread if callback returns true - if(callback_return) { - set_cond_flag(&sync_event, true); - event_handle_thread_running = false; - break; - } - } - } - - return NULL; -} - -char *mesh_event_sock_create(const char *if_name) { - struct sockaddr_in server = {0}; - char *ip; - struct ifreq req_if = {0}; - struct sockaddr_in *resp_if_addr; - - assert(if_name); - assert(!event_receive_thread_running); - - server_fd = socket(AF_INET, SOCK_DGRAM, 0); - assert(server_fd >= 0); - - int reuse = 1; - assert(setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) != -1); - - req_if.ifr_addr.sa_family = AF_INET; - strncpy(req_if.ifr_name, if_name, IFNAMSIZ - 1); - assert(ioctl(server_fd, SIOCGIFADDR, &req_if) != -1); - resp_if_addr = (struct sockaddr_in *) & (req_if.ifr_addr); - - server.sin_family = AF_INET; - server.sin_addr = resp_if_addr->sin_addr; - server.sin_port = htons(atoi(SERVER_LISTEN_PORT)); - assert(bind(server_fd, (struct sockaddr *) &server, sizeof(struct sockaddr)) != -1); - - assert((ip = malloc(30))); - strncpy(ip, inet_ntoa(resp_if_addr->sin_addr), 20); - strcat(ip, ":"); - strcat(ip, SERVER_LISTEN_PORT); - - meshlink_queue_init(&event_queue); - event_receive_thread_running = true; - assert(!pthread_create(&event_receive_thread, NULL, event_receive_handler, NULL)); - - return ip; -} - -void mesh_event_sock_connect(const char *import) { - assert(import); - - char *ip = strdup(import); - assert(ip); - char *port = strchr(ip, ':'); - assert(port); - *port = '\0'; - port++; - - memset(&server_addr, 0, sizeof(server_addr)); - server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = inet_addr(ip); - server_addr.sin_port = htons(atoi(port)); - client_fd = socket(AF_INET, SOCK_DGRAM, 0); - free(ip); - assert(client_fd >= 0); -} - -bool mesh_event_sock_send(int client_id, mesh_event_t event, const void *payload, size_t payload_length) { - if(client_fd < 0) { - fprintf(stderr, "mesh_event_sock_send called without calling mesh_event_sock_connect\n"); - return false; - } - - if(client_id < 0 || event < 0 || event >= MAX_EVENT || (payload == NULL && payload_length)) { - fprintf(stderr, "Invalid parameters\n"); - return false; - } - - ssize_t send_size = sizeof(mesh_event_payload_t) + payload_length; - char *send_packet = malloc(send_size); - assert(send_packet); - mesh_event_payload_t mesh_event_send_packet; - - mesh_event_send_packet.client_id = client_id; - mesh_event_send_packet.mesh_event = event; - mesh_event_send_packet.payload_length = payload_length; - mesh_event_send_packet.payload = NULL; - memcpy(send_packet, &mesh_event_send_packet, sizeof(mesh_event_send_packet)); - - if(payload_length) { - memcpy(send_packet + sizeof(mesh_event_send_packet), payload, payload_length); - } - - ssize_t send_ret = sendto(client_fd, send_packet, send_size, 0, (const struct sockaddr *) &server_addr, sizeof(server_addr)); - free(send_packet); - - if(send_ret < 0) { - perror("sendto status"); - return false; - } else { - return true; - } -} - -bool wait_for_event(mesh_event_callback_t callback, int seconds) { - if(callback == NULL || seconds == 0) { - fprintf(stderr, "Invalid parameters\n"); - return false; - } - - if(event_handle_thread_running) { - fprintf(stderr, "Event handle thread is already running\n"); - return false; - } else { - event_handle_thread_running = true; - } - - set_cond_flag(&sync_event, false); - assert(!pthread_create(&event_handle_thread, NULL, event_handler, (void *)&callback)); - bool wait_ret = wait_cond_flag(&sync_event, seconds); - event_handle_thread_running = false; - pthread_cancel(event_handle_thread); - - return wait_ret; -} - -void mesh_events_flush(void) { - mesh_event_payload_t *data; - - while((data = meshlink_queue_pop(&event_queue)) != NULL) { - if(data->payload_length) { - free(data->payload); - } - - free(data); - } -} - -void mesh_event_destroy(void) { - mesh_events_flush(); - event_receive_thread_running = false; - pthread_cancel(event_receive_thread); -} diff --git a/test/blackbox/common/mesh_event_handler.h b/test/blackbox/common/mesh_event_handler.h deleted file mode 100644 index 609b1cf..0000000 --- a/test/blackbox/common/mesh_event_handler.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - mesh_event_handler.h - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef _MESH_EVENT_HANDLER_H_ -#define _MESH_EVENT_HANDLER_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/// mesh events -// TODO: Add more mesh event if required. -typedef enum { - NO_PREFERENCE = 0, - META_CONN_SUCCESSFUL, - META_CONN, - META_DISCONN, - META_CONN_CLOSED, - NODE_INVITATION, - CHANGED_IP_ADDRESS, - NODE_UNREACHABLE, - NODE_REACHABLE, - META_RECONN_SUCCESSFUL, - META_RECONN_FAILURE, - MESH_DATA_RECEIVED, - NODE_STARTED, - NODE_LEFT, - NODE_RESTARTED, - NODE_JOINED, - NODE_JOINED1, - NODE_JOINED2, - NODE_JOINED3, - PORT_NO, - OPTIMAL_PMTU_PEER, - OPTIMAL_PMTU_RELAY, - ERR_NETWORK, - SIG_ABORT, - MESH_DATA_VERIFED, - CHANNEL_OPENED, - CHANNEL_REQ_RECIEVED, - CHANNEL_CONNECTED, - CHANNEL_DATA_RECIEVED, - MESH_NODE_DISCOVERED, - INCOMING_META_CONN, - OUTGOING_META_CONN, - AUTO_DISCONN, - MESH_EVENT_COMPLETED, - MAX_EVENT // Maximum event enum -} mesh_event_t; - -extern const char *event_status[]; - -/// mesh event UDP packet -typedef struct mesh_event_payload { - void *payload; - mesh_event_t mesh_event; - uint16_t client_id; - uint32_t payload_length; -} mesh_event_payload_t; - -struct cond_flag { - pthread_mutex_t mutex; - pthread_cond_t cond; - bool flag; -}; - -/// callback for handling the mesh event -/** mesh event callback called from wait_for_event() if the mesh event UDP server gets a mesh event. - * - * @param mesh_event_packet packet containing client-id, mesh event & payload (if any). - */ -typedef bool (*mesh_event_callback_t)(mesh_event_payload_t mesh_event_packet); - -/// Creates an UDP server for listening mesh events. -/** This function creates an UDP socket, binds it with given interface address and returns a NULL - * terminated string containing server's IP address & port number. - * - * @param ifname Name of the network interface to which the socket has to be created. - * - * @return This function returns a NULL terminated string which has IP address and - * port number of the server socket. The application should call free() after - * it has finished using the exported string. - */ -extern char *mesh_event_sock_create(const char *ifname); - -/// Waits for the mesh event for about the given timeout. -/** This function waits for the mesh event that's expected to occur for the given timeout. If a mesh event - * is received then the given callback will be invoked. - * - * @param callback callback which handles the mesh event packet. - * @param timeout timeout for which the the function has to wait for the event. - * - * @return This function returns true if a mesh event occurred else false if timeout exceeded. - */ -extern bool wait_for_event(mesh_event_callback_t callback, int timeout); - -/// Sends the mesh event to server. -/** This function sends the mesh event to the server. At the server end it's expected to wait_for_event() - * otherwise the packet will be dropped. - * - * @param client_id Client id by which server can identify the client/node. - * @param event An enum describing the mesh event. - * @param payload Payload can also be attached along with the mesh event if any, else NULL can - * can be specified. - * @param payload_length Length of the payload if specified else 0 can be specified. - * the maximum payload size can be up to PAYLOAD_MAX_SIZE and if the - * PAYLOAD_MAX_SIZE macro is changed it should not exceed the UDP datagram size. - * - * @return This function returns true on success else returns false. - */ -extern bool mesh_event_sock_send(int client_id, mesh_event_t event, const void *payload, size_t payload_length); - -/// Imports the server address, saves it and opens an UDP client socket. -/** This function creates an UDP socket, binds it with given interface address and returns a NULL - * terminated string containing server's IP address & port number. - * - * @param server_address NULL terminated string that's exported by mesh_event_sock_create() which - * which contains IP address and port number of the mesh event server. - * - * @return void - */ -extern void mesh_event_sock_connect(const char *server_address); - -extern void mesh_event_destroy(void); - -extern void mesh_events_flush(void); - -#endif // _MESH_EVENT_HANDLER_H_ diff --git a/test/blackbox/common/network_namespace_framework.c b/test/blackbox/common/network_namespace_framework.c deleted file mode 100644 index 8f65296..0000000 --- a/test/blackbox/common/network_namespace_framework.c +++ /dev/null @@ -1,569 +0,0 @@ -/* - test_optimal_pmtu.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include "network_namespace_framework.h" - -#define DEFAULT_PUB_NET_ADDR "203.0.113.0/24" -#define DEFAULT_GATEWAY_NET_ADDR "203.0.113.254" -#define NS_PEER0 " ns_peer0 " -#define NS_ETH0 " ns_eth0 " -#define PEER_INDEX i ? 0 : 1 -#define get_namespace_handle_by_index(state_ptr, index) index < state_ptr->num_namespaces ? &(state_ptr->namespaces[index]) : NULL -#define get_interface_handle_by_index(namespace, index) index < namespace->interfaces_no ? &((namespace->interfaces)[index]) : NULL - -static int ipv4_str_check_cidr(const char *ip_addr) { - int cidr = 0; - sscanf(ip_addr, "%*d.%*d.%*d.%*d/%d", &cidr); - return cidr; -} - -static char *ipv4_str_remove_cidr(const char *ipv4_addr) { - char *ptr = strdup(ipv4_addr); - assert(ptr); - - if(ipv4_str_check_cidr(ptr)) { - char *end = strchr(ptr, '/'); - *end = '\0'; - } - - return ptr; -} - -namespace_t *find_namespace(netns_state_t *state, const char *namespace_name) { - int i; - - for(i = 0; i < state->num_namespaces; i++) { - if(!strcmp((state->namespaces[i]).name, namespace_name)) { - return &(state->namespaces[i]); - } - } - - return NULL; -} - -static int netns_delete_namespace(namespace_t *namespace_handle) { - char cmd[200]; - - if(namespace_handle->type != BRIDGE) { - assert(sprintf(cmd, "ip netns del %s 2>/dev/null", namespace_handle->name) >= 0); - } else { - assert(sprintf(cmd, "ip link del %s 2>/dev/null", namespace_handle->name) >= 0); - } - - return system(cmd); -} - -/* Create new network namespace using namespace handle */ -static void netns_create_namespace(netns_state_t *test_state, namespace_t *namespace_handle) { - (void)test_state; - - char cmd[200]; - - // Add the network namespace - - sprintf(cmd, "ip netns add %s", namespace_handle->name); - assert(system(cmd) == 0); - - sprintf(cmd, "ip netns exec %s ip link set dev lo up", namespace_handle->name); - assert(system(cmd) == 0); -} - -static void netns_create_bridge(netns_state_t *test_state, namespace_t *namespace_handle) { - (void)test_state; - - char cmd[200]; - - sprintf(cmd, "ip link add name %s type bridge", namespace_handle->name); - assert(system(cmd) == 0); - - sprintf(cmd, "ip link set %s up", namespace_handle->name); - assert(system(cmd) == 0); -} - -interface_t *get_peer_interface_handle(netns_state_t *test_state, namespace_t *namespace, namespace_t *peer_namespace) { - (void)test_state; - - int i; - interface_t *interfaces = namespace->interfaces; - int if_no = namespace->interfaces_no; - char *peer_name = peer_namespace->name; - - for(i = 0; i < if_no; i++) { - if(!strcasecmp(interfaces[i].if_peer, peer_name)) { - return &interfaces[i]; - } - } - - return NULL; -} - -interface_t *get_interface_handle_by_name(netns_state_t *test_state, namespace_t *namespace, const char *peer_name) { - namespace_t *peer_ns; - peer_ns = find_namespace(test_state, peer_name); - assert(peer_ns); - - return get_peer_interface_handle(test_state, namespace, peer_ns); -} - -bool check_interfaces_visited(netns_state_t *test_state, namespace_t *ns1, namespace_t *ns2) { - interface_t *iface, *peer_iface; - iface = get_peer_interface_handle(test_state, ns1, ns2); - peer_iface = get_peer_interface_handle(test_state, ns2, ns1); - assert(iface && peer_iface); - - return iface->priv || peer_iface->priv; -} - -void netns_connect_namespaces(netns_state_t *test_state, namespace_t *ns1, namespace_t *ns2) { - char buff[20], cmd[200]; - int i; - char eth_pairs[2][20]; - namespace_t *ns[2] = { ns1, ns2 }; - interface_t *interface; - char *set = "set"; - - // Check if visited already - if(check_interfaces_visited(test_state, ns1, ns2)) { - return; - } - - assert(sprintf(eth_pairs[0], "%.9s_eth0", ns2->name) >= 0); - assert(sprintf(eth_pairs[1], "%.9s_peer0", ns1->name) >= 0); - - // Delete veth pair if already exists - for(i = 0; i < 2; i++) { - assert(sprintf(cmd, "ip link del %s 2>/dev/null", eth_pairs[i]) >= 0); - system(cmd); - } - - // Create veth pair - assert(sprintf(cmd, "ip link add %s type veth peer name %s", eth_pairs[0], eth_pairs[1]) >= 0); - assert(system(cmd) == 0); - - for(i = 0; i < 2; i++) { - - // Find interface handle that with it's peer interface - interface = get_peer_interface_handle(test_state, ns[i], ns[PEER_INDEX]); - assert(interface); - - if(ns[i]->type != BRIDGE) { - - // Define interface name - char *if_name; - - if(interface->if_name) { - if_name = interface->if_name; - } else { - assert(sprintf(buff, "eth_%s", interface->if_peer) >= 0); - if_name = buff; - } - - interface->if_name = strdup(if_name); - - assert(interface->if_name); - - // Connect one end of the the veth pair to the namespace's interface - assert(sprintf(cmd, "ip link set %s netns %s name %s", eth_pairs[i], ns[i]->name, interface->if_name) >= 0); - - assert(system(cmd) == 0); - } else { - - // Connect one end of the the veth pair to the bridge - assert(sprintf(cmd, "ip link set %s master %s up\n", eth_pairs[i], ns[i]->name) >= 0); - assert(system(cmd) == 0); - } - - // Mark interfaces as connected - interface->priv = set; - interface = get_peer_interface_handle(test_state, ns[PEER_INDEX], ns[i]); - assert(interface); - interface->priv = set; - } -} - -void netns_configure_ip_address(netns_state_t *test_state) { - int i, if_no; - namespace_t *namespace; - interface_t *if_handle; - char cmd[200]; - - for(i = 0; i < test_state->num_namespaces; i++) { - namespace = get_namespace_handle_by_index(test_state, i); - - for(if_no = 0; if_no < namespace->interfaces_no; if_no++) { - if_handle = get_interface_handle_by_index(namespace, if_no); - assert(if_handle); - - if(if_handle->if_addr && namespace->type != BRIDGE) { - assert(sprintf(cmd, "ip netns exec %s ip addr add %s dev %s", namespace->name, if_handle->if_addr, if_handle->if_name) >= 0); - assert(system(cmd) == 0); - assert(sprintf(cmd, "ip netns exec %s ip link set dev %s up", namespace->name, if_handle->if_name) >= 0); - assert(system(cmd) == 0); - - if(if_handle->if_default_route_ip) { - char *route_ip = ipv4_str_remove_cidr(if_handle->if_default_route_ip); - assert(sprintf(cmd, "ip netns exec %s ip route add default via %s", namespace->name, route_ip) >= 0); - assert(system(cmd) == 0); - free(route_ip); - } - } - } - } -} - -void netns_enable_all_nats(netns_state_t *test_state) { - int i, j; - namespace_t *namespace, *peer_namespace; - interface_t *interface_handle; - char cmd[200]; - char *ip_addr; - - for(i = 0; i < test_state->num_namespaces; i++) { - namespace = get_namespace_handle_by_index(test_state, i); - - if(namespace->type == FULL_CONE) { - assert(namespace->nat_arg); - netns_fullcone_handle_t **nat_rules = namespace->nat_arg; - char *eth0; - - for(j = 0; nat_rules[j]; j++) { - assert(nat_rules[j]->snat_to_source && nat_rules[j]->dnat_to_destination); - - interface_handle = get_interface_handle_by_name(test_state, namespace, nat_rules[j]->snat_to_source); - assert(interface_handle); - eth0 = interface_handle->if_name; - ip_addr = ipv4_str_remove_cidr(interface_handle->if_addr); - assert(sprintf(cmd, "ip netns exec %s iptables -t nat -A POSTROUTING -o %s -j SNAT --to-source %s", namespace->name, eth0, ip_addr) >= 0); - assert(system(cmd) == 0); - free(ip_addr); - - peer_namespace = find_namespace(test_state, nat_rules[j]->dnat_to_destination); - interface_handle = get_interface_handle_by_name(test_state, peer_namespace, namespace->name); - assert(interface_handle); - - ip_addr = ipv4_str_remove_cidr(interface_handle->if_addr); - assert(sprintf(cmd, "ip netns exec %s iptables -t nat -A PREROUTING -i %s -j DNAT --to-destination %s", namespace->name, eth0, ip_addr) >= 0); - assert(system(cmd) == 0); - free(ip_addr); - } - } - } -} - -void netns_create_all_namespaces(netns_state_t *test_state) { - int i; - namespace_t *namespace; - - for(i = 0; i < test_state->num_namespaces; i++) { - namespace = get_namespace_handle_by_index(test_state, i); - - // Delete the namespace if already exists - netns_delete_namespace(namespace); - - // Create namespace - - if(namespace->type != BRIDGE) { - netns_create_namespace(test_state, namespace); - } else { - netns_create_bridge(test_state, namespace); - } - } -} - -void netns_connect_all_namespaces(netns_state_t *test_state) { - int i, j; - namespace_t *namespace, *peer_namespace; - interface_t *interfaces; - interface_t *interface_handle; - - for(i = 0; i < test_state->num_namespaces; i++) { - namespace = get_namespace_handle_by_index(test_state, i); - assert(namespace->interfaces); - interfaces = namespace->interfaces; - - for(j = 0; j < namespace->interfaces_no; j++) { - peer_namespace = find_namespace(test_state, interfaces[j].if_peer); - assert(peer_namespace); - netns_connect_namespaces(test_state, namespace, peer_namespace); - } - } - - // Reset all priv members of the interfaces - - for(i = 0; i < test_state->num_namespaces; i++) { - namespace = get_namespace_handle_by_index(test_state, i); - assert(namespace->interfaces); - - for(j = 0; j < namespace->interfaces_no; j++) { - interface_handle = get_interface_handle_by_index(namespace, j); - assert(interface_handle); - interface_handle->priv = NULL; - } - } -} - -void increment_ipv4_str(char *ip_addr, int ip_addr_size) { - uint32_t addr_int_n, addr_int_h; - - assert(inet_pton(AF_INET, ip_addr, &addr_int_n) > 0); - addr_int_h = ntohl(addr_int_n); - addr_int_h = addr_int_h + 1; - addr_int_n = htonl(addr_int_h); - assert(inet_ntop(AF_INET, &addr_int_n, ip_addr, ip_addr_size)); -} - -void increment_ipv4_cidr_str(char *ip) { - int subnet; - assert(sscanf(ip, "%*d.%*d.%*d.%*d/%d", &subnet) >= 0); - char *ptr = strchr(ip, '/'); - *ptr = '\0'; - increment_ipv4_str(ip, INET6_ADDRSTRLEN); - sprintf(ip + strlen(ip), "/%d", subnet); -} - -interface_t *netns_get_priv_addr(netns_state_t *test_state, const char *namespace_name) { - namespace_t *namespace_handle; - interface_t *interface_handle; - int if_no; - - namespace_handle = find_namespace(test_state, namespace_name); - assert(namespace_handle); - - for(if_no = 0; if_no < namespace_handle->interfaces_no; if_no++) { - interface_handle = get_interface_handle_by_index(namespace_handle, if_no); - - if(!strcmp(namespace_handle->name, interface_handle->fetch_ip_netns_name)) { - return interface_handle; - } - } - - return NULL; -} - -void netns_add_default_route_addr(netns_state_t *test_state) { - int ns, if_no; - namespace_t *namespace_handle; - interface_t *interface_handle, *peer_interface_handle; - - for(ns = 0; ns < test_state->num_namespaces; ns++) { - namespace_handle = get_namespace_handle_by_index(test_state, ns); - assert(namespace_handle); - - if(namespace_handle->type != HOST) { - continue; - } - - for(if_no = 0; if_no < namespace_handle->interfaces_no; if_no++) { - interface_handle = get_interface_handle_by_index(namespace_handle, if_no); - - if(interface_handle->if_default_route_ip == NULL) { - peer_interface_handle = netns_get_priv_addr(test_state, interface_handle->fetch_ip_netns_name); - assert(peer_interface_handle); - interface_handle->if_default_route_ip = ipv4_str_remove_cidr(peer_interface_handle->if_addr); - } else { - char *dup = strdup(interface_handle->if_default_route_ip); - assert(dup); - interface_handle->if_default_route_ip = dup; - } - } - } -} - -void netns_assign_ip_addresses(netns_state_t *test_state) { - int ns, j; - namespace_t *namespace_handle; - interface_t *interface_handle; - - char *addr = malloc(INET6_ADDRSTRLEN); - assert(addr); - - if(test_state->public_net_addr) { - assert(strncpy(addr, test_state->public_net_addr, INET6_ADDRSTRLEN)); - } else { - assert(strncpy(addr, DEFAULT_PUB_NET_ADDR, INET6_ADDRSTRLEN)); - } - - test_state->public_net_addr = addr; - - for(ns = 0; ns < test_state->num_namespaces; ns++) { - namespace_handle = get_namespace_handle_by_index(test_state, ns); - assert(namespace_handle); - - if(namespace_handle->type == BRIDGE) { - continue; - } - - for(j = 0; j < namespace_handle->interfaces_no; j++) { - interface_handle = get_interface_handle_by_index(namespace_handle, j); - assert(interface_handle); - - if(interface_handle->if_addr) { - continue; - } - - // If fetch ip net namespace name is given get IP address from it, else get a public IP address - - if(interface_handle->fetch_ip_netns_name) { - namespace_t *gw_netns_handle = find_namespace(test_state, interface_handle->fetch_ip_netns_name); - assert(gw_netns_handle); - assert(gw_netns_handle->static_config_net_addr); - - increment_ipv4_cidr_str(gw_netns_handle->static_config_net_addr); - interface_handle->if_addr = strdup(gw_netns_handle->static_config_net_addr); - } else { - increment_ipv4_cidr_str(test_state->public_net_addr); - interface_handle->if_addr = strdup(test_state->public_net_addr); - - if(namespace_handle->type == HOST) { - if(interface_handle->if_default_route_ip) { - char *dup = strdup(interface_handle->if_default_route_ip); - assert(dup); - interface_handle->if_default_route_ip = dup; - } else { - interface_handle->if_default_route_ip = strdup(DEFAULT_GATEWAY_NET_ADDR); - } - } - } - } - } - - netns_add_default_route_addr(test_state); -} - -static void netns_namespace_init_pids(netns_state_t *test_state) { - int if_no; - namespace_t *namespace_handle; - - for(if_no = 0; if_no < test_state->num_namespaces; if_no++) { - namespace_handle = get_namespace_handle_by_index(test_state, if_no); - assert(namespace_handle); - namespace_handle->pid_nos = 0; - namespace_handle->pids = NULL; - } -} - -pid_t run_cmd_in_netns(netns_state_t *test_state, char *namespace_name, char *cmd_str) { - pid_t pid; - namespace_t *namespace_handle; - char cmd[1000]; - - assert(namespace_name && cmd_str); - namespace_handle = find_namespace(test_state, namespace_name); - assert(namespace_handle); - - if((pid = fork()) == 0) { - assert(daemon(1, 0) != -1); - assert(sprintf(cmd, "ip netns exec %s %s", namespace_name, cmd_str) >= 0); - assert(system(cmd) == 0); - exit(0); - } - - pid_t *pid_ptr; - pid_ptr = realloc(namespace_handle->pids, (namespace_handle->pid_nos + 1) * sizeof(pid_t)); - assert(pid_ptr); - namespace_handle->pids = pid_ptr; - (namespace_handle->pids)[namespace_handle->pid_nos] = pid; - namespace_handle->pid_nos = namespace_handle->pid_nos + 1; - - return pid; -} - -static void *pthread_fun(void *arg) { - netns_thread_t *netns_arg = (netns_thread_t *)arg; - char namespace_path[100]; - void *ret; - assert(sprintf(namespace_path, "/var/run/netns/%s", netns_arg->namespace_name) >= 0); - int fd = open(namespace_path, O_RDONLY); - assert(fd != -1); - assert(setns(fd, CLONE_NEWNET) != -1); - - ret = (netns_arg->netns_thread)(netns_arg->arg); - pthread_detach(netns_arg->thread_handle); - pthread_exit(ret); -} - -void run_node_in_namespace_thread(netns_thread_t *netns_arg) { - assert(netns_arg->namespace_name && netns_arg->netns_thread); - assert(!pthread_create(&(netns_arg->thread_handle), NULL, pthread_fun, netns_arg)); -} - -void netns_destroy_topology(netns_state_t *test_state) { - namespace_t *namespace_handle; - interface_t *interface_handle; - int if_no, j, i; - pid_t pid, pid_ret; - - for(if_no = 0; if_no < test_state->num_namespaces; if_no++) { - namespace_handle = get_namespace_handle_by_index(test_state, if_no); - assert(namespace_handle->interfaces); - - for(i = 0; i < namespace_handle->pid_nos; i++) { - pid = (namespace_handle->pids)[i]; - kill(pid, SIGINT); - pid_ret = waitpid(pid, NULL, WNOHANG); - assert(pid_ret != -1); - - if(pid_ret == 0) { - fprintf(stderr, "pid: %d, is still running\n", pid); - } - } - - // Free interface name, interface address, interface default address etc., - // which are dynamically allocated and set the values to NULL - - for(j = 0; j < namespace_handle->interfaces_no; j++) { - interface_handle = get_interface_handle_by_index(namespace_handle, j); - assert(interface_handle); - - free(interface_handle->if_name); - interface_handle->if_name = NULL; - free(interface_handle->if_addr); - interface_handle->if_addr = NULL; - free(interface_handle->if_default_route_ip); - interface_handle->if_default_route_ip = NULL; - } - - // Delete namespace - assert(netns_delete_namespace(namespace_handle) == 0); - } - - free(test_state->public_net_addr); - test_state->public_net_addr = NULL; -} - -bool netns_create_topology(netns_state_t *test_state) { - - // (Re)create name-spaces and bridges - netns_create_all_namespaces(test_state); - - // Connect namespaces and bridges(if any) with their interfaces - netns_connect_all_namespaces(test_state); - - // Assign IP addresses for the interfaces in namespaces - netns_assign_ip_addresses(test_state); - - // Configure assigned IP addresses with the interfaces in netns - netns_configure_ip_address(test_state); - - // Enable all NATs - netns_enable_all_nats(test_state); - - netns_namespace_init_pids(test_state); - - return true; -} diff --git a/test/blackbox/common/network_namespace_framework.h b/test/blackbox/common/network_namespace_framework.h deleted file mode 100644 index 9e6005e..0000000 --- a/test/blackbox/common/network_namespace_framework.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - network_namespace_framework.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PUB_IF 0 -#define PRIV_IF 1 - -typedef enum { - HOST, - FULL_CONE, - PORT_REST, - ADDR_REST, - SYMMERTRIC, - BRIDGE, -} namespace_type_t; - -typedef void *pthread_fun_ptr_t(void *arg); - -typedef struct { - char *if_name; - int if_type; - char *if_peer; - char *if_addr; - char *if_route; - char *addr_host; - char *fetch_ip_netns_name; - char *if_default_route_ip; - void *priv; -} interface_t; - -typedef struct { - char *snat_to_source; - char *dnat_to_destination; -} netns_fullcone_handle_t; - -typedef struct { - char *name; - namespace_type_t type; - void *nat_arg; - char static_config_net_addr[INET6_ADDRSTRLEN]; // Buffer should be of length INET_ADDRSTRLEN or INET6_ADDRSTRLEN - interface_t *interfaces; - int interfaces_no; - pid_t *pids; - int pid_nos; - void *priv; -} namespace_t; - -typedef struct { - char *test_case_name; - namespace_t *namespaces; - int num_namespaces; - char *public_net_addr; - pthread_t **threads; - bool test_result; -} netns_state_t; - -typedef struct { - char *namespace_name; - pthread_fun_ptr_t *netns_thread; - pthread_t thread_handle; - void *arg; -} netns_thread_t; - -typedef struct { - char *node_name; - char *confbase; - char *app_name; - int dev_class; - char *join_invitation; -} mesh_arg_t; - -typedef struct { - mesh_arg_t *mesh_arg; - char *invitee_name; - char *invite_str; -} mesh_invite_arg_t; - -extern bool netns_create_topology(netns_state_t *state); -extern void netns_destroy_topology(netns_state_t *test_state); -extern void run_node_in_namespace_thread(netns_thread_t *netns_arg); -extern pid_t run_cmd_in_netns(netns_state_t *test_state, char *namespace_name, char *cmd_str); diff --git a/test/blackbox/common/tcpdump.c b/test/blackbox/common/tcpdump.c deleted file mode 100644 index 1d9b23f..0000000 --- a/test/blackbox/common/tcpdump.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - tcpdump.c -- Implementation of Black Box Test Execution for meshlink - - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include "common_handlers.h" -#include "tcpdump.h" - -pid_t tcpdump_start(char *interface) { - char *argv[] = { "tcpdump", "-i", interface, NULL }; - // child process have a pipe to the parent process when parent process terminates SIGPIPE kills the tcpdump - int pipes[2]; - assert(pipe(pipes) != -1); - PRINT_TEST_CASE_MSG("\x1b[32mLaunching TCP Dump ..\x1b[0m\n"); - - pid_t tcpdump_pid = fork(); - - if(tcpdump_pid == 0) { - prctl(PR_SET_PDEATHSIG, SIGHUP); - close(pipes[1]); - // Open log file for TCP Dump - int fd = open(TCPDUMP_LOG_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); - assert(fd != -1); - close(STDOUT_FILENO); - assert(dup2(fd, STDOUT_FILENO) != -1); - - // Launch TCPDump with port numbers of sleepy, gateway & relay - execvp("/usr/sbin/tcpdump", argv); - perror("execvp "); - exit(1); - } else { - close(pipes[0]); - } - - return tcpdump_pid; -} - -void tcpdump_stop(pid_t tcpdump_pid) { - PRINT_TEST_CASE_MSG("\n\x1b[32mStopping TCP Dump.\x1b[0m\n"); - assert(!kill(tcpdump_pid, SIGTERM)); -} diff --git a/test/blackbox/common/tcpdump.h b/test/blackbox/common/tcpdump.h deleted file mode 100644 index 37e92b8..0000000 --- a/test/blackbox/common/tcpdump.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - tcpdump.h -- Declarations of common callback handlers and signal handlers for - black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef TCPDUMP_H -#define TCPDUMP_H - -#define TCPDUMP_LOG_FILE "tcpdump.log" - -extern pid_t tcpdump_start(char *); -extern void tcpdump_stop(pid_t tcpdump_pid); - -#endif // TCPDUMP_H diff --git a/test/blackbox/common/test_step.c b/test/blackbox/common/test_step.c deleted file mode 100644 index 29cc5a6..0000000 --- a/test/blackbox/common/test_step.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - test_step.c -- Handlers for executing test steps during node simulation - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. -ŝ - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include "../../../src/meshlink-tiny.h" -#include "test_step.h" -#include "common_handlers.h" - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -meshlink_handle_t *mesh_handle = NULL; -bool mesh_started = false; -char *eth_if_name = NULL; - -meshlink_handle_t *execute_open(char *node_name, char *dev_class) { - /* Set up logging for Meshlink */ - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - mesh_handle = meshlink_open("testconf", node_name, "node_sim", atoi(dev_class)); - fprintf(stderr, "meshlink_open status: %s\n", meshlink_strerror(meshlink_errno)); - meshlink_enable_discovery(mesh_handle, false); - PRINT_TEST_CASE_MSG("meshlink_open status: %s\n", meshlink_strerror(meshlink_errno)); - assert(mesh_handle); - - /* Set up logging for Meshlink with the newly acquired Mesh Handle */ - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - /* Set up callback for node status (reachable / unreachable) */ - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - - return mesh_handle; -} - -char *execute_invite(char *invitee, meshlink_submesh_t *submesh) { - char *invite_url = meshlink_invite_ex(mesh_handle, submesh, invitee, MESHLINK_INVITE_LOCAL | MESHLINK_INVITE_NUMERIC); - - PRINT_TEST_CASE_MSG("meshlink_invite status: %s\n", meshlink_strerror(meshlink_errno)); - assert(invite_url); - - return invite_url; -} - -void execute_join(char *invite_url) { - bool join_status; - - join_status = meshlink_join(mesh_handle, invite_url); - assert(join_status); -} - -void execute_start(void) { - bool start_init_status = meshlink_start(mesh_handle); - - PRINT_TEST_CASE_MSG("meshlink_start status: %s\n", meshlink_strerror(meshlink_errno)); - assert(start_init_status); - mesh_started = true; -} - -void execute_stop(void) { - assert(mesh_handle); - meshlink_stop(mesh_handle); - mesh_started = false; -} - -void execute_close(void) { - assert(mesh_handle); - meshlink_close(mesh_handle); -} - -void execute_change_ip(void) { - char *eth_if_ip; - int last_byte; - char new_ip[20] = "", gateway_ip[20] = ""; - char *last_dot_in_ip; - char *eth_if_netmask; - - /* Get existing IP Address of Ethernet Bridge Interface */ - assert((eth_if_ip = get_ip(eth_if_name))); - - /* Set new IP Address by replacing the last byte with last byte + 1 */ - strncpy(new_ip, eth_if_ip, sizeof(new_ip) - 1); - assert((last_dot_in_ip = strrchr(new_ip, '.'))); - last_byte = atoi(last_dot_in_ip + 1); - assert(snprintf(last_dot_in_ip + 1, 4, "%d", (last_byte > 253) ? 2 : (last_byte + 1)) >= 0); - - /* TO DO: Check for IP conflicts with other interfaces and existing Containers */ - /* Bring the network interface down before making changes */ - stop_nw_intf(eth_if_name); - /* Save the netmask first, then restore it after setting the new IP Address */ - assert((eth_if_netmask = get_netmask(eth_if_name))); - set_ip(eth_if_name, new_ip); - set_netmask(eth_if_name, eth_if_netmask); - /* Bring the network interface back up again to apply changes */ - start_nw_intf(eth_if_name); - - /* Get Gateway's IP Address, by replacing the last byte with 1 in the current IP Address */ - /* TO DO: Obtain the actual Gateway IP Address */ - strncpy(gateway_ip, eth_if_ip, sizeof(gateway_ip) - 1); - assert((last_dot_in_ip = strrchr(gateway_ip, '.'))); - assert(snprintf(last_dot_in_ip + 1, 4, "%d", 1) >= 0); - - /* Add the default route back again, which would have been deleted when the - network interface was brought down */ - /* TO DO: Perform this action using ioctl with SIOCADDRT */ - /*assert(snprintf(route_chg_command, sizeof(route_chg_command), "route add default gw %s", - gateway_ip) >= 0); - route_chg_status = system(route_chg_command); - PRINT_TEST_CASE_MSG("Default Route Add status = %d\n", route_chg_status); - assert(route_chg_status == 0); */ - // Not necessary for ubuntu versions of 16.04 and 18.04 - - PRINT_TEST_CASE_MSG("Node '%s' IP Address changed to %s\n", NUT_NODE_NAME, new_ip); - - free(eth_if_ip); - free(eth_if_netmask); -} - diff --git a/test/blackbox/common/test_step.h b/test/blackbox/common/test_step.h deleted file mode 100644 index 8ef6d76..0000000 --- a/test/blackbox/common/test_step.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - test_step.h -- Handlers for executing test steps during node simulation - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef TEST_STEP_H -#define TEST_STEP_H - -#include "../../../src/meshlink-tiny.h" - -meshlink_handle_t *execute_open(char *node_name, char *dev_class); -char *execute_invite(char *invitee, meshlink_submesh_t *submesh); -void execute_join(char *invite_url); -void execute_start(void); -void execute_stop(void); -void execute_close(void); -void execute_change_ip(void); - -#endif // TEST_STEP_H diff --git a/test/blackbox/run_blackbox_tests/.gitignore b/test/blackbox/run_blackbox_tests/.gitignore deleted file mode 100644 index 076f4db..0000000 --- a/test/blackbox/run_blackbox_tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/run_blackbox_tests diff --git a/test/blackbox/run_blackbox_tests/Makefile.am b/test/blackbox/run_blackbox_tests/Makefile.am deleted file mode 100644 index e4251a6..0000000 --- a/test/blackbox/run_blackbox_tests/Makefile.am +++ /dev/null @@ -1,73 +0,0 @@ -check_PROGRAMS = run_blackbox_tests - -run_blackbox_tests_SOURCES = \ - run_blackbox_tests.c \ - test_cases.c execute_tests.c \ - ../common/mesh_event_handler.c \ - ../common/containers.c \ - ../common/tcpdump.c \ - ../common/common_handlers.c \ - ../common/test_step.c \ - ../common/network_namespace_framework.c \ - ../../utils.c \ - test_cases_destroy.c \ - test_cases_export.c \ - test_cases_get_all_nodes.c \ - test_cases_get_fingerprint.c \ - test_cases_invite.c \ - test_cases_rec_cb.c \ - test_cases_set_port.c \ - test_cases_sign.c \ - test_cases_verify.c \ - test_cases_channel_ex.c \ - test_cases_channel_get_flags.c \ - test_cases_status_cb.c \ - test_cases_set_log_cb.c \ - test_cases_join.c \ - test_cases_import.c \ - test_cases_channel_set_accept_cb.c \ - test_cases_channel_set_poll_cb.c \ - test_cases_hint_address.c \ - test_cases_channel_set_receive_cb.c \ - test_cases_open.c \ - test_cases_start.c \ - test_cases_stop_close.c \ - test_cases_pmtu.c \ - test_cases_get_self.c \ - test_cases_send.c \ - test_cases_get_node.c \ - test_cases_add_addr.c \ - test_cases_get_ex_addr.c \ - test_cases_add_ex_addr.c \ - test_cases_get_port.c \ - test_cases_blacklist.c \ - test_cases_whitelist.c \ - test_cases_default_blacklist.c \ - test_cases_channel_open.c \ - test_cases_channel_close.c \ - test_cases_channel_send.c \ - test_cases_channel_shutdown.c \ - test_cases_channel_conn.c \ - test_cases_get_all_nodes_by_dev_class.c \ - ../test_case_optimal_pmtu_01/node_sim_nut.c \ - ../test_case_optimal_pmtu_01/node_sim_relay.c \ - ../test_case_optimal_pmtu_01/node_sim_peer.c \ - test_optimal_pmtu.c \ - ../test_case_channel_blacklist_01/node_sim_nut_01.c \ - ../test_case_channel_blacklist_01/node_sim_peer_01.c \ - ../test_case_channel_blacklist_01/node_sim_relay_01.c \ - test_cases_channel_blacklist.c \ - test_cases_submesh01.c \ - test_cases_submesh02.c \ - test_cases_submesh03.c \ - test_cases_submesh04.c \ - test_cases_autoconnect.c \ - test_cases_set_connection_try_cb.c \ - test_cases_random_port_bindings01.c \ - test_cases_random_port_bindings02.c \ - test_cases_key_rotation.c \ - test_cases_get_node_reachability.c - -run_blackbox_tests_LDADD = ../../../src/libmeshlink.la $(LXC_LIBS) $(CMOCKA_LIBS) -run_blackbox_tests_CFLAGS = -D_GNU_SOURCE $(LXC_CFLAGS) $(CMOCKA_CFLAGS) - diff --git a/test/blackbox/run_blackbox_tests/execute_tests.c b/test/blackbox/run_blackbox_tests/execute_tests.c deleted file mode 100644 index 6b534ee..0000000 --- a/test/blackbox/run_blackbox_tests/execute_tests.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - execute_tests.c -- Utility functions for black box test execution - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "../common/common_handlers.h" -#include "../common/containers.h" -#include "../common/test_step.h" - -int setup_test(void **state) { - int i; - - fprintf(stderr, "Setting up Containers\n"); - state_ptr = (black_box_state_t *)(*state); - - for(i = 0; i < state_ptr->num_nodes; i++) { - meta_conn_status[i] = false; - } - - setup_containers(state); - - return EXIT_SUCCESS; -} - -void execute_test(test_step_func_t step_func, void **state) { - black_box_state_t *test_state = (black_box_state_t *)(*state); - - fprintf(stderr, "\n\x1b[32mRunning Test\x1b[0m : \x1b[34m%s\x1b[0m\n", test_state->test_case_name); - test_state->test_result = step_func(); - - if(!test_state->test_result) { - fail(); - } -} - -int teardown_test(void **state) { - black_box_state_t *test_state = (black_box_state_t *)(*state); - char container_old_name[100], container_new_name[100]; - int i; - - if(test_state->test_result) { - PRINT_TEST_CASE_MSG("Test successful! Shutting down nodes.\n"); - - for(i = 0; i < test_state->num_nodes; i++) { - /* Shut down node */ - node_step_in_container(test_state->node_names[i], "SIGTERM"); - /* Rename Container to run_ - this allows it to be re-used for the - next test, otherwise it will be ignored assuming that it has been saved - for debugging */ - assert(snprintf(container_old_name, sizeof(container_old_name), "%s_%s", - test_state->test_case_name, test_state->node_names[i]) >= 0); - assert(snprintf(container_new_name, sizeof(container_new_name), "run_%s", - test_state->node_names[i]) >= 0); - rename_container(container_old_name, container_new_name); - } - } - - state_ptr = NULL; - - return EXIT_SUCCESS; -} - -bool change_state(node_status_t *status, mesh_event_t currentEv) { - - if(status->current_index == status->max_events) { - return false; - } - - if(currentEv == status->expected_events[status->current_index]) { - status->current_index = status->current_index + 1; - - return true; - } else { - return false; - } -} - -void signal_node_start(node_status_t *node_status, int start, int end, char *node_ids[]) { - int i, index; - - for(i = start; i <= end; i++) { - index = node_status[i].current_index; - - if(index < 1 || NODE_JOINED != node_status[i].expected_events[index - 1]) { - return; - } - } - - - for(i = start; i <= end; i++) { - fprintf(stderr, "\tSending signals to '%s'\n", node_ids[i]); - node_step_in_container(node_ids[i], "SIGIO"); - } - - return; -} - -bool check_nodes_finished(node_status_t *node_status, int length) { - for(int i = 0; i < length; i++) { - if(node_status[i].current_index != node_status[i].max_events) { - return false; - } - } - - return true; -} diff --git a/test/blackbox/run_blackbox_tests/execute_tests.h b/test/blackbox/run_blackbox_tests/execute_tests.h deleted file mode 100644 index cafc83f..0000000 --- a/test/blackbox/run_blackbox_tests/execute_tests.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef EXECUTE_TESTS_H -#define EXECUTE_TESTS_H - -/* - execute_tests.h -- header file for execute_tests.c - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include -#include "../common/mesh_event_handler.h" - -typedef struct { - const mesh_event_t *expected_events; - int current_index; - int max_events; -} node_status_t; - -typedef bool (*test_step_func_t)(void); - -int setup_test(void **state); -void execute_test(test_step_func_t step_func, void **state); -int teardown_test(void **state); - -/// Changes the state of the node state machine. -/** This function changes the current state of the node - * - * @param status Pointer to status handle of that node. - * @param currentEv Current event triggered by the node. - * - * @return This function returns true if state change is successful else returns false - */ -extern bool change_state(node_status_t *status, mesh_event_t currentEv); - -/// Sends SIGIO signal to all the nodes in the container. -/** This function Triggers SIGIO signal to all the target applications running inside the container - * - * @param status Pointer to array of status handles of target nodes. - * @param start Starting index from which to start in the array. - * @param end Ending index of the array - * @param node_ids Pointer to array of node id strings - * - * @return Void - */ -extern void signal_node_start(node_status_t *node_status, int start, int end, char *node_ids[]); - -/// Checks for the completion of nodes state machines. -/** This function checks whether the nodes state machines have reached their maximum state indexes - * - * @param status Pointer to array of status handles of target nodes. - * @param length Number of nodes to check. - * - * @return This function returns true if all the nodes reached their max states - */ -extern bool check_nodes_finished(node_status_t *node_status, int length); - -#endif // TEST_STEP_H diff --git a/test/blackbox/run_blackbox_tests/run_blackbox_tests.c b/test/blackbox/run_blackbox_tests/run_blackbox_tests.c deleted file mode 100644 index fe6f9a9..0000000 --- a/test/blackbox/run_blackbox_tests/run_blackbox_tests.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - run_blackbox_tests.c -- Implementation of Black Box Test Execution for meshlink - - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases.h" -#include "test_cases_open.h" -#include "test_cases_start.h" -#include "test_cases_stop_close.h" -#include "test_cases_send.h" -#include "test_cases_pmtu.h" -#include "test_cases_get_self.h" -#include "test_cases_get_node.h" -#include "test_cases_add_addr.h" -#include "test_cases_get_ex_addr.h" -#include "test_cases_add_ex_addr.h" -#include "test_cases_get_port.h" -#include "test_cases_blacklist.h" -#include "test_cases_default_blacklist.h" -#include "test_cases_whitelist.h" -#include "test_cases_channel_open.h" -#include "test_cases_channel_close.h" -#include "test_cases_channel_send.h" -#include "test_cases_channel_shutdown.h" - -#include "test_cases_destroy.h" -#include "test_cases_get_all_nodes.h" -#include "test_cases_get_fingerprint.h" -#include "test_cases_rec_cb.h" -#include "test_cases_sign.h" -#include "test_cases_set_port.h" -#include "test_cases_verify.h" -#include "test_cases_invite.h" -#include "test_cases_export.h" -#include "test_cases_channel_ex.h" -#include "test_cases_channel_get_flags.h" -#include "test_cases_status_cb.h" -#include "test_cases_set_log_cb.h" -#include "test_cases_join.h" -#include "test_cases_import.h" -#include "test_cases_channel_set_accept_cb.h" -#include "test_cases_channel_set_poll_cb.h" -#include "test_cases_channel_set_receive_cb.h" -#include "test_cases_hint_address.h" -#include "test_optimal_pmtu.h" -#include "test_cases_key_rotation.h" - -#include "test_cases_channel_conn.h" -#include "test_cases_get_all_nodes_by_dev_class.h" -#include "test_cases_submesh01.h" -#include "test_cases_submesh02.h" -#include "test_cases_submesh03.h" -#include "test_cases_submesh04.h" -#include "test_cases_autoconnect.h" -#include "test_cases_set_connection_try_cb.h" - -#include "test_cases_random_port_bindings01.h" -#include "test_cases_random_port_bindings02.h" - -#include "test_cases_get_node_reachability.h" - -#include "../common/containers.h" -#include "../common/common_handlers.h" - -char *meshlink_root_path = NULL; -char *choose_arch = NULL; -int total_tests; - -int main(int argc, char *argv[]) { - /* Set configuration */ - assert(argc > 5); - meshlink_root_path = argv[1]; - lxc_path = argv[2]; - lxc_bridge = argv[3]; - eth_if_name = argv[4]; - choose_arch = argv[5]; - - int failed_tests = 0; - - failed_tests += test_meta_conn(); - failed_tests += test_meshlink_set_status_cb(); - failed_tests += test_meshlink_join(); - failed_tests += test_meshlink_set_channel_poll_cb(); - failed_tests += test_meshlink_channel_open_ex(); - failed_tests += test_meshlink_channel_get_flags(); - failed_tests += test_meshlink_set_channel_accept_cb(); - failed_tests += test_meshlink_destroy(); - failed_tests += test_meshlink_export(); - failed_tests += test_meshlink_get_fingerprint(); - failed_tests += test_meshlink_get_all_nodes(); - failed_tests += test_meshlink_get_all_node_by_device_class(); - failed_tests += test_meshlink_set_port(); - failed_tests += test_meshlink_sign(); - failed_tests += test_meshlink_verify(); - failed_tests += test_meshlink_import(); - failed_tests += test_meshlink_invite(); - failed_tests += test_meshlink_set_receive_cb(); - failed_tests += test_meshlink_set_log_cb(); - failed_tests += test_meshlink_set_channel_receive_cb(); - failed_tests += test_meshlink_hint_address(); - - failed_tests += test_meshlink_open(); - failed_tests += test_meshlink_start(); - failed_tests += test_meshlink_stop_close(); - failed_tests += test_meshlink_send(); - failed_tests += test_meshlink_channel_send(); - failed_tests += test_meshlink_channel_shutdown(); - failed_tests += test_meshlink_pmtu(); - failed_tests += test_meshlink_get_self(); - failed_tests += test_meshlink_get_node(); - failed_tests += test_meshlink_add_address(); - failed_tests += test_meshlink_get_external_address(); - failed_tests += test_meshlink_add_external_address(); - failed_tests += test_meshlink_get_port(); - failed_tests += test_meshlink_blacklist(); - failed_tests += test_meshlink_whitelist(); - failed_tests += test_meshlink_default_blacklist(); - failed_tests += test_meshlink_channel_open(); - failed_tests += test_meshlink_channel_close(); - - failed_tests += test_meshlink_channel_conn(); - failed_tests += test_optimal_pmtu(); - - failed_tests += test_cases_submesh01(); - failed_tests += test_cases_submesh02(); - failed_tests += test_cases_submesh03(); - failed_tests += test_cases_submesh04(); - - failed_tests += test_meshlink_autoconnect(); - failed_tests += test_cases_connection_try(); - - failed_tests += test_optimal_pmtu(); - failed_tests += test_meshlink_encrypted_key_rotation(); - - failed_tests += test_meshlink_random_port_bindings01(); - failed_tests += test_meshlink_random_port_bindings02(); - - failed_tests += test_get_node_reachability(); - - printf("[ PASSED ] %d test(s).\n", total_tests - failed_tests); - printf("[ FAILED ] %d test(s).\n", failed_tests); - - return failed_tests; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases.c b/test/blackbox/run_blackbox_tests/test_cases.c deleted file mode 100644 index c07edec..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - test_cases.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases.h" -#include "pthread.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/mesh_event_handler.h" - -#define RELAY_ID "0" -#define PEER_ID "1" -#define NUT_ID "2" - -static void test_case_meta_conn_01(void **state); -static bool test_steps_meta_conn_01(void); -static void test_case_meta_conn_02(void **state); -static bool test_steps_meta_conn_02(void); -static void test_case_meta_conn_03(void **state); -static bool test_steps_meta_conn_03(void); -static void test_case_meta_conn_04(void **state); -static bool test_steps_meta_conn_04(void); -static void test_case_meta_conn_05(void **state); -static bool test_steps_meta_conn_05(void); - -/* State structure for Meta-connections Test Case #1 */ -static char *test_meta_conn_1_nodes[] = { "relay", "peer", "nut" }; -static black_box_state_t test_meta_conn_1_state = { - .test_case_name = "test_case_meta_conn_01", - .node_names = test_meta_conn_1_nodes, - .num_nodes = 3, -}; - -/* State structure for Meta-connections Test Case #2 */ -static char *test_meta_conn_2_nodes[] = { "relay", "peer", "nut" }; -static black_box_state_t test_meta_conn_2_state = { - .test_case_name = "test_case_meta_conn_02", - .node_names = test_meta_conn_2_nodes, - .num_nodes = 3, -}; - -/* State structure for Meta-connections Test Case #3 */ -static char *test_meta_conn_3_nodes[] = { "relay", "peer", "nut" }; -static black_box_state_t test_meta_conn_3_state = { - .test_case_name = "test_case_meta_conn_03", - .node_names = test_meta_conn_3_nodes, - .num_nodes = 3, -}; - -/* State structure for Meta-connections Test Case #4 */ -static char *test_meta_conn_4_nodes[] = { "peer", "nut" }; -static black_box_state_t test_meta_conn_4_state = { - .test_case_name = "test_case_meta_conn_04", - .node_names = test_meta_conn_4_nodes, - .num_nodes = 2, -}; - -/* State structure for Meta-connections Test Case #5 */ -static char *test_meta_conn_5_nodes[] = { "peer", "nut" }; -static black_box_state_t test_meta_conn_5_state = { - .test_case_name = "test_case_meta_conn_05", - .node_names = test_meta_conn_5_nodes, - .num_nodes = 2, -}; - -int black_box_group0_setup(void **state) { - (void)state; - - const char *nodes[] = { "peer", "relay", "nut"}; - int num_nodes = sizeof(nodes) / sizeof(nodes[0]); - - PRINT_TEST_CASE_MSG("Creating Containers\n"); - destroy_containers(); - create_containers(nodes, num_nodes); - - return 0; -} - -int black_box_group0_teardown(void **state) { - (void)state; - - PRINT_TEST_CASE_MSG("Destroying Containers\n"); - destroy_containers(); - - return 0; -} - -int black_box_all_nodes_setup(void **state) { - (void)state; - - const char *nodes[] = { "peer" }; - int num_nodes = sizeof(nodes) / sizeof(nodes[0]); - - PRINT_TEST_CASE_MSG("Creating Containers\n"); - destroy_containers(); - create_containers(nodes, num_nodes); - PRINT_TEST_CASE_MSG("Created Containers\n"); - return 0; -} - -static bool meta_conn01_conn; -static bool meta_conn01_closed; -static bool meta_conn01_reconn; - -static bool meta_conn01_cb(mesh_event_payload_t payload) { - char event_node_name[][10] = {"RELAY", "PEER", "NUT"}; - fprintf(stderr, "%s : ", event_node_name[payload.client_id]); - - switch(payload.mesh_event) { - case META_CONN_SUCCESSFUL : - meta_conn01_conn = true; - break; - - case NODE_STARTED : - fprintf(stderr, "Node started\n"); - break; - - case META_CONN_CLOSED : - meta_conn01_closed = true; - break; - - case META_RECONN_SUCCESSFUL : - meta_conn01_reconn = true; - break; - - default: - break; - } - - return true; -} - -/* Execute Meta-connections Test Case # 1 - re-connection to peer after disconnection when - connected via a third node */ -static void test_case_meta_conn_01(void **state) { - execute_test(test_steps_meta_conn_01, state); -} - -/* Test Steps for Meta-connections Test Case # 1 - re-connection to peer after disconnection when - connected via a third (relay) node - - Test Steps: - 1. Run NUT, relay and peer nodes with relay inviting the other two nodes - 2. After connection to peer, terminate the peer node's running instance - 3. After peer becomes unreachable, wait 60 seconds then re-start the peer node's instance - - Expected Result: - NUT is re-connected to peer -*/ -static bool test_steps_meta_conn_01(void) { - char *invite_peer, *invite_nut; - char *import; - - import = mesh_event_sock_create(eth_if_name); - invite_peer = invite_in_container("relay", "peer"); - invite_nut = invite_in_container("relay", NUT_NODE_NAME); - node_sim_in_container_event("relay", "1", NULL, RELAY_ID, import); - wait_for_event(meta_conn01_cb, 5); - node_sim_in_container_event("peer", "1", invite_peer, PEER_ID, import); - wait_for_event(meta_conn01_cb, 5); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - wait_for_event(meta_conn01_cb, 5); - - PRINT_TEST_CASE_MSG("Waiting for peer to be connected with NUT\n"); - assert(wait_for_event(meta_conn01_cb, 60)); - assert(meta_conn01_conn); - - PRINT_TEST_CASE_MSG("Sending SIGTERM to peer\n"); - node_step_in_container("peer", "SIGTERM"); - PRINT_TEST_CASE_MSG("Waiting for peer to become unreachable\n"); - assert(wait_for_event(meta_conn01_cb, 60)); - assert(meta_conn01_closed); - - node_sim_in_container_event("peer", "1", NULL, PEER_ID, import); - wait_for_event(meta_conn01_cb, 5); - PRINT_TEST_CASE_MSG("Waiting for peer to be re-connected\n"); - wait_for_event(meta_conn01_cb, 60); - - mesh_event_destroy(); - free(invite_peer); - free(invite_nut); - - assert_int_equal(meta_conn01_reconn, true); - - return true; -} - - -static bool meta_conn02_conn; - -static bool meta_conn02_cb(mesh_event_payload_t payload) { - char event_node_name[][10] = {"RELAY", "PEER", "NUT"}; - fprintf(stderr, "%s : ", event_node_name[payload.client_id]); - - switch(payload.mesh_event) { - case META_CONN_SUCCESSFUL : - fprintf(stderr, "Meta Connection Successful\n"); - meta_conn02_conn = true; - break; - - case NODE_STARTED : - fprintf(stderr, "Node started\n"); - break; - - default: - break; - } - - return true; -} -/* Execute Meta-connections Test Case # 2 - re-connection to peer via third node - after changing IP of NUT and peer */ -static void test_case_meta_conn_02(void **state) { - execute_test(test_steps_meta_conn_02, state); -} -/* Test Steps for Meta-connections Test Case # 2 - re-connection to peer via third node - after changing IP of NUT and peer - - Test Steps: - 1. Run NUT, relay and peer nodes with relay inviting the other two nodes - 2. After connection to peer, change the NUT's IP Address and the peer node's IP Address - - Expected Result: - NUT is first disconnected from peer then automatically re-connected to peer -*/ -static bool test_steps_meta_conn_02(void) { - char *invite_peer, *invite_nut; - char *import; - - import = mesh_event_sock_create(eth_if_name); - invite_peer = invite_in_container("relay", "peer"); - invite_nut = invite_in_container("relay", NUT_NODE_NAME); - node_sim_in_container_event("relay", "1", NULL, RELAY_ID, import); - wait_for_event(meta_conn02_cb, 5); - node_sim_in_container_event("peer", "1", invite_peer, PEER_ID, import); - wait_for_event(meta_conn02_cb, 5); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - wait_for_event(meta_conn02_cb, 5); - - PRINT_TEST_CASE_MSG("Waiting for peer to be connected with NUT\n"); - assert(wait_for_event(meta_conn02_cb, 60)); - assert(meta_conn02_conn); - - meta_conn02_conn = false; - node_sim_in_container_event("peer", "1", NULL, PEER_ID, import); - wait_for_event(meta_conn02_cb, 5); - node_sim_in_container_event("nut", "1", NULL, NUT_ID, import); - wait_for_event(meta_conn02_cb, 5); - - PRINT_TEST_CASE_MSG("Waiting for peer to be connected with NUT\n"); - wait_for_event(meta_conn02_cb, 60); - - mesh_event_destroy(); - free(invite_peer); - free(invite_nut); - - assert_int_equal(meta_conn02_conn, true); - - return true; -} - -static bool meta_conn03_result; -static bool meta_conn03_conn; - -static bool meta_conn03_cb(mesh_event_payload_t payload) { - char event_node_name[][10] = {"RELAY", "PEER", "NUT"}; - fprintf(stderr, "%s : ", event_node_name[payload.client_id]); - - switch(payload.mesh_event) { - case META_CONN_SUCCESSFUL : - fprintf(stderr, "Meta Connection Successful\n"); - meta_conn03_conn = true; - break; - - case NODE_STARTED : - fprintf(stderr, "Node started\n"); - break; - - case META_RECONN_FAILURE : - fprintf(stderr, "Failed to reconnect with"); - meta_conn03_result = false; - break; - - case META_RECONN_SUCCESSFUL : - fprintf(stderr, "Reconnected\n"); - meta_conn03_result = true; - break; - - default: - break; - } - - return true; -} -/* Execute Meta-connections Test Case # 3 - re-connection to peer via third node - after changing IP of peer */ -static void test_case_meta_conn_03(void **state) { - execute_test(test_steps_meta_conn_03, state); -} -/* Test Steps for Meta-connections Test Case # 3 - re-connection to peer via third node - after changing IP of peer - - Test Steps: - 1. Run NUT, relay and peer nodes with relay inviting the other two nodes - 2. After connection to peer, change the peer node's IP Address - - Expected Result: - NUT is first disconnected from peer then automatically re-connected to peer -*/ -static bool test_steps_meta_conn_03(void) { - char *invite_peer, *invite_nut; - char *import; - - import = mesh_event_sock_create(eth_if_name); - invite_peer = invite_in_container("relay", "peer"); - invite_nut = invite_in_container("relay", NUT_NODE_NAME); - node_sim_in_container_event("relay", "1", NULL, RELAY_ID, import); - wait_for_event(meta_conn03_cb, 5); - node_sim_in_container_event("peer", "1", invite_peer, PEER_ID, import); - wait_for_event(meta_conn03_cb, 5); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - wait_for_event(meta_conn03_cb, 5); - - PRINT_TEST_CASE_MSG("Waiting for peer to be connected with NUT\n"); - assert(wait_for_event(meta_conn03_cb, 60)); - assert(meta_conn03_conn); - - PRINT_TEST_CASE_MSG("Changing IP address of PEER container\n"); - change_ip(1); - sleep(3); - node_sim_in_container_event("peer", "1", NULL, PEER_ID, import); - wait_for_event(meta_conn03_cb, 5); - PRINT_TEST_CASE_MSG("Waiting for peer to be re-connected\n"); - wait_for_event(meta_conn03_cb, 5); - - mesh_event_destroy(); - free(invite_peer); - free(invite_nut); - - assert_int_equal(meta_conn03_result, true); - - return true; -} - -static char *invite_peer = NULL; -static bool meta_conn04 = false; - -static bool meta_conn04_cb(mesh_event_payload_t payload) { - char event_node_name[][10] = {"PEER", "NUT"}; - fprintf(stderr, "%s : ", event_node_name[payload.client_id]); - - switch(payload.mesh_event) { - case META_CONN_SUCCESSFUL : - fprintf(stderr, "Meta Connection Successful\n"); - meta_conn04 = true; - break; - - case NODE_INVITATION : - fprintf(stderr, "Invitation generated\n"); - invite_peer = malloc(payload.payload_length); - strcpy(invite_peer, (char *)payload.payload); - break; - - case NODE_STARTED : - fprintf(stderr, "Node started\n"); - break; - - default : - fprintf(stderr, "Undefined mesh event\n"); - break; - } - - return true; -} - -/* Execute Meta-connections Test Case # 4 - re-connection to peer after changing IP of - NUT and peer */ -static void test_case_meta_conn_04(void **state) { - execute_test(test_steps_meta_conn_04, state); -} - -/* Execute Meta-connections Test Case # 4 - re-connection to peer after changing IP of - NUT and peer - - Test Steps: - 1. Run NUT and peer nodes with NUT inviting the peer node - 2. After connection to peer, change the NUT's IP Address and the peer node's IP Address - - Expected Result: - NUT is first disconnected from peer then automatically re-connected to peer -*/ -static bool test_steps_meta_conn_04(void) { - char *import; - - import = mesh_event_sock_create(eth_if_name); - node_sim_in_container_event("nut", "1", NULL, "1", import); - wait_for_event(meta_conn04_cb, 5); - - PRINT_TEST_CASE_MSG("Waiting for NUT to generate invitation to PEER\n"); - wait_for_event(meta_conn04_cb, 5); - - assert(invite_peer); - - PRINT_TEST_CASE_MSG("Running PEER node in the container\n"); - fprintf(stderr, "inv: %s\n", invite_peer); - node_sim_in_container_event("peer", "1", invite_peer, "0", import); - wait_for_event(meta_conn04_cb, 5); - PRINT_TEST_CASE_MSG("Waiting for peer to be connected with NUT\n"); - - assert(wait_for_event(meta_conn04_cb, 60)); - - PRINT_TEST_CASE_MSG("Changing IP address of NUT container\n"); - change_ip(1); - - node_sim_in_container_event("nut", "1", "restart", "1", import); - wait_for_event(meta_conn04_cb, 5); - PRINT_TEST_CASE_MSG("Changing IP address of PEER container\n"); - change_ip(0); - node_sim_in_container_event("peer", "1", NULL, "0", import); - wait_for_event(meta_conn04_cb, 5); - - PRINT_TEST_CASE_MSG("Waiting for peer to be re-connected\n"); - wait_for_event(meta_conn04_cb, 5); - - mesh_event_destroy(); - free(invite_peer); - free(import); - - assert_int_equal(meta_conn04, true); - - return true; -} - -static char *invitation = NULL; - -static bool meta_conn05 = false; - -static bool meta_conn05_cb(mesh_event_payload_t payload) { - char event_node_name[][10] = {"PEER", "NUT"}; - fprintf(stderr, "%s : ", event_node_name[payload.client_id]); - - switch(payload.mesh_event) { - case META_CONN_SUCCESSFUL : - meta_conn05 = true; - break; - - case NODE_INVITATION : - invitation = malloc(payload.payload_length); - strcpy(invitation, (char *)payload.payload); - break; - - case NODE_STARTED : - fprintf(stderr, "Node started\n"); - break; - - default: - break; - } - - return true; -} - -/* Execute Meta-connections Test Case # 5 - re-connection to peer after changing IP of peer */ -static void test_case_meta_conn_05(void **state) { - execute_test(test_steps_meta_conn_05, state); -} - -/* Execute Meta-connections Test Case # 5 - re-connection to peer after changing IP of peer - - Test Steps: - 1. Run NUT and peer nodes with NUT inviting the peer node - 2. After connection to peer, change the peer node's IP Address - - Expected Result: - NUT is first disconnected from peer then automatically re-connected to peer -*/ -static bool test_steps_meta_conn_05(void) { - char *import; - - import = mesh_event_sock_create(eth_if_name); - node_sim_in_container_event("nut", "1", NULL, "1", import); - wait_for_event(meta_conn05_cb, 5); - - wait_for_event(meta_conn05_cb, 5); - - assert(invitation); - - node_sim_in_container_event("peer", "1", invitation, "0", import); - wait_for_event(meta_conn05_cb, 5); - - assert(wait_for_event(meta_conn05_cb, 5)); - - change_ip(0); - meta_conn05 = false; - node_sim_in_container_event("peer", "1", NULL, "0", import); - wait_for_event(meta_conn05_cb, 5); - PRINT_TEST_CASE_MSG("Waiting for peer to be re-connected\n"); - wait_for_event(meta_conn05_cb, 5); - - mesh_event_destroy(); - free(invitation); - free(import); - - assert_int_equal(meta_conn05, true); - - return true; -} - -int test_meta_conn(void) { - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_meta_conn_01, setup_test, teardown_test, - (void *)&test_meta_conn_1_state), - cmocka_unit_test_prestate_setup_teardown(test_case_meta_conn_02, setup_test, teardown_test, - (void *)&test_meta_conn_2_state), - cmocka_unit_test_prestate_setup_teardown(test_case_meta_conn_03, setup_test, teardown_test, - (void *)&test_meta_conn_3_state), - cmocka_unit_test_prestate_setup_teardown(test_case_meta_conn_04, setup_test, teardown_test, - (void *)&test_meta_conn_4_state), - cmocka_unit_test_prestate_setup_teardown(test_case_meta_conn_05, setup_test, teardown_test, - (void *)&test_meta_conn_5_state) - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases.h b/test/blackbox/run_blackbox_tests/test_cases.h deleted file mode 100644 index 9260d01..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_H -#define TEST_CASES_H - -/* - test_cases.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include - -extern int total_tests; -extern int test_meta_conn(void); - -#endif // TEST_STEP_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_add_addr.c b/test/blackbox/run_blackbox_tests/test_cases_add_addr.c deleted file mode 100644 index 02453ef..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_add_addr.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - test_cases_add_addr.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_add_addr.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_add_address_01(void **state); -static bool test_steps_mesh_add_address_01(void); -static void test_case_mesh_add_address_02(void **state); -static bool test_steps_mesh_add_address_02(void); -static void test_case_mesh_add_address_03(void **state); -static bool test_steps_mesh_add_address_03(void); - -/* State structure for meshlink_add_address Test Case #1 */ -static black_box_state_t test_mesh_add_address_01_state = { - .test_case_name = "test_case_mesh_add_address_01", -}; - -/* State structure for meshlink_add_address Test Case #2 */ -static black_box_state_t test_mesh_add_address_02_state = { - .test_case_name = "test_case_mesh_add_address_02", -}; - -/* State structure for meshlink_add_address Test Case #3 */ -static black_box_state_t test_mesh_add_address_03_state = { - .test_case_name = "test_case_mesh_add_address_03", -}; - -/* Execute meshlink_add_address Test Case # 1 */ -static void test_case_mesh_add_address_01(void **state) { - execute_test(test_steps_mesh_add_address_01, state); -} - -/* Test Steps for meshlink_add_address Test Case # 1 - - Test Steps: - 1. Create node instance - 2. Add an address to the host node - 2. Open host file from confbase & verify address being added - - Expected Result: - meshlink_add_address API adds the new address given to it's confbase -*/ -static bool test_steps_mesh_add_address_01(void) { - char *node = "foo"; - assert(meshlink_destroy("add_conf.1")); - - // Create node instance - meshlink_handle_t *mesh = meshlink_open("add_conf.1", node, "chat", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - - char *hostname = "localhost"; - bool ret = meshlink_add_address(mesh, hostname); - assert_int_equal(ret, true); - - // Open the foo host file from confbase to verify address being added - bool found = false; - FILE *fp = fopen("./add_conf.1/hosts/foo", "r"); - assert(fp); - char line[100]; - - while(fgets(line, 100, fp) != NULL) { - if(strcasestr(line, "Address") && strcasestr(line, hostname)) { - found = true; - } - } - - assert(!fclose(fp)); - - assert_int_equal(found, true); - - // Clean up - meshlink_close(mesh); - assert(meshlink_destroy("add_conf.1")); - return true; -} - -/* Execute meshlink_add_address Test Case # 2 */ -static void test_case_mesh_add_address_02(void **state) { - execute_test(test_steps_mesh_add_address_02, state); -} - -/* Test Steps for meshlink_add_address Test Case # 2 - - Test Steps: - 1. Create node instance - 2. Call meshlink_add_address API using NULL as mesh handle argument - - Expected Result: - meshlink_add_address API returns false by reporting error successfully. -*/ -static bool test_steps_mesh_add_address_02(void) { - // Passing NULL as mesh handle argument to meshlink_add_address API - bool result = meshlink_add_address(NULL, "localhost"); - assert_int_equal(result, false); - - return true; -} - -/* Execute meshlink_add_address Test Case # 3 */ -static void test_case_mesh_add_address_03(void **state) { - execute_test(test_steps_mesh_add_address_03, state); -} - -/* Test Steps for meshlink_add_address Test Case # 3 - - Test Steps: - 1. Create node instance - 2. Call meshlink_add_address API using NULL as address argument - - Expected Result: - meshlink_add_address API returns false by reporting error successfully. -*/ -static bool test_steps_mesh_add_address_03(void) { - assert(meshlink_destroy("add_conf.3")); - - // Create node instance - meshlink_handle_t *mesh = meshlink_open("add_conf.3", "foo", "chat", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - - bool result = meshlink_add_address(mesh, NULL); - assert_int_equal(result, false); - - meshlink_close(mesh); - assert(meshlink_destroy("add_conf.3")); - return true; -} - -int test_meshlink_add_address(void) { - const struct CMUnitTest blackbox_add_addr_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_01, NULL, NULL, - (void *)&test_mesh_add_address_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_02, NULL, NULL, - (void *)&test_mesh_add_address_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_03, NULL, NULL, - (void *)&test_mesh_add_address_03_state) - }; - - total_tests += sizeof(blackbox_add_addr_tests) / sizeof(blackbox_add_addr_tests[0]); - - return cmocka_run_group_tests(blackbox_add_addr_tests, NULL, NULL); -} - diff --git a/test/blackbox/run_blackbox_tests/test_cases_add_addr.h b/test/blackbox/run_blackbox_tests/test_cases_add_addr.h deleted file mode 100644 index bfa3c05..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_add_addr.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_ADD_ADDR_H -#define TEST_CASES_ADD_ADDR_H - -/* - test_cases_add_addr.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include - -extern int test_meshlink_add_address(void); -extern int total_tests; - -#endif //TEST_CASES_ADD_ADDR_H_INCLUDED diff --git a/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c b/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c deleted file mode 100644 index 894d3d3..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - test_cases_add_ex_addr.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_add_ex_addr.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_add_ex_address_01(void **state); -static bool test_steps_mesh_add_ex_address_01(void); -static void test_case_mesh_add_ex_address_02(void **state); -static bool test_steps_mesh_add_ex_address_02(void); - -/* State structure for meshlink_add_external_address Test Case #1 */ -static black_box_state_t test_mesh_add_ex_address_01_state = { - .test_case_name = "test_case_mesh_add_ex_address_01", -}; - -/* State structure for meshlink_add_external_address Test Case #2 */ -static black_box_state_t test_mesh_add_ex_address_02_state = { - .test_case_name = "test_case_mesh_add_ex_address_01", -}; - -/* Execute meshlink_add_external_address Test Case # 1 */ -void test_case_mesh_add_ex_address_01(void **state) { - execute_test(test_steps_mesh_add_ex_address_01, state); -} - -/* Test Steps for meshlink_add_external_address Test Case # 1 - - Test Steps: - 1. Create node instance - 2. Get mesh's external address - 3. Add external address using meshlink_add_external_address API - 4. Open nodes confbase and read the external address from the list if addresses - - Expected Result: - meshlink_add_external_address API adds the new address given to it's confbase -*/ -bool test_steps_mesh_add_ex_address_01(void) { - assert(meshlink_destroy("addex_conf.1")); - - // Create node instance - meshlink_handle_t *mesh = meshlink_open("addex_conf.1", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - - char *external_address = meshlink_get_external_address(mesh); - assert(external_address); - - bool ret = meshlink_add_external_address(mesh); - assert_int_equal(ret, true); - - // Open the foo host file from confbase to verify address being added - bool found = false; - FILE *fp = fopen("./addex_conf.1/hosts/foo", "r"); - assert(fp); - char line[100]; - - while(fgets(line, 100, fp) != NULL) { - if(strcasestr(line, "Address") && strcasestr(line, external_address)) { - found = true; - } - } - - assert(!fclose(fp)); - - assert_int_equal(found, true); - - meshlink_close(mesh); - assert(meshlink_destroy("addex_conf.1")); - return true; -} - -/* Execute meshlink_add_external_address Test Case # 2 */ -void test_case_mesh_add_ex_address_02(void **state) { - execute_test(test_steps_mesh_add_ex_address_02, state); -} - -/* Test Steps for meshlink_add_external_address Test Case # 2 - - Test Steps: - 1. Create node instance - 2. Call meshlink_add_external_address API using NULL as mesh handle argument - - Expected Result: - meshlink_add_external_address API returns false by reporting error successfully. -*/ -bool test_steps_mesh_add_ex_address_02(void) { - bool result = meshlink_add_external_address(NULL); - assert_int_equal(result, false); - - return true; -} - -int test_meshlink_add_external_address(void) { - const struct CMUnitTest blackbox_add_ex_addr_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_ex_address_01, NULL, NULL, - (void *)&test_mesh_add_ex_address_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_ex_address_02, NULL, NULL, - (void *)&test_mesh_add_ex_address_02_state) - }; - - total_tests += sizeof(blackbox_add_ex_addr_tests) / sizeof(blackbox_add_ex_addr_tests[0]); - - return cmocka_run_group_tests(blackbox_add_ex_addr_tests, NULL, NULL); -} - diff --git a/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.h b/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.h deleted file mode 100644 index c5eca66..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_ADD_EX_ADDR_H -#define TEST_CASES_ADD_EX_ADDR_H - -/* - test_cases_add_ex_addr.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include - -extern int test_meshlink_add_external_address(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_autoconnect.c b/test/blackbox/run_blackbox_tests/test_cases_autoconnect.c deleted file mode 100644 index f9c2771..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_autoconnect.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - test_cases_blacklist.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -#include "execute_tests.h" -#include "test_cases_autoconnect.h" -#include -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include -#include -#include -#include -#include -#include - -static void test_case_autoconnect(void **state); -static bool test_steps_mesh_autoconnect(void); -static meshlink_handle_t *mesh1, *mesh2; - -/* State structure for meshlink_blacklist Test Case #1 */ -static black_box_state_t test_mesh_autoconnect_state = { - .test_case_name = "test_case_mesh_autoconnect", -}; -struct sync_flag test_autoconnect_m1n1_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -struct sync_flag test_autoconnect_blacklisted = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -struct sync_flag test_autoconnect_successful = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -/* Execute meshlink_blacklist Test Case # 1*/ -void test_case_autoconnect(void **state) { - execute_test(test_steps_mesh_autoconnect, state); -} - -void callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, - const char *text) { - (void)level; - - fprintf(stderr, "%s: {%s}\n", mesh->name, text); - - if((check_sync_flag(&test_autoconnect_blacklisted) == true) && (strcmp("m1n2", mesh->name) == 0) && (strcmp("* could not find node for initial connect", text) == 0)) { - fprintf(stderr, "Test case successful\n"); - set_sync_flag(&test_autoconnect_successful, true); - } else if((check_sync_flag(&test_autoconnect_blacklisted) == true) && (strcmp("m1n2", mesh->name) == 0)) { - assert(strcmp(text, "Autoconnect trying to connect to m1n1") != 0); - } - -} - -static void receive(meshlink_handle_t *mesh, meshlink_node_t *src, const void *data, size_t len) { - (void)mesh; - (void)src; - (void)data; - assert(len); -} - -static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - fprintf(stderr, "Status of node {%s} is %d\n", node->name, reachable); - - if(!strcmp(node->name, "m1n1") && reachable) { - set_sync_flag(&test_autoconnect_m1n1_reachable, true); - } -} - - -/* Test Steps for meshlink_blacklist Test Case # 1 - - Test Steps: - 1. Open both the node instances - 2. Join bar node with foo and Send & Receive data - 3. Blacklist bar and Send & Receive data - - Expected Result: - When default blacklist is disabled, foo node should receive data from bar - but when enabled foo node should not receive data -*/ -bool test_steps_mesh_autoconnect(void) { - char *invite = NULL; - meshlink_node_t *node = NULL; - - assert(meshlink_destroy("m1n1")); - assert(meshlink_destroy("m1n2")); - - // Open two new meshlink instance. - mesh1 = meshlink_open("m1n1", "m1n1", "autoconnect", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, callback_logger); - - mesh2 = meshlink_open("m1n2", "m1n2", "autoconnect", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, callback_logger); - meshlink_set_receive_cb(mesh1, receive); - - // Start both instances - meshlink_set_node_status_cb(mesh1, status_cb); - assert(meshlink_start(mesh1)); - - invite = meshlink_invite(mesh1, NULL, "m1n2"); - assert(invite); - - assert(meshlink_join(mesh2, invite)); - - meshlink_set_node_status_cb(mesh2, status_cb); - assert(meshlink_start(mesh2)); - - assert(wait_sync_flag(&test_autoconnect_m1n1_reachable, 30)); - - node = meshlink_get_node(mesh2, "m1n1"); - assert(meshlink_blacklist(mesh2, node)); - set_sync_flag(&test_autoconnect_blacklisted, true); - - assert(wait_sync_flag(&test_autoconnect_successful, 60)); - - // Clean up. - meshlink_close(mesh1); - fprintf(stderr, "Meshlink node1 closed\n"); - meshlink_close(mesh2); - fprintf(stderr, "Meshlink node2 closed\n"); - - assert(meshlink_destroy("m1n1")); - assert(meshlink_destroy("m1n2")); - fprintf(stderr, "Meshlink nodes destroyed\n"); - - return true; -} - -int test_meshlink_autoconnect(void) { - const struct CMUnitTest blackbox_blacklist_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_autoconnect, NULL, NULL, - (void *)&test_mesh_autoconnect_state) - }; - - total_tests += sizeof(blackbox_blacklist_tests) / sizeof(blackbox_blacklist_tests[0]); - - return cmocka_run_group_tests(blackbox_blacklist_tests, NULL, NULL); -} - diff --git a/test/blackbox/run_blackbox_tests/test_cases_autoconnect.h b/test/blackbox/run_blackbox_tests/test_cases_autoconnect.h deleted file mode 100644 index 10b4911..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_autoconnect.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_AUTOCONNECT_H -#define TEST_CASES_AUTOCONNECT_H - -/* - test_cases_autoconnect.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_autoconnect(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_blacklist.c b/test/blackbox/run_blackbox_tests/test_cases_blacklist.c deleted file mode 100644 index 8f9a118..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_blacklist.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - test_cases_blacklist.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -#include "execute_tests.h" -#include "test_cases_blacklist.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_blacklist_01(void **state); -static bool test_steps_mesh_blacklist_01(void); -static void test_case_mesh_blacklist_02(void **state); -static bool test_steps_mesh_blacklist_02(void); -static void test_case_mesh_blacklist_03(void **state); -static bool test_steps_mesh_blacklist_03(void); - -/* State structure for meshlink_blacklist Test Case #1 */ -static black_box_state_t test_mesh_blacklist_01_state = { - .test_case_name = "test_case_mesh_blacklist_01", -}; - -/* State structure for meshlink_blacklist Test Case #2 */ -static black_box_state_t test_mesh_blacklist_02_state = { - .test_case_name = "test_case_mesh_blacklist_02", -}; - -/* State structure for meshlink_blacklist Test Case #3 */ -static black_box_state_t test_mesh_blacklist_03_state = { - .test_case_name = "test_case_mesh_blacklist_03", -}; - -/* Execute meshlink_blacklist Test Case # 1*/ -void test_case_mesh_blacklist_01(void **state) { - execute_test(test_steps_mesh_blacklist_01, state); -} - -static bool received; - -static void receive(meshlink_handle_t *mesh, meshlink_node_t *src, const void *data, size_t len) { - (void)mesh; - - const char *msg = data; - assert(len); - - if(!strcmp(src->name, "bar") && len == 5 && !strcmp(msg, "test")) { - received = true; - } -} - -static bool bar_reachable; - -static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcmp(node->name, "bar") && reachable) { - bar_reachable = true; - } -} - - -/* Test Steps for meshlink_blacklist Test Case # 1 - - Test Steps: - 1. Open both the node instances - 2. Join bar node with foo and Send & Receive data - 3. Blacklist bar and Send & Receive data - - Expected Result: - When default blacklist is disabled, foo node should receive data from bar - but when enabled foo node should not receive data -*/ -bool test_steps_mesh_blacklist_01(void) { - assert(meshlink_destroy("blacklist_conf.1")); - assert(meshlink_destroy("blacklist_conf.2")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("blacklist_conf.1", "foo", "blacklist", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("blacklist_conf.2", "bar", "blacklist", DEV_CLASS_BACKBONE); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_receive_cb(mesh1, receive); - - // Start both instances - bar_reachable = false; - meshlink_set_node_status_cb(mesh1, status_cb); - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - sleep(1); - - char *foo_export = meshlink_export(mesh1); - assert(foo_export != NULL); - assert(meshlink_import(mesh2, foo_export)); - char *bar_export = meshlink_export(mesh2); - assert(meshlink_import(mesh1, bar_export)); - sleep(5); - assert_int_equal(bar_reachable, true); - - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar); - meshlink_node_t *foo = meshlink_get_node(mesh2, "foo"); - assert(foo); - - received = false; - assert(meshlink_send(mesh2, foo, "test", 5)); - sleep(1); - assert(received); - - assert(meshlink_blacklist(mesh1, bar)); - - received = false; - assert(meshlink_send(mesh2, foo, "test", 5)); - sleep(1); - assert_int_equal(received, false); - - // Clean up. - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("blacklist_conf.1")); - assert(meshlink_destroy("blacklist_conf.2")); - return true; -} - -/* Execute meshlink_blacklist Test Case # 2*/ -void test_case_mesh_blacklist_02(void **state) { - execute_test(test_steps_mesh_blacklist_02, state); -} - - -/* Test Steps for meshlink_blacklist Test Case # 2 - - Test Steps: - 1. Calling meshlink_blacklist with NULL as mesh handle argument. - - Expected Result: - meshlink_blacklist API handles the invalid parameter when called by giving proper error number. -*/ -bool test_steps_mesh_blacklist_02(void) { - assert(meshlink_destroy("blacklist_conf.3")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh = meshlink_open("blacklist_conf.3", "foo", "blacklist", DEV_CLASS_BACKBONE); - assert(mesh != NULL); - - meshlink_node_t *node = meshlink_get_self(mesh); - assert(node); - - // Passing NULL as mesh handle and node handle being some valid node handle - assert(!meshlink_blacklist(NULL, node)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Clean up. - meshlink_close(mesh); - assert(meshlink_destroy("blacklist_conf.3")); - return true; -} - -/* Execute meshlink_blacklist Test Case # 3*/ -void test_case_mesh_blacklist_03(void **state) { - execute_test(test_steps_mesh_blacklist_03, state); -} - -/* Test Steps for meshlink_blacklist Test Case # 3 - - Test Steps: - 1. Create node instance - 2. Calling meshlink_blacklist with NULL as node handle argument. - - Expected Result: - meshlink_blacklist API handles the invalid parameter when called by giving proper error number. -*/ -bool test_steps_mesh_blacklist_03(void) { - assert(meshlink_destroy("blacklist_conf.4")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh = meshlink_open("blacklist_conf.4", "foo", "blacklist", DEV_CLASS_BACKBONE); - assert(mesh != NULL); - - // Passing NULL as node handle and mesh handle being some valid mesh handle value - assert(!meshlink_blacklist(mesh, NULL)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Clean up. - meshlink_close(mesh); - assert(meshlink_destroy("blacklist_conf.4")); - return true; -} - -int test_meshlink_blacklist(void) { - const struct CMUnitTest blackbox_blacklist_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_blacklist_01, NULL, NULL, - (void *)&test_mesh_blacklist_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_blacklist_02, NULL, NULL, - (void *)&test_mesh_blacklist_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_blacklist_03, NULL, NULL, - (void *)&test_mesh_blacklist_03_state) - }; - - total_tests += sizeof(blackbox_blacklist_tests) / sizeof(blackbox_blacklist_tests[0]); - - return cmocka_run_group_tests(blackbox_blacklist_tests, NULL, NULL); -} - diff --git a/test/blackbox/run_blackbox_tests/test_cases_blacklist.h b/test/blackbox/run_blackbox_tests/test_cases_blacklist.h deleted file mode 100644 index b591d02..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_blacklist.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_BLACKLIST_H -#define TEST_CASES_BLACKLIST_H - -/* - test_cases_blacklist.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_blacklist(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c b/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c deleted file mode 100644 index 568a475..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - test_optimal_pmtu.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" -#include "test_cases_channel_blacklist.h" -#include "../test_case_channel_blacklist_01/node_sim_nut_01.h" - -typedef bool (*test_step_func_t)(void); -extern int total_tests; - -static bool test_steps_channel_blacklist_01(void); -static void test_case_channel_blacklist_01(void **state); - -static int setup_test(void **state); -static int teardown_test(void **state); -static void *gen_inv(void *arg); - -netns_state_t *test_channel_disconnection_state; - -static mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; -static mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; -static mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; -static mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; -static mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; -static netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; -static netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; -static netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = test_channel_blacklist_disonnection_relay_01, .arg = &relay_arg}; -static netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = test_channel_blacklist_disonnection_peer_01, .arg = &peer_arg}; -static netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = test_channel_blacklist_disonnection_nut_01, .arg = &nut_arg}; - -struct sync_flag test_channel_discon_nut_close = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static int setup_test(void **state) { - (void)state; - - netns_create_topology(test_channel_disconnection_state); - fprintf(stderr, "\nCreated topology\n"); - - assert(meshlink_destroy("nut")); - assert(meshlink_destroy("peer")); - assert(meshlink_destroy("relay")); - channel_discon_case_ping = false; - channel_discon_network_failure_01 = false; - channel_discon_network_failure_02 = false; - test_channel_restart_01 = false; - set_sync_flag(&test_channel_discon_nut_close, false); - - return EXIT_SUCCESS; -} - -static int teardown_test(void **state) { - (void)state; - - assert(meshlink_destroy("nut")); - assert(meshlink_destroy("peer")); - assert(meshlink_destroy("relay")); - netns_destroy_topology(test_channel_disconnection_state); - - return EXIT_SUCCESS; -} - -static void execute_test(test_step_func_t step_func, void **state) { - (void)state; - - - fprintf(stderr, "\n\x1b[32mRunning Test\x1b[0m\n"); - bool test_result = step_func(); - - if(!test_result) { - fail(); - } -} - -static void *gen_inv(void *arg) { - mesh_invite_arg_t *mesh_invite_arg = (mesh_invite_arg_t *)arg; - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_invite_arg->mesh_arg->node_name, mesh_invite_arg->mesh_arg->confbase, mesh_invite_arg->mesh_arg->app_name, mesh_invite_arg->mesh_arg->dev_class); - assert(mesh); - - char *invitation = meshlink_invite(mesh, NULL, mesh_invite_arg->invitee_name); - assert(invitation); - mesh_invite_arg->invite_str = invitation; - meshlink_close(mesh); - - return NULL; -} - -static void launch_3_nodes(void) { - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - relay_arg.join_invitation = NULL; - - run_node_in_namespace_thread(&netns_relay_handle); - sleep(1); - - run_node_in_namespace_thread(&netns_peer_handle); - sleep(1); - - run_node_in_namespace_thread(&netns_nut_handle); -} - -static void test_case_channel_blacklist_01(void **state) { - execute_test(test_steps_channel_blacklist_01, state); - return; -} - -static bool test_steps_channel_blacklist_01(void) { - - launch_3_nodes(); - - wait_sync_flag(&test_channel_discon_nut_close, 240); - - test_channel_blacklist_disonnection_peer_01_running = false; - test_channel_blacklist_disonnection_relay_01_running = false; - assert_int_equal(total_reachable_callbacks_01, 1); - assert_int_equal(total_unreachable_callbacks_01, 1); - assert_int_equal(total_channel_closure_callbacks_01, 2); - - return true; -} - -int test_meshlink_channel_blacklist(void) { - - interface_t relay_ifs[] = { { .if_peer = "wan_bridge" } }; - namespace_t relay = { - .name = "relay", - .type = HOST, - .interfaces = relay_ifs, - .interfaces_no = 1, - }; - - interface_t peer_ifs[] = { { .if_peer = "wan_bridge" } }; - namespace_t peer = { - .name = "peer", - .type = HOST, - .interfaces = peer_ifs, - .interfaces_no = 1, - }; - - interface_t nut_ifs[] = { { .if_peer = "wan_bridge" } }; - namespace_t nut = { - .name = "nut", - .type = HOST, - .interfaces = nut_ifs, - .interfaces_no = 1, - }; - - interface_t wan_ifs[] = { { .if_peer = "peer" }, { .if_peer = "nut" }, { .if_peer = "relay" } }; - namespace_t wan_bridge = { - .name = "wan_bridge", - .type = BRIDGE, - .interfaces = wan_ifs, - .interfaces_no = 3, - }; - - namespace_t test_channel_nodes[] = { relay, wan_bridge, nut, peer }; - - netns_state_t test_channels_nodes = { - .test_case_name = "test_case_channel", - .namespaces = test_channel_nodes, - .num_namespaces = 4, - }; - test_channel_disconnection_state = &test_channels_nodes; - - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_channel_blacklist_01, setup_test, teardown_test, - (void *)NULL), - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.h b/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.h deleted file mode 100644 index 5d9445f..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef TEST_CASES_CHANNEL_CONN_H -#define TEST_CASES_CHANNEL_CONN_H - -/* - test_cases_channel_blacklist.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include - -extern int test_meshlink_channel_blacklist(void); - -extern void *test_channel_blacklist_disonnection_nut_01(void *arg); -extern void *test_channel_blacklist_disonnection_peer_01(void *arg); -extern void *test_channel_blacklist_disonnection_relay_01(void *arg); - -extern int total_reachable_callbacks_01; -extern int total_unreachable_callbacks_01; -extern int total_channel_closure_callbacks_01; -extern bool channel_discon_case_ping; -extern bool channel_discon_network_failure_01; -extern bool channel_discon_network_failure_02; -extern bool test_channel_blacklist_disonnection_peer_01_running; -extern bool test_channel_blacklist_disonnection_relay_01_running; -extern bool test_blacklist_whitelist_01; -extern bool test_channel_restart_01; - -#endif // TEST_CASES_CHANNEL_CONN_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_close.c b/test/blackbox/run_blackbox_tests/test_cases_channel_close.c deleted file mode 100644 index 9f2c9c9..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_close.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - test_cases_channel_close.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_channel_close.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_channel_close_01(void **state); -static bool test_steps_mesh_channel_close_01(void); -static void test_case_mesh_channel_close_02(void **state); -static bool test_steps_mesh_channel_close_02(void); - -/* State structure for meshlink_channel_close Test Case #1 */ -static black_box_state_t test_mesh_channel_close_01_state = { - .test_case_name = "test_case_mesh_channel_close_01", -}; - -/* State structure for meshlink_channel_close Test Case #2 */ -static black_box_state_t test_mesh_channel_close_02_state = { - .test_case_name = "test_case_mesh_channel_close_02", -}; - -/* Execute meshlink_channel_close Test Case # 1*/ -static void test_case_mesh_channel_close_01(void **state) { - execute_test(test_steps_mesh_channel_close_01, state); - return; -} - -/* Test Steps for meshlink_channel_close Test Case # 1*/ -static bool test_steps_mesh_channel_close_01(void) { - assert(meshlink_destroy("chan_close_conf.3")); - assert(meshlink_destroy("chan_close_conf.4")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("chan_close_conf.3", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - - meshlink_handle_t *mesh2 = meshlink_open("chan_close_conf.4", "bar", "channels", DEV_CLASS_BACKBONE); - assert(mesh2 != NULL); - - if(!mesh2) { - fprintf(stderr, "Could not initialize configuration for bar\n"); - return false; - } - - char *exp = meshlink_export(mesh1); - assert(exp != NULL); - assert(meshlink_import(mesh2, exp)); - free(exp); - exp = meshlink_export(mesh2); - assert(exp != NULL); - assert(meshlink_import(mesh1, exp)); - free(exp); - - // Start both instances - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - sleep(2); - - // Open a channel from foo to bar. - - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar != NULL); - meshlink_channel_t *channel = meshlink_channel_open(mesh1, bar, 7, NULL, NULL, 0); - assert(channel != NULL); - - meshlink_channel_close(NULL, channel); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - - // Clean up. - - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("chan_close_conf.3")); - assert(meshlink_destroy("chan_close_conf.4")); - return true; -} - -/* Execute meshlink_channel_close Test Case # 2*/ -static void test_case_mesh_channel_close_02(void **state) { - execute_test(test_steps_mesh_channel_close_02, state); - return; -} - -/* Test Steps for meshlink_channel_close Test Case # 2*/ -static bool test_steps_mesh_channel_close_02(void) { - assert(meshlink_destroy("chan_close_conf.5")); - // Open two new meshlink instance. - - meshlink_handle_t *mesh = meshlink_open("chan_close_conf.5", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh != NULL); - - // Start both instances - assert(meshlink_start(mesh)); - - // Pass NULL as mesh handle - meshlink_channel_close(mesh, NULL); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Clean up. - - meshlink_close(mesh); - assert(meshlink_destroy("chan_close_conf.5")); - return true; -} - -int test_meshlink_channel_close(void) { - const struct CMUnitTest blackbox_channel_close_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_close_01, NULL, NULL, - (void *)&test_mesh_channel_close_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_close_02, NULL, NULL, - (void *)&test_mesh_channel_close_02_state) - }; - - total_tests += sizeof(blackbox_channel_close_tests) / sizeof(blackbox_channel_close_tests[0]); - - return cmocka_run_group_tests(blackbox_channel_close_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_close.h b/test/blackbox/run_blackbox_tests/test_cases_channel_close.h deleted file mode 100644 index 7203a19..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_close.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_CHANNEL_CLOSE_H -#define TEST_CASES_CHANNEL_CLOSE_H - -/* - test_cases_channel_close.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_channel_close(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_conn.c b/test/blackbox/run_blackbox_tests/test_cases_channel_conn.c deleted file mode 100644 index 9bed91b..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_conn.c +++ /dev/null @@ -1,802 +0,0 @@ -/* - test_cases_channel_conn.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_channel_conn.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/mesh_event_handler.h" - -#define PEER_ID "0" -#define NUT_ID "1" -#define RELAY_ID "2" - -static void test_case_channel_conn_01(void **state); -static bool test_steps_channel_conn_01(void); -static void test_case_channel_conn_02(void **state); -static bool test_steps_channel_conn_02(void); -static void test_case_channel_conn_03(void **state); -static bool test_steps_channel_conn_03(void); -static void test_case_channel_conn_04(void **state); -static bool test_steps_channel_conn_04(void); -static void test_case_channel_conn_05(void **state); -static bool test_steps_channel_conn_05(void); -static void test_case_channel_conn_06(void **state); -static bool test_steps_channel_conn_06(void); -static void test_case_channel_conn_07(void **state); -static bool test_steps_channel_conn_07(void); -static void test_case_channel_conn_08(void **state); -static bool test_steps_channel_conn_08(void); - -static char *test_channel_conn_2_nodes[] = { "peer", "nut" }; -static char *test_channel_conn_3_nodes[] = { "peer", "nut", "relay" }; - -static black_box_state_t test_case_channel_conn_01_state = { - .test_case_name = "test_case_channel_conn_01", - .node_names = test_channel_conn_2_nodes, - .num_nodes = 2, -}; -static black_box_state_t test_case_channel_conn_02_state = { - .test_case_name = "test_case_channel_conn_02", - .node_names = test_channel_conn_2_nodes, - .num_nodes = 2, -}; -static black_box_state_t test_case_channel_conn_03_state = { - .test_case_name = "test_case_channel_conn_03", - .node_names = test_channel_conn_2_nodes, - .num_nodes = 2, -}; -static black_box_state_t test_case_channel_conn_04_state = { - .test_case_name = "test_case_channel_conn_04", - .node_names = test_channel_conn_2_nodes, - .num_nodes = 2, -}; -static black_box_state_t test_case_channel_conn_05_state = { - .test_case_name = "test_case_channel_conn_05", - .node_names = test_channel_conn_3_nodes, - .num_nodes = 3, -}; -static black_box_state_t test_case_channel_conn_06_state = { - .test_case_name = "test_case_channel_conn_06", - .node_names = test_channel_conn_3_nodes, - .num_nodes = 3, -}; -static black_box_state_t test_case_channel_conn_07_state = { - .test_case_name = "test_case_channel_conn_07", - .node_names = test_channel_conn_3_nodes, - .num_nodes = 3, -}; -static black_box_state_t test_case_channel_conn_08_state = { - .test_case_name = "test_case_channel_conn_08", - .node_names = test_channel_conn_3_nodes, - .num_nodes = 3, -}; - -static bool joined; -static bool channel_opened; -static bool node_restarted; -static bool received_error; -static bool channel_received; -static bool node_reachable; -static bool node_unreachable; - -/* Callback function for handling channel connection test cases mesh events */ -static bool channel_conn_cb(mesh_event_payload_t payload) { - switch(payload.mesh_event) { - case NODE_JOINED : - joined = true; - break; - - case CHANNEL_OPENED : - channel_opened = true; - break; - - case NODE_RESTARTED : - node_restarted = true; - break; - - case ERR_NETWORK : - received_error = true; - break; - - case CHANNEL_DATA_RECIEVED : - channel_received = true; - break; - - case NODE_UNREACHABLE : - node_unreachable = true; - break; - - case NODE_REACHABLE : - node_reachable = true; - break; - - default : - PRINT_TEST_CASE_MSG("Undefined event occurred\n"); - } - - return true; -} - -/* Execute channel connections Test Case # 1 - simulate a temporary network - failure of about 30 seconds, messages sent while the network was down - should be received by the other side after the network comes up again. */ -static void test_case_channel_conn_01(void **state) { - execute_test(test_steps_channel_conn_01, state); - return; -} - -/* Test Steps for channel connections Test Case # 1 - - Test Steps: - 1. Run NUT & peer node instances and open a channel between them - 2. Simulate a network failure in NUT's container for about 30 secs, - meanwhile send data via channel from NUT to peer. - 3. After restoring network, peer node receive's data via channel. - - Expected Result: - Peer node receives data via channel without any error after restoring network. -*/ -static bool test_steps_channel_conn_01(void) { - char *invite_nut; - char *import; - - joined = false; - channel_opened = false; - channel_received = false; - - // Setup Containers - - install_in_container("nut", "iptables"); - accept_port_rule("nut", "OUTPUT", "udp", 9000); - import = mesh_event_sock_create(eth_if_name); - invite_nut = invite_in_container("peer", "nut"); - assert(invite_nut); - - // Run node instances in containers & open a channel - - node_sim_in_container_event("peer", "1", NULL, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(channel_opened, true); - - // Simulate network failure in NUT's LXC container with it's IP address as NAT rule - - block_node_ip("nut"); - sleep(2); - - // Sending SIGUSR1 signal to node-under-test indicating the network failure - - node_step_in_container("nut", "SIGUSR1"); - sleep(30); - - // Restore NUT's network - - unblock_node_ip("nut"); - - // Wait for peer node to receive data via channel from NUT - - wait_for_event(channel_conn_cb, 60); - - mesh_event_destroy(); - free(invite_nut); - free(import); - - assert_int_equal(channel_received, true); - - return true; -} - -/* Execute channel connections Test Case # 2 - a simulated network failure - of more than 1 minute, and sending messages over the channel during the - failure. Then after about 1 minute, the channel should receive an error */ -static void test_case_channel_conn_02(void **state) { - execute_test(test_steps_channel_conn_02, state); - return; -} - -/* Test Steps for channel connections Test Case # 2 - - Test Steps: - 1. Run NUT and peer node instances in containers and open a channel between them. - 2. Create a network failure for about 90 secs in NUT container - and signal NUT node about the network failure. - 3. Meanwhile NUT sends data to peer via channel and restore the network after - 90 secs. - - Expected Result: - Peer node should receive error closing the channel after channel timeout(60 secs). -*/ -static bool test_steps_channel_conn_02(void) { - char *invite_nut; - char *import; - - joined = false; - channel_opened = false; - received_error = false; - - // Setup containers - - install_in_container("nut", "iptables"); - accept_port_rule("nut", "OUTPUT", "udp", 9000); - import = mesh_event_sock_create(eth_if_name); - invite_nut = invite_in_container("peer", "nut"); - assert(invite_nut); - - // Run NUT and peer node instances in containers & open a channel - - node_sim_in_container_event("peer", "1", NULL, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 10); - assert_int_equal(channel_opened, true); - - // Simulate network failure in NUT's LXC container with it's IP address as NAT rule - - block_node_ip("nut"); - - // Sending SIGUSR1 signal to node-under-test indicating the network failure - - node_step_in_container("nut", "SIGUSR1"); - sleep(90); - - // Restore NUT containers network after 90 secs - - unblock_node_ip("nut"); - - // Wait for peer node to send the event about the channel error occurred with length = 0 - - wait_for_event(channel_conn_cb, 90); - - mesh_event_destroy(); - free(invite_nut); - free(import); - - assert_int_equal(received_error, true); - - return true; -} - -/* Execute channel connections Test Case # 3 - a simulated network failure - once node instance is made offline restore the network and send data via - channel */ -static void test_case_channel_conn_03(void **state) { - execute_test(test_steps_channel_conn_03, state); - return; -} - -/* Test Steps for channel connections Test Case # 3 - - Test Steps: - 1. Run NUT and peer node instances and open a channel between them. - 2. Create a network failure in NUT container, bring NUT node offline - and receive the status at test driver and restore the network - 3. After peer node instance is reachable to NUT node send data via channel - - Expected Result: - Peer node should receive data from NUT without any error. -*/ -static bool test_steps_channel_conn_03(void) { - char *invite_nut; - char *import; - - joined = false; - channel_opened = false; - node_unreachable = false; - node_reachable = false; - channel_received = false; - - // Setup containers - - install_in_container("nut", "iptables"); - accept_port_rule("nut", "OUTPUT", "udp", 9000); - import = mesh_event_sock_create(eth_if_name); - invite_nut = invite_in_container("peer", "nut"); - assert(invite_nut); - - // Run NUT and peer node instances in containers & open a channel - - node_sim_in_container_event("peer", "1", NULL, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 10); - assert_int_equal(channel_opened, true); - - // Simulate network failure in NUT's LXC container with it's IP address as NAT rule - - node_reachable = false; - block_node_ip("nut"); - - // Sending SIGUSR1 signal to node-under-test indicating the network failure - - node_step_in_container("nut", "SIGUSR1"); - - // Wait for the node status to become unreachable - - wait_for_event(channel_conn_cb, 100); - assert_int_equal(node_unreachable, true); - - // Restore NUT container's network - - unblock_node_ip("nut"); - - // Wait for the node status to become reachable - - wait_for_event(channel_conn_cb, 100); - assert_int_equal(node_reachable, true); - - // Wait for data to be received at peer via channel from NUT after restoring n/w - - wait_for_event(channel_conn_cb, 90); - - mesh_event_destroy(); - free(invite_nut); - free(import); - - assert_int_equal(channel_received, true); - - return true; -} - -/* Execute channel connections Test Case # 4 - receiving an error when node-under-test - tries to send data on channel to peer node after peer node stops and starts the - node instance */ -static void test_case_channel_conn_04(void **state) { - execute_test(test_steps_channel_conn_04, state); - return; -} - -/* Test Steps for Meta-connections Test Case # 4 - - Test Steps: - 1. Run peer and NUT node instances in containers and open a channel between them. - 2. Stop and start the NUT node instance and wait for about > 60 secs. - 3. Send data via channel from Peer node and wait for event in test driver. - - Expected Result: - Peer node should receive error(as length = 0) in receive callback of peer node's instance. -*/ -static bool test_steps_channel_conn_04(void) { - char *invite_nut; - char *import; - - joined = false; - channel_opened = false; - node_restarted = false; - received_error = false; - import = mesh_event_sock_create(eth_if_name); - invite_nut = invite_in_container("peer", "nut"); - assert(invite_nut); - - // Run NUT and peer node instances in containers and open a channel - - node_sim_in_container_event("peer", "1", NULL, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 10); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 10); - assert_int_equal(channel_opened, true); - - // Wait for NUT node instance to stop and start - - wait_for_event(channel_conn_cb, 60); - assert_int_equal(node_restarted, true); - - sleep(60); - - // After 1 min the channel between NUT and peer should result in error - - wait_for_event(channel_conn_cb, 10); - - - mesh_event_destroy(); - free(invite_nut); - free(import); - - assert_int_equal(received_error, true); - - return true; -} - -/* Execute channel connections Test Case # 5 - simulate a temporary network - failure of about 30 seconds, messages sent while the network was down - should be received by the other side after the network comes up again. */ -static void test_case_channel_conn_05(void **state) { - execute_test(test_steps_channel_conn_05, state); - return; -} - -/* Test Steps for channel connections Test Case # 5 - - Test Steps: - 1. Run NUT, relay & peer node instances with relay inviting NUT and peer - and open a channel between them - 2. Simulate a network failure in NUT's container for about 30 secs, - meanwhile send data via channel from NUT to peer. - 3. After restoring network, peer node receive's data via channel. - - Expected Result: - Peer node receives data via channel without any error after restoring network. -*/ -static bool test_steps_channel_conn_05(void) { - char *invite_nut, *invite_peer; - char *import; - - joined = false; - channel_opened = false; - channel_received = false; - - // Setup containers - - install_in_container("nut", "iptables"); - accept_port_rule("nut", "OUTPUT", "udp", 9000); - import = mesh_event_sock_create(eth_if_name); - invite_peer = invite_in_container("relay", "peer"); - invite_nut = invite_in_container("relay", "nut"); - assert(invite_nut); - assert(invite_peer); - - // Run node instances and open a channel between NUT and peer nodes - - node_sim_in_container_event("relay", "1", NULL, RELAY_ID, import); - node_sim_in_container_event("peer", "1", invite_peer, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(channel_opened, true); - - // Create a network failure in NUT node's container with it's IP address - - block_node_ip("nut"); - - // Sending SIGUSR1 signal to node-under-test indicating the network failure - - node_step_in_container("nut", "SIGUSR1"); - sleep(30); - - // Restore the network - - unblock_node_ip("nut"); - - // Wait for peer to get data from NUT node via channel after restoring network in < 60 secs - - wait_for_event(channel_conn_cb, 60); - - mesh_event_destroy(); - free(invite_peer); - free(invite_nut); - free(import); - - assert_int_equal(channel_received, true); - - return true; -} - -/* Execute channel connections Test Case # 6 - a simulated network failure - of more than 1 minute, and sending messages over the channel during the - failure. Then after about 1 minute, the channel should receive an error */ -static void test_case_channel_conn_06(void **state) { - execute_test(test_steps_channel_conn_06, state); - return; -} - -/* Test Steps for channel connections Test Case # 6 - - Test Steps: - 1. Run NUT, relay & peer node instances with relay inviting NUT and peer - and open a channel between them - 2. Create a network failure for about 90 secs in NUT container - and signal NUT node about the network failure. - 3. Meanwhile NUT sends data to peer via channel and restore the network after - 90 secs. - - Expected Result: - Peer node should receive error closing the channel after channel timeout(60 secs). -*/ -static bool test_steps_channel_conn_06(void) { - char *invite_nut, *invite_peer; - char *import; - - joined = false; - channel_opened = false; - received_error = false; - - // Setup containers - - install_in_container("nut", "iptables"); - accept_port_rule("nut", "OUTPUT", "udp", 9000); - import = mesh_event_sock_create(eth_if_name); - invite_peer = invite_in_container("relay", "peer"); - assert(invite_peer); - invite_nut = invite_in_container("relay", "nut"); - assert(invite_nut); - - // Run nodes in containers and open a channel between NUt and peer - - node_sim_in_container_event("relay", "1", NULL, RELAY_ID, import); - node_sim_in_container_event("peer", "1", invite_peer, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 10); - assert_int_equal(channel_opened, true); - - // Simulate a network failure in NUT's container for > 60 secs - - block_node_ip("nut"); - - // Sending SIGUSR1 signal to node-under-test indicating the network failure - - node_step_in_container("nut", "SIGUSR1"); - sleep(90); - - // Restore the network after 90 secs - - unblock_node_ip("nut"); - - // Wait for channel to receive error and receive the event - - wait_for_event(channel_conn_cb, 90); - - mesh_event_destroy(); - free(invite_peer); - free(invite_nut); - free(import); - - assert_int_equal(received_error, true); - - return true; -} - -/* Execute channel connections Test Case # 7 - a simulated network failure - once node instance is made offline restore the network and send data via - channel */ -static void test_case_channel_conn_07(void **state) { - execute_test(test_steps_channel_conn_07, state); - return; -} - -/* Test Steps for channel connections Test Case # 7 - - Test Steps: - 1. Run NUT, relay & peer node instances with relay inviting NUT and peer - and open a channel between them - 2. Create a network failure in NUT container, bring NUT node offline - and receive the status at test driver and restore the network - 3. After peer node instance is reachable to NUT node send data via channel - - Expected Result: - Peer node should receive data from NUT without any error. -*/ -static bool test_steps_channel_conn_07(void) { - char *invite_nut, *invite_peer; - char *import; - - joined = false; - channel_opened = false; - node_unreachable = false; - node_reachable = false; - channel_received = false; - - // Setup containers - - install_in_container("nut", "iptables"); - accept_port_rule("nut", "OUTPUT", "udp", 9000); - import = mesh_event_sock_create(eth_if_name); - invite_peer = invite_in_container("relay", "peer"); - invite_nut = invite_in_container("relay", "nut"); - assert(invite_nut); - assert(invite_peer); - - // Run nodes and open a channel - - node_sim_in_container_event("relay", "1", NULL, RELAY_ID, import); - node_sim_in_container_event("peer", "1", invite_peer, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 30); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 15); - assert_int_equal(channel_opened, true); - - // Simulate a network failure - - node_reachable = false; - block_node_ip("nut"); - - // Sending SIGUSR1 signal to node-under-test indicating the network failure - - node_step_in_container("nut", "SIGUSR1"); - - // Wait for node to become unreachable - - wait_for_event(channel_conn_cb, 100); - assert_int_equal(node_unreachable, true); - - // Restore the network - - unblock_node_ip("nut"); - - // Wait for node to become reachable after restoring n/w - - wait_for_event(channel_conn_cb, 100); - assert_int_equal(node_reachable, true); - - // Wait for peer node to receive data via channel without any error - - wait_for_event(channel_conn_cb, 90); - - mesh_event_destroy(); - free(invite_peer); - free(invite_nut); - free(import); - - assert_int_equal(channel_received, true); - - return true; -} - -/* Execute channel connections Test Case # 8 - receiving an error when node-under-test - tries to send data on channel to peer node after peer node stops and starts the - node instance */ -static void test_case_channel_conn_08(void **state) { - execute_test(test_steps_channel_conn_08, state); - return; -} - -/* Test Steps for Meta-connections Test Case # 8 - - Test Steps: - 1. Run NUT, relay & peer node instances with relay inviting NUT and peer - and open a channel between them - 2. Stop and start the NUT node instance and wait for about > 60 secs. - 3. Send data via channel from Peer node and wait for event in test driver. - - Expected Result: - Peer node should receive error(as length = 0) in receive callback of peer node's instance. -*/ -static bool test_steps_channel_conn_08(void) { - char *invite_nut, *invite_peer; - char *import; - - joined = false; - channel_opened = false; - node_restarted = false; - received_error = false; - - // Setup containers - - import = mesh_event_sock_create(eth_if_name); - invite_peer = invite_in_container("relay", "peer"); - invite_nut = invite_in_container("relay", "nut"); - assert(invite_nut); - assert(invite_peer); - - // Run nodes and open a channel between NUT and peer - - node_sim_in_container_event("relay", "1", NULL, RELAY_ID, import); - node_sim_in_container_event("peer", "1", invite_peer, PEER_ID, import); - node_sim_in_container_event("nut", "1", invite_nut, NUT_ID, import); - - wait_for_event(channel_conn_cb, 10); - assert_int_equal(joined, true); - - wait_for_event(channel_conn_cb, 10); - assert_int_equal(channel_opened, true); - - // Wait for NUT node to restart it's instance - - wait_for_event(channel_conn_cb, 60); - assert_int_equal(node_restarted, true); - - sleep(60); - - // Signal peer to send data to NUT node via channel - - node_step_in_container("peer", "SIGUSR1"); - - // Wait for peer to receive channel error - - wait_for_event(channel_conn_cb, 10); - - mesh_event_destroy(); - free(invite_peer); - free(invite_nut); - free(import); - - assert_int_equal(received_error, true); - - return true; -} - -static int black_box_group_setup(void **state) { - (void)state; - - const char *nodes[] = { "peer", "nut", "relay" }; - int num_nodes = sizeof(nodes) / sizeof(nodes[0]); - - printf("Creating Containers\n"); - destroy_containers(); - create_containers(nodes, num_nodes); - - return 0; -} - -static int black_box_group_teardown(void **state) { - (void)state; - - printf("Destroying Containers\n"); - destroy_containers(); - - return 0; -} - -int test_meshlink_channel_conn(void) { - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_01, setup_test, teardown_test, - (void *)&test_case_channel_conn_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_02, setup_test, teardown_test, - (void *)&test_case_channel_conn_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_03, setup_test, teardown_test, - (void *)&test_case_channel_conn_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_04, setup_test, teardown_test, - (void *)&test_case_channel_conn_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_05, setup_test, teardown_test, - (void *)&test_case_channel_conn_05_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_06, setup_test, teardown_test, - (void *)&test_case_channel_conn_06_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_07, setup_test, teardown_test, - (void *)&test_case_channel_conn_07_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_conn_08, setup_test, teardown_test, - (void *)&test_case_channel_conn_08_state), - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, black_box_group_setup, black_box_group_teardown); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_conn.h b/test/blackbox/run_blackbox_tests/test_cases_channel_conn.h deleted file mode 100644 index f05e165..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_conn.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_CHANNEL_CONN_H -#define TEST_CASES_CHANNEL_CONN_H - -/* - test_cases_channel_conn.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include - -extern int total_tests; -extern int test_meshlink_channel_conn(void); - -#endif // TEST_CASES_CHANNEL_CONN_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_ex.c b/test/blackbox/run_blackbox_tests/test_cases_channel_ex.c deleted file mode 100644 index 2687477..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_ex.c +++ /dev/null @@ -1,664 +0,0 @@ -/* - test_cases_channel_ex.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_channel_ex.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG -/* Modify this to change the port number */ -#define PORT 8000 - -#define NUT "nut" -#define PEER "peer" -#define TEST_CHANNEL_OPEN "test_channel_open" -#define create_path(confbase, node_name, test_case_no) assert(snprintf(confbase, sizeof(confbase), TEST_CHANNEL_OPEN "_%ld_%s_%02d", (long) getpid(), node_name, test_case_no) > 0) - -typedef struct test_cb_data { - size_t cb_data_len; - size_t cb_total_data_len; - int total_cb_count; - void (*cb_handler)(void); - bool cb_flag; -} test_cb_t; - -static void test_case_channel_ex_01(void **state); -static bool test_steps_channel_ex_01(void); -static void test_case_channel_ex_02(void **state); -static bool test_steps_channel_ex_02(void); -static void test_case_channel_ex_03(void **state); -static bool test_steps_channel_ex_03(void); -static void test_case_channel_ex_04(void **state); -static bool test_steps_channel_ex_04(void); -static void test_case_channel_ex_05(void **state); -static bool test_steps_channel_ex_05(void); -static void test_case_channel_ex_06(void **state); -static bool test_steps_channel_ex_06(void); -static void test_case_channel_ex_07(void **state); -static bool test_steps_channel_ex_07(void); - -static void cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -/* channel_acc gives us access to test whether the accept callback has been invoked or not */ -static bool channel_acc; -/* mutex for the common variable */ -pthread_mutex_t lock; - -static black_box_state_t test_case_channel_ex_01_state = { - .test_case_name = "test_case_channel_ex_01", -}; -static black_box_state_t test_case_channel_ex_02_state = { - .test_case_name = "test_case_channel_ex_02", -}; -static black_box_state_t test_case_channel_ex_03_state = { - .test_case_name = "test_case_channel_ex_03", -}; -static black_box_state_t test_case_channel_ex_04_state = { - .test_case_name = "test_case_channel_ex_04", -}; -static black_box_state_t test_case_channel_ex_05_state = { - .test_case_name = "test_case_channel_ex_05", -}; -static black_box_state_t test_case_channel_ex_06_state = { - .test_case_name = "test_case_channel_ex_06", -}; -static black_box_state_t test_case_channel_ex_07_state = { - .test_case_name = "test_case_channel_ex_07", -}; -/* mutex for the common variable */ -static pthread_mutex_t accept_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t accept_cond = PTHREAD_COND_INITIALIZER; - -static bool channel_acc; - -/* channel receive callback */ -static void cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - assert_int_equal(port, PORT); - - pthread_mutex_lock(&accept_lock); - channel_acc = true; - assert(!pthread_cond_broadcast(&accept_cond)); - pthread_mutex_unlock(&accept_lock); - - return true; -} - -/* Execute meshlink_channel_open_ex Test Case # 1 - testing meshlink_channel_open_ex API's - valid case by passing all valid arguments */ -static void test_case_channel_ex_01(void **state) { - execute_test(test_steps_channel_ex_01, state); -} - -/* Test Steps for meshlink_channel_open_ex Test Case # 1 - Valid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel to ourself - - Expected Result: - Opens a channel and echoes the send queue data. -*/ -/* TODO: When send queue & send queue length are passed with some value other - than NULL it throws segmentation fault*/ -static bool test_steps_channel_ex_01(void) { - /* Set up logging for Meshlink */ - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelexconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, channel_accept); - - assert(meshlink_start(mesh_handle)); - - /* Getting node handle for itself */ - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - char string[100] = "Test the 1st case"; - pthread_mutex_lock(&lock); - channel_acc = false; - pthread_mutex_unlock(&lock); - - /* Passing all valid arguments for meshlink_channel_open_ex */ - meshlink_channel_t *channel = NULL; - channel = meshlink_channel_open_ex(mesh_handle, node, PORT, cb, string, strlen(string) + 1, MESHLINK_CHANNEL_UDP); - assert_int_not_equal(channel, NULL); - - // Delay for establishing a channel - sleep(1); - - pthread_mutex_lock(&lock); - bool ret = channel_acc; - pthread_mutex_unlock(&lock); - - assert_int_equal(ret, true); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelexconf")); - - return true; -} - -/* Execute meshlink_channel_open_ex Test Case # 2 - testing API's valid case by passing NULL and - 0 for send queue & it's length respectively and others with valid arguments */ -static void test_case_channel_ex_02(void **state) { - execute_test(test_steps_channel_ex_02, state); -} -/* Test Steps for meshlink_channel_open_ex Test Case # 2 - Valid case (TCP channel) - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel to ourself - - Expected Result: - Opens a TCP channel successfully by setting channel_acc true*/ -static bool test_steps_channel_ex_02(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelexconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, channel_accept); - - assert(meshlink_start(mesh_handle)); - - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - pthread_mutex_lock(&lock); - channel_acc = false; - pthread_mutex_unlock(&lock); - sleep(1); - - PRINT_TEST_CASE_MSG("Opening TCP alike channel ex\n"); - /* Passing all valid arguments for meshlink_channel_open_ex */ - meshlink_channel_t *channel; - channel = meshlink_channel_open_ex(mesh_handle, node, PORT, cb, NULL, 0, MESHLINK_CHANNEL_TCP); - assert_int_not_equal(channel, NULL); - - // Delay for establishing a channel - sleep(1); - pthread_mutex_lock(&lock); - bool ret = channel_acc; - pthread_mutex_unlock(&lock); - - assert_int_equal(ret, true); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelexconf")); - return true; -} - -/* Execute meshlink_channel_open_ex Test Case # 3 - Open a UDP channel */ -static void test_case_channel_ex_03(void **state) { - execute_test(test_steps_channel_ex_03, state); -} -/* Test Steps for meshlink_channel_open_ex Test Case # 3 - Valid case (UDP channel) - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel to ourself - - Expected Result: - Opens a UDP channel successfully by setting channel_acc true */ -static bool test_steps_channel_ex_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelexconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, channel_accept); - - assert(meshlink_start(mesh_handle)); - - /* Getting node handle for itself */ - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - pthread_mutex_lock(&lock); - channel_acc = false; - pthread_mutex_unlock(&lock); - sleep(1); - - /* Passing all valid arguments for meshlink_channel_open_ex */ - meshlink_channel_t *channel; - channel = meshlink_channel_open_ex(mesh_handle, node, PORT, cb, NULL, 0, MESHLINK_CHANNEL_UDP); - assert_int_not_equal(channel, NULL); - - // Delay for establishing a channel - sleep(1); - - pthread_mutex_lock(&lock); - bool ret = channel_acc; - pthread_mutex_unlock(&lock); - - assert_int_equal(ret, true); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelexconf")); - return true; -} - -/* Execute meshlink_channel_open_ex Test Case # 4 - Open a TCP channel with no receive callback - and send queue */ -static void test_case_channel_ex_04(void **state) { - execute_test(test_steps_channel_ex_04, state); -} -/* Test Steps for meshlink_channel_open_ex Test Case # 4 - Valid Case (Disabling receive callback) - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel to ourself - - Expected Result: - Opens a channel -*/ - -static bool test_steps_channel_ex_04(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelexconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, channel_accept); - - assert(meshlink_start(mesh_handle)); - - /* Getting node handle for itself */ - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - pthread_mutex_lock(&lock); - channel_acc = false; - pthread_mutex_unlock(&lock); - - /* Passing all valid arguments for meshlink_channel_open_ex i.e disabling receive callback and send queue */ - meshlink_channel_t *channel; - channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_UDP); - assert(channel != NULL); - // Delay for establishing a channel - - pthread_mutex_lock(&lock); - bool ret = channel_acc; - pthread_mutex_unlock(&lock); - - assert_int_equal(ret, true); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelexconf")); - return true; -} - -/* Execute meshlink_channel_open_ex Test Case # 5 - Opening channel using NULL as mesh handle argument - for the API */ -static void test_case_channel_ex_05(void **state) { - execute_test(test_steps_channel_ex_05, state); -} -/* Test Steps for meshlink_channel_open_ex Test Case # 5 - Invalid case (NULL as mesh argument) - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel by passing NULL as argument for mesh handle - - Expected Result: - meshlink_channel_open_ex returns NULL as channel handle reporting error accordingly -*/ -static bool test_steps_channel_ex_05(void) { - /* Set up logging for Meshlink */ - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelexconf", "nut", "node_sim", 1); - assert(mesh_handle); - - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, channel_accept); - - assert(meshlink_start(mesh_handle)); - /* Getting node handle for itself */ - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - /* Trying to open channel using mesh handle as NULL argument */ - meshlink_channel_t *channel = meshlink_channel_open_ex(NULL, node, PORT, cb, NULL, 0, MESHLINK_CHANNEL_TCP); - assert(channel == NULL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelexconf")); - return true; -} - -/* Execute meshlink_channel_open_ex Test Case # 6 - Opening channel using NULL as node handle argument - for the API*/ -static void test_case_channel_ex_06(void **state) { - execute_test(test_steps_channel_ex_06, state); -} - -/* Test Steps for meshlink_channel_open_ex Test Case # 6 - Invalid case (NULL as node argument) - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel by passing NULL as argument for node handle - - Expected Result: - meshlink_channel_open_ex returns NULL as channel handle reporting error accordingly -*/ -static bool test_steps_channel_ex_06(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelexconf", "nut", "node_sim", 1); - assert(mesh_handle); - - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, channel_accept); - - assert(meshlink_start(mesh_handle)); - - /* Trying to open channel using node handle as NULL argument */ - meshlink_channel_t *channel = meshlink_channel_open_ex(mesh_handle, NULL, PORT, cb, NULL, 0, MESHLINK_CHANNEL_TCP); - - assert_int_equal(channel, NULL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelexconf")); - return true; -} - -static test_cb_t recv_cb_data; -static test_cb_t nut_recv_cb_data; - -/* Peer node's receive callback handler */ -static void peer_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { - (void)mesh; - (void)channel; - (void)data; - - (recv_cb_data.total_cb_count)++; - recv_cb_data.cb_total_data_len += len; - recv_cb_data.cb_data_len = len; - - assert_int_equal(meshlink_channel_send(mesh, channel, data, len), len); -} - -/* NUT's receive callback handler */ -static void nut_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { - (void)mesh; - (void)channel; - (void)data; - - (nut_recv_cb_data.total_cb_count)++; - nut_recv_cb_data.cb_total_data_len += len; - nut_recv_cb_data.cb_data_len = len; - -} - -/* NUT's poll callback handler */ -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)mesh; - (void)channel; - - fail(); -} - -static bool peer_accept_flag; - -/* Peer node's accept callback handler */ -static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)port; - (void)data; - (void)len; - - channel->node->priv = channel; - meshlink_set_channel_receive_cb(mesh, channel, peer_receive_cb); - return peer_accept_flag; -} - -/* Execute meshlink_channel_open_ex Test Case # 7 - UDP channel corner cases */ -static void test_case_channel_ex_07(void **state) { - execute_test(test_steps_channel_ex_07, state); -} - -static bool test_steps_channel_ex_07(void) { - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - char *buffer; - size_t mss_size; - size_t send_size; - meshlink_channel_t *channel_peer; - create_path(nut_confbase, NUT, 5); - create_path(peer_confbase, PEER, 5); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_CHANNEL_OPEN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_CHANNEL_OPEN, DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - - link_meshlink_pair(mesh, mesh_peer); - meshlink_set_channel_accept_cb(mesh_peer, accept_cb); - bzero(&recv_cb_data, sizeof(recv_cb_data)); - - meshlink_node_t *node = meshlink_get_node(mesh, PEER); - meshlink_node_t *node_peer = meshlink_get_node(mesh_peer, NUT); - assert_true(meshlink_start(mesh)); - assert_true(meshlink_start(mesh_peer)); - - /* 1. Peer rejects the channel that's being opened by NUT, when data is sent on that rejected channel - it should not lead to any undefined behavior and the peer should ignore the data sent */ - - peer_accept_flag = false; - meshlink_channel_t *channel = meshlink_channel_open_ex(mesh, node, PORT, nut_receive_cb, NULL, 0, MESHLINK_CHANNEL_UDP); - assert_non_null(channel); - - assert_after(node_peer->priv, 5); - assert_after((nut_recv_cb_data.total_cb_count == 1), 5); - assert_int_equal(nut_recv_cb_data.cb_data_len, 0); - - mss_size = meshlink_channel_get_mss(mesh, channel); - - if((mss_size != -1) && !mss_size) { - buffer = malloc(mss_size); - assert_non_null(buffer); - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, mss_size), mss_size); - sleep(5); - assert_int_equal(nut_recv_cb_data.total_cb_count, 0); - free(buffer); - } - - meshlink_channel_close(mesh, channel); - - /* 2. Open channel to an offline node and sleep for 30 seconds once the offline node comes back online - both the nodes should be able to create the channel */ - - peer_accept_flag = true; - meshlink_stop(mesh_peer); - node_peer->priv = NULL; - channel = meshlink_channel_open_ex(mesh, node, PORT, nut_receive_cb, NULL, 0, MESHLINK_CHANNEL_UDP); - assert_non_null(channel); - - sleep(30); - assert_true(meshlink_start(mesh_peer)); - - // Peer set's this while accepting channel - - assert_after(node_peer->priv, 5); - - /* 2. Active UDP channel should be able to do bi-directional data transfer */ - - bzero(&recv_cb_data, sizeof(recv_cb_data)); - bzero(&nut_recv_cb_data, sizeof(nut_recv_cb_data)); - buffer = malloc(mss_size); - assert_non_null(buffer); - mss_size = meshlink_channel_get_mss(mesh, channel); - assert_int_not_equal(mss_size, -1); - send_size = mss_size; - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, send_size), send_size); - assert_after((recv_cb_data.cb_total_data_len == send_size), 5); - assert_int_equal(recv_cb_data.total_cb_count, 1); - assert_after((nut_recv_cb_data.cb_total_data_len == send_size), 5); - assert_int_equal(nut_recv_cb_data.total_cb_count, 1); - - /* 3. Set poll callback for an UDP channel - Even though poll callback's return value is void - according to the design poll callback is meant only for TCP channel. */ - - // Set the poll callback and sleep for 5 seconds, fail the test case if poll callback gets invoked - - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - sleep(5); - - /* 4. Sent data on the active channel with data length more than the obtained MSS value. - It's expected that peer node doesn't receive it if received then the MSS calculations might be wrong */ - - bzero(&recv_cb_data, sizeof(recv_cb_data)); - send_size = mss_size + 100; - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, send_size), send_size); - sleep(5); - assert_int_equal(recv_cb_data.total_cb_count, 0); - - /* 5. Sent the minimum data (here 1 byte) possible to the peer node via the active UDP channel */ - - bzero(&recv_cb_data, sizeof(recv_cb_data)); - send_size = 1; - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, send_size), send_size); - assert_after((recv_cb_data.cb_total_data_len == send_size), 5); - assert_int_equal(recv_cb_data.total_cb_count, 1); - - /* 6. Sent more than maximum allowed data i.e, > UDP max length */ - - bzero(&recv_cb_data, sizeof(recv_cb_data)); - send_size = USHRT_MAX + 2; // 65537 bytes should fail - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, send_size), -1); - sleep(5); - assert_int_equal(recv_cb_data.total_cb_count, 0); - - /* 7. Pass get MSS API with NULL as mesh handle */ - - assert_int_equal(meshlink_channel_get_mss(NULL, channel), -1); - - /* 8. Pass get MSS API with NULL as channel handle */ - - assert_int_equal(meshlink_channel_get_mss(mesh, NULL), -1); - - /* 9. Obtained MSS value should be less than PMTU value */ - - ssize_t pmtu_size = meshlink_get_pmtu(mesh, node); - assert_int_not_equal(pmtu_size, -1); - assert_true(mss_size <= pmtu_size); - - /* 10. Close/free the channel at the NUT's end, but when peer node still tries to send data on that channel - meshlink should gracefully handle it */ - - bzero(&recv_cb_data, sizeof(recv_cb_data)); - bzero(&nut_recv_cb_data, sizeof(nut_recv_cb_data)); - recv_cb_data.cb_data_len = 1; - meshlink_channel_close(mesh, channel); - assert_after((recv_cb_data.total_cb_count == 1), 5); - assert_int_equal(recv_cb_data.cb_data_len, 0); - - channel_peer = node_peer->priv; - send_size = mss_size / 2; - assert_int_equal(meshlink_channel_send(mesh_peer, channel_peer, buffer, send_size), send_size); - sleep(5); - assert_int_equal(nut_recv_cb_data.total_cb_count, 0); - - /* 11. Getting MSS value on a node which is closed by other node but not freed/closed by the host node */ - - assert_int_equal(meshlink_channel_get_mss(mesh_peer, channel_peer), -1); - - // Cleanup - - free(buffer); - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return true; -} - -int test_meshlink_channel_open_ex(void) { - const struct CMUnitTest blackbox_channel_ex_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_channel_ex_01, NULL, NULL, - (void *)&test_case_channel_ex_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_ex_02, NULL, NULL, - (void *)&test_case_channel_ex_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_ex_03, NULL, NULL, - (void *)&test_case_channel_ex_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_ex_04, NULL, NULL, - (void *)&test_case_channel_ex_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_ex_05, NULL, NULL, - (void *)&test_case_channel_ex_05_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_ex_06, NULL, NULL, - (void *)&test_case_channel_ex_06_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_ex_07, NULL, NULL, - (void *)&test_case_channel_ex_07_state) - }; - - total_tests += sizeof(blackbox_channel_ex_tests) / sizeof(blackbox_channel_ex_tests[0]); - - assert(pthread_mutex_init(&lock, NULL) == 0); - int failed = cmocka_run_group_tests(blackbox_channel_ex_tests, NULL, NULL); - assert(pthread_mutex_destroy(&lock) == 0); - - return failed; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_ex.h b/test/blackbox/run_blackbox_tests/test_cases_channel_ex.h deleted file mode 100644 index e15fa28..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_ex.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_CHANNELS_EX_H -#define TEST_CASES_CHANNELS_EX_H - -/* - test_cases_channel_ex.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_channel_open_ex(void); - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c b/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c deleted file mode 100644 index 5bb2683..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - test_cases_channel_get_flags.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_channel_get_flags.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG -/* Modify this to change the port number */ -#define PORT 8000 - -static void test_case_channel_get_flags_01(void **state); -static bool test_steps_channel_get_flags_01(void); -static void test_case_channel_get_flags_02(void **state); -static bool test_steps_channel_get_flags_02(void); -static void test_case_channel_get_flags_03(void **state); -static bool test_steps_channel_get_flags_03(void); - -static black_box_state_t test_case_channel_get_flags_01_state = { - .test_case_name = "test_case_channel_get_flags_01", -}; - -static black_box_state_t test_case_channel_get_flags_02_state = { - .test_case_name = "test_case_channel_get_flags_02", -}; - -static black_box_state_t test_case_channel_get_flags_03_state = { - .test_case_name = "test_case_channel_get_flags_03", -}; - -/* Execute meshlink_channel_get_flags Test Case # 1 - Valid case*/ -static void test_case_channel_get_flags_01(void **state) { - execute_test(test_steps_channel_get_flags_01, state); -} -/* Test Steps for meshlink_channel_get_flags Test Case # 1 - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel to ourself (with TCP semantic here) - 3. Get flag(s) of that channel - - Expected Result: - API returning exact flag that has been assigned while opening (here TCP) -*/ -static bool test_steps_channel_get_flags_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, NULL); - - assert(meshlink_start(mesh_handle)); - - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - sleep(1); - - /* Passing all valid arguments for meshlink_channel_open_ex */ - meshlink_channel_t *channel; - channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP); - assert(channel != NULL); - - // Obtaining channel flags using meshlink_channel_get_flags - uint32_t flags = meshlink_channel_get_flags(mesh_handle, channel); - assert_int_equal(flags, MESHLINK_CHANNEL_TCP); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("getflagsconf")); - - return true; -} - -/* Execute meshlink_channel_get_flags Test Case # 2 - Invalid case*/ -static void test_case_channel_get_flags_02(void **state) { - execute_test(test_steps_channel_get_flags_02, state); -} -/* Test Steps for meshlink_channel_get_flags Test Case # 2 - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Open channel to ourself (with TCP semantic here) - 3. Call meshlink_channel_get_flags by passing NULL as mesh handle argument - - Expected Result: - API reporting error accordingly. -*/ -static bool test_steps_channel_get_flags_02(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1); - assert(mesh_handle); - - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, NULL); - - assert(meshlink_start(mesh_handle)); - - /* Getting node handle for itself */ - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - sleep(1); - - /* Passing all valid arguments for meshlink_channel_open_ex */ - meshlink_channel_t *channel; - channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP); - assert(channel != NULL); - - // passing NULL as mesh handle argument for meshlink_channel_get_flags - uint32_t flags = meshlink_channel_get_flags(NULL, channel); - - assert_int_equal((int32_t)flags, -1); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("getflagsconf")); - return true; -} - -/* Execute meshlink_channel_get flags Test Case # 3 - Invalid case*/ -static void test_case_channel_get_flags_03(void **state) { - execute_test(test_steps_channel_get_flags_03, state); -} -/* Test Steps for meshlink_channel_get_flags Test Case # 3 - - Test Steps: - 1. Run NUT(Node Under Test) - 3. Call meshlink_channel_get_flags by passing NULL as channel handle argument - - Expected Result: - API reporting error accordingly. -*/ -static bool test_steps_channel_get_flags_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status); - meshlink_set_channel_accept_cb(mesh_handle, NULL); - - assert(meshlink_start(mesh_handle)); - - // passing NULL as channel handle argument for meshlink_channel_get_flags - uint32_t flags = meshlink_channel_get_flags(mesh_handle, NULL); - - assert_int_equal((int32_t)flags, -1); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("getflagsconf")); - return true; -} - - -int test_meshlink_channel_get_flags(void) { - const struct CMUnitTest blackbox_channel_get_flags_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_01, NULL, NULL, - (void *)&test_case_channel_get_flags_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_02, NULL, NULL, - (void *)&test_case_channel_get_flags_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_03, NULL, NULL, - (void *)&test_case_channel_get_flags_03_state) - }; - - total_tests += sizeof(blackbox_channel_get_flags_tests) / sizeof(blackbox_channel_get_flags_tests[0]); - - return cmocka_run_group_tests(blackbox_channel_get_flags_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.h b/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.h deleted file mode 100644 index d60ec90..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_CHANNELS_SET_ACCEPT_H -#define TEST_CASES_CHANNELS_SET_ACCEPT_H - -/* - test_cases_get_self.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_channel_get_flags(void); - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_open.c b/test/blackbox/run_blackbox_tests/test_cases_channel_open.c deleted file mode 100644 index 9792aec..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_open.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - test_cases_channel_open.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_channel_open.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_channel_open_01(void **state); -static bool test_steps_mesh_channel_open_01(void); -static void test_case_mesh_channel_open_02(void **state); -static bool test_steps_mesh_channel_open_02(void); -static void test_case_mesh_channel_open_03(void **state); -static bool test_steps_mesh_channel_open_03(void); -static void test_case_mesh_channel_open_04(void **state); -static bool test_steps_mesh_channel_open_04(void); - -/* State structure for meshlink_channel_open Test Case #1 */ -static black_box_state_t test_mesh_channel_open_01_state = { - .test_case_name = "test_case_mesh_channel_open_01", -}; - -/* State structure for meshlink_channel_open Test Case #2 */ -static black_box_state_t test_mesh_channel_open_02_state = { - .test_case_name = "test_case_mesh_channel_open_02", -}; - -/* State structure for meshlink_channel_open Test Case #3 */ -static black_box_state_t test_mesh_channel_open_03_state = { - .test_case_name = "test_case_mesh_channel_open_03", -}; - -/* State structure for meshlink_channel_open Test Case #4 */ -static black_box_state_t test_mesh_channel_open_04_state = { - .test_case_name = "test_case_mesh_channel_open_04", -}; - -/* Execute meshlink_channel_open Test Case # 1*/ -static void test_case_mesh_channel_open_01(void **state) { - execute_test(test_steps_mesh_channel_open_01, state); -} - -/* Test Steps for meshlink_channel_open Test Case # 1 - - Test Steps: - 1. Open both the node instances - 2. Join bar node with foo - 3. Open channel between the nodes - - Expected Result: - meshlink_channel_open should open a channel by returning a channel handler -*/ -static bool test_steps_mesh_channel_open_01(void) { - assert(meshlink_destroy("channels_conf.1")); - assert(meshlink_destroy("channels_conf.2")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("channels_conf.1", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - meshlink_handle_t *mesh2 = meshlink_open("channels_conf.2", "bar", "channels", DEV_CLASS_BACKBONE); - assert(mesh2 != NULL); - - // Import and export both side's data - char *exp = meshlink_export(mesh1); - assert(exp != NULL); - assert(meshlink_import(mesh2, exp)); - free(exp); - exp = meshlink_export(mesh2); - assert(exp != NULL); - assert(meshlink_import(mesh1, exp)); - free(exp); - - // Start both instances - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - sleep(2); - - // Open a channel from foo to bar. - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar != NULL); - meshlink_channel_t *channel = meshlink_channel_open(mesh1, bar, 7000, NULL, NULL, 0); - assert_int_not_equal(channel, NULL); - - // Clean up. - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("channels_conf.1")); - assert(meshlink_destroy("channels_conf.2")); - return true; -} - -/* Execute meshlink_channel_open Test Case # 2 - - Test Steps: - 1. Open both the node instances - 2. Join bar node with foo - 3. Open channel between the nodes with NULL as receive callback argument - - Expected Result: - meshlink_channel_open should open a channel by returning a channel handler -*/ -static void test_case_mesh_channel_open_02(void **state) { - execute_test(test_steps_mesh_channel_open_02, state); -} - -/* Test Steps for meshlink_channel_open Test Case # 2*/ -static bool test_steps_mesh_channel_open_02(void) { - assert(meshlink_destroy("channels_conf.3")); - assert(meshlink_destroy("channels_conf.4")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("channels_conf.3", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - meshlink_handle_t *mesh2 = meshlink_open("channels_conf.4", "bar", "channels", DEV_CLASS_BACKBONE); - assert(mesh2 != NULL); - - char *exp = meshlink_export(mesh1); - assert(exp != NULL); - assert(meshlink_import(mesh2, exp)); - free(exp); - exp = meshlink_export(mesh2); - assert(exp != NULL); - assert(meshlink_import(mesh1, exp)); - free(exp); - - // Start both instances - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - sleep(1); - - // Open a channel from foo to bar. - - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar != NULL); - - meshlink_channel_t *channel = meshlink_channel_open(mesh1, bar, 7000, NULL, NULL, 0); - assert_int_not_equal(channel, NULL); - - // Clean up. - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("channels_conf.3")); - assert(meshlink_destroy("channels_conf.4")); - return true; -} - -/* Execute meshlink_channel_open Test Case # 3 */ -static void test_case_mesh_channel_open_03(void **state) { - execute_test(test_steps_mesh_channel_open_03, state); -} - -/* Test Steps for meshlink_channel_open Test Case # 3 - - Test Steps: - 1. Create the node instance & obtain node handle - 2. Open a channel with NULL as mesh handle argument - and rest other arguments being valid. - - Expected Result: - meshlink_channel_open API handles the invalid parameter - when called by giving proper error number. -*/ -static bool test_steps_mesh_channel_open_03(void) { - assert(meshlink_destroy("channels_conf.5")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh = meshlink_open("channels_conf.5", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh != NULL); - - meshlink_node_t *node = meshlink_get_self(mesh); - assert(node); - - meshlink_channel_t *channel = meshlink_channel_open(NULL, node, 7000, NULL, NULL, 0); - assert_int_equal(channel, NULL); - - // Clean up. - meshlink_close(mesh); - assert(meshlink_destroy("channels_conf.5")); - return true; -} - -/* Execute meshlink_channel_open Test Case # 4*/ -static void test_case_mesh_channel_open_04(void **state) { - execute_test(test_steps_mesh_channel_open_04, state); -} - -/* Test Steps for meshlink_channel_open Test Case # 4 - - Test Steps: - 1. Create the node instance & obtain node handle - 2. Open a channel with NULL as node handle argument - and rest other arguments being valid. - - Expected Result: - meshlink_channel_open API handles the invalid parameter - when called by giving proper error number. -*/ -static bool test_steps_mesh_channel_open_04(void) { - assert(meshlink_destroy("channels_conf.7")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh = meshlink_open("channels_conf.7", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh != NULL); - - // Start both instances - assert(meshlink_start(mesh)); - - meshlink_channel_t *channel = meshlink_channel_open(mesh, NULL, 7000, NULL, NULL, 0); - assert_int_equal(channel, NULL); - - // Clean up. - meshlink_close(mesh); - assert(meshlink_destroy("channels_conf.7")); - return true; -} - -int test_meshlink_channel_open(void) { - const struct CMUnitTest blackbox_channel_open_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_open_01, NULL, NULL, - (void *)&test_mesh_channel_open_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_open_02, NULL, NULL, - (void *)&test_mesh_channel_open_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_open_03, NULL, NULL, - (void *)&test_mesh_channel_open_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_open_04, NULL, NULL, - (void *)&test_mesh_channel_open_04_state) - }; - - total_tests += sizeof(blackbox_channel_open_tests) / sizeof(blackbox_channel_open_tests[0]); - - return cmocka_run_group_tests(blackbox_channel_open_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_open.h b/test/blackbox/run_blackbox_tests/test_cases_channel_open.h deleted file mode 100644 index a1140a0..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_open.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_CHANNEL_OPEN_H -#define TEST_CASES_CHANNEL_OPEN_H - -/* - test_cases_channel_open.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_channel_open(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_send.c b/test/blackbox/run_blackbox_tests/test_cases_channel_send.c deleted file mode 100644 index d818a0c..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_send.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - test_cases_channel_send.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_channel_send.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_channel_send_01(void **state); -static bool test_steps_mesh_channel_send_01(void); -static void test_case_mesh_channel_send_02(void **state); -static bool test_steps_mesh_channel_send_02(void); -static void test_case_mesh_channel_send_03(void **state); -static bool test_steps_mesh_channel_send_03(void); -static void test_case_mesh_channel_send_04(void **state); -static bool test_steps_mesh_channel_send_04(void); - -static void receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len); - -/* State structure for meshlink_channel_send Test Case #1 */ -static black_box_state_t test_mesh_channel_send_01_state = { - .test_case_name = "test_case_mesh_channel_send_01", -}; - -/* State structure for meshlink_channel_send Test Case #2 */ -static black_box_state_t test_mesh_channel_send_02_state = { - .test_case_name = "test_case_mesh_channel_send_02", -}; - -/* State structure for meshlink_channel_send Test Case #3 */ -static black_box_state_t test_mesh_channel_send_03_state = { - .test_case_name = "test_case_mesh_channel_send_03", -}; - -/* State structure for meshlink_channel_send Test Case #4 */ -static black_box_state_t test_mesh_channel_send_04_state = { - .test_case_name = "test_case_mesh_channel_send_04", -}; - -/* Execute meshlink_channel_send Test Case # 1*/ -static void test_case_mesh_channel_send_01(void **state) { - execute_test(test_steps_mesh_channel_send_01, state); -} - -static pthread_mutex_t poll_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t bar_reach_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t bar_responded_lock = PTHREAD_MUTEX_INITIALIZER; - -static pthread_cond_t poll_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t status_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t send_cond = PTHREAD_COND_INITIALIZER; - -static bool polled; -static bool bar_reachable; -static bool bar_responded; - -static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcmp(node->name, "bar")) { - pthread_mutex_lock(& bar_reach_lock); - bar_reachable = reachable; - assert(!pthread_cond_broadcast(&status_cond)); - pthread_mutex_unlock(& bar_reach_lock); - } -} - -static bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)mesh; - (void)channel; - (void)port; - (void)data; - (void)len; - return false; -} - -static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)data; - - assert(port == 7); - assert(!len); - - meshlink_set_channel_receive_cb(mesh, channel, receive_cb); - - return true; -} - -/* channel receive callback */ -static void receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - - if(len == 5 && !memcmp(dat, "Hello", 5)) { - pthread_mutex_lock(& bar_responded_lock); - bar_responded = true; - assert(!pthread_cond_broadcast(&send_cond)); - pthread_mutex_unlock(& bar_responded_lock); - } -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - - meshlink_set_channel_poll_cb(mesh, channel, NULL); - pthread_mutex_lock(&poll_lock); - polled = true; - assert(!pthread_cond_broadcast(&poll_cond)); - pthread_mutex_unlock(&poll_lock); -} - - -/* Test Steps for meshlink_channel_send Test Case # 1*/ -static bool test_steps_mesh_channel_send_01(void) { - struct timespec timeout = {0}; - assert(meshlink_destroy("chan_send_conf.1")); - assert(meshlink_destroy("chan_send_conf.2")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("chan_send_conf.1", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - meshlink_handle_t *mesh2 = meshlink_open("chan_send_conf.2", "bar", "channels", DEV_CLASS_BACKBONE); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, meshlink_callback_logger); - - char *data = meshlink_export(mesh1); - assert(data); - assert(meshlink_import(mesh2, data)); - free(data); - data = meshlink_export(mesh2); - assert(data); - assert(meshlink_import(mesh1, data)); - free(data); - - // Set the callbacks. - - meshlink_set_channel_accept_cb(mesh1, reject_cb); - meshlink_set_channel_accept_cb(mesh2, accept_cb); - - meshlink_set_node_status_cb(mesh1, status_cb); - - // Start both instances - bar_reachable = false; - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&bar_reach_lock); - - while(bar_reachable == false) { - assert(!pthread_cond_timedwait(&status_cond, &bar_reach_lock, &timeout)); - } - - pthread_mutex_unlock(&bar_reach_lock); - - // Open a channel from foo to bar. - - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar); - - bar_responded = false; - meshlink_channel_t *channel = meshlink_channel_open(mesh1, bar, 7, NULL, NULL, 0); - meshlink_set_channel_poll_cb(mesh1, channel, poll_cb); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&poll_lock); - - while(polled == false) { - assert(!pthread_cond_timedwait(&poll_cond, &poll_lock, &timeout)); - } - - pthread_mutex_unlock(&poll_lock); - - assert(meshlink_channel_send(mesh1, channel, "Hello", 5) >= 0); - - timeout.tv_sec = time(NULL) + 20; - pthread_mutex_lock(&bar_responded_lock); - - if(bar_responded == false) { - assert(!pthread_cond_timedwait(&send_cond, &bar_responded_lock, &timeout)); - } - - pthread_mutex_unlock(&bar_responded_lock); - - // Clean up. - - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("chan_send_conf.1")); - assert(meshlink_destroy("chan_send_conf.2")); - - return true; -} - -/* Execute meshlink_channel_send Test Case # 2*/ -static void test_case_mesh_channel_send_02(void **state) { - execute_test(test_steps_mesh_channel_send_02, state); -} - -/* Test Steps for meshlink_channel_send Test Case # 2*/ -static bool test_steps_mesh_channel_send_02(void) { - struct timespec timeout = {0}; - assert(meshlink_destroy("chan_send_conf.5")); - - // Open new meshlink instance. - - meshlink_handle_t *mesh1 = meshlink_open("chan_send_conf.5", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - - meshlink_set_channel_accept_cb(mesh1, accept_cb); - - // Start node instance - - assert(meshlink_start(mesh1)); - - meshlink_node_t *node = meshlink_get_self(mesh1); - assert(node); - - meshlink_channel_t *channel = meshlink_channel_open(mesh1, node, 7, receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh1, channel, poll_cb); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&poll_lock); - - while(polled == false) { - assert(!pthread_cond_timedwait(&poll_cond, &poll_lock, &timeout)); - } - - pthread_mutex_unlock(&poll_lock); - - ssize_t send_return = meshlink_channel_send(NULL, channel, "Hello", 5); - - assert_int_equal(send_return, -1); - - // Clean up. - - meshlink_close(mesh1); - assert(meshlink_destroy("chan_send_conf.5")); - - return true; -} - -/* Execute meshlink_channel_send Test Case # 3*/ -static void test_case_mesh_channel_send_03(void **state) { - execute_test(test_steps_mesh_channel_send_03, state); -} - -/* Test Steps for meshlink_channel_send Test Case # 3*/ -static bool test_steps_mesh_channel_send_03(void) { - assert(meshlink_destroy("chan_send_conf.7")); - // Open new meshlink instance. - - meshlink_handle_t *mesh1 = meshlink_open("chan_send_conf.7", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - meshlink_set_channel_accept_cb(mesh1, accept_cb); - - // Start node instance - - assert(meshlink_start(mesh1)); - - ssize_t send_return = meshlink_channel_send(mesh1, NULL, "Hello", 5); - - assert_int_equal(send_return, -1); - - // Clean up. - - meshlink_close(mesh1); - assert(meshlink_destroy("chan_send_conf.7")); - - return true; -} - -/* Execute meshlink_channel_send Test Case # 4*/ -static void test_case_mesh_channel_send_04(void **state) { - execute_test(test_steps_mesh_channel_send_04, state); -} - -/* Test Steps for meshlink_channel_send Test Case # 4*/ -static bool test_steps_mesh_channel_send_04(void) { - struct timespec timeout = {0}; - assert(meshlink_destroy("chan_send_conf.9")); - // Open two new meshlink instance. - - meshlink_handle_t *mesh1 = meshlink_open("chan_send_conf.9", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - - meshlink_set_channel_accept_cb(mesh1, accept_cb); - - // Start node instance - - assert(meshlink_start(mesh1)); - - meshlink_node_t *node = meshlink_get_self(mesh1); - assert(node); - - meshlink_channel_t *channel = meshlink_channel_open(mesh1, node, 7, receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh1, channel, poll_cb); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&poll_lock); - - while(polled == false) { - assert(!pthread_cond_timedwait(&poll_cond, &poll_lock, &timeout)); - } - - pthread_mutex_unlock(&poll_lock); - - ssize_t send_return = meshlink_channel_send(mesh1, channel, NULL, 5); - - assert_int_equal(send_return, -1); - - // Clean up. - - meshlink_close(mesh1); - assert(meshlink_destroy("chan_send_conf.9")); - - return true; -} - -int test_meshlink_channel_send(void) { - const struct CMUnitTest blackbox_channel_send_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_send_01, NULL, NULL, - (void *)&test_mesh_channel_send_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_send_02, NULL, NULL, - (void *)&test_mesh_channel_send_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_send_03, NULL, NULL, - (void *)&test_mesh_channel_send_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_send_04, NULL, NULL, - (void *)&test_mesh_channel_send_04_state) - }; - - total_tests += sizeof(blackbox_channel_send_tests) / sizeof(blackbox_channel_send_tests[0]); - - return cmocka_run_group_tests(blackbox_channel_send_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_send.h b/test/blackbox/run_blackbox_tests/test_cases_channel_send.h deleted file mode 100644 index b9e624f..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_send.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef TEST_CASES_CHANNEL_SEND_H -#define TEST_CASES_CHANNEL_SEND_H - -/* - test_cases_channel_send.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_channel_send(void); -extern int total_tests; - - - - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c b/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c deleted file mode 100644 index fa345b3..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - test_cases_channel_set_accept_cb.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "test_cases_channel_set_accept_cb.h" -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG -/* Modify this to change the port number */ -#define PORT 8000 - -static void test_case_set_channel_accept_cb_01(void **state); -static bool test_steps_set_channel_accept_cb_01(void); -static void test_case_set_channel_accept_cb_02(void **state); -static bool test_steps_set_channel_accept_cb_02(void); - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len); -static bool channel_reject(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len); - -static bool channel_acc; -static bool polled; -static bool rejected; - -/* mutex for the common variable */ -static pthread_mutex_t accept_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t poll_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t lock_receive = PTHREAD_MUTEX_INITIALIZER; - -static pthread_cond_t accept_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t poll_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t receive_cond = PTHREAD_COND_INITIALIZER; - -static black_box_state_t test_case_channel_set_accept_cb_01_state = { - .test_case_name = "test_case_channel_set_accept_cb_01", -}; -static black_box_state_t test_case_channel_set_accept_cb_02_state = { - .test_case_name = "test_case_channel_set_accept_cb_02", -}; - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - - if(!len) { - if(!meshlink_errno) { - pthread_mutex_lock(&lock_receive); - rejected = true; - assert(!pthread_cond_broadcast(&receive_cond)); - pthread_mutex_unlock(&lock_receive); - } - } -} - -/* channel reject callback */ -static bool channel_reject(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)mesh; - (void)channel; - (void)port; - (void)data; - (void)len; - return false; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - assert_int_equal(port, PORT); - - pthread_mutex_lock(&accept_lock); - channel_acc = true; - assert(!pthread_cond_broadcast(&accept_cond)); - pthread_mutex_unlock(&accept_lock); - - return true; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - pthread_mutex_lock(&poll_lock); - polled = true; - assert(!pthread_cond_broadcast(&poll_cond)); - pthread_mutex_unlock(&poll_lock); -} - -/* Execute meshlink_channel_set_accept_cb Test Case # 1 - Valid case*/ -static void test_case_set_channel_accept_cb_01(void **state) { - execute_test(test_steps_set_channel_accept_cb_01, state); -} -/* Test Steps for meshlink_channel_set_accept_cb Test Case # 1 - Valid case - - Test Steps: - 1. Open NUT(Node Under Test) & bar meshes. - 2. Set channel_accept callback for NUT's meshlink_set_channel_accept_cb API. - 3. Export and Import nodes. - 4. Open a channel with NUT from bar to invoke channel accept callback - 5. Open a channel with bar from NUT to invoke channel accept callback - - Expected Result: - Opens a channel by invoking accept callback, when accept callback rejects the channel - it should invoke the other node's receive callback with length = 0 and no error. -*/ -static bool test_steps_set_channel_accept_cb_01(void) { - /* deleting the confbase if already exists */ - struct timespec timeout = {0}; - assert(meshlink_destroy("acceptconf1")); - assert(meshlink_destroy("acceptconf2")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instances */ - meshlink_handle_t *mesh1 = meshlink_open("acceptconf1", "nut", "chat", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_handle_t *mesh2 = meshlink_open("acceptconf2", "bar", "chat", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh1, MESHLINK_INFO, meshlink_callback_logger); - meshlink_set_log_cb(mesh2, MESHLINK_INFO, meshlink_callback_logger); - - meshlink_set_channel_accept_cb(mesh2, channel_reject); - meshlink_set_channel_accept_cb(mesh1, channel_accept); - - /* Export and Import on both sides */ - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - assert(meshlink_import(mesh1, exp2)); - assert(meshlink_import(mesh2, exp1)); - - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - sleep(1); - - meshlink_node_t *destination = meshlink_get_node(mesh2, "nut"); - assert(destination != NULL); - - /* Open channel for nut node from bar node which should be accepted */ - polled = false; - channel_acc = false; - meshlink_channel_t *channel2 = meshlink_channel_open(mesh2, destination, PORT, NULL, NULL, 0); - assert(channel2); - meshlink_set_channel_poll_cb(mesh2, channel2, poll_cb); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&poll_lock); - - while(polled == false) { - assert(!pthread_cond_timedwait(&poll_cond, &poll_lock, &timeout)); - } - - pthread_mutex_unlock(&poll_lock); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&accept_lock); - - while(channel_acc == false) { - assert(!pthread_cond_timedwait(&accept_cond, &accept_lock, &timeout)); - } - - pthread_mutex_unlock(&accept_lock); - - /* Open channel for bar node from nut node which should be rejected */ - polled = false; - rejected = false; - channel_acc = false; - destination = meshlink_get_node(mesh1, "bar"); - assert(destination != NULL); - - meshlink_channel_t *channel1 = meshlink_channel_open(mesh1, destination, PORT, channel_receive_cb, NULL, 0); - assert(channel1); - meshlink_set_channel_poll_cb(mesh1, channel1, poll_cb); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&poll_lock); - - while(polled == false) { - assert(!pthread_cond_timedwait(&poll_cond, &poll_lock, &timeout)); - } - - pthread_mutex_unlock(&poll_lock); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&lock_receive); - - while(rejected == false) { - assert(!pthread_cond_timedwait(&receive_cond, &lock_receive, &timeout)); - } - - pthread_mutex_unlock(&lock_receive); - - /* closing channel, meshes and destroying confbase */ - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("acceptconf1")); - assert(meshlink_destroy("acceptconf2")); - - return true; -} - -/* Execute meshlink_channel_set_accept_cb Test Case # 2 - Invalid case*/ -static void test_case_set_channel_accept_cb_02(void **state) { - execute_test(test_steps_set_channel_accept_cb_02, state); -} -/* Test Steps for meshlink_channel_set_accept_cb Test Case # 2 - Invalid case - - Test Steps: - 1. Passing NULL as mesh handle argument for channel accept callback. - - Expected Result: - meshlink_channel_set_accept_cb returning proper meshlink_errno. -*/ -static bool test_steps_set_channel_accept_cb_02(void) { - /* setting channel accept cb with NULL as mesh handle and valid callback */ - meshlink_set_channel_accept_cb(NULL, channel_accept); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - return true; -} - - -int test_meshlink_set_channel_accept_cb(void) { - const struct CMUnitTest blackbox_channel_set_accept_cb_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_set_channel_accept_cb_01, NULL, NULL, - (void *)&test_case_channel_set_accept_cb_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_channel_accept_cb_02, NULL, NULL, - (void *)&test_case_channel_set_accept_cb_02_state) - }; - - total_tests += sizeof(blackbox_channel_set_accept_cb_tests) / sizeof(blackbox_channel_set_accept_cb_tests[0]); - - int failed = cmocka_run_group_tests(blackbox_channel_set_accept_cb_tests, NULL, NULL); - - return failed; -} - - - diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.h b/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.h deleted file mode 100644 index 9d91d59..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_CHANNELS_SET_ACCEPT_CB_H -#define TEST_CASES_CHANNELS_SET_ACCEPT_CB_H - -/* - test_cases_channel_set_accept_cb.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_set_channel_accept_cb(void); - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c b/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c deleted file mode 100644 index f0cfbfd..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c +++ /dev/null @@ -1,519 +0,0 @@ -/* - test_cases_channel_set_poll_cb.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_channel_set_poll_cb.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG -/* Modify this to change the port number */ -#define PORT 8000 - -#define NUT "nut" -#define PEER "peer" -#define TEST_POLL_CB "test_poll_cb" -#define create_path(confbase, node_name, test_case_no) assert(snprintf(confbase, sizeof(confbase), TEST_POLL_CB "_%ld_%s_%02d", (long) getpid(), node_name, test_case_no) > 0) - -typedef struct test_cb_data { - size_t cb_data_len; - size_t cb_total_data_len; - int total_cb_count; - void (*cb_handler)(void); - bool cb_flag; -} test_cb_t; - -static void test_case_channel_set_poll_cb_01(void **state); -static bool test_steps_channel_set_poll_cb_01(void); -static void test_case_channel_set_poll_cb_02(void **state); -static bool test_steps_channel_set_poll_cb_02(void); -static void test_case_channel_set_poll_cb_03(void **state); -static bool test_steps_channel_set_poll_cb_03(void); -static void test_case_channel_set_poll_cb_04(void **state); -static bool test_steps_channel_set_poll_cb_04(void); -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len); - -static black_box_state_t test_case_channel_set_poll_cb_01_state = { - .test_case_name = "test_case_channel_set_poll_cb_01", -}; -static black_box_state_t test_case_channel_set_poll_cb_02_state = { - .test_case_name = "test_case_channel_set_poll_cb_02", -}; -static black_box_state_t test_case_channel_set_poll_cb_03_state = { - .test_case_name = "test_case_channel_set_poll_cb_03", -}; -static black_box_state_t test_case_channel_set_poll_cb_04_state = { - .test_case_name = "test_case_channel_set_poll_cb_04", -}; - -static bool polled; -static bool reachable; - -static pthread_mutex_t poll_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t poll_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t reachable_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t reachable_cond = PTHREAD_COND_INITIALIZER; - -/* channel accept callback */ -static bool channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)mesh; - (void)channel; - (void)port; - (void)data; - (void)len; - return false; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - pthread_mutex_lock(&poll_lock); - polled = true; - assert(!pthread_cond_broadcast(&poll_cond)); - pthread_mutex_unlock(&poll_lock); -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *source, bool reach) { - (void)mesh; - (void)source; - - if(!reach) { - return; - } - - pthread_mutex_lock(&reachable_lock); - reachable = true; - assert(!pthread_cond_broadcast(&reachable_cond)); - pthread_mutex_unlock(&reachable_lock); -} - -/* Execute meshlink_channel_set_poll_cb Test Case # 1 */ -static void test_case_channel_set_poll_cb_01(void **state) { - execute_test(test_steps_channel_set_poll_cb_01, state); -} -/* Test Steps for meshlink_channel_set_poll_cb Test Case # 1 - - Test Steps: - 1. Run NUT - 2. Open channel of the NUT itself - - Expected Result: - Opens a channel and also invokes poll callback. -*/ -static bool test_steps_channel_set_poll_cb_01(void) { - /* deleting the confbase if already exists */ - struct timespec timeout = {0}; - assert(meshlink_destroy("pollconf1")); - assert(meshlink_destroy("pollconf2")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instances */ - meshlink_handle_t *mesh1 = meshlink_open("pollconf1", "nut", "chat", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_handle_t *mesh2 = meshlink_open("pollconf2", "bar", "chat", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh1, MESHLINK_INFO, meshlink_callback_logger); - meshlink_set_log_cb(mesh2, MESHLINK_INFO, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh1, node_status_cb); - meshlink_set_channel_accept_cb(mesh1, channel_accept_cb); - - /* Export and Import on both sides */ - reachable = false; - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - assert(meshlink_import(mesh1, exp2)); - assert(meshlink_import(mesh2, exp1)); - - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&reachable_lock); - - while(reachable == false) { - assert(!pthread_cond_timedwait(&reachable_cond, &reachable_lock, &timeout)); - } - - pthread_mutex_unlock(&reachable_lock); - - meshlink_node_t *destination = meshlink_get_node(mesh2, "nut"); - assert(destination != NULL); - - /* Open channel for nut node from bar node which should be accepted */ - polled = false; - meshlink_channel_t *channel = meshlink_channel_open(mesh2, destination, PORT, NULL, NULL, 0); - assert(channel); - meshlink_set_channel_poll_cb(mesh2, channel, poll_cb); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&poll_lock); - - while(polled == false) { - assert(!pthread_cond_timedwait(&poll_cond, &poll_lock, &timeout)); - } - - pthread_mutex_unlock(&poll_lock); - - /* closing channel, meshes and destroying confbase */ - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("pollconf1")); - assert(meshlink_destroy("pollconf2")); - - return true; -} - -/* Execute meshlink_channel_set_poll_cb Test Case # 2 */ -static void test_case_channel_set_poll_cb_02(void **state) { - execute_test(test_steps_channel_set_poll_cb_02, state); -} -/* Test Steps for meshlink_channel_set_poll_cb Test Case # 2 - - Test Steps: - 1. Run NUT - 2. Open channel of the NUT itself - 3. Pass NULL as mesh handle argument for meshlink_set_channel_poll_cb API - - Expected Result: - Reports error accordingly by returning NULL -*/ -static bool test_steps_channel_set_poll_cb_02(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelpollconf3", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - assert(meshlink_start(mesh_handle)); - - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - /* Opening channel */ - meshlink_channel_t *channel = meshlink_channel_open(mesh_handle, node, PORT, NULL, NULL, 0); - assert(channel != NULL); - - /* Setting poll cb with NULL as mesh handler */ - meshlink_set_channel_poll_cb(NULL, channel, poll_cb); - assert_int_not_equal(meshlink_errno, 0); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelpollconf3")); - return true; -} - -/* Execute meshlink_channel_set_poll_cb Test Case # 3 */ -static void test_case_channel_set_poll_cb_03(void **state) { - execute_test(test_steps_channel_set_poll_cb_03, state); -} -/* Test Steps for meshlink_channel_set_poll_cb Test Case # 3 - - Test Steps: - 1. Run NUT - 2. Open channel of the NUT itself - 3. Pass NULL as channel handle argument for meshlink_set_channel_poll_cb API - - Expected Result: - Reports error accordingly by returning NULL -*/ -static bool test_steps_channel_set_poll_cb_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelpollconf4", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - assert(meshlink_start(mesh_handle)); - - /* Setting poll cb with NULL as channel handler */ - meshlink_set_channel_poll_cb(mesh_handle, NULL, poll_cb); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelpollconf4")); - return true; -} - -static test_cb_t poll_cb_data; -static test_cb_t recv_cb_data; -static meshlink_handle_t *mesh; - -/* Peer node channel receive callback's internal handler function - Blocks for 2 seconds whenever it gets invoked */ -static void recv_cb_data_handler(void) { - static int poll_cb_last_count; - - // Sleep for 1 second to allow NUT's callback to invoke already scheduled callbacks - // i.e, this sleeps prevents a condition where if the flag is set assuming that - // further callbacks are invalid then pending poll callbacks can misinterpreted as invalid. - // TODO: Fix this race condition in the test case without sleep() - - sleep(1); - - // Make sure there is change in the cumulative poll callbacks count - - if(!poll_cb_last_count) { - poll_cb_last_count = poll_cb_data.total_cb_count; - } else { - assert(poll_cb_data.total_cb_count > poll_cb_last_count); - } - - // Set the receive callback block flag and reset it back after 2 seconds sleep - - recv_cb_data.cb_flag = true; - sleep(2); - recv_cb_data.cb_flag = false; -} - -/* Peer node channel receive callback's internal handler function - Stops the NUT's instance and - resets it's own internal handler */ -static void recv_cb_data_handler2(void) { - - // Stop the NUT's meshlink instance, set the receive callback flag indicating that further - // poll callbacks are considered to be invalid - - meshlink_stop(mesh); - recv_cb_data.cb_flag = true; - - // Reset the callback handler (i.e, this is a one-time operation) - - recv_cb_data.cb_handler = NULL; -} - -/* Peer node channel receive callback's internal handler function - Blocks for straight 5 seconds and - resets it's own internal handler */ -static void recv_cb_data_handler3(void) { - sleep(5); - recv_cb_data.cb_handler = NULL; - recv_cb_data.cb_flag = false; -} - -/* NUT channel poll callback's internal handler function - Assert on peer node receive callback's flag */ -static void poll_cb_data_handler(void) { - assert_false(recv_cb_data.cb_flag); -} - -/* Peer node's receive callback handler */ -static void receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { - (void)mesh; - (void)channel; - (void)data; - - // printf("Received %zu bytes\n", len); - (recv_cb_data.total_cb_count)++; - recv_cb_data.cb_total_data_len += len; - recv_cb_data.cb_data_len = len; - - if(recv_cb_data.cb_handler) { - recv_cb_data.cb_handler(); - } -} - -/* NUT's poll callback handler */ -static void poll_cb2(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)mesh; - (void)channel; - - // printf("Poll len: %zu\n", len); - assert(len); - (poll_cb_data.total_cb_count)++; - poll_cb_data.cb_total_data_len += len; - poll_cb_data.cb_data_len = len; - - if(poll_cb_data.cb_handler) { - (poll_cb_data.cb_handler)(); - } -} - -/* Peer node's accept callback handler */ -static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)port; - (void)data; - (void)len; - - channel->node->priv = channel; - meshlink_set_channel_receive_cb(mesh, channel, receive_cb); - return true; -} - -/* Execute meshlink_channel_set_poll_cb Test Case # 4 - Corner cases */ -static void test_case_channel_set_poll_cb_04(void **state) { - execute_test(test_steps_channel_set_poll_cb_04, state); -} -/* Test Steps for meshlink_channel_set_poll_cb Test Case # 4 - - Test Scenarios: - 1. Validate that Node-Under-Test never invokes the poll callback from a silent channel, here 65 seconds - 2. Send some data on to the data channel and block the reader end of the channel for a while where - at that instance nUT should not invokes any periodic callbacks. Once the peer node unblocks it's - instance it should continue to invokes callbacks. - This should repeat until the NUT channel sends it's complete data or the poll callback invokes with - max default size as length. - 3. Send a big packet of maximum send buffer size where length becomes 0 bytes, still NUT channel - should not invoke 0 length callback. Make sure by blocking the receiver and assert on the poll callback. - 4. NUT channel should not invoke the poll callback after self node going offline or due to it's reachability status. - 5. Modify the channel send buffer queue size which should be the new poll callback size further. -*/ -static bool test_steps_channel_set_poll_cb_04(void) { - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 4); - create_path(peer_confbase, PEER, 4); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - mesh = meshlink_open(nut_confbase, NUT, TEST_POLL_CB, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_POLL_CB, DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - - link_meshlink_pair(mesh, mesh_peer); - meshlink_set_channel_accept_cb(mesh_peer, accept_cb); - - assert_true(meshlink_start(mesh)); - assert_true(meshlink_start(mesh_peer)); - meshlink_node_t *node = meshlink_get_node(mesh, PEER); - - /* 1. Accept and stay idle for 65 seconds */ - - bzero(&poll_cb_data, sizeof(poll_cb_data)); - bzero(&recv_cb_data, sizeof(recv_cb_data)); - - meshlink_channel_t *channel = meshlink_channel_open(mesh, node, PORT, NULL, NULL, 0); - assert_non_null(channel); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb2); - sleep(65); - assert_int_equal(poll_cb_data.total_cb_count, 1); - assert_int_not_equal(poll_cb_data.cb_data_len, 0); - size_t default_max_size = poll_cb_data.cb_data_len; - - // Send 7 MSS size packet - - char *buffer = malloc(default_max_size); - assert_non_null(buffer); - size_t send_size = default_max_size; - bzero(&poll_cb_data, sizeof(poll_cb_data)); - bzero(&recv_cb_data, sizeof(recv_cb_data)); - - size_t mss_size = meshlink_channel_get_mss(mesh, channel); - assert_int_not_equal(mss_size, -1); - - if(mss_size * 7 <= default_max_size) { - send_size = mss_size * 7; - } - - /* 2. Validate whether poll callback is invoked in case of channel is holding data in send buffer for a while */ - - bzero(&poll_cb_data, sizeof(poll_cb_data)); - bzero(&recv_cb_data, sizeof(recv_cb_data)); - poll_cb_data.cb_handler = poll_cb_data_handler; - recv_cb_data.cb_handler = recv_cb_data_handler; - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, send_size), send_size); - assert_after(poll_cb_data.cb_data_len == default_max_size, 60); - assert_int_equal(recv_cb_data.cb_total_data_len, send_size); - - /* 3. On sending max send buffer sized packed on a channel should not invoke callback with length 0 */ - - bzero(&poll_cb_data, sizeof(poll_cb_data)); - bzero(&recv_cb_data, sizeof(recv_cb_data)); - poll_cb_data.cb_handler = poll_cb_data_handler; - recv_cb_data.cb_handler = recv_cb_data_handler3; - recv_cb_data.cb_flag = true; - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, default_max_size), default_max_size); - assert_after(poll_cb_data.cb_data_len == default_max_size, 60); - - - /* 4. Poll callback should not be invoked when the self node is offline and it has data in it's buffer */ - - bzero(&recv_cb_data, sizeof(recv_cb_data)); - recv_cb_data.cb_handler = recv_cb_data_handler2; - poll_cb_data.cb_handler = poll_cb_data_handler; - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, send_size), send_size); - assert_after(recv_cb_data.cb_flag, 20); - sleep(2); - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, 50), 50); - sleep(2); - recv_cb_data.cb_flag = false; - assert_true(meshlink_start(mesh)); - assert_after(poll_cb_data.cb_data_len == default_max_size, 10); - - /* 5. Changing the sendq size should reflect on the poll callback length */ - - bzero(&poll_cb_data, sizeof(poll_cb_data)); - bzero(&recv_cb_data, sizeof(recv_cb_data)); - - size_t new_size = meshlink_channel_get_mss(mesh, channel) * 3; - assert_int_not_equal(new_size, -1); - meshlink_set_channel_sndbuf(mesh, channel, new_size); - assert_after(new_size == poll_cb_data.cb_data_len, 5); - send_size = new_size / 2; - assert_int_equal(meshlink_channel_send(mesh, channel, buffer, send_size), send_size); - assert_after(new_size == poll_cb_data.cb_data_len, 5); - - /* If peer node's channel is closed/freed but the host node is not freed then poll callback with length 0 is expected */ - - /*assert_int_not_equal(poll_cb_data.cb_total_data_len, 0); - - meshlink_node_t *channel_peer = node_peer->priv; - meshlink_channel_close(mesh_peer, channel_peer); - assert_after(!poll_cb_data.cb_data_len, 60);*/ - - // Cleanup - - free(buffer); - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return true; -} - -int test_meshlink_set_channel_poll_cb(void) { - const struct CMUnitTest blackbox_channel_set_poll_cb_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_channel_set_poll_cb_01, NULL, NULL, - (void *)&test_case_channel_set_poll_cb_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_set_poll_cb_02, NULL, NULL, - (void *)&test_case_channel_set_poll_cb_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_set_poll_cb_03, NULL, NULL, - (void *)&test_case_channel_set_poll_cb_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_channel_set_poll_cb_04, NULL, NULL, - (void *)&test_case_channel_set_poll_cb_04_state) - }; - total_tests += sizeof(blackbox_channel_set_poll_cb_tests) / sizeof(blackbox_channel_set_poll_cb_tests[0]); - - return cmocka_run_group_tests(blackbox_channel_set_poll_cb_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.h b/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.h deleted file mode 100644 index 71796e2..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_SET_POLL_CB_H -#define TEST_CASES_SET_POLL_CB_H - -/* - test_cases_set_poll_cb.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_set_channel_poll_cb(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c b/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c deleted file mode 100644 index 697812e..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - test_cases_channel_set_receive_cb.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "test_cases_channel_set_receive_cb.h" -#include -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -/* Modify this to change the port number */ -#define PORT 8000 - -/* Modify this to change the channel receive callback access buffer */ -#define TCP_TEST 8000 - -static void test_case_set_channel_receive_cb_01(void **state); -static bool test_steps_set_channel_receive_cb_01(void); -static void test_case_set_channel_receive_cb_02(void **state); -static bool test_steps_set_channel_receive_cb_02(void); -static void test_case_set_channel_receive_cb_03(void **state); -static bool test_steps_set_channel_receive_cb_03(void); - -static bool rec_stat = false; -static bool accept_stat = false; - -/* mutex for the receive callback common resources */ -static pthread_mutex_t lock_accept = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t lock_receive = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t accept_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t receive_cond = PTHREAD_COND_INITIALIZER; - -static black_box_state_t test_case_channel_set_receive_cb_01_state = { - .test_case_name = "test_case_channel_set_receive_cb_01", -}; - -static black_box_state_t test_case_channel_set_receive_cb_02_state = { - .test_case_name = "test_case_channel_set_receive_cb_02", -}; - -static black_box_state_t test_case_channel_set_receive_cb_03_state = { - .test_case_name = "test_case_channel_set_receive_cb_03", -}; - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - pthread_mutex_lock(& lock_receive); - rec_stat = true; - assert(!pthread_cond_broadcast(&receive_cond)); - pthread_mutex_unlock(& lock_receive); -} - -static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)port; - (void)data; - (void)len; - - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - - pthread_mutex_lock(& lock_accept); - accept_stat = true; - assert(!pthread_cond_broadcast(&accept_cond)); - pthread_mutex_unlock(& lock_accept); - - return true; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "Hello", 5) >= 0); -} - -/* Execute meshlink_channel_set_receive_cb Test Case # 1 */ -static void test_case_set_channel_receive_cb_01(void **state) { - execute_test(test_steps_set_channel_receive_cb_01, state); -} -/* Test Steps for meshlink_channel_set_receive_cb Test Case # 1 - Valid case - - Test Steps: - 1. Run NUT and Open channel for itself. - 2. Set channel receive callback and send data. - - Expected Result: - Opens a channel by invoking channel receive callback when data sent to it. -*/ -static bool test_steps_set_channel_receive_cb_01(void) { - struct timespec timeout = {0}; - assert(meshlink_destroy("channelreceiveconf")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelreceiveconf", "nut", "node_sim", 1); - assert(mesh_handle != NULL); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh_handle, accept_cb); - - assert(meshlink_start(mesh_handle)); - - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - rec_stat = false; - accept_stat = false; - meshlink_channel_t *channel = meshlink_channel_open(mesh_handle, node, 8000, NULL, NULL, 0); - meshlink_set_channel_poll_cb(mesh_handle, channel, poll_cb); - - timeout.tv_sec = time(NULL) + 20; - pthread_mutex_lock(& lock_accept); - - while(accept_stat == false) { - assert(!pthread_cond_timedwait(&accept_cond, &lock_accept, &timeout)); - } - - pthread_mutex_unlock(& lock_accept); - - timeout.tv_sec = time(NULL) + 20; - pthread_mutex_lock(& lock_receive); - - while(rec_stat == false) { - assert(pthread_cond_timedwait(&receive_cond, &lock_receive, &timeout) == 0); - } - - pthread_mutex_unlock(& lock_receive); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelreceiveconf")); - - return true; -} - -/* Execute meshlink_channel_set_receive_cb Test Case # 2 */ -static void test_case_set_channel_receive_cb_02(void **state) { - execute_test(test_steps_set_channel_receive_cb_02, state); -} -/* Test Steps for meshlink_channel_set_receive_cb Test Case # 2 - Invalid case - - Test Steps: - 1. Run NUT and Open channel for itself. - 2. Set channel receive callback with NULL as mesh handle. - - Expected Result: - meshlink_channel_set_receive_cb returning proper meshlink_errno. -*/ -static bool test_steps_set_channel_receive_cb_02(void) { - assert(meshlink_destroy("channelreceiveconf")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelreceiveconf", "nut", "node_sim", 1); - assert(mesh_handle != NULL); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh_handle, accept_cb); - - /* Starting NUT */ - assert(meshlink_start(mesh_handle)); - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - meshlink_channel_t *channel = meshlink_channel_open_ex(mesh_handle, node, 8000, NULL, NULL, 0, MESHLINK_CHANNEL_UDP); - assert(channel != NULL); - meshlink_set_channel_poll_cb(mesh_handle, channel, poll_cb); - - /* Setting channel for NUT using meshlink_set_channel_receive_cb API with NULL as mesh handle */ - meshlink_set_channel_receive_cb(NULL, channel, channel_receive_cb); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelreceiveconf")); - - return true; -} - -/* Execute meshlink_channel_set_receive_cb Test Case # 3 */ -static void test_case_set_channel_receive_cb_03(void **state) { - execute_test(test_steps_set_channel_receive_cb_03, state); -} -/* Test Steps for meshlink_channel_set_receive_cb Test Case # 3 - Invalid case - - Test Steps: - 1. Run NUT and Open channel for itself. - 2. Set channel receive callback with NULL as channel handle. - - Expected Result: - meshlink_channel_set_receive_cb returning proper meshlink_errno. -*/ -static bool test_steps_set_channel_receive_cb_03(void) { - assert(meshlink_destroy("channelreceiveconf")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelreceiveconf", "nut", "node_sim", 1); - fprintf(stderr, "meshlink_open status: %s\n", meshlink_strerror(meshlink_errno)); - assert(mesh_handle != NULL); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh_handle, accept_cb); - - /* Starting NUT */ - assert(meshlink_start(mesh_handle)); - - /* Setting channel for NUT using meshlink_set_channel_receive_cb API channel handle as NULL */ - meshlink_set_channel_receive_cb(mesh_handle, NULL, channel_receive_cb); - - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelreceiveconf")); - return true; -} - - -int test_meshlink_set_channel_receive_cb(void) { - const struct CMUnitTest blackbox_channel_set_receive_cb_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_set_channel_receive_cb_01, NULL, NULL, - (void *)&test_case_channel_set_receive_cb_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_channel_receive_cb_02, NULL, NULL, - (void *)&test_case_channel_set_receive_cb_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_channel_receive_cb_03, NULL, NULL, - (void *)&test_case_channel_set_receive_cb_03_state) - }; - total_tests += sizeof(blackbox_channel_set_receive_cb_tests) / sizeof(blackbox_channel_set_receive_cb_tests[0]); - - int failed = cmocka_run_group_tests(blackbox_channel_set_receive_cb_tests, NULL, NULL); - - return failed; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.h b/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.h deleted file mode 100644 index e781f8c..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_CHANNELS_SET_RECEIVE_H -#define TEST_CASES_CHANNELS_SET_RECEIVE_H - -/* - test_cases_channel_set_receive_cb.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_set_channel_receive_cb(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c b/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c deleted file mode 100644 index c8f6ef4..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - test_cases_channel_shutdown.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_channel_shutdown.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_mesh_channel_shutdown_01(void **state); -static bool test_steps_mesh_channel_shutdown_01(void); -static void test_case_mesh_channel_shutdown_02(void **state); -static bool test_steps_mesh_channel_shutdown_02(void); -static void test_case_mesh_channel_shutdown_03(void **state); -static bool test_steps_mesh_channel_shutdown_03(void); - -static void receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len); - -/* State structure for meshlink_channel_shutdown Test Case #1 */ -static black_box_state_t test_mesh_channel_shutdown_01_state = { - .test_case_name = "test_case_mesh_channel_shutdown_01", -}; - -/* State structure for meshlink_channel_shutdown Test Case #2 */ -static black_box_state_t test_mesh_channel_shutdown_02_state = { - .test_case_name = "test_case_mesh_channel_shutdown_02", -}; - -/* State structure for meshlink_channel_shutdown Test Case #3 */ -static black_box_state_t test_mesh_channel_shutdown_03_state = { - .test_case_name = "test_case_mesh_channel_shutdown_03", -}; - -static bool channel_acc; -static bool polled; -static bool foo_responded; -static bool bar_responded; - -/* mutex for the common variable */ -static pthread_mutex_t accept_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t poll_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t bar_responded_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t foo_responded_lock = PTHREAD_MUTEX_INITIALIZER; - -static pthread_cond_t accept_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t poll_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t foo_cond = PTHREAD_COND_INITIALIZER; -static pthread_cond_t bar_cond = PTHREAD_COND_INITIALIZER; - -static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { - (void)data; - - assert(port == 7); - assert(!len); - - meshlink_set_channel_receive_cb(mesh, channel, receive_cb); - channel->node->priv = channel; - pthread_mutex_lock(&accept_lock); - channel_acc = true; - assert(!pthread_cond_broadcast(&accept_cond)); - pthread_mutex_unlock(&accept_lock); - - return true; -} - -/* channel receive callback */ -static void receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)dat; - (void)len; - - if(!strcmp(mesh->name, "foo")) { - pthread_mutex_lock(& foo_responded_lock); - foo_responded = true; - assert(!pthread_cond_broadcast(&foo_cond)); - pthread_mutex_unlock(& foo_responded_lock); - - } else if(!strcmp(mesh->name, "bar")) { - pthread_mutex_lock(& bar_responded_lock); - bar_responded = true; - assert(!pthread_cond_broadcast(&bar_cond)); - pthread_mutex_unlock(& bar_responded_lock); - - assert(meshlink_channel_send(mesh, channel, "echo", 4) >= 0); - - } -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - - meshlink_set_channel_poll_cb(mesh, channel, NULL); - pthread_mutex_lock(&poll_lock); - polled = true; - assert(!pthread_cond_broadcast(&poll_cond)); - pthread_mutex_unlock(&poll_lock); -} - -/* Execute meshlink_channel_shutdown Test Case # 1*/ -static void test_case_mesh_channel_shutdown_01(void **state) { - execute_test(test_steps_mesh_channel_shutdown_01, state); -} - -/* Test Steps for meshlink_channel_shutdown Test Case # 1 - Valid case - - Test Steps: - 1. Open foo and bar instances and open a channel between them - 2. Send data through the channel. - 3. Shut down channel's read and send data - 4. Shutdown channel's write and send data - - Expected Result: - Data is able to receive through channel before shutting down, - On shutting down read its should not able to receive data and when write - is shut down its should be able to send data through channel. -*/ -static bool test_steps_mesh_channel_shutdown_01(void) { - struct timespec timeout = {0}; - assert(meshlink_destroy("chan_shutdown_conf.1")); - assert(meshlink_destroy("chan_shutdown_conf.2")); - // Open two new meshlink instance. - - meshlink_handle_t *mesh1 = meshlink_open("chan_shutdown_conf.1", "foo", "channels", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - - meshlink_handle_t *mesh2 = meshlink_open("chan_shutdown_conf.2", "bar", "channels", DEV_CLASS_BACKBONE); - assert(mesh2 != NULL); - - char *data = meshlink_export(mesh1); - assert(data); - assert(meshlink_import(mesh2, data)); - free(data); - data = meshlink_export(mesh2); - assert(data); - assert(meshlink_import(mesh1, data)); - free(data); - - // Set the callbacks. - - meshlink_set_channel_accept_cb(mesh2, accept_cb); - - // Start both instances - - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - sleep(1); - - // Open a channel from foo to bar. - - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar); - - meshlink_channel_t *channel1 = meshlink_channel_open(mesh1, bar, 7, receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh1, channel1, poll_cb); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&poll_lock); - - while(polled == false) { - assert(!pthread_cond_timedwait(&poll_cond, &poll_lock, &timeout)); - } - - pthread_mutex_unlock(&poll_lock); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&accept_lock); - - while(channel_acc == false) { - assert(!pthread_cond_timedwait(&accept_cond, &accept_lock, &timeout)); - } - - pthread_mutex_unlock(&accept_lock); - - // Sending to bar and testing the echo - - assert(meshlink_channel_send(mesh1, channel1, "echo", 4) >= 0); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&foo_responded_lock); - - while(foo_responded == false) { - assert(!pthread_cond_timedwait(&foo_cond, &foo_responded_lock, &timeout)); - } - - pthread_mutex_unlock(&foo_responded_lock); - assert(foo_responded); - - // Shutting down channel read - - meshlink_channel_shutdown(mesh1, channel1, SHUT_RD); - bar_responded = false; - foo_responded = false; - assert(meshlink_channel_send(mesh1, channel1, "echo", 4) >= 0); - - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&bar_responded_lock); - - while(bar_responded == false) { - assert(!pthread_cond_timedwait(&bar_cond, &bar_responded_lock, &timeout)); - } - - pthread_mutex_unlock(&bar_responded_lock); - assert_int_equal(bar_responded, true); - sleep(1); - assert_int_equal(foo_responded, false); - - // Shutting down channel write - - meshlink_channel_shutdown(mesh1, channel1, SHUT_WR); - - ssize_t send_ret = meshlink_channel_send(mesh1, channel1, "echo", 4); - assert_int_equal(send_ret, -1); - - // Clean up. - - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("chan_shutdown_conf.1")); - assert(meshlink_destroy("chan_shutdown_conf.2")); - - return true; -} - -/* Execute meshlink_channel_shutdown Test Case # 2*/ -static void test_case_mesh_channel_shutdown_02(void **state) { - execute_test(test_steps_mesh_channel_shutdown_02, state); -} - -/* Test Steps for meshlink_channel_shutdown Test Case # 2 - Invalid case - - Test Steps: - 1. Open node instance and create a channel - 2. Call meshlink_channel_shutdown API by passing NULL as mesh handle - - Expected Result: - meshlink_channel_shutdown API should report proper error handling -*/ -static bool test_steps_mesh_channel_shutdown_02(void) { - assert(meshlink_destroy("channelshutdownconf.3")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelshutdownconf.3", "nut", "node_sim", 1); - assert(mesh_handle != NULL); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh_handle, accept_cb); - - assert(meshlink_start(mesh_handle)); - - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - meshlink_channel_t *channel = meshlink_channel_open(mesh_handle, node, 8000, NULL, NULL, 0); - assert(channel); - meshlink_set_channel_poll_cb(mesh_handle, channel, poll_cb); - - // Passing NULL as mesh handle and other arguments being valid - - meshlink_channel_shutdown(NULL, channel, SHUT_WR); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelshutdownconf.3")); - - return true; -} - -/* Execute meshlink_channel_shutdown Test Case # 3*/ -static void test_case_mesh_channel_shutdown_03(void **state) { - execute_test(test_steps_mesh_channel_shutdown_03, state); -} - -/* Test Steps for meshlink_channel_shutdown Test Case # 3 - - Test Steps: - 1. Open node instance - 2. Call meshlink_channel_shutdown API by passing NULL as channel handle - - Expected Result: - meshlink_channel_shutdown API should report proper error handling -*/ -static bool test_steps_mesh_channel_shutdown_03(void) { - assert(meshlink_destroy("channelshutdownconf.4")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("channelshutdownconf.4", "nut", "node_sim", 1); - assert(mesh_handle != NULL); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh_handle, accept_cb); - - assert(meshlink_start(mesh_handle)); - - // Passing NULL as mesh handle and other arguments being valid - - meshlink_channel_shutdown(mesh_handle, NULL, SHUT_WR); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("channelshutdownconf.4")); - - return true; -} - - -int test_meshlink_channel_shutdown(void) { - const struct CMUnitTest blackbox_channel_shutdown_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_shutdown_01, NULL, NULL, - (void *)&test_mesh_channel_shutdown_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_shutdown_02, NULL, NULL, - (void *)&test_mesh_channel_shutdown_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_channel_shutdown_03, NULL, NULL, - (void *)&test_mesh_channel_shutdown_03_state) - }; - total_tests += sizeof(blackbox_channel_shutdown_tests) / sizeof(blackbox_channel_shutdown_tests[0]); - - return cmocka_run_group_tests(blackbox_channel_shutdown_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.h b/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.h deleted file mode 100644 index 13f4690..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_CHANNEL_SHUTDOWN_H -#define TEST_CASES_CHANNEL_SHUTDOWN_H - -/* - test_cases_channel_shutdown.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_channel_shutdown(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c b/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c deleted file mode 100644 index 508e784..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - test_cases_default_blacklist.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_default_blacklist.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_mesh_default_blacklist_01(void **state); -static bool test_steps_mesh_default_blacklist_01(void); -static void test_case_mesh_default_blacklist_02(void **state); -static bool test_steps_mesh_default_blacklist_02(void); - -/* State structure for meshlink_default_blacklist Test Case #1 */ -static black_box_state_t test_mesh_default_blacklist_01_state = { - .test_case_name = "test_case_mesh_default_blacklist_01", -}; - -/* State structure for meshlink_default_blacklist Test Case #2 */ -static black_box_state_t test_mesh_default_blacklist_02_state = { - .test_case_name = "test_case_mesh_default_blacklist_02", -}; - -/* Execute meshlink_default_blacklist Test Case # 1*/ -static void test_case_mesh_default_blacklist_01(void **state) { - execute_test(test_steps_mesh_default_blacklist_01, state); - return; -} - -static bool received = false; - -static void receive(meshlink_handle_t *mesh, meshlink_node_t *src, const void *data, size_t len) { - (void)mesh; - (void)data; - - assert(len); - - if(!strcmp(src->name, "bar") || !strcmp(src->name, "foz")) { - received = true; - } -} - -static bool bar_reachable = false; -static bool foz_reachable = false; - -void status_cb1(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcmp(node->name, "bar")) { - bar_reachable = reachable; - } else if(!strcmp(node->name, "foz")) { - foz_reachable = reachable; - } -} - -/* Test Steps for meshlink_default_blacklist Test Case # 1 - - Test Steps: - 1. Open all the node instances & Disable default blacklist - 2. Join bar node with foo and Send & Receive data - 3. Enable default blacklist and join foz node with foo node - and follow the steps done for bar node - - Expected Result: - When default blacklist is disabled, foo node should receive data from bar - but when enabled foo node should not receive data from foz -*/ -static bool test_steps_mesh_default_blacklist_01(void) { - assert(meshlink_destroy("def_blacklist_conf.1")); - assert(meshlink_destroy("def_blacklist_conf.2")); - assert(meshlink_destroy("def_blacklist_conf.3")); - - // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("def_blacklist_conf.1", "foo", "blacklist", DEV_CLASS_BACKBONE); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("def_blacklist_conf.2", "bar", "blacklist", DEV_CLASS_BACKBONE); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh3 = meshlink_open("def_blacklist_conf.3", "foz", "blacklist", DEV_CLASS_BACKBONE); - assert(mesh3); - meshlink_set_log_cb(mesh3, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_receive_cb(mesh1, receive); - - meshlink_set_default_blacklist(mesh1, false); - - // Start both instances - bar_reachable = false; - foz_reachable = false; - meshlink_set_node_status_cb(mesh1, status_cb1); - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - assert(meshlink_start(mesh3)); - sleep(1); - - char *foo_export = meshlink_export(mesh1); - assert(foo_export != NULL); - assert(meshlink_import(mesh2, foo_export)); - char *bar_export = meshlink_export(mesh2); - assert(meshlink_import(mesh1, bar_export)); - sleep(5); - assert(bar_reachable); - - // Nodes should learn about each other - meshlink_node_t *foo = NULL; - foo = meshlink_get_node(mesh2, "foo"); - assert(foo); - - received = false; - assert(meshlink_send(mesh2, foo, "test", 5)); - assert_after(received, 2); - - // Enable default blacklist and join another node - meshlink_set_default_blacklist(mesh1, true); - - char *foz_export = meshlink_export(mesh3); - assert(foz_export); - assert(meshlink_import(mesh1, foz_export)); - assert(meshlink_import(mesh3, foo_export)); - sleep(5); - assert(foz_reachable); - - foo = meshlink_get_node(mesh3, "foo"); - assert(foo); - assert(meshlink_send(mesh3, foo, "test", 5)); - received = false; - assert(meshlink_send(mesh3, foo, "test", 5)); - assert_after(!received, 2); - - // Clean up. - free(foo_export); - free(foz_export); - free(bar_export); - meshlink_close(mesh1); - meshlink_close(mesh2); - meshlink_close(mesh3); - assert(meshlink_destroy("def_blacklist_conf.1")); - assert(meshlink_destroy("def_blacklist_conf.2")); - assert(meshlink_destroy("def_blacklist_conf.3")); - - return true; -} - -/* Execute meshlink_default_blacklist Test Case # 2*/ -static void test_case_mesh_default_blacklist_02(void **state) { - execute_test(test_steps_mesh_default_blacklist_02, state); -} - -/* Test Steps for meshlink_default_blacklist Test Case # 2 - - Test Steps: - 1. Calling meshlink_default_blacklist with NULL as mesh handle argument. - - Expected Result: - meshlink_default_blacklist API handles the invalid parameter when called by giving proper error number. -*/ -static bool test_steps_mesh_default_blacklist_02(void) { - // Passing NULL as mesh handle argument to the API - meshlink_set_default_blacklist(NULL, true); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - return true; -} - -int test_meshlink_default_blacklist(void) { - const struct CMUnitTest blackbox_default_blacklist_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_default_blacklist_01, NULL, NULL, - (void *)&test_mesh_default_blacklist_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_default_blacklist_02, NULL, NULL, - (void *)&test_mesh_default_blacklist_02_state) - }; - - total_tests += sizeof(blackbox_default_blacklist_tests) / sizeof(blackbox_default_blacklist_tests[0]); - - return cmocka_run_group_tests(blackbox_default_blacklist_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.h b/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.h deleted file mode 100644 index c8e7af2..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_DEFAULT_BLACKLIST_H -#define TEST_CASES_DEFAULT_BLACKLIST_H - -/* - test_cases_default_blacklist.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_default_blacklist(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_destroy.c b/test/blackbox/run_blackbox_tests/test_cases_destroy.c deleted file mode 100644 index 489e4d6..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_destroy.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - test_cases_destroy.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_destroy.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_meshlink_destroy_01(void **state); -static bool test_meshlink_destroy_01(void); -static void test_case_meshlink_destroy_02(void **state); -static bool test_meshlink_destroy_02(void); -static void test_case_meshlink_destroy_03(void **state); -static bool test_meshlink_destroy_03(void); - -static black_box_state_t test_case_meshlink_destroy_01_state = { - .test_case_name = "test_case_meshlink_destroy_01", -}; -static black_box_state_t test_case_meshlink_destroy_02_state = { - .test_case_name = "test_case_meshlink_destroy_02", -}; -static black_box_state_t test_case_meshlink_destroy_03_state = { - .test_case_name = "test_case_meshlink_destroy_03", -}; - - -/* Execute destroy Test Case # 1 - valid case*/ -static void test_case_meshlink_destroy_01(void **state) { - execute_test(test_meshlink_destroy_01, state); -} - -/* Test Steps for destroy Test Case # 1 - Valid case - Test Steps: - 1. Open instance for NUT - 2. Close NUT, and destroy the confbase - 3. Open the same confbase directory - - Expected Result: - confbase should be deleted -*/ -static bool test_meshlink_destroy_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - char *confbase = "destroyconf"; - mesh_handle = meshlink_open(confbase, "nut", "node_sim", 1); - assert(mesh_handle); - - meshlink_close(mesh_handle); - - // Destroying NUT's confbase - bool result = meshlink_destroy(confbase); - assert_int_equal(result, true); - - // Verify whether confbase is removed or not - DIR *dir = opendir(confbase); - assert_int_equal(dir, NULL); - - return true; -} - -/* Execute destroy Test Case # 2 - passing NULL argument to the API */ -static void test_case_meshlink_destroy_02(void **state) { - execute_test(test_meshlink_destroy_02, state); -} - -/* Test Steps for destroy Test Case # 2 - Invalid case - Test Steps: - 1. Just passing NULL as argument to the API - - Expected Result: - Return false reporting failure -*/ -static bool test_meshlink_destroy_02(void) { - // Passing NULL as an argument to meshlink_destroy - bool result = meshlink_destroy(NULL); - assert_int_equal(result, false); - - return true; -} - -/* Execute status Test Case # 3 - destroying non existing file */ -static void test_case_meshlink_destroy_03(void **state) { - execute_test(test_meshlink_destroy_03, state); -} -/* Test Steps for destroy Test Case # 3 - Invalid case - Test Steps: - 1. unlink if there's any such test file - 2. Call API with that file name - - Expected Result: - Return false reporting failure -*/ -static bool test_meshlink_destroy_03(void) { - bool result = false; - - // Deletes if there is any file named 'non_existing' already - unlink("non_existing"); - - // Passing non-existing file as an argument to meshlink_destroy - result = meshlink_destroy("non_existing"); - assert_int_equal(result, false); - - return true; -} - - -int test_meshlink_destroy(void) { - const struct CMUnitTest blackbox_destroy_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_01, NULL, NULL, - (void *)&test_case_meshlink_destroy_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_02, NULL, NULL, - (void *)&test_case_meshlink_destroy_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_03, NULL, NULL, - (void *)&test_case_meshlink_destroy_03_state) - }; - - total_tests += sizeof(blackbox_destroy_tests) / sizeof(blackbox_destroy_tests[0]); - - return cmocka_run_group_tests(blackbox_destroy_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_destroy.h b/test/blackbox/run_blackbox_tests/test_cases_destroy.h deleted file mode 100644 index 3d90dcb..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_destroy.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_DESTROY_H -#define TEST_CASES_DESTROY_H - -/* - test_cases_destroy.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_destroy(void); - -#endif // TEST_CASES_DESTROY_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_export.c b/test/blackbox/run_blackbox_tests/test_cases_export.c deleted file mode 100644 index 0281f0b..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_export.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - test_cases_export.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_export.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_export_01(void **state); -static bool test_export_01(void); -static void test_case_export_02(void **state); -static bool test_export_02(void); - -/* State structure for export API Test Case #1 */ -static black_box_state_t test_case_export_01_state = { - .test_case_name = "test_case_export_01", -}; -/* State structure for export API Test Case #2 */ -static black_box_state_t test_case_export_02_state = { - .test_case_name = "test_case_export_02", -}; - - -/* Execute export Test Case # 1 - valid case*/ -static void test_case_export_01(void **state) { - execute_test(test_export_01, state); -} -/* Test Steps for export Test Case # 1 - Valid case - Test Steps: - 1. Run NUT - 2. Export mesh - - Expected Result: - API returns a NULL terminated string containing meta data of NUT. -*/ -static bool test_export_01(void) { - assert(meshlink_destroy("exportconf")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("exportconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - char *expo = meshlink_export(mesh_handle); - assert_int_not_equal(expo, NULL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("exportconf")); - - return true; -} - -/* Execute export Test Case # 2 - Invalid case*/ -static void test_case_export_02(void **state) { - execute_test(test_export_02, state); -} -/* Test Steps for export Test Case # 2 - Invalid case - Test Steps: - 1. Run NUT - 2. calling meshlink_export by passing NULL as mesh handle - - Expected Result: - API returns NULL reporting error when NULL being passed as mesh handle. -*/ -static bool test_export_02(void) { - // Calling export API with NULL as mesh handle - char *expo = meshlink_export(NULL); - assert_int_equal(expo, NULL); - - return true; -} - - -int test_meshlink_export(void) { - const struct CMUnitTest blackbox_export_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_export_01, NULL, NULL, - (void *)&test_case_export_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_export_02, NULL, NULL, - (void *)&test_case_export_02_state) - }; - - total_tests += sizeof(blackbox_export_tests) / sizeof(blackbox_export_tests[0]); - - return cmocka_run_group_tests(blackbox_export_tests, NULL, NULL); -} - diff --git a/test/blackbox/run_blackbox_tests/test_cases_export.h b/test/blackbox/run_blackbox_tests/test_cases_export.h deleted file mode 100644 index ecea12e..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_export.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_EXPORT_H -#define TEST_CASES_EXPORT_H - -/* - test_cases_export.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_export(void); - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c deleted file mode 100644 index 6fd409b..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - test_cases_get_all_nodes.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "test_cases_get_all_nodes.h" -#include -#include -#include -#include -#include -#include - - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_get_all_nodes_01(void **state); -static bool test_get_all_nodes_01(void); -static void test_case_get_all_nodes_02(void **state); -static bool test_get_all_nodes_02(void); -static void test_case_get_all_nodes_03(void **state); -static bool test_get_all_nodes_03(void); - -/* State structure for get_all_nodes Test Case #1 */ -static black_box_state_t test_case_get_all_nodes_01_state = { - .test_case_name = "test_case_get_all_nodes_01", -}; - -/* State structure for get_all_nodes Test Case #2 */ -static black_box_state_t test_case_get_all_nodes_02_state = { - .test_case_name = "test_case_get_all_nodes_02", -}; - -/* State structure for get_all_nodes Test Case #3 */ -static black_box_state_t test_case_get_all_nodes_03_state = { - .test_case_name = "test_case_get_all_nodes_03", -}; - -/* Execute get_all_nodes Test Case # 1 - Valid case - get all nodes in the mesh */ -static void test_case_get_all_nodes_01(void **state) { - execute_test(test_get_all_nodes_01, state); -} -/* Test Steps for get_all_nodes Test Case # 1 - Valid case - - Test Steps: - 1. Open NUT and get list of nodes - 2. Open bar and join with NUT - 3. get list of nodes together - - Expected Result: - Obtaining list of nodes in the mesh at the given instance -*/ -static bool test_get_all_nodes_01(void) { - assert(meshlink_destroy("getnodeconf1")); - assert(meshlink_destroy("getnodeconf2")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance for NUT */ - meshlink_handle_t *mesh1 = meshlink_open("getnodeconf1", "nut", "node_sim", DEV_CLASS_STATIONARY); - assert(mesh1); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - size_t nnodes = 0; - meshlink_node_t **nodes = NULL; - nodes = meshlink_get_all_nodes(mesh1, nodes, &nnodes); - assert_int_not_equal(nodes, NULL); - assert_int_equal(nnodes, 1); - - /* Create meshlink instance for bar */ - meshlink_handle_t *mesh2 = meshlink_open("getnodeconf2", "bar", "node_sim", DEV_CLASS_STATIONARY); - assert(mesh2); - - /* importing and exporting mesh meta data */ - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - assert(meshlink_import(mesh1, exp2)); - assert(meshlink_import(mesh2, exp1)); - - nodes = meshlink_get_all_nodes(mesh1, nodes, &nnodes); - assert_int_not_equal(nodes, NULL); - assert_int_equal(nnodes, 2); - - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("getnodeconf1")); - assert(meshlink_destroy("getnodeconf2")); - - return true; -} - - - -/* Execute get_all_nodes Test Case # 2 - Invalid case - get all nodes in the mesh passing NULL */ -static void test_case_get_all_nodes_02(void **state) { - execute_test(test_get_all_nodes_02, state); -} - -/* Test Steps for get_all_nodes Test Case # 2 - Invalid case - - Test Steps: - 1. Passing NULL as mesh handle argument for meshlink_get_all_nodes - - Expected Result: - Error reported correctly by returning NULL -*/ -static bool test_get_all_nodes_02(void) { - size_t nmemb = 0; - - meshlink_node_t **nodes = meshlink_get_all_nodes(NULL, NULL, &nmemb); - assert_null(nodes); - assert_int_equal(nmemb, NULL); - - return true; -} - -/* Execute get_all_nodes Test Case # 3 - Invalid case - get all nodes in the mesh passing NULL as nmeb arg */ -static void test_case_get_all_nodes_03(void **state) { - execute_test(test_get_all_nodes_03, state); -} -/* Test Steps for get_all_nodes Test Case # 3 - Invalid case - - Test Steps: - 1. Passing NULL as pointer to node members argument for meshlink_get_all_nodes - - Expected Result: - Error reported correctly by returning NULL -*/ -static bool test_get_all_nodes_03(void) { - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("getallnodesconf", "nut", "node_sim", 1); - assert(mesh_handle); - assert(meshlink_start(mesh_handle)); - - meshlink_node_t **nodes = NULL; - nodes = meshlink_get_all_nodes(mesh_handle, nodes, NULL); - assert_int_equal(nodes, NULL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("getallnodesconf")); - - return true; -} - -int test_meshlink_get_all_nodes(void) { - const struct CMUnitTest blackbox_get_all_nodes[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_get_all_nodes_01, NULL, NULL, - (void *)&test_case_get_all_nodes_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_all_nodes_02, NULL, NULL, - (void *)&test_case_get_all_nodes_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_all_nodes_03, NULL, NULL, - (void *)&test_case_get_all_nodes_03_state) - }; - total_tests += sizeof(blackbox_get_all_nodes) / sizeof(blackbox_get_all_nodes[0]); - - return cmocka_run_group_tests(blackbox_get_all_nodes, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.h b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.h deleted file mode 100644 index 898114a..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_GET_ALL_NODES_H -#define TEST_CASES_GET_ALL_NODES_H - -/* - test_cases_get_all_nodes.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_get_all_nodes(void); - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c deleted file mode 100644 index f3c73a9..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - test_cases_get_all_nodes_by_dev_class.c.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_get_all_nodes_by_dev_class.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_mesh_get_node_by_dev_class_01(void **state); -static bool test_steps_mesh_get_node_by_dev_class_01(void); -static void test_case_mesh_get_node_by_dev_class_02(void **state); -static bool test_steps_mesh_get_node_by_dev_class_02(void); -static void test_case_mesh_get_node_dev_class_01(void **state); -static bool test_steps_mesh_get_node_dev_class_01(void); -static void test_case_mesh_get_node_dev_class_02(void **state); -static bool test_steps_mesh_get_node_dev_class_02(void); - -/* State structure for meshlink_get_node Test Case #1 */ -static black_box_state_t test_mesh_get_node_by_dev_class_01_state = { - .test_case_name = "test_case_mesh_get_node_by_dev_class_01", -}; - -/* State structure for meshlink_get_node Test Case #2 */ -static black_box_state_t test_mesh_get_node_by_dev_class_02_state = { - .test_case_name = "test_case_mesh_get_node_by_dev_class_02", -}; - -/* State structure for meshlink_get_node Test Case #3 */ -static black_box_state_t test_mesh_get_node_01_state = { - .test_case_name = "test_mesh_get_node_01_state", -}; - -/* State structure for meshlink_get_node Test Case #4 */ -static black_box_state_t test_mesh_get_node_02_state = { - .test_case_name = "test_mesh_get_node_02_state", -}; - -static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - - static const char *levelstr[] = { - [MESHLINK_DEBUG] = "\x1b[34mDEBUG", - [MESHLINK_INFO] = "\x1b[32mINFO", - [MESHLINK_WARNING] = "\x1b[33mWARNING", - [MESHLINK_ERROR] = "\x1b[31mERROR", - [MESHLINK_CRITICAL] = "\x1b[31mCRITICAL", - }; - - fprintf(stderr, "%s(%s):\x1b[0m %s\n", mesh->name, levelstr[level], text); -} - -/* Execute meshlink_get_node Test Case # 1 */ -static void test_case_mesh_get_node_by_dev_class_01(void **state) { - execute_test(test_steps_mesh_get_node_by_dev_class_01, state); -} - -/* Test Steps for meshlink_get_node Test Case # 1 - - Test Steps: - 1. Open nut, peer1, relay1, relay2, relay3 node instances, export and - import the configuration of NUT with other nodes. - 2. Run the node instances. - 3. Call meshlink_get_all_nodes_by_dev_class API with NULL as nodes array parameter - for DEV_CLASS_STATIONARY - 4. Call meshlink_get_all_nodes_by_dev_class API with previously allocated nodes array - parameter for DEV_CLASS_BACKBONE - 5. Call meshlink_get_all_nodes_by_dev_class API with previously allocated nodes array - parameter for DEV_CLASS_PORTABLE - - Expected Result: - meshlink_get_all_nodes_by_dev_class API should return appropriate node array pointer and - node member parameter when called and return accordingly. -*/ -static bool test_steps_mesh_get_node_by_dev_class_01(void) { - meshlink_node_t **nodes; - size_t nnodes = 0, i; - - /* Create meshlink instance for NUT */ - meshlink_handle_t *mesh_nut = meshlink_open("getnodeconf.1", "nut", "node_sim", DEV_CLASS_STATIONARY); - assert(mesh_nut); - meshlink_set_log_cb(mesh_nut, TEST_MESHLINK_LOG_LEVEL, log_message); - - /* Create meshlink instance for peer1 */ - meshlink_handle_t *mesh_peer1 = meshlink_open("getnodeconf.2", "peer1", "node_sim", DEV_CLASS_STATIONARY); - assert(mesh_peer1); - meshlink_set_log_cb(mesh_peer1, TEST_MESHLINK_LOG_LEVEL, log_message); - - /* Create meshlink instance for relay1 */ - meshlink_handle_t *mesh_relay1 = meshlink_open("getnodeconf.3", "relay1", "node_sim", DEV_CLASS_BACKBONE); - assert(mesh_relay1); - meshlink_set_log_cb(mesh_relay1, TEST_MESHLINK_LOG_LEVEL, log_message); - - /* Create meshlink instance for relay2 */ - meshlink_handle_t *mesh_relay2 = meshlink_open("getnodeconf.4", "relay2", "node_sim", DEV_CLASS_BACKBONE); - assert(mesh_relay2); - meshlink_set_log_cb(mesh_relay2, TEST_MESHLINK_LOG_LEVEL, log_message); - - /* Create meshlink instance for relay3 */ - meshlink_handle_t *mesh_relay3 = meshlink_open("getnodeconf.5", "relay3", "node_sim", DEV_CLASS_BACKBONE); - assert(mesh_relay3); - meshlink_set_log_cb(mesh_relay3, TEST_MESHLINK_LOG_LEVEL, log_message); - - /* importing and exporting mesh meta data */ - char *exp_nut = meshlink_export(mesh_nut); - assert(exp_nut != NULL); - char *export = meshlink_export(mesh_peer1); - assert(export != NULL); - assert(meshlink_import(mesh_nut, export)); - assert(meshlink_import(mesh_peer1, exp_nut)); - free(export); - - export = meshlink_export(mesh_relay1); - assert(export != NULL); - assert(meshlink_import(mesh_nut, export)); - assert(meshlink_import(mesh_relay1, exp_nut)); - free(export); - - export = meshlink_export(mesh_relay2); - assert(export != NULL); - assert(meshlink_import(mesh_nut, export)); - assert(meshlink_import(mesh_relay2, exp_nut)); - free(export); - - export = meshlink_export(mesh_relay3); - assert(export != NULL); - assert(meshlink_import(mesh_nut, export)); - assert(meshlink_import(mesh_relay3, exp_nut)); - free(export); - free(exp_nut); - - nodes = meshlink_get_all_nodes_by_dev_class(mesh_nut, DEV_CLASS_STATIONARY, NULL, &nnodes); - assert_int_not_equal(nodes, NULL); - assert_int_equal(nnodes, 2); - - for(i = 0; i < nnodes; i++) { - if(strcasecmp(nodes[i]->name, "nut") && strcasecmp(nodes[i]->name, "peer1")) { - fail(); - } - } - - nodes = meshlink_get_all_nodes_by_dev_class(mesh_nut, DEV_CLASS_BACKBONE, nodes, &nnodes); - assert_int_not_equal(nodes, NULL); - assert_int_equal(nnodes, 3); - - for(i = 0; i < nnodes; i++) { - if(strcasecmp(nodes[i]->name, "relay1") && strcasecmp(nodes[i]->name, "relay2") && strcasecmp(nodes[i]->name, "relay3")) { - fail(); - } - } - - nodes = meshlink_get_all_nodes_by_dev_class(mesh_nut, DEV_CLASS_PORTABLE, nodes, &nnodes); - assert_int_equal(nodes, NULL); - assert_int_equal(nnodes, 0); - assert_int_equal(meshlink_errno, 0); - - free(nodes); - meshlink_close(mesh_nut); - meshlink_close(mesh_peer1); - meshlink_close(mesh_relay1); - meshlink_close(mesh_relay2); - meshlink_close(mesh_relay3); - - return true; -} - -/* Execute meshlink_get_node Test Case # 2 - Invalid case - Passing invalid parameters as input arguments */ -static void test_case_mesh_get_node_by_dev_class_02(void **state) { - execute_test(test_steps_mesh_get_node_by_dev_class_02, state); -} - -/* Test Steps for meshlink_get_node Test Case # 2 - - Test Steps: - 1. Create NUT - 2. Call meshlink_get_all_nodes_by_dev_class API with invalid parameters - - Expected Result: - meshlink_get_all_nodes_by_dev_class API should return NULL and set appropriate - meshlink_errno. -*/ -static bool test_steps_mesh_get_node_by_dev_class_02(void) { - meshlink_node_t **nodes; - size_t nnodes = 0; - - assert(meshlink_destroy("getnodeconf.1")); - - /* Create meshlink instance for NUT */ - meshlink_handle_t *mesh_nut = meshlink_open("getnodeconf.1", "nut", "node_sim", DEV_CLASS_STATIONARY); - assert(mesh_nut); - meshlink_set_log_cb(mesh_nut, TEST_MESHLINK_LOG_LEVEL, log_message); - - nodes = meshlink_get_all_nodes_by_dev_class(mesh_nut, DEV_CLASS_COUNT + 10, NULL, &nnodes); - assert_int_equal(nodes, NULL); - assert_int_not_equal(meshlink_errno, 0); - - nodes = meshlink_get_all_nodes_by_dev_class(mesh_nut, DEV_CLASS_STATIONARY, NULL, NULL); - assert_int_equal(nodes, NULL); - assert_int_not_equal(meshlink_errno, 0); - - nodes = meshlink_get_all_nodes_by_dev_class(NULL, DEV_CLASS_STATIONARY, NULL, &nnodes); - assert_int_equal(nodes, NULL); - assert_int_not_equal(meshlink_errno, 0); - - meshlink_close(mesh_nut); - assert(meshlink_destroy("getnodeconf.1")); - return true; -} - -/* Execute meshlink_get_node_dev_class Test Case # 1 */ -static void test_case_mesh_get_node_dev_class_01(void **state) { - execute_test(test_steps_mesh_get_node_dev_class_01, state); -} - -/* Test Steps for meshlink_get_node_dev_class Test Case # 1 - - Test Steps: - 1. Create NUT node with DEV_CLASS_STATIONARY device class and obtain node handle - 2. Call meshlink_get_node_dev_class API - - Expected Result: - meshlink_get_node_dev_class API should return DEV_CLASS_STATIONARY device class -*/ -static bool test_steps_mesh_get_node_dev_class_01(void) { - assert(meshlink_destroy("getnodeconf.1")); - - /* Create meshlink instance for NUT */ - meshlink_handle_t *mesh_nut = meshlink_open("getnodeconf.1", "nut", "node_sim", DEV_CLASS_STATIONARY); - assert(mesh_nut); - meshlink_set_log_cb(mesh_nut, TEST_MESHLINK_LOG_LEVEL, log_message); - - meshlink_node_t *node; - node = meshlink_get_self(mesh_nut); - assert(node); - - dev_class_t dev_class = meshlink_get_node_dev_class(mesh_nut, node); - assert_int_equal(dev_class, DEV_CLASS_STATIONARY); - - meshlink_close(mesh_nut); - assert(meshlink_destroy("getnodeconf.1")); - return true; -} - -/* Execute meshlink_get_node_dev_class Test Case # 2 */ -static void test_case_mesh_get_node_dev_class_02(void **state) { - execute_test(test_steps_mesh_get_node_dev_class_02, state); -} - -/* Test Steps for meshlink_get_node_dev_class Test Case # 2 - - Test Steps: - 1. Create NUT and obtain NUT node handle - 2. Call meshlink_get_node_dev_class API with invalid parameters - - Expected Result: - meshlink_get_node_dev_class API should return NULL and set appropriate - meshlink_errno. -*/ -static bool test_steps_mesh_get_node_dev_class_02(void) { - assert(meshlink_destroy("getnodeconf.1")); - - /* Create meshlink instance for NUT */ - meshlink_handle_t *mesh_nut = meshlink_open("getnodeconf.1", "nut", "node_sim", DEV_CLASS_STATIONARY); - assert(mesh_nut); - meshlink_set_log_cb(mesh_nut, TEST_MESHLINK_LOG_LEVEL, log_message); - - meshlink_node_t *node; - node = meshlink_get_self(mesh_nut); - assert(node); - - int dev_class = meshlink_get_node_dev_class(NULL, node); - assert_int_equal(dev_class, -1); - assert_int_not_equal(meshlink_errno, 0); - - dev_class = meshlink_get_node_dev_class(mesh_nut, NULL); - assert_int_equal(dev_class, -1); - assert_int_not_equal(meshlink_errno, 0); - - meshlink_close(mesh_nut); - assert(meshlink_destroy("getnodeconf.1")); - return true; -} - -static int black_box_setup_test_case(void **state) { - (void)state; - - fprintf(stderr, "Destroying confbases\n"); - assert(meshlink_destroy("getnodeconf.1")); - assert(meshlink_destroy("getnodeconf.2")); - assert(meshlink_destroy("getnodeconf.3")); - assert(meshlink_destroy("getnodeconf.4")); - assert(meshlink_destroy("getnodeconf.5")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_errno = MESHLINK_OK; - - return 0; -} - -int test_meshlink_get_all_node_by_device_class(void) { - const struct CMUnitTest blackbox_get_node_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_by_dev_class_01, black_box_setup_test_case, black_box_setup_test_case, - (void *)&test_mesh_get_node_by_dev_class_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_by_dev_class_02, NULL, NULL, - (void *)&test_mesh_get_node_by_dev_class_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_dev_class_01, NULL, NULL, - (void *)&test_mesh_get_node_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_dev_class_02, NULL, NULL, - (void *)&test_mesh_get_node_02_state), - }; - - total_tests += sizeof(blackbox_get_node_tests) / sizeof(blackbox_get_node_tests[0]); - - return cmocka_run_group_tests(blackbox_get_node_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.h b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.h deleted file mode 100644 index 127a87d..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_GET_ALL_NODES_BY_DEV_CLASS_H -#define TEST_CASES_GET_ALL_NODES_BY_DEV_CLASS_H - - -/* - test_cases_get_all_nodes_by_dev_class.c.h -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_get_all_node_by_device_class(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c b/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c deleted file mode 100644 index 02cb4d6..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - test_cases_get_ex_addr.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_get_ex_addr.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_get_address_01(void **state); -static bool test_steps_mesh_get_address_01(void); -static void test_case_mesh_get_address_02(void **state); -static bool test_steps_mesh_get_address_02(void); -static void test_case_mesh_get_address_03(void **state); -static bool test_steps_mesh_get_address_03(void); - -/* State structure for meshlink_get_external_address Test Case #1 */ -static black_box_state_t test_mesh_get_address_01_state = { - .test_case_name = "test_case_mesh_get_address_01", -}; - -/* State structure for meshlink_get_external_address Test Case #2 */ -static black_box_state_t test_mesh_get_address_02_state = { - .test_case_name = "test_case_mesh_get_address_02", -}; - -/* State structure for meshlink_get_external_address Test Case #3 */ -static black_box_state_t test_mesh_get_address_03_state = { - .test_case_name = "test_case_mesh_get_address_03", -}; - -/* Execute meshlink_get_external_address Test Case # 1 */ -static void test_case_mesh_get_address_01(void **state) { - execute_test(test_steps_mesh_get_address_01, state); -} - -/* Test Steps for meshlink_get_external_address Test Case # 1 - - Test Steps: - 1. Create an instance of the node & start it - 2. Get node's external address using meshlink_get_external_address - - Expected Result: - API returns the external address successfully. -*/ -static bool test_steps_mesh_get_address_01(void) { - meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - assert(meshlink_start(mesh)); - - char *addr = meshlink_get_external_address(mesh); - assert_int_not_equal(addr, NULL); - - free(addr); - meshlink_close(mesh); - assert(meshlink_destroy("getex_conf")); - return true; -} - -/* Execute meshlink_get_external_address Test Case # 2 */ -static void test_case_mesh_get_address_02(void **state) { - execute_test(test_steps_mesh_get_address_02, state); -} - -/* Test Steps for meshlink_get_external_address Test Case # 2 - - Test Steps: - 1. Obtain external address by passing NULL as mesh handle - to meshlink_get_external_address API - - Expected Result: - Return NULL by reporting error successfully. -*/ -static bool test_steps_mesh_get_address_02(void) { - char *ext = meshlink_get_external_address(NULL); - assert_int_equal(ext, NULL); - - return true; -} - -/* Execute meshlink_get_external_address Test Case # 3 */ -static void test_case_mesh_get_address_03(void **state) { - execute_test(test_steps_mesh_get_address_03, state); -} - -/* Test Steps for meshlink_get_external_address Test Case # 3 - Functionality test - - Test Steps: - 1. Create an instance of the node - 2. Get node's external address using meshlink_get_external_address - - Expected Result: - API returns the external address successfully even if the mesh is started. -*/ -static bool test_steps_mesh_get_address_03(void) { - meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - assert(meshlink_start(mesh)); - - char *addr = meshlink_get_external_address(mesh); - assert_int_not_equal(addr, NULL); - - free(addr); - meshlink_close(mesh); - assert(meshlink_destroy("getex_conf")); - return true; -} - -int test_meshlink_get_external_address(void) { - const struct CMUnitTest blackbox_get_ex_addr_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_01, NULL, NULL, - (void *)&test_mesh_get_address_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_02, NULL, NULL, - (void *)&test_mesh_get_address_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_03, NULL, NULL, - (void *)&test_mesh_get_address_03_state) - }; - total_tests += sizeof(blackbox_get_ex_addr_tests) / sizeof(blackbox_get_ex_addr_tests[0]); - - return cmocka_run_group_tests(blackbox_get_ex_addr_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.h b/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.h deleted file mode 100644 index ccd4bb9..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_GET_EX_ADDR_H -#define TEST_CASES_GET_EX_ADDR_H - -/* - test_cases_get_ex_addr.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_get_external_address(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c b/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c deleted file mode 100644 index 3435f6e..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - test_cases_get_fingerprint.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "test_cases_get_fingerprint.h" -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_get_fingerprint_cb_01(void **state); -static bool test_get_fingerprint_cb_01(void); -static void test_case_get_fingerprint_cb_02(void **state); -static bool test_get_fingerprint_cb_02(void); -static void test_case_get_fingerprint_cb_03(void **state); -static bool test_get_fingerprint_cb_03(void); - -/* State structure for get_fingerprint Test Case #1 */ -static black_box_state_t test_case_get_fingerprint_cb_01_state = { - .test_case_name = "test_case_get_fingerprint_cb_01", -}; -/* State structure for get_fingerprint Test Case #2 */ -static black_box_state_t test_case_get_fingerprint_cb_02_state = { - .test_case_name = "test_case_get_fingerprint_cb_02", -}; -/* State structure for get_fingerprint Test Case #3 */ -static black_box_state_t test_case_get_fingerprint_cb_03_state = { - .test_case_name = "test_case_get_fingerprint_cb_03", -}; - -/* Execute get_fingerprint Test Case # 1 - Valid Case of obtaing publickey of NUT */ -static void test_case_get_fingerprint_cb_01(void **state) { - execute_test(test_get_fingerprint_cb_01, state); -} -/* Test Steps for get_fingerprint Test Case # 1 - Valid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Get node handle for ourself(for NUT) and obtain fingerprint - - Expected Result: - Obtain fingerprint of NUT successfully. -*/ -static bool test_get_fingerprint_cb_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - char *fp = meshlink_get_fingerprint(mesh_handle, node); - assert_int_not_equal(fp, NULL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("getfingerprintconf")); - - return true; -} - -/* Execute get_fingerprint Test Case # 2 - Invalid Case - trying t0 obtain publickey of a node in a - mesh by passing NULL as mesh handle argument*/ -static void test_case_get_fingerprint_cb_02(void **state) { - execute_test(test_get_fingerprint_cb_02, state); -} - -/* Test Steps for get_fingerprint Test Case # 2 - Invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Get node handle for ourself(for NUT) - 3. Obtain fingerprint by passing NULL as mesh handle - - Expected Result: - Return NULL by reporting error successfully. -*/ -static bool test_get_fingerprint_cb_02(void) { - /* Set up logging for Meshlink */ - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - PRINT_TEST_CASE_MSG("Opening NUT\n"); - meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1); - assert(mesh_handle); - - /* Set up logging for Meshlink with the newly acquired Mesh Handle */ - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - /* Getting node handle for itself */ - meshlink_node_t *node = meshlink_get_self(mesh_handle); - assert(node != NULL); - - /* passing NULL as mesh handle for meshlink_get_fingerprint API */ - char *fp = meshlink_get_fingerprint(NULL, node); - assert_int_equal(fp, NULL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("getfingerprintconf")); - - return true; -} - -/* Execute get_fingerprint Test Case # 3 - Invalid Case - trying t0 obtain publickey of a node in a - mesh by passing NULL as node handle argument */ -static void test_case_get_fingerprint_cb_03(void **state) { - execute_test(test_get_fingerprint_cb_03, state); -} -/* Test Steps for get_fingerprint Test Case # 3 - Invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Get node handle for ourself(for NUT) - 3. Obtain fingerprint by passing NULL as node handle - - Expected Result: - Return NULL by reporting error successfully. -*/ -static bool test_get_fingerprint_cb_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("getfingerprintconf", "nut", "test", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - char *fp = meshlink_get_fingerprint(mesh_handle, NULL); - assert_int_equal(fp, NULL); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("getfingerprintconf")); - - return true; -} - -int test_meshlink_get_fingerprint(void) { - const struct CMUnitTest blackbox_get_fingerprint_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_01, NULL, NULL, - (void *)&test_case_get_fingerprint_cb_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_02, NULL, NULL, - (void *)&test_case_get_fingerprint_cb_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_fingerprint_cb_03, NULL, NULL, - (void *)&test_case_get_fingerprint_cb_03_state) - }; - - total_tests += sizeof(blackbox_get_fingerprint_tests) / sizeof(blackbox_get_fingerprint_tests[0]); - - return cmocka_run_group_tests(blackbox_get_fingerprint_tests, NULL, NULL); - -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.h b/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.h deleted file mode 100644 index dafc4bf..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_GET_FINGERPRINT_H -#define TEST_CASES_GET_FINGERPRINT_H - -/* - test_cases_get_fingerprint.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_get_fingerprint(void); -extern int total_tests; - -#endif // TEST_CASES_GET_FINGERPRINT_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_node.c b/test/blackbox/run_blackbox_tests/test_cases_get_node.c deleted file mode 100644 index a13b475..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_node.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - test_cases_get_node.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_get_node.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_mesh_get_node_01(void **state); -static bool test_steps_mesh_get_node_01(void); -static void test_case_mesh_get_node_02(void **state); -static bool test_steps_mesh_get_node_02(void); -static void test_case_mesh_get_node_03(void **state); -static bool test_steps_mesh_get_node_03(void); -static void test_case_mesh_get_node_04(void **state); -static bool test_steps_mesh_get_node_04(void); - -/* State structure for meshlink_get_node Test Case #1 */ -static black_box_state_t test_mesh_get_node_01_state = { - .test_case_name = "test_case_mesh_get_node_01", -}; - -/* State structure for meshlink_get_node Test Case #2 */ -static black_box_state_t test_mesh_get_node_02_state = { - .test_case_name = "test_case_mesh_get_node_02", -}; - -/* State structure for meshlink_get_node Test Case #3 */ -static black_box_state_t test_mesh_get_node_03_state = { - .test_case_name = "test_case_mesh_get_node_03", -}; - -/* State structure for meshlink_get_node Test Case #4 */ -static black_box_state_t test_mesh_get_node_04_state = { - .test_case_name = "test_case_mesh_get_node_04", -}; - -/* Execute meshlink_get_node Test Case # 1 */ -static void test_case_mesh_get_node_01(void **state) { - execute_test(test_steps_mesh_get_node_01, state); -} - -/* Test Steps for meshlink_get_node Test Case # 1 - - Test Steps: - 1. Open nodes instance - 2. Get node's handle - - Expected Result: - node handle of it's own is obtained -*/ -static bool test_steps_mesh_get_node_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_destroy("getnode1")); - assert(meshlink_destroy("getnode2")); - - // Opening NUT and bar nodes - meshlink_handle_t *mesh1 = meshlink_open("getnode1", "nut", "test", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("getnode2", "bar", "test", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Exporting and Importing mutually - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - bool imp1 = meshlink_import(mesh1, exp2); - assert(imp1); - bool imp2 = meshlink_import(mesh2, exp1); - assert(imp2); - - // Get node handles - meshlink_node_t *get_node = meshlink_get_node(mesh1, "bar"); - assert_int_not_equal(get_node, NULL); - get_node = meshlink_get_node(mesh1, "nut"); - assert_int_not_equal(get_node, NULL); - - // Cleanup - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("getnode1")); - assert(meshlink_destroy("getnode2")); - return true; -} - -/* Execute meshlink_get_node Test Case # 2 */ -static void test_case_mesh_get_node_02(void **state) { - execute_test(test_steps_mesh_get_node_02, state); -} - -/* Test Steps for meshlink_get_node Test Case # 2 - - Test Steps: - 1. Get node handles by passing NULL as mesh handle argument - - Expected Result: - Reports error successfully by returning NULL -*/ -static bool test_steps_mesh_get_node_02(void) { - meshlink_node_t *get_node = meshlink_get_node(NULL, "foo"); - assert_int_equal(get_node, NULL); - - return true; -} - -/* Execute meshlink_get_node Test Case # 3 */ -static void test_case_mesh_get_node_03(void **state) { - execute_test(test_steps_mesh_get_node_03, state); -} - -/* Test Steps for meshlink_get_node Test Case # 3 - - Test Steps: - 1. Get node handles by passing NULL as node name argument - - Expected Result: - Reports error successfully by returning NULL -*/ -static bool test_steps_mesh_get_node_03(void) { - meshlink_handle_t *mesh = meshlink_open("node_conf.3", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh); - assert(meshlink_start(mesh)); - - meshlink_node_t *get_node = meshlink_get_node(mesh, NULL); - assert_int_equal(get_node, NULL); - - meshlink_close(mesh); - assert(meshlink_destroy("node_conf.3")); - return true; -} - -/* Execute meshlink_get_node Test Case # 4 */ -static void test_case_mesh_get_node_04(void **state) { - execute_test(test_steps_mesh_get_node_04, state); -} - -/* Test Steps for meshlink_get_node Test Case # 4 - - Test Steps: - 1. Open node instance - 2. Get node handle with the name of the node - that's not in the mesh - - Expected Result: - Reports error successfully by returning NULL -*/ -static bool test_steps_mesh_get_node_04(void) { - meshlink_handle_t *mesh = meshlink_open("node_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh); - assert(meshlink_start(mesh)); - - const char *nonexisting_node = "bar"; - meshlink_node_t *get_node = meshlink_get_node(mesh, nonexisting_node); - assert_int_equal(get_node, NULL); - - meshlink_close(mesh); - assert(meshlink_destroy("node_conf")); - return true; -} - -int test_meshlink_get_node(void) { - const struct CMUnitTest blackbox_get_node_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_01, NULL, NULL, - (void *)&test_mesh_get_node_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_02, NULL, NULL, - (void *)&test_mesh_get_node_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_03, NULL, NULL, - (void *)&test_mesh_get_node_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_node_04, NULL, NULL, - (void *)&test_mesh_get_node_04_state) - }; - - total_tests += sizeof(blackbox_get_node_tests) / sizeof(blackbox_get_node_tests[0]); - - return cmocka_run_group_tests(blackbox_get_node_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_node.h b/test/blackbox/run_blackbox_tests/test_cases_get_node.h deleted file mode 100644 index 7d5eb41..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_node.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_GET_NODE_H -#define TEST_CASES_GET_NODE_H - -/* - test_cases_get_node.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_get_node(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.c b/test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.c deleted file mode 100644 index d5ae46f..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.c +++ /dev/null @@ -1,960 +0,0 @@ -/* - test_cases_get_node_reachability.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_get_node_reachability.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" - -#define NUT "nut" -#define PEER "peer" -#define PEER2 "peer2" -#define GET_NODE_REACHABILITY "test_get_node_reachability" -#define create_path(confbase, node_name, test_case_no) assert(snprintf(confbase, sizeof(confbase), GET_NODE_REACHABILITY "_%ld_%s_%02d", (long) getpid(), node_name, test_case_no) > 0) - -static struct sync_flag peer_reachable_status_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static bool peer_reachable_status; -static struct sync_flag nut_reachable_status_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static bool nut_reachable_status; -static struct sync_flag nut_started_status_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static bool peer_node_callback_test_status; - -static void test_case_get_node_reachability_01(void **state); -static bool test_get_node_reachability_01(void); -static void test_case_get_node_reachability_02(void **state); -static bool test_get_node_reachability_02(void); -static void test_case_get_node_reachability_03(void **state); -static bool test_get_node_reachability_03(void); -static void test_case_get_node_reachability_04(void **state); -static bool test_get_node_reachability_04(void); -static void test_case_get_node_reachability_05(void **state); -static bool test_get_node_reachability_05(void); -static void test_case_get_node_reachability_06(void **state); -static bool test_get_node_reachability_06(void); -static void test_case_get_node_reachability_07(void **state); -static bool test_get_node_reachability_07(void); - -/* Node reachable status callback which signals the respective conditional varibale */ -static void meshlink_node_reachable_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable_status) { - if(meshlink_get_self(mesh) == node) { - return; - } - - if(!strcasecmp(mesh->name, NUT)) { - if(!strcasecmp(node->name, PEER)) { - peer_reachable_status = reachable_status; - set_sync_flag(&peer_reachable_status_cond, true); - } - } else if(!strcasecmp(mesh->name, PEER)) { - if(!strcasecmp(node->name, NUT)) { - nut_reachable_status = reachable_status; - set_sync_flag(&nut_reachable_status_cond, true); - } - } - - // Reset the node reachability status callback, as the two nodes making a simultaneous connection to each other, and then one connection will win and cause the other one to be disconnected. - meshlink_set_node_status_cb(mesh, NULL); -} - -static void meshlink_node_reachable_status_cb_2(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable_status) { - meshlink_node_t *peer_handle; - char *peer_name = NULL; - time_t last_unreachable, last_reachable; - static int count = 2; - - if(meshlink_get_self(mesh) == node) { - return; - } - - /* Of the 2 node reachable callbacks, the latest callback calls meshlink_get_node_reachability API - for the 1st node joined */ - if(count && reachable_status && !strcasecmp(mesh->name, NUT)) { - --count; - - if(!count) { - if(!strcasecmp(node->name, PEER)) { - peer_name = PEER2; - } else if(!strcasecmp(node->name, PEER2)) { - peer_name = PEER; - } - - peer_handle = meshlink_get_node(mesh, peer_name); - assert_non_null(peer_handle); - - bool status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - - peer_node_callback_test_status = status && last_reachable && !last_unreachable; - set_sync_flag(&peer_reachable_status_cond, true); - } - } -} - -/* SIGUSR2 signal handler that signals the NUT started and PEER node can join */ -void nut_started_user_signal_handler(int signum) { - if(signum == SIGUSR2) { - set_sync_flag(&nut_started_status_cond, true); - } - -} - -/* - Execute meshlink get last node reachability times feature Test Case # 1 - - Sanity API test -*/ -static void test_case_get_node_reachability_01(void **state) { - execute_test(test_get_node_reachability_01, state); -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 1 - - Test steps and scenarios: - 1. Open Node-Under-Test (NUT) instance, Call meshlink_get_node_reachability API - with valid mesh handle, self node handle, last_reachable pointer and - last_unreachable pointer. - Expected Result: - API returns self node unreachable, last_reachable and last_unreachable values - as 0 seconds - - 2. Call meshlink_get_node_reachability API with valid mesh handle, self node handle. - But pass NULL pointers for last_reachable and last_unreachable arguments - Expected Result: - API returns self node unreachable - - 3. Call meshlink_get_node_reachability API with NULL as mesh handle, - valid self node handle, last_reachable pointer and last_unreachable pointer. - Expected Result: - API fails and sets MESHLINK_EINVAL as meshlink errno value - - 4. Call meshlink_get_node_reachability API with NULL as mesh handle, - valid self node handle, NULL pointers for last_reachable and last_unreachable - arguments - Expected Result: - API fails and sets MESHLINK_EINVAL as meshlink errno value - - 5. Call meshlink_get_node_reachability API with valid mesh handle, - NULL as self node handle, last_reachable pointer and last_unreachable pointer. - Expected Result: - API fails and sets MESHLINK_EINVAL as meshlink errno value - - 6. Call meshlink_get_node_reachability API with valid mesh handle, - NULL as self node handle, NULL pointers for last_reachable and last_unreachable - arguments - Expected Result: - API fails and sets MESHLINK_EINVAL as meshlink errno value - -*/ -static bool test_get_node_reachability_01(void) { - bool status; - time_t last_unreachable, last_reachable; - char nut_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 1); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open Node-Under-Test node instance - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_int_not_equal(mesh, NULL); - - // Call meshlink_get_node_reachability API with all valid arguments - - status = meshlink_get_node_reachability(mesh, meshlink_get_self(mesh), &last_reachable, &last_unreachable); - assert_int_equal(status, false); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Call meshlink_get_node_reachability API with all valid arguments - - status = meshlink_get_node_reachability(mesh, meshlink_get_self(mesh), NULL, NULL); - assert_int_equal(status, false); - - // Call meshlink_get_node_reachability API with invalid parameters - - meshlink_errno = MESHLINK_OK; - meshlink_get_node_reachability(NULL, meshlink_get_self(mesh), NULL, NULL); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - meshlink_errno = MESHLINK_OK; - meshlink_get_node_reachability(NULL, meshlink_get_self(mesh), &last_reachable, &last_unreachable); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - meshlink_errno = MESHLINK_OK; - meshlink_get_node_reachability(mesh, NULL, NULL, NULL); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - meshlink_errno = MESHLINK_OK; - meshlink_get_node_reachability(mesh, NULL, &last_reachable, &last_unreachable); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Cleanup - - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* - Execute meshlink get last node reachability times feature Test Case # 2 - - API testing with stand-alone node -*/ -static void test_case_get_node_reachability_02(void **state) { - execute_test(test_get_node_reachability_02, state); -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 2 - - Test steps and scenarios: - 1. Open and start Node-Under-Test (NUT) instance, Call meshlink_get_node_reachability API. - Expected Result: - API returns self node reachable status, last_reachable as some positive non-zero integer - and last_unreachable value as 0 seconds - - 2. Stop the NUT instance, Call meshlink_get_node_reachability API. - Expected Result: - API returns self node unreachable, both last_reachable and last_unreachable values - as some positive non-zero time in seconds - - 3. Close and reopen NUT instance, Call meshlink_get_node_reachability API. - Expected Result: - API returns self node unreachable, both last_reachable and last_unreachable values - as some positive non-zero time in seconds - -*/ -static bool test_get_node_reachability_02(void) { - bool status; - time_t last_unreachable, last_reachable, last_peer_unreachable, last_peer_reachable; - char nut_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 2); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open and start Node-Under-Test node instance - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - assert_true(meshlink_start(mesh)); - - // Call meshlink_get_node_reachability API with all valid arguments - - status = meshlink_get_node_reachability(mesh, meshlink_get_self(mesh), &last_reachable, &last_unreachable); - assert_true(status); - assert_int_not_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - last_peer_reachable = last_reachable; - - // Stop NUT node instance - - meshlink_stop(mesh); - - // Call meshlink_get_node_reachability API with all valid arguments - - status = meshlink_get_node_reachability(mesh, meshlink_get_self(mesh), &last_reachable, &last_unreachable); - assert_false(status); - assert_int_not_equal(last_unreachable, 0); - assert_int_equal(last_reachable, last_peer_reachable); - last_peer_unreachable = last_unreachable; - - // Reinitialize NUT node instance - - meshlink_close(mesh); - mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - // Call meshlink_get_node_reachability API with all valid arguments - - status = meshlink_get_node_reachability(mesh, meshlink_get_self(mesh), &last_reachable, &last_unreachable); - assert_false(status); - assert_int_equal(last_reachable, last_peer_reachable); - assert_int_equal(last_unreachable, last_peer_unreachable); - - // Cleanup - - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* - Execute meshlink get last node reachability times feature Test Case # 3 - - API testing with host node which already joined with a peer node which later - goes offline, test host node with an offline peer node case. -*/ -static void test_case_get_node_reachability_03(void **state) { - execute_test(test_get_node_reachability_03, state); -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 3 - - Test steps and scenarios: - 1. Open Node-Under-Test (NUT) and peer node instance, start peer node instance - and invite NUT. NUT joins peer and destroy peer node instance. - Call meshlink_get_node_reachability API. - Expected Result: - API returns peer node unreachable status, last_reachable and last_unreachable - value as 0 seconds. - - 2. Start the NUT instance, Call meshlink_get_node_reachability API. - Expected Result: - API returns peer node unreachable status, last_reachable and last_unreachable - value as 0 seconds. - - 3. Stop the NUT instance, Call meshlink_get_node_reachability API. - Expected Result: - API returns peer node unreachable status, last_reachable and last_unreachable - value as 0 seconds. - - 4. Close and reopen NUT instance, Call meshlink_get_node_reachability API. - Expected Result: - API returns peer node unreachable status, last_reachable and last_unreachable - value as 0 seconds. - -*/ -static bool test_get_node_reachability_03(void) { - bool status; - time_t last_unreachable, last_reachable; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 3); - create_path(peer_confbase, PEER, 3); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open and start peer node instance, invite NUT. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - assert_true(meshlink_start(mesh_peer)); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - - // Open NUT node instance and join with the peer node - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - assert_true(meshlink_join(mesh, invitation)); - free(invitation); - meshlink_node_t *peer_handle = meshlink_get_node(mesh, PEER); - assert_non_null(peer_handle); - - // Cleanup peer node instance - - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(peer_confbase)); - - // Call meshlink_get_node_reachability API with valid arguments - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Start NUT node instance - - assert_true(meshlink_start(mesh)); - - // Call meshlink_get_node_reachability API with valid arguments - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Stop NUT node instance - - meshlink_stop(mesh); - - // Call meshlink_get_node_reachability API with valid arguments - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Reinitialize NUT node instance - - meshlink_close(mesh); - mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - peer_handle = meshlink_get_node(mesh, PEER); - assert_non_null(peer_handle); - - // Call meshlink_get_node_reachability API with valid arguments - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Cleanup NUT - - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* - Execute meshlink get last node reachability times feature Test Case # 4 - - API testing around invited and invitee node. -*/ -static void test_case_get_node_reachability_04(void **state) { - execute_test(test_get_node_reachability_04, state); -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 4 - - Test steps and scenarios: - 1. Open Node-Under-Test (NUT) and peer node instance, join both the node and - bring them online. Call meshlink_get_node_reachability API from both the nodes. - Expected Result: - API for both the nodes returns reachable status, last_reachable should be - some non-zero positive seconds and last_unreachable should be 0 seconds. - - 2. Stop both the node instances, Call meshlink_get_node_reachability API from both the nodes. - Expected Result: - API for both the nodes returns unreachable status. last_reachable should match with - the old value and last_unreachable should be non-zero positive value. - - 3. Restart both the node instances, Call meshlink_get_node_reachability APIs. - Expected Result: - API for both the nodes should return reachable status. last_reachable should not match with - the old value, but last_unreachable should remain same - - 4. Close and reopen both the node instances, Call meshlink_get_node_reachability APIs. - Expected Result: - API returns self node unreachable status, last_reachable should remain same - but last_unreachable should vary. - - 4. Start both the node instances, Call meshlink_get_node_reachability APIs. - Expected Result: - API returns self node reachable status, last_reachable should vary and - last_unreachable remains same. - -*/ -static bool test_get_node_reachability_04(void) { - bool status; - time_t last_nut_unreachable, last_nut_reachable; - time_t last_peer_unreachable, last_peer_reachable; - time_t last_reachable, last_unreachable; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 4); - create_path(peer_confbase, PEER, 4); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open both NUT and peer node instance, invite and join NUT with peer node. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - assert_true(meshlink_start(mesh_peer)); - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - assert_true(meshlink_join(mesh, invitation)); - free(invitation); - - meshlink_node_t *peer_handle = meshlink_get_node(mesh, PEER); - assert_non_null(peer_handle); - meshlink_node_t *nut_handle = meshlink_get_node(mesh_peer, NUT); - assert_non_null(nut_handle); - - // Bring nodes online. - - set_sync_flag(&peer_reachable_status_cond, false); - set_sync_flag(&nut_reachable_status_cond, false); - assert_true(meshlink_start(mesh)); - assert_true(wait_sync_flag(&peer_reachable_status_cond, 60)); - assert_true(peer_reachable_status); - assert_true(wait_sync_flag(&nut_reachable_status_cond, 60)); - assert_true(nut_reachable_status); - - // Call meshlink_get_node_reachability API from joined node and also from joining node. - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_true(status); - assert_int_not_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - last_peer_reachable = last_reachable; - - status = meshlink_get_node_reachability(mesh_peer, nut_handle, &last_reachable, &last_unreachable); - assert_true(status); - assert_int_not_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - last_nut_reachable = last_reachable; - - // Stop the node instances of both peer and NUT. - - meshlink_stop(mesh); - meshlink_stop(mesh_peer); - - // Call meshlink_get_node_reachability API from joined node and also from joining node. - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_not_equal(last_unreachable, 0); - assert_int_equal(last_reachable, last_peer_reachable); - last_peer_unreachable = last_unreachable; - - status = meshlink_get_node_reachability(mesh_peer, nut_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_not_equal(last_unreachable, 0); - assert_int_equal(last_reachable, last_nut_reachable); - last_nut_unreachable = last_unreachable; - - // Restart the node instances of both peer and NUT and wait for nodes to come online - - sleep(2); - set_sync_flag(&peer_reachable_status_cond, false); - set_sync_flag(&nut_reachable_status_cond, false); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - assert_true(meshlink_start(mesh)); - assert_true(meshlink_start(mesh_peer)); - - assert_true(wait_sync_flag(&peer_reachable_status_cond, 60)); - assert_true(peer_reachable_status); - assert_true(wait_sync_flag(&nut_reachable_status_cond, 60)); - assert_true(nut_reachable_status); - - // Call meshlink_get_node_reachability API from joined node and also from joining node. - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_true(status); - assert_int_not_equal(last_reachable, last_peer_reachable); - assert_true(last_unreachable >= last_peer_unreachable); - last_peer_reachable = last_reachable; - - status = meshlink_get_node_reachability(mesh_peer, nut_handle, &last_reachable, &last_unreachable); - assert_true(status); - assert_int_not_equal(last_reachable, last_nut_reachable); - assert_true(last_unreachable >= last_nut_unreachable); - last_nut_reachable = last_reachable; - - // Reinitialize the node instances of both peer and NUT - - meshlink_close(mesh); - meshlink_close(mesh_peer); - - sleep(2); - - mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - mesh_peer = meshlink_open(peer_confbase, PEER, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - - peer_handle = meshlink_get_node(mesh, PEER); - assert_non_null(peer_handle); - nut_handle = meshlink_get_node(mesh_peer, NUT); - assert_non_null(nut_handle); - - // Call meshlink_get_node_reachability API from joined node and also from joining node. - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_equal(last_reachable, last_peer_reachable); - assert_int_not_equal(last_unreachable, last_peer_unreachable); - last_peer_unreachable = last_unreachable; - - status = meshlink_get_node_reachability(mesh_peer, nut_handle, &last_reachable, &last_unreachable); - assert_false(status); - assert_int_equal(last_reachable, last_nut_reachable); - assert_int_not_equal(last_unreachable, last_nut_unreachable); - last_nut_unreachable = last_unreachable; - - // Restart the node instances of both peer and NUT - - set_sync_flag(&peer_reachable_status_cond, false); - set_sync_flag(&nut_reachable_status_cond, false); - - assert_true(meshlink_start(mesh)); - assert_true(meshlink_start(mesh_peer)); - - assert_true(wait_sync_flag(&peer_reachable_status_cond, 60)); - assert_true(peer_reachable_status); - assert_true(wait_sync_flag(&nut_reachable_status_cond, 60)); - assert_true(nut_reachable_status); - - // Call meshlink_get_node_reachability API from joined node and also from joining node. - - status = meshlink_get_node_reachability(mesh, peer_handle, &last_reachable, &last_unreachable); - assert_true(status); - assert_int_not_equal(last_reachable, last_peer_reachable); - assert_true(last_unreachable >= last_peer_unreachable); - - status = meshlink_get_node_reachability(mesh_peer, nut_handle, &last_reachable, &last_unreachable); - assert_true(status); - assert_int_not_equal(last_reachable, last_nut_reachable); - assert_true(last_unreachable >= last_nut_unreachable); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return true; -} - -/* - Execute meshlink get last node reachability times feature Test Case # 5 - - API testing by calling it in the meshlink callback(s) and also isolation property. -*/ -static void test_case_get_node_reachability_05(void **state) { - execute_test(test_get_node_reachability_05, state); -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 5 - - Test steps and scenarios: - 1. Open Node-Under-Test (NUT), peer and peer2 node instances. Join both the peer nodes - with NUT and bring them online. - Expected Result: - API called from the node reachable callback of the latest peer node from NUT - about other peer node which joined 1st should return reachable status, - last_reachable status as some positive non-zero value and last unreachable value as 0. - -*/ -static bool test_get_node_reachability_05(void) { - char *invitation; - bool status; - time_t last_reachable, last_unreachable; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - char peer2_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 5); - create_path(peer_confbase, PEER, 5); - create_path(peer2_confbase, PEER2, 5); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open NUT, peer and peer2 and join peer nodes with NUT. - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb_2); - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_handle_t *mesh_peer2 = meshlink_open(peer2_confbase, PEER2, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer2); - - assert_true(meshlink_start(mesh)); - - invitation = meshlink_invite(mesh, NULL, PEER); - assert_non_null(invitation); - assert_true(meshlink_join(mesh_peer, invitation)); - invitation = meshlink_invite(mesh, NULL, PEER2); - assert_non_null(invitation); - assert_true(meshlink_join(mesh_peer2, invitation)); - - // Call meshlink_get_node_reachability API from NUT and check they remained 0 and unreachable - - status = meshlink_get_node_reachability(mesh, meshlink_get_node(mesh, PEER), &last_reachable, &last_unreachable); - assert_int_equal(status, false); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - status = meshlink_get_node_reachability(mesh, meshlink_get_node(mesh, PEER2), &last_reachable, &last_unreachable); - assert_int_equal(status, false); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Start and wait for the signal from the node reachable callback which is raised when - // NUT is able to call meshlink_get_node_reachability API from callback of other peer node. - - set_sync_flag(&peer_reachable_status_cond, false); - assert_true(meshlink_start(mesh_peer)); - assert_true(meshlink_start(mesh_peer2)); - assert_true(wait_sync_flag(&peer_reachable_status_cond, 60)); - assert_true(peer_node_callback_test_status); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - meshlink_close(mesh_peer2); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - assert_true(meshlink_destroy(peer2_confbase)); - return true; -} - -/* - Execute meshlink get last node reachability times feature Test Case # 6 - - Persistence testing on the joining node. -*/ -static void test_case_get_node_reachability_06(void **state) { - execute_test(test_get_node_reachability_06, state); -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 6 - - Test steps and scenarios: - 1. Open Node-Under-Test (NUT) and invite peer node and close it's instance. - Spawn a process which waits for the peer node to join and raises SIGINT if the - appropriate callback is received (on the other hand the test suite opens and joins - the peer node with NUT in the forked process). - Reopen NUT instance in the test suite process and call meshlink_get_node_reachability. - Expected Result: - API returns peer node unreachable, last_reachable and last_unreachable values - as 0 seconds. It is expected that this feature synchronize it at least for the first time - when the NUT receives that a new peer node joined. - -*/ -static bool test_get_node_reachability_06(void) { - bool status; - time_t last_reachable, last_unreachable; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 6); - create_path(peer_confbase, PEER, 6); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open NUT node instance and invite peer node. Close NUT node instance. - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - char *invitation = meshlink_invite(mesh, NULL, PEER); - meshlink_close(mesh); - - // Set the SIGUSR2 signal handler with handler that signal the condition to the test suite - - sighandler_t usr2sighandler = signal(SIGUSR2, nut_started_user_signal_handler); - assert_int_not_equal(usr2sighandler, SIG_ERR); - - // Fork a new process and run NUT in it which just waits for the peer node reachable status callback - // and terminates the process immediately. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - assert(signal(SIGUSR2, SIG_DFL) != SIG_ERR); - - mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - - set_sync_flag(&peer_reachable_status_cond, false); - assert(meshlink_start(mesh)); - - assert(kill(getppid(), SIGUSR2) != -1); - - assert(wait_sync_flag(&peer_reachable_status_cond, 60)); - assert(peer_reachable_status); - - raise(SIGINT); - } - - // Open peer node instance and join with the invitation obtained. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - - // Wait for the started signal from NUT and reset the previous SIGUSR2 signal handler - - assert_true(wait_sync_flag(&nut_started_status_cond, 60)); - assert_int_not_equal(signal(SIGUSR2, usr2sighandler), SIG_ERR); - - assert_true(meshlink_join(mesh_peer, invitation)); - assert_true(meshlink_start(mesh_peer)); - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - // Call meshlink_get_node_reachability API and verify that the time stamps has persisted. - - status = meshlink_get_node_reachability(mesh, meshlink_get_node(mesh, PEER), &last_reachable, &last_unreachable); - assert_int_equal(status, false); - assert_int_not_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return true; -} - -/* - Execute meshlink get last node reachability times feature Test Case # 7 - - Persistence testing on the invited node. -*/ -static void test_case_get_node_reachability_07(void **state) { - execute_test(test_get_node_reachability_07, state); -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 7 - - Test steps and scenarios: - 1. Open peer node instance, invite NUT and start peer node. Spawn a new process in - which it opens and joins the NUT with peer node. - Reopen NUT instance in the test suite process and call meshlink_get_node_reachability API. - Expected Result: - API returns peer node unreachable, last_reachable and last_unreachable values - as 0 seconds. It is expected that this feature synchronize it at least for the first time - when the Node-Under-Test joined with the peer node. - -*/ -static bool test_get_node_reachability_07(void) { - bool status; - time_t last_reachable, last_unreachable; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 7); - create_path(peer_confbase, PEER, 7); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open peer node instance and invite NUT. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, GET_NODE_REACHABILITY, - DEV_CLASS_STATIONARY); - assert_int_not_equal(mesh_peer, NULL); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - - assert_true(meshlink_start(mesh_peer)); - - // Fork a new process in which NUT is joins with the peer node and raises SIGINT to terminate. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - - assert(meshlink_join(mesh, invitation)); - - raise(SIGINT); - } - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, GET_NODE_REACHABILITY, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - // Call meshlink_get_node_reachability API and verify that the time stamps has persisted. - - status = meshlink_get_node_reachability(mesh, meshlink_get_node(mesh, PEER), &last_reachable, &last_unreachable); - assert_int_equal(status, false); - assert_int_equal(last_reachable, 0); - assert_int_equal(last_unreachable, 0); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return true; -} - -int test_get_node_reachability(void) { - /* State structures for get node reachability Test Cases */ - black_box_state_t test_case_get_node_reachability_01_state = { - .test_case_name = "test_case_get_node_reachability_01", - }; - black_box_state_t test_case_get_node_reachability_02_state = { - .test_case_name = "test_case_get_node_reachability_02", - }; - black_box_state_t test_case_get_node_reachability_03_state = { - .test_case_name = "test_case_get_node_reachability_03", - }; - black_box_state_t test_case_get_node_reachability_04_state = { - .test_case_name = "test_case_get_node_reachability_04", - }; - black_box_state_t test_case_get_node_reachability_05_state = { - .test_case_name = "test_case_get_node_reachability_05", - }; - black_box_state_t test_case_get_node_reachability_06_state = { - .test_case_name = "test_case_get_node_reachability_06", - }; - black_box_state_t test_case_get_node_reachability_07_state = { - .test_case_name = "test_case_get_node_reachability_07", - }; - - const struct CMUnitTest blackbox_status_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_get_node_reachability_01, NULL, NULL, - (void *)&test_case_get_node_reachability_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_node_reachability_02, NULL, NULL, - (void *)&test_case_get_node_reachability_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_node_reachability_03, NULL, NULL, - (void *)&test_case_get_node_reachability_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_node_reachability_04, NULL, NULL, - (void *)&test_case_get_node_reachability_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_node_reachability_05, NULL, NULL, - (void *)&test_case_get_node_reachability_05_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_node_reachability_06, NULL, NULL, - (void *)&test_case_get_node_reachability_06_state), - cmocka_unit_test_prestate_setup_teardown(test_case_get_node_reachability_07, NULL, NULL, - (void *)&test_case_get_node_reachability_07_state), - }; - total_tests += sizeof(blackbox_status_tests) / sizeof(blackbox_status_tests[0]); - - return cmocka_run_group_tests(blackbox_status_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.h b/test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.h deleted file mode 100644 index 72a6ea3..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_node_reachability.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef TEST_CASES_GET_NODE_REACHABILITY -#define TEST_CASES_GET_NODE_REACHABILITY - -/* - test_cases_get_node_reachability.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -extern int test_get_node_reachability(void); -extern int total_tests; - -#endif // TEST_CASES_GET_NODE_REACHABILITY diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_port.c b/test/blackbox/run_blackbox_tests/test_cases_get_port.c deleted file mode 100644 index 71f7cb4..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_port.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - test_cases_get_port.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_get_port.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_get_port_01(void **state); -static bool test_steps_mesh_get_port_01(void); -static void test_case_mesh_get_port_02(void **state); -static bool test_steps_mesh_get_port_02(void); - -/* State structure for meshlink_get_port Test Case #1 */ -static black_box_state_t test_mesh_get_port_01_state = { - .test_case_name = "test_case_mesh_get_port_01", -}; - -/* State structure for meshlink_get_port Test Case #2 */ -static black_box_state_t test_mesh_get_port_02_state = { - .test_case_name = "test_case_mesh_get_port_02", -}; - -/* Execute meshlink_get_port Test Case # 1 */ -static void test_case_mesh_get_port_01(void **state) { - execute_test(test_steps_mesh_get_port_01, state); -} - -/* Test Steps for meshlink_get_port Test Case # 1 - - Test Steps: - 1. Open node instance - 2. Run the node instance - 3. Obtain port of that mesh using meshlink_get_port API - - Expected Result: - API returns valid port number. -*/ -static bool test_steps_mesh_get_port_01(void) { - meshlink_handle_t *mesh = meshlink_open("port_conf", "foo", "chat", DEV_CLASS_STATIONARY); - assert(mesh); - assert(meshlink_start(mesh)); - - int port = meshlink_get_port(mesh); - assert_int_not_equal(port, -1); - - meshlink_close(mesh); - assert(meshlink_destroy("port_conf")); - return true; -} - -/* Execute meshlink_get_port Test Case # 2 */ -static void test_case_mesh_get_port_02(void **state) { - execute_test(test_steps_mesh_get_port_02, state); -} - -/* Test Steps for meshlink_get_port Test Case # 2 - Invalid case - - Test Steps: - 1. Pass NULL as mesh handle argument to meshlink_get_port API - - Expected Result: - Reports error successfully by returning -1 -*/ -static bool test_steps_mesh_get_port_02(void) { - int port = meshlink_get_port(NULL); - assert_int_equal(port, -1); - - return true; -} - -int test_meshlink_get_port(void) { - const struct CMUnitTest blackbox_get_port_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_port_01, NULL, NULL, - (void *)&test_mesh_get_port_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_port_02, NULL, NULL, - (void *)&test_mesh_get_port_02_state) - }; - - total_tests += sizeof(blackbox_get_port_tests) / sizeof(blackbox_get_port_tests[0]); - - return cmocka_run_group_tests(blackbox_get_port_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_port.h b/test/blackbox/run_blackbox_tests/test_cases_get_port.h deleted file mode 100644 index 0386a8a..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_port.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_GET_PORT_H -#define TEST_CASES_GET_PORT_H - -/* - test_cases_get_port.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_get_port(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_self.c b/test/blackbox/run_blackbox_tests/test_cases_get_self.c deleted file mode 100644 index 3368a42..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_self.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - test_cases_get_port.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_get_self.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_get_self_01(void **state); -static bool test_steps_mesh_get_self_01(void); -static void test_case_mesh_get_self_02(void **state); -static bool test_steps_mesh_get_self_02(void); - -/* State structure for meshlink_get_self Test Case #1 */ -static black_box_state_t test_mesh_get_self_01_state = { - .test_case_name = "test_case_mesh_get_self_01", -}; - -/* State structure for meshlink_get_self Test Case #2 */ -static black_box_state_t test_mesh_get_self_02_state = { - .test_case_name = "test_case_mesh_get_self_02", -}; - -/* Execute meshlink_get_self Test Case # 1 */ -static void test_case_mesh_get_self_01(void **state) { - execute_test(test_steps_mesh_get_self_01, state); -} - -/* Test Steps for meshlink_get_self Test Case # 1 - - Test Steps: - 1. Open node instance - 2. Get node's self handle - - Expected Result: - node handle of it's own is obtained -*/ -static bool test_steps_mesh_get_self_01(void) { - meshlink_handle_t *mesh = meshlink_open("self_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh); - - assert(meshlink_start(mesh)); - meshlink_node_t *dest_node = meshlink_get_self(mesh); - assert_int_not_equal(dest_node, NULL); - - if(strcmp(dest_node->name, "foo")) { - return false; - } - - meshlink_close(mesh); - assert(meshlink_destroy("self_conf")); - return true; - -} - -/* Execute meshlink_get_self Test Case # 2 */ -static void test_case_mesh_get_self_02(void **state) { - execute_test(test_steps_mesh_get_self_02, state); -} - -/* Test Steps for meshlink_get_self Test Case # 2 - - Test Steps: - 1. Open NUT(Node Under Test) & bar meshes. - 2. Export and Import mutually - - Expected Result: - Both the nodes imports successfully -*/ -static bool test_steps_mesh_get_self_02(void) { - meshlink_node_t *dest_node = meshlink_get_self(NULL); - assert_int_equal(dest_node, NULL); - - return true; -} - -int test_meshlink_get_self(void) { - const struct CMUnitTest blackbox_get_self_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_self_01, NULL, NULL, - (void *)&test_mesh_get_self_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_self_02, NULL, NULL, - (void *)&test_mesh_get_self_02_state) - }; - - total_tests += sizeof(blackbox_get_self_tests) / sizeof(blackbox_get_self_tests[0]); - - return cmocka_run_group_tests(blackbox_get_self_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_self.h b/test/blackbox/run_blackbox_tests/test_cases_get_self.h deleted file mode 100644 index 24d7fc9..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_get_self.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_GET_SELF_H -#define TEST_CASES_GET_SELF_H - -/* - test_cases_get_self.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_get_self(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_hint_address.c b/test/blackbox/run_blackbox_tests/test_cases_hint_address.c deleted file mode 100644 index 61be451..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_hint_address.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - test_cases_hint_address.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_hint_address.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -/* Port number used in the structure */ -#define PORT 8000 - -/* hint address used in the socket structure */ -#define ADDR "10.1.1.1" - -static void test_case_hint_address_01(void **state); -static bool test_steps_hint_address_01(void); - -static black_box_state_t test_case_hint_address_01_state = { - .test_case_name = "test_case_hint_address_01", -}; - - -/* Execute meshlink_hint_address Test Case # 1 - Valid Case*/ -void test_case_hint_address_01(void **state) { - execute_test(test_steps_hint_address_01, state); -} -/* Test Steps for meshlink_hint_address Test Case # 1 - Valid case */ -bool test_steps_hint_address_01(void) { - assert(meshlink_destroy("hintconf1")); - assert(meshlink_destroy("hintconf2")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance for the nodes - meshlink_handle_t *mesh1 = meshlink_open("hintconf1", "nut", "test", DEV_CLASS_STATIONARY); - assert(mesh1); - meshlink_handle_t *mesh2 = meshlink_open("hintconf2", "bar", "test", DEV_CLASS_STATIONARY); - assert(mesh2); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // importing and exporting mesh meta data - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - assert(meshlink_import(mesh1, exp2)); - assert(meshlink_import(mesh2, exp1)); - free(exp1); - free(exp2); - - // Nodes should learn about each other - sleep(1); - - // Start the nodes - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - - // socket structure to be hinted - struct sockaddr_in hint; - hint.sin_family = AF_INET; - hint.sin_port = htons(PORT); - assert(inet_aton(ADDR, &hint.sin_addr)); - - // Getting node handle for the NUT itself - meshlink_node_t *node = meshlink_get_node(mesh1, "bar"); - assert(node != NULL); - - meshlink_hint_address(mesh_handle, node, (struct sockaddr *)&hint); - - int fp; - fp = open("./hintconf1/hosts/bar", O_RDONLY); - assert(fp >= 0); - off_t fsize = lseek(fp, 0, SEEK_END); - assert(fsize >= 0); - char *buff = (char *) calloc(1, fsize + 1); - assert(buff != NULL); - assert(lseek(fp, 0, SEEK_SET) == 0); - assert(read(fp, buff, fsize) >= 0); - buff[fsize] = '\0'; - assert(close(fp) != -1); - - assert_int_not_equal(strstr(buff, ADDR), NULL); - - free(buff); - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("hintconf1")); - assert(meshlink_destroy("hintconf2")); - - return true; -} - - -int test_meshlink_hint_address(void) { - const struct CMUnitTest blackbox_hint_address_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_hint_address_01, NULL, NULL, - (void *)&test_case_hint_address_01_state) - }; - - total_tests += sizeof(blackbox_hint_address_tests) / sizeof(blackbox_hint_address_tests[0]); - - return cmocka_run_group_tests(blackbox_hint_address_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_hint_address.h b/test/blackbox/run_blackbox_tests/test_cases_hint_address.h deleted file mode 100644 index e64ba5e..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_hint_address.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_HINT_H -#define TEST_CASES_HINT_H - -/* - test_cases_hint_address.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_hint_address(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_import.c b/test/blackbox/run_blackbox_tests/test_cases_import.c deleted file mode 100644 index fb1b559..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_import.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - test_cases_import.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_import.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_import_01(void **state); -static bool test_import_01(void); -static void test_case_import_02(void **state); -static bool test_import_02(void); -static void test_case_import_03(void **state); -static bool test_import_03(void); -static void test_case_import_04(void **state); -static bool test_import_04(void); -static void test_case_import_05(void **state); -static bool test_import_05(void); - -/* State structure for import API Test Case #1 */ -static black_box_state_t test_case_import_01_state = { - .test_case_name = "test_case_import_01", -}; - -/* State structure for import API Test Case #2 */ -static black_box_state_t test_case_import_02_state = { - .test_case_name = "test_case_import_02", -}; - -/* State structure for import API Test Case #3 */ -static black_box_state_t test_case_import_03_state = { - .test_case_name = "test_case_import_03", -}; - -/* State structure for import API Test Case #4 */ -static black_box_state_t test_case_import_04_state = { - .test_case_name = "test_case_import_04", -}; - -/* State structure for import API Test Case #5 */ -static black_box_state_t test_case_import_05_state = { - .test_case_name = "test_case_import_05", -}; - -/* Execute import Test Case # 1 - valid case*/ -static void test_case_import_01(void **state) { - execute_test(test_import_01, state); -} -/* Test Steps for meshlink_import Test Case # 1 - Valid case - - Test Steps: - 1. Open NUT(Node Under Test) & bar meshes. - 2. Export and Import mutually - - Expected Result: - Both the nodes imports successfully -*/ -static bool test_import_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - - // Opening NUT and bar nodes - meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "test", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("importconf2", "bar", "test", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Exporting and Importing mutually - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - bool imp1 = meshlink_import(mesh1, exp2); - bool imp2 = meshlink_import(mesh2, exp1); - - assert_int_equal(imp1 && imp2, true); - - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - return imp1 && imp2; -} - -/* Execute import Test Case # 2 - invalid case*/ -static void test_case_import_02(void **state) { - execute_test(test_import_02, state); -} -/* Test Steps for meshlink_import Test Case # 2 - Invalid case - - Test Steps: - 1. Open NUT(Node Under Test) & bar meshes. - 2. Passing NULL as mesh handle argument for meshlink_import API - - Expected Result: - Reports error successfully by returning false -*/ -static bool test_import_02(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - - // Opening NUT and bar nodes - meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "test", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("importconf2", "bar", "test", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Exporting & Importing nodes - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - - bool imp1 = meshlink_import(NULL, exp2); - bool imp2 = meshlink_import(mesh2, exp1); - assert_int_equal((!imp1) && imp2, true); - - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - return true; -} - - -/* Execute import Test Case # 3 - invalid case*/ -static void test_case_import_03(void **state) { - execute_test(test_import_03, state); -} -/* Test Steps for meshlink_import Test Case # 3 - Invalid case - - Test Steps: - 1. Open NUT(Node Under Test) & bar meshes. - 2. Passing NULL as exported data argument for meshlink_import API - - Expected Result: - Reports error successfully by returning false -*/ -static bool test_import_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - - /* Opening NUT and bar nodes */ - meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "chat", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("importconf2", "bar", "chat", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Exporting & Importing nodes */ - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - - bool imp1 = meshlink_import(mesh1, NULL); - bool imp2 = meshlink_import(mesh2, exp1); - - assert_int_equal((!imp1) && imp2, true); - - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - return true; -} - -/* Execute import Test Case # 4 - invalid case garbage string*/ -static void test_case_import_04(void **state) { - execute_test(test_import_04, state); -} -/* Test Steps for meshlink_import Test Case # 4 - Invalid case - - Test Steps: - 1. Open NUT(Node Under Test) & bar meshes. - 2. Passing some garbage string(NULL terminated) - as an argument for meshlink_import API - - Expected Result: - Reports error successfully by returning false -*/ -static bool test_import_04(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - - // Opening NUT and bar nodes - meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "chat", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("importconf2", "bar", "chat", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Exporting & Importing nodes - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - - // Importing NUT with garbage string as exported data argument - bool imp1 = meshlink_import(mesh1, "1/2/3"); - bool imp2 = meshlink_import(mesh2, exp1); - assert_int_equal((!imp1) && imp2, true); - - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - return true; -} - -/* Execute import Test Case # 5 - valid case*/ -static void test_case_import_05(void **state) { - execute_test(test_import_05, state); -} -/* Test Steps for meshlink_import Test Case # 5 - Invalid case - - Test Steps: - 1. Open NUT(Node Under Test) & bar meshes. - 2. Export and Import mutually - 2. Try to import NUT again/twice at 'bar' node - - Expected Result: - Reports error successfully by returning false -*/ -static bool test_import_05(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - - /* Opening NUT and bar nodes */ - meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "chat", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("importconf2", "bar", "chat", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Exporting & Importing nodes */ - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - bool imp1 = meshlink_import(mesh1, exp2); - assert(imp1); - bool imp2 = meshlink_import(mesh2, exp1); - assert(imp2); - - /** Trying to import twice **/ - bool imp3 = meshlink_import(mesh2, exp1); - - assert_int_equal(imp3, false); - - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("importconf1")); - assert(meshlink_destroy("importconf2")); - return true; -} - -int test_meshlink_import(void) { - const struct CMUnitTest blackbox_import_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_import_01, NULL, NULL, - (void *)&test_case_import_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_import_02, NULL, NULL, - (void *)&test_case_import_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_import_03, NULL, NULL, - (void *)&test_case_import_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_import_04, NULL, NULL, - (void *)&test_case_import_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_import_05, NULL, NULL, - (void *)&test_case_import_05_state) - }; - total_tests += sizeof(blackbox_import_tests) / sizeof(blackbox_import_tests[0]); - - return cmocka_run_group_tests(blackbox_import_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_import.h b/test/blackbox/run_blackbox_tests/test_cases_import.h deleted file mode 100644 index 4316b93..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_import.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_IMPORT_H -#define TEST_CASES_IMPORT_H - -/* - test_cases_import.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_import(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_invite.c b/test/blackbox/run_blackbox_tests/test_cases_invite.c deleted file mode 100644 index f04cb09..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_invite.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - test_cases_invite.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_invite.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -#define NUT "nut" -#define PEER "peer" -#define TEST_MESHLINK_INVITE "test_invite" -#define create_path(confbase, node_name, test_case_no) assert(snprintf(confbase, sizeof(confbase), TEST_MESHLINK_INVITE "_%ld_%s_%02d", (long) getpid(), node_name, test_case_no) > 0) - -static void test_case_invite_01(void **state); -static bool test_invite_01(void); -static void test_case_invite_02(void **state); -static bool test_invite_02(void); -static void test_case_invite_03(void **state); -static bool test_invite_03(void); -static void test_case_invite_04(void **state); -static bool test_invite_04(void); -static void test_case_invite_05(void **state); -static bool test_invite_05(void); - -/* State structure for invite API Test Case #1 */ -static black_box_state_t test_case_invite_01_state = { - .test_case_name = "test_case_invite_01", -}; - -/* State structure for invite API Test Case #2 */ -static black_box_state_t test_case_invite_02_state = { - .test_case_name = "test_case_invite_02", -}; - -/* State structure for invite API Test Case #3 */ -static black_box_state_t test_case_invite_03_state = { - .test_case_name = "test_case_invite_03", -}; - -/* State structure for invite API Test Case #4 */ -static black_box_state_t test_case_invite_04_state = { - .test_case_name = "test_case_invite_04", -}; - -/* State structure for invite API Test Case #5 */ -static black_box_state_t test_case_invite_05_state = { - .test_case_name = "test_case_invite_05", -}; - -/* Execute invite Test Case # 1 - valid case*/ -static void test_case_invite_01(void **state) { - execute_test(test_invite_01, state); -} -/*Test Steps for meshlink_invite Test Case # 1 - Valid case - Test Steps: - 1. Run NUT - 2. Invite 'new' node - - Expected Result: - Generates an invitation -*/ -static bool test_invite_01(void) { - char nut_confbase[PATH_MAX]; - char peer_invitation[1000]; - create_path(nut_confbase, NUT, 1); - - // Create meshlink instance - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_INVITE, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - char *invitation = meshlink_invite(mesh, NULL, "new"); - assert_non_null(invitation); - - free(invitation); - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* Execute invite Test Case # 2 - Invalid case*/ -static void test_case_invite_02(void **state) { - execute_test(test_invite_02, state); -} -/*Test Steps for meshlink_invite Test Case # 2 - Invalid case - Test Steps: - 1. Calling meshlink_invite API with NULL as mesh handle argument - - Expected Result: - Reports appropriate error by returning NULL -*/ -static bool test_invite_02(void) { - // Trying to generate INVITATION by passing NULL as mesh link handle - char *invitation = meshlink_invite(NULL, NULL, "nut"); - assert_int_equal(invitation, NULL); - - return true; -} - -/* Execute invite Test Case # 3 - Invalid case*/ -static void test_case_invite_03(void **state) { - execute_test(test_invite_03, state); -} -/*Test Steps for meshlink_invite Test Case # 3 - Invalid case - Test Steps: - 1. Run NUT - 2. Call meshlink_invite with NULL node name argument - - Expected Result: - Reports appropriate error by returning NULL -*/ -static bool test_invite_03(void) { - char nut_confbase[PATH_MAX]; - char peer_invitation[1000]; - create_path(nut_confbase, NUT, 3); - - // Create meshlink instance - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_INVITE, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - char *invitation = meshlink_invite(mesh, NULL, NULL); - assert_int_equal(invitation, NULL); - - free(invitation); - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* Execute invite Test Case # 4 - Functionality test*/ -static void test_case_invite_04(void **state) { - execute_test(test_invite_04, state); -} -/*Test Steps for meshlink_invite Test Case # 4 - Functionality test - - Test Steps: - 1. Create node instance - 2. Add a new address to the mesh and invite a node - 3. Add another new address and invite a node - - Expected Result: - Newly added address should be there in the invitation. -*/ -static bool test_invite_04(void) { - char nut_confbase[PATH_MAX]; - char peer_invitation[1000]; - create_path(nut_confbase, NUT, 4); - - // Create meshlink instance - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_INVITE, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - assert_true(meshlink_add_invitation_address(mesh, "11.11.11.11", "2020")); - char *invitation = meshlink_invite(mesh, NULL, "foo"); - assert_non_null(strstr(invitation, "11.11.11.11:2020")); - free(invitation); - - assert_true(meshlink_add_invitation_address(mesh, "fe80::1548:d713:3899:f645", "3030")); - invitation = meshlink_invite(mesh, NULL, "bar"); - assert_non_null(strstr(invitation, "11.11.11.11:2020")); - assert_non_null(strstr(invitation, "[fe80::1548:d713:3899:f645]:3030")); - free(invitation); - - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* Execute invite Test Case # 5 - Synchronization testing */ -static void test_case_invite_05(void **state) { - execute_test(test_invite_05, state); -} - -static bool test_invite_05(void) { - bool status; - pid_t pid; - int pid_status; - int pipefd[2]; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - char peer_invitation[1000]; - create_path(nut_confbase, NUT, 5); - create_path(peer_confbase, PEER, 5); - - assert_int_not_equal(pipe(pipefd), -1); - - // Fork a new process in which NUT opens it's instance and raises SIGINT to terminate. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - assert(!close(pipefd[0])); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_INVITE, DEV_CLASS_STATIONARY); - assert(mesh); - - char *invitation = meshlink_invite(mesh, NULL, PEER); - write(pipefd[1], invitation, strlen(invitation) + 1); - - raise(SIGINT); - } - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - assert_int_equal(close(pipefd[1]), 0); - assert_int_not_equal(read(pipefd[0], peer_invitation, sizeof(peer_invitation)), -1); - - // Reopen the NUT instance in the same test suite - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_INVITE, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_INVITE, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - assert_true(meshlink_start(mesh)); - assert_true(meshlink_join(mesh_peer, peer_invitation)); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return true; -} - -int test_meshlink_invite(void) { - const struct CMUnitTest blackbox_invite_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_invite_01, NULL, NULL, - (void *)&test_case_invite_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_invite_02, NULL, NULL, - (void *)&test_case_invite_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_invite_03, NULL, NULL, - (void *)&test_case_invite_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_invite_04, NULL, NULL, - (void *)&test_case_invite_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_invite_05, NULL, NULL, - (void *)&test_case_invite_05_state) - }; - - total_tests += sizeof(blackbox_invite_tests) / sizeof(blackbox_invite_tests[0]); - - return cmocka_run_group_tests(blackbox_invite_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_invite.h b/test/blackbox/run_blackbox_tests/test_cases_invite.h deleted file mode 100644 index e8c06c7..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_invite.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_INVITE_H -#define TEST_CASES_INVITE_H - -/* - test_cases_invite.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_invite(void); - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_join.c b/test/blackbox/run_blackbox_tests/test_cases_join.c deleted file mode 100644 index 882ec2c..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_join.c +++ /dev/null @@ -1,788 +0,0 @@ -/* - test_cases_join.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_get_node_reachability.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include "../../../src/devtools.h" - -#define NUT "nut" -#define PEER "peer" -#define PEER2 "peer2" -#define TEST_MESHLINK_JOIN "test_meshlink_join" -#define create_path(confbase, node_name, test_case_no) assert(snprintf(confbase, sizeof(confbase), TEST_MESHLINK_JOIN "_%ld_%s_%02d", (long) getpid(), node_name, test_case_no) > 0) - -static struct sync_flag peer_reachable_status_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static bool peer_reachable_status; -static struct sync_flag nut_reachable_status_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static bool nut_reachable_status; -static struct sync_flag nut_started_status_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -/* Node reachable status callback which signals the respective conditional varibale */ -static void meshlink_node_reachable_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable_status) { - if(!strcasecmp(mesh->name, NUT)) { - if(!strcasecmp(node->name, PEER)) { - peer_reachable_status = reachable_status; - set_sync_flag(&peer_reachable_status_cond, true); - } - } else if(!strcasecmp(mesh->name, PEER)) { - if(!strcasecmp(node->name, NUT)) { - nut_reachable_status = reachable_status; - set_sync_flag(&nut_reachable_status_cond, true); - } - } -} - -/* SIGUSR2 signal handler that signals the NUT started and PEER node can join */ -static void nut_started_user_signal_handler(int signum) { - if(signum == SIGUSR2) { - set_sync_flag(&nut_started_status_cond, true); - } - -} - -/* Test Steps for meshlink_join Test Case # 1 - Valid case - - Test Steps: - 1. Open instances for NUT and peer, peer invites NUT and starts instance. - 2. NUT consumes the invitation generated by peer - - Expected Result: - NUT joins peer using the invitation generated. -*/ -static void test_case_meshlink_join_01(void **state) { - (void) state; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 1); - create_path(peer_confbase, PEER, 1); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open both NUT and peer node instance, invite and join NUT with peer node. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_inviter_commits_first(mesh_peer, true); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - assert_true(meshlink_start(mesh_peer)); - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_inviter_commits_first(mesh, true); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - assert_true(meshlink_join(mesh, invitation)); - free(invitation); - - meshlink_node_t *peer_handle = meshlink_get_node(mesh, PEER); - assert_non_null(peer_handle); - meshlink_node_t *nut_handle = meshlink_get_node(mesh_peer, NUT); - assert_non_null(nut_handle); - - // Bring nodes online. - - set_sync_flag(&peer_reachable_status_cond, false); - set_sync_flag(&nut_reachable_status_cond, false); - assert_true(meshlink_start(mesh)); - assert_true(wait_sync_flag(&peer_reachable_status_cond, 60)); - assert_true(peer_reachable_status); - assert_true(wait_sync_flag(&nut_reachable_status_cond, 60)); - assert_true(nut_reachable_status); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -/* Test Steps for meshlink_join Test Case # 2 - Invalid case - - Test Steps: - 1. Call meshlink_join with NULL as mesh handler or node name argument. - - Expected Result: - NUT joining fails when NULL is passed as mesh handle or node name argument -*/ -static void test_case_meshlink_join_02(void **state) { - (void) state; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 2); - create_path(peer_confbase, PEER, 2); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open both NUT and peer node instance, invite and join NUT with peer node. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - assert_true(meshlink_start(mesh_peer)); - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - - // meshlink_join called with NULL as mesh handle and with valid invitation - - assert_int_equal(meshlink_join(NULL, invitation), false); - assert_int_equal(meshlink_join(mesh, NULL), false); - - // Cleanup - - free(invitation); - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -/* Test Steps for meshlink_join Test Case # 3 - Persistence testing around inviter - - Test steps and scenarios: - 1. Open Node-Under-Test (NUT) and invite peer node and close it's instance. - Spawn a process which waits for the peer node to join and raises SIGINT if the - appropriate callback is received (on the other hand the test suite opens and joins - the peer node with NUT in the forked process). - Expected Result: - NUT joins peer successfully - - -*/ -static void test_case_meshlink_join_03(void **state) { - (void) state; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 3); - create_path(peer_confbase, PEER, 3); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open NUT node instance and invite peer node. Close NUT node instance. - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - char *invitation = meshlink_invite(mesh, NULL, PEER); - meshlink_close(mesh); - - // Set the SIGUSR2 signal handler with handler that signal the condition to the test suite - - sighandler_t usr2sighandler = signal(SIGUSR2, nut_started_user_signal_handler); - assert_int_not_equal(usr2sighandler, SIG_ERR); - - // Fork a new process and run NUT in it which just waits for the peer node reachable status callback - // and terminates the process immediately. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - assert(signal(SIGUSR2, SIG_DFL) != SIG_ERR); - - mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - - set_sync_flag(&peer_reachable_status_cond, false); - assert(meshlink_start(mesh)); - - assert(kill(getppid(), SIGUSR2) != -1); - - assert(wait_sync_flag(&peer_reachable_status_cond, 60)); - assert(peer_reachable_status); - - raise(SIGINT); - } - - // Open peer node instance and join with the invitation obtained. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - - // Wait for the started signal from NUT and reset the previous SIGUSR2 signal handler - - assert_true(wait_sync_flag(&nut_started_status_cond, 60)); - assert_int_not_equal(signal(SIGUSR2, usr2sighandler), SIG_ERR); - - assert_true(meshlink_join(mesh_peer, invitation)); - assert_true(meshlink_start(mesh_peer)); - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - assert_non_null(meshlink_get_node(mesh, PEER)); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 4 - Persistence testing around invitee - - Test steps and scenarios: - 1. Open peer node instance, invite NUT and start peer node. Spawn a new process in - which it opens and joins the NUT with peer node. - Reopen NUT instance in the test suite process and verify peer is joined. - Expected Result: - NUT joins peer successfully - -*/ -static void test_case_meshlink_join_04(void **state) { - (void) state; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 4); - create_path(peer_confbase, PEER, 4); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open peer node instance and invite NUT. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_int_not_equal(mesh_peer, NULL); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - - assert_true(meshlink_start(mesh_peer)); - - // Fork a new process in which NUT is joins with the peer node and raises SIGINT to terminate. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - - assert(meshlink_join(mesh, invitation)); - - raise(SIGINT); - } - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - assert_non_null(meshlink_get_node(mesh, PEER)); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -static void nop_stage(bool stage) { - (void)stage; - return; -} - -static void debug_probe(bool stage) { - (void)stage; - raise(SIGINT); - return; -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 5 - Test the invitee committing first scenario - - Test steps and scenarios: - 1. Open peer node instance, invite NUT and start peer node. Enable the debug probe, Spawn a new process in - which it opens and joins the NUT with peer node which terminates the NUT while joining. - Reopen NUT instance in the test suite process and verify peer is joined. - Expected Result: - NUT(invitee) commits the config file(s) first but peer is unaware of NUT. - -*/ -static void test_case_meshlink_join_05(void **state) { - (void) state; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 5); - create_path(peer_confbase, PEER, 5); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - assert(signal(SIGINT, SIG_DFL) != SIG_ERR); - assert(signal(SIGABRT, SIG_DFL) != SIG_ERR); - - // Set debug_probe callback - - devtool_set_inviter_commits_first = debug_probe; - - // Open peer node instance and invite NUT. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_int_not_equal(mesh_peer, NULL); - meshlink_set_inviter_commits_first(mesh_peer, false); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - - assert_true(meshlink_start(mesh_peer)); - - // Fork a new process in which NUT is joins with the peer node and raises SIGINT to terminate. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert(mesh); - meshlink_set_inviter_commits_first(mesh_peer, false); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - - assert_true(meshlink_join(mesh, invitation)); - - raise(SIGABRT); - } - - // Wait for child exit and verify which signal terminated it - printf("\n"); - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - // Invitee committed host config file but invitee should not - - assert_non_null(meshlink_get_node(mesh, PEER)); - assert_null(meshlink_get_node(mesh_peer, NUT)); - - // Cleanup - - free(invitation); - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - - devtool_set_inviter_commits_first = nop_stage; - return; -} - -/* Test Steps for meshlink_get_node_reachability Test Case # 6 - Test the inviter committing first scenario - - Test steps and scenarios: - 1. Open NUT node instance, invite peer and close the instance. Enable the debug probe, Spawn a new process in - which it starts the NUT instance. At the parents/test vector thread wait for the signal that NUT raises after starting - and join peer with NUT. NUT terminates in debug probe after committing into the disk - Reopen NUT instance in the test suite process and verify peer is joined. - Expected Result: - NUT(inviter) commits the config file(s) first but peer is unaware of NUT. - -*/ -static void test_case_meshlink_join_06(void **state) { - (void) state; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 6); - create_path(peer_confbase, PEER, 6); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - assert(signal(SIGINT, SIG_DFL) != SIG_ERR); - assert(signal(SIGABRT, SIG_DFL) != SIG_ERR); - - // Set debug_probe callback - - devtool_set_inviter_commits_first = debug_probe; - - // Open NUT node instance and invite peer node. Close NUT node instance. - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_inviter_commits_first(mesh, true); - char *invitation = meshlink_invite(mesh, NULL, PEER); - meshlink_close(mesh); - - // Set the SIGUSR2 signal handler with handler that signal the condition to the test suite - - sighandler_t usr2sighandler = signal(SIGUSR2, nut_started_user_signal_handler); - assert_int_not_equal(usr2sighandler, SIG_ERR); - set_sync_flag(&peer_reachable_status_cond, false); - - // Fork a new process and run NUT in it which just waits for the peer node reachable status callback - // and terminates the process immediately. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - assert(signal(SIGUSR2, SIG_DFL) != SIG_ERR); - - mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert(mesh); - meshlink_set_inviter_commits_first(mesh, true); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - - assert(meshlink_start(mesh)); - - assert(kill(getppid(), SIGUSR2) != -1); - - sleep(10); - - raise(SIGABRT); - } - - // Open peer node instance and join with the invitation obtained. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_inviter_commits_first(mesh_peer, true); - - // Wait for the started signal from NUT and reset the previous SIGUSR2 signal handler - - assert_true(wait_sync_flag(&nut_started_status_cond, 60)); - assert_int_not_equal(signal(SIGUSR2, usr2sighandler), SIG_ERR); - - assert_false(meshlink_join(mesh_peer, invitation)); - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - // Inviter should first commit config file(s) into the disk - - assert_null(meshlink_get_node(mesh_peer, NUT)); - assert_non_null(meshlink_get_node(mesh, PEER)); - - // Cleanup - - free(invitation); - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - devtool_set_inviter_commits_first = nop_stage; - return; -} - -/* Test Steps for meshlink_join Test Case # 7 - Inviter sets that invitee should commit first, - even invitee sets that inviter should commit first. - - Test Steps: - 1. Open instances for NUT and peer, peer invites NUT and starts instance. - Both the instances sets meshlink_set_inviter_commits_first API mutually exclusively - NUT tries to consume the invitation generated by peer - - Expected Result: - NUT fails to join peer using the invitation generated. -*/ -static void test_case_meshlink_join_07(void **state) { - (void) state; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 7); - create_path(peer_confbase, PEER, 7); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open both NUT and peer node instance, invite and join NUT with peer node. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_inviter_commits_first(mesh_peer, false); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - assert_true(meshlink_start(mesh_peer)); - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_inviter_commits_first(mesh, true); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - assert_false(meshlink_join(mesh, invitation)); - free(invitation); - - meshlink_node_t *peer_handle = meshlink_get_node(mesh, PEER); - assert_null(peer_handle); - meshlink_node_t *nut_handle = meshlink_get_node(mesh_peer, NUT); - assert_null(nut_handle); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -/* Test Steps for meshlink_join Test Case # 8 - Inviter sets that it should commit first, - even invitee sets that it should commit first - - Test Steps: - 1. Open instances for NUT and peer, peer invites NUT and starts instance. - Both the instances sets meshlink_set_inviter_commits_first API mutually exclusively - NUT tries to consume the invitation generated by peer - - Expected Result: - NUT fails to join peer using the invitation generated. -*/ -static void test_case_meshlink_join_08(void **state) { - (void) state; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 8); - create_path(peer_confbase, PEER, 8); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open both NUT and peer node instance, invite and join NUT with peer node. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_inviter_commits_first(mesh_peer, true); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - assert_true(meshlink_start(mesh_peer)); - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_inviter_commits_first(mesh, false); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - assert_false(meshlink_join(mesh, invitation)); - free(invitation); - - meshlink_node_t *peer_handle = meshlink_get_node(mesh, PEER); - assert_null(peer_handle); - meshlink_node_t *nut_handle = meshlink_get_node(mesh_peer, NUT); - assert_null(nut_handle); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -/* Test Steps for meshlink_join Test Case # 9 - Invitee already started its instance - - Test Steps: - 1. Open instances for NUT and peer, peer invites NUT and both the instances starts their instances. - NUT tries to join the peer with the generated invitation. - - Expected Result: - NUT fails to join peer using the invitation generated. -*/ -static void test_case_meshlink_join_09(void **state) { - (void) state; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 9); - create_path(peer_confbase, PEER, 9); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open both NUT and peer node instance, invite and join NUT with peer node. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - assert_true(meshlink_start(mesh_peer)); - - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - - assert_true(meshlink_start(mesh)); - - assert_false(meshlink_join(mesh, invitation)); - free(invitation); - - meshlink_node_t *peer_handle = meshlink_get_node(mesh, PEER); - assert_null(peer_handle); - meshlink_node_t *nut_handle = meshlink_get_node(mesh_peer, NUT); - assert_null(nut_handle); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -/* Test Steps for meshlink_join Test Case # 10 - Invitee already joined in a mesh - - Test Steps: - 1. Open instances for NUT, peer2 and peer, peer invites NUT. Peer2 and NUT both mutually imports data - i.e, both formed or joined the mesh. - NUT tries to join the peer with the generated invitation. - - Expected Result: - NUT fails to join peer using the invitation generated. -*/ -static void test_case_meshlink_join_10(void **state) { - (void) state; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - char peer_confbase2[PATH_MAX]; - create_path(nut_confbase, NUT, 10); - create_path(peer_confbase, PEER, 10); - create_path(peer_confbase2, PEER2, 10); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open both NUT and peer node instance, invite and join NUT with peer node. - - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - meshlink_set_node_status_cb(mesh_peer, meshlink_node_reachable_status_cb); - char *invitation = meshlink_invite(mesh_peer, NULL, NUT); - assert_non_null(invitation); - assert_true(meshlink_start(mesh_peer)); - - meshlink_handle_t *mesh_peer2 = meshlink_open(peer_confbase2, PEER2, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer2); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_JOIN, - DEV_CLASS_STATIONARY); - assert_non_null(mesh); - meshlink_set_node_status_cb(mesh, meshlink_node_reachable_status_cb); - - char *data = meshlink_export(mesh); - assert_non_null(data); - assert_true(meshlink_import(mesh_peer2, data)); - free(data); - data = meshlink_export(mesh_peer2); - assert_non_null(data); - assert_true(meshlink_import(mesh, data)); - free(data); - - assert_true(meshlink_start(mesh)); - - assert_false(meshlink_join(mesh, invitation)); - free(invitation); - - meshlink_node_t *peer_handle = meshlink_get_node(mesh, PEER); - assert_null(peer_handle); - meshlink_node_t *nut_handle = meshlink_get_node(mesh_peer, NUT); - assert_null(nut_handle); - - // Cleanup - - meshlink_close(mesh); - meshlink_close(mesh_peer); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return; -} - -int test_meshlink_join(void) { - const struct CMUnitTest blackbox_join_tests[] = { - cmocka_unit_test(test_case_meshlink_join_01), - cmocka_unit_test(test_case_meshlink_join_02), - cmocka_unit_test(test_case_meshlink_join_03), - cmocka_unit_test(test_case_meshlink_join_04), - cmocka_unit_test(test_case_meshlink_join_05), - cmocka_unit_test(test_case_meshlink_join_06), - cmocka_unit_test(test_case_meshlink_join_07), - cmocka_unit_test(test_case_meshlink_join_08), - cmocka_unit_test(test_case_meshlink_join_09), - cmocka_unit_test(test_case_meshlink_join_10) - }; - total_tests += sizeof(blackbox_join_tests) / sizeof(blackbox_join_tests[0]); - - int failed = cmocka_run_group_tests(blackbox_join_tests, NULL, NULL); - - return failed; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_join.h b/test/blackbox/run_blackbox_tests/test_cases_join.h deleted file mode 100644 index c10af0f..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_join.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_JOIN_H -#define TEST_CASES_JOIN_H - -/* - test_cases_join.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_join(void); -extern int total_tests; - - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c b/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c deleted file mode 100644 index 8987d7c..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c +++ /dev/null @@ -1,503 +0,0 @@ -/* - test_cases_key_rotation.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_key_rotation.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../../src/devtools.h" -#include "../../utils.h" - -static void test_case_key_rotation_01(void **state); -static bool test_key_rotation_01(void); -static void test_case_key_rotation_02(void **state); -static bool test_key_rotation_02(void); -static void test_case_key_rotation_03(void **state); -static bool test_key_rotation_03(void); -static void test_case_key_rotation_04(void **state); -static bool test_key_rotation_04(void); -static void test_case_key_rotation_05(void **state); -static bool test_key_rotation_05(void); - -/* Execute key rotation Test Case # 1 - Sanity test */ -static void test_case_key_rotation_01(void **state) { - execute_test(test_key_rotation_01, state); -} - -/* Test Steps for key rotation Test Case # 1 - - Test Steps: - 1. Open encrypted node instance, call encrypted rotate API with - invalid input parameters to the call. - - Expected Result: - Key rotate should fail when called with invalid parameters. -*/ -static bool test_key_rotation_01(void) { - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - assert(meshlink_destroy("encrypted_conf")); - - // Open a new meshlink instance. - - meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "oldkey", 6); - assert_int_not_equal(mesh, NULL); - - // Pass invalid arguments - - bool keyrotation_status = meshlink_encrypted_key_rotate(mesh, NULL, 5); - assert_int_equal(keyrotation_status, false); - - keyrotation_status = meshlink_encrypted_key_rotate(NULL, "newkey", 6); - assert_int_equal(keyrotation_status, false); - - keyrotation_status = meshlink_encrypted_key_rotate(mesh, "newkey", 0); - assert_int_equal(keyrotation_status, false); - - // Cleanup - - meshlink_close(mesh); - assert(meshlink_destroy("encrypted_conf")); - - return true; -} - -/* Execute key rotation Test Case # 2 - Sanity test */ -static void test_case_key_rotation_02(void **state) { - execute_test(test_key_rotation_02, state); -} - -/* Test Steps for key rotation Test Case # 2 - - Test Steps: - 1. Open encrypted node instance, rotate it's key with a newkey and close the node. - 2. Reopen the encrypted node instance with the newkey - - Expected Result: - Opening encrypted node instance should succeed when tried to open with newkey that's - been changed to new by key rotate API. -*/ -static bool test_key_rotation_02(void) { - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - assert(meshlink_destroy("encrypted_conf")); - - // Open a new meshlink instance. - - meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "oldkey", 6); - assert_int_not_equal(mesh, NULL); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - - // Set a new port for the mesh - - int port = 0x1000 + (rand() & 0x7fff); - assert_int_equal(meshlink_set_port(mesh, port), true); - - // Key rotate the encrypted_conf storage with new key - - bool keyrotation_status = meshlink_encrypted_key_rotate(mesh, "newkey", 6); - assert_int_equal(keyrotation_status, true); - - meshlink_close(mesh); - - // Reopen the meshlink instance with the new key - - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey", 6); - assert_int_not_equal(mesh, NULL); - - // Validate the port number that we changed in the last run. - - assert_int_equal(meshlink_get_port(mesh), port); - - // Cleanup - - meshlink_close(mesh); - assert(meshlink_destroy("encrypted_conf")); - - return true; -} - -/* Execute key rotation Test Case # 3 - Sanity test */ -static void test_case_key_rotation_03(void **state) { - execute_test(test_key_rotation_03, state); -} - -/* Test Steps for key rotation Test Case # 3 - - Test Steps: - 1. Open encrypted node instance, rotate it's key with a newkey and close the node. - 2. Reopen the encrypted node instance with the oldkey - - Expected Result: - Opening encrypted node instance should fail when tried to open with oldkey that's - been changed to new by key rotate API. -*/ -static bool test_key_rotation_03(void) { - assert(meshlink_destroy("encrypted_conf")); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open a new meshlink instance. - - meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "oldkey", 6); - assert_int_not_equal(mesh, NULL); - - // Key rotate the encrypted_conf storage with new key - - bool keyrotation_status = meshlink_encrypted_key_rotate(mesh, "newkey", 6); - assert_int_equal(keyrotation_status, true); - - meshlink_close(mesh); - - // Reopen the meshlink instance with the new key - - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "oldkey", 6); - assert_int_equal(mesh, NULL); - - // Cleanup - - assert(meshlink_destroy("encrypted_conf")); - - return true; -} - -/* Execute key rotation Test Case # 4 - Sanity test */ -static void test_case_key_rotation_04(void **state) { - execute_test(test_key_rotation_04, state); -} - -/* Test Steps for key rotation Test Case # 4 - Verify whether key rotation API gracefully handles invitations porting from - old key to new key. - - Test Steps: - 1. Open foo node instance and generate invitations for peer and bar. - 2. Do key rotation with newkey and verify invitation timestamps post key rotation. - 3. Change timestamp of peer key to expire and Open instances of foo, bar and peer nodes - and try to join bar and peer node. - - Expected Result: - Key rotation API should never change the any file status attributes of an invitation file. -*/ -static bool test_key_rotation_04(void) { - meshlink_handle_t *mesh; - meshlink_handle_t *mesh1; - meshlink_handle_t *mesh2; - struct dirent *ent; - DIR *d; - char invitation_path_buff[500]; - struct stat temp_stat; - struct stat peer_stat; - struct utimbuf timebuf; - bool join_status; - char *invitations_directory_path = "encrypted_conf/current/invitations/"; - - assert(meshlink_destroy("encrypted_conf")); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - // Open a new meshlink instance. - - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "oldkey", 6); - assert_int_not_equal(mesh, NULL); - - // Generate invitations - - char *invitation1 = meshlink_invite(mesh, NULL, "peer"); - assert_int_not_equal(invitation1, NULL); - - // Read the peer invitation file status structure - - strcpy(invitation_path_buff, invitations_directory_path); - d = opendir(invitation_path_buff); - assert(d); - - while((ent = readdir(d)) != NULL) { - if(ent->d_name[0] == '.') { - continue; - } - - strcpy(invitation_path_buff, invitations_directory_path); - strcat(invitation_path_buff, ent->d_name); - assert(stat(invitation_path_buff, &temp_stat) != -1); - - if((temp_stat.st_mode & S_IFMT) == S_IFREG) { - break; - } - } - - assert(ent); - - closedir(d); - - char *invitation2 = meshlink_invite(mesh, NULL, "bar"); - assert_int_not_equal(invitation2, NULL); - - // Key rotate the encrypted_conf storage with new key - - bool keyrotation_status = meshlink_encrypted_key_rotate(mesh, "newkey", 6); - assert_int_equal(keyrotation_status, true); - - meshlink_close(mesh); - - // Compare invitation file timestamps of old key with new key - - assert(stat(invitation_path_buff, &peer_stat) != -1); - assert_int_equal(peer_stat.st_mtime, temp_stat.st_mtime); - - // Change timestamp for @ peer @ node invitation - - timebuf.actime = peer_stat.st_atime; - timebuf.modtime = peer_stat.st_mtime - 604805; // > 1 week - - assert(utime(invitation_path_buff, &timebuf) != -1); - - - // Reopen the meshlink instance with the new key - - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey", 6); - assert_int_not_equal(mesh, NULL); - - mesh1 = meshlink_open("encrypted_conf.1", "peer", "encrypted", DEV_CLASS_BACKBONE); - assert_int_not_equal(mesh1, NULL); - - mesh2 = meshlink_open("encrypted_conf.2", "bar", "encrypted", DEV_CLASS_BACKBONE); - assert_int_not_equal(mesh2, NULL); - - assert(meshlink_start(mesh)); - - join_status = meshlink_join(mesh1, invitation1); - assert_int_equal(join_status, false); - - join_status = meshlink_join(mesh2, invitation2); - assert_int_equal(join_status, true); - - // Cleanup - - free(invitation1); - free(invitation2); - meshlink_close(mesh); - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("encrypted_conf")); - assert(meshlink_destroy("encrypted_conf.1")); - assert(meshlink_destroy("encrypted_conf.2")); - - return true; -} - -/* Execute key rotation Test Case # 5 - Atomicity test */ -static void test_case_key_rotation_05(void **state) { - execute_test(test_key_rotation_05, state); -} - -static int break_stage; - -static void nop_stage(int stage) { - (void)stage; - - return; -} - -static void debug_probe(int stage) { - - // Terminate the node at the specified stage (by @ break_stage @ ) - if(stage == break_stage) { - raise(SIGINT); - } else if((break_stage < 1) || (break_stage > 3)) { - fprintf(stderr, "INVALID stage break\n"); - raise(SIGABRT); - } - - return; -} - -/* Test Steps for key rotation Test Case # 5 - Debug all stages of key rotate API and verify it's atomicity - - Test Steps: - 1. Open foo node instance. - 2. In a loop break meshlink node instance at each stage incrementally - in a fork process - 3. Reopen node instance post termination. - - Expected Result: - Terminating node instance when meshlink_encrypted_key_rotate function called - at any stage should give atomic result when reopened. -*/ -static bool test_key_rotation_05(void) { - pid_t pid; - int status; - meshlink_handle_t *mesh; - assert(meshlink_destroy("encrypted_conf")); - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - - assert(signal(SIGINT, SIG_DFL) != SIG_ERR); - assert(signal(SIGABRT, SIG_DFL) != SIG_ERR); - - // Set debug_probe callback - - devtool_keyrotate_probe = debug_probe; - int new_port = 12000; - int pipefd[2]; - - // incrementally debug meshlink_encrypted_key_rotate API atomicity - - for(break_stage = 1; break_stage <= 3; break_stage += 1) { - fprintf(stderr, "Debugging stage %d\n", break_stage); - assert(meshlink_destroy("encrypted_conf")); - - assert(pipe(pipefd) != -1); - - pid = fork(); - assert(pid != -1); - - if(!pid) { - close(pipefd[0]); - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "oldkey", 6); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - meshlink_enable_discovery(mesh, false); - - assert(meshlink_set_port(mesh, new_port)); - - char *invitation = meshlink_invite(mesh, NULL, "bar"); - assert(invitation); - - assert(write(pipefd[1], invitation, strlen(invitation) + 1) != -1); - - assert(meshlink_encrypted_key_rotate(mesh, "newkey", 6)); - raise(SIGABRT); - } - - close(pipefd[1]); - - // Wait for child exit and verify which signal terminated it - - assert(waitpid(pid, &status, 0) != -1); - assert_int_equal(WIFSIGNALED(status), true); - assert_int_equal(WTERMSIG(status), SIGINT); - - // Reopen the node with invalid key other than old and new key should fail and should not affect - // the existing confbase - - fprintf(stderr, "Opening mesh with invalid key\n"); - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "invalidkey", 9); - assert_int_equal(mesh, NULL); - - // Reopen the node with the "newkey", if it failed to open with "newkey" then - // opening with the "oldkey" should succeed - - fprintf(stderr, "Opening mesh with new-key\n"); - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey", 6); - - if(!mesh) { - fprintf(stderr, "Opening mesh with new-key failed trying to open with old-key\n"); - mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "oldkey", 6); - assert_int_not_equal(mesh, NULL); - } - - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb); - meshlink_enable_discovery(mesh, false); - - // Verify the newly set port and generated invitation - - int get_port = meshlink_get_port(mesh); - assert_int_equal(get_port, new_port); - - char invitation[200]; - assert(read(pipefd[0], invitation, sizeof(invitation)) != -1); - - assert(meshlink_start(mesh)); - - assert(meshlink_destroy("encrypted_conf.1")); - - meshlink_handle_t *mesh2 = meshlink_open("encrypted_conf.1", "bar", "bar", DEV_CLASS_BACKBONE); - assert(mesh2); - - meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, log_cb); - meshlink_enable_discovery(mesh2, false); - - assert_int_equal(meshlink_join(mesh2, invitation), true); - - // cleanup - - meshlink_close(mesh); - meshlink_close(mesh2); - - close(pipefd[0]); - } - - // Cleanup - - assert(meshlink_destroy("encrypted_conf")); - assert(meshlink_destroy("encrypted_conf.1")); - devtool_keyrotate_probe = nop_stage; - return true; -} - -int test_meshlink_encrypted_key_rotation(void) { - /* State structures for key rotation Test Cases */ - black_box_state_t test_case_key_rotation_01_state = { - .test_case_name = "test_case_key_rotation_01", - }; - black_box_state_t test_case_key_rotation_02_state = { - .test_case_name = "test_case_key_rotation_02", - }; - black_box_state_t test_case_key_rotation_03_state = { - .test_case_name = "test_case_key_rotation_03", - }; - black_box_state_t test_case_key_rotation_04_state = { - .test_case_name = "test_case_key_rotation_04", - }; - black_box_state_t test_case_key_rotation_05_state = { - .test_case_name = "test_case_key_rotation_05", - }; - - const struct CMUnitTest blackbox_status_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_key_rotation_01, NULL, NULL, - (void *)&test_case_key_rotation_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_key_rotation_02, NULL, NULL, - (void *)&test_case_key_rotation_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_key_rotation_03, NULL, NULL, - (void *)&test_case_key_rotation_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_key_rotation_04, NULL, NULL, - (void *)&test_case_key_rotation_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_key_rotation_05, NULL, NULL, - (void *)&test_case_key_rotation_05_state), - }; - total_tests += sizeof(blackbox_status_tests) / sizeof(blackbox_status_tests[0]); - - return cmocka_run_group_tests(blackbox_status_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.h b/test/blackbox/run_blackbox_tests/test_cases_key_rotation.h deleted file mode 100644 index 1562b24..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef TEST_CASES_KEY_ROTATION_H -#define TEST_CASES_KEY_ROTATION_H - -/* - test_cases_key_rotation.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -extern int test_meshlink_encrypted_key_rotation(void); -extern int total_tests; - -#endif // TEST_CASES_KEY_ROTATION_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_open.c b/test/blackbox/run_blackbox_tests/test_cases_open.c deleted file mode 100644 index a1c1b1e..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_open.c +++ /dev/null @@ -1,355 +0,0 @@ -/* - test_cases_open.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_open.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -#define NUT "nut" -#define PEER "peer" -#define TEST_MESHLINK_OPEN "test_open" -#define create_path(confbase, node_name, test_case_no) assert(snprintf(confbase, sizeof(confbase), TEST_MESHLINK_OPEN "_%ld_%s_%02d", (long) getpid(), node_name, test_case_no) > 0) - -static void test_case_mesh_open_01(void **state); -static bool test_steps_mesh_open_01(void); -static void test_case_mesh_open_02(void **state); -static bool test_steps_mesh_open_02(void); -static void test_case_mesh_open_03(void **state); -static bool test_steps_mesh_open_03(void); -static void test_case_mesh_open_04(void **state); -static bool test_steps_mesh_open_04(void); -static void test_case_mesh_open_05(void **state); -static bool test_steps_mesh_open_05(void); -static void test_case_mesh_open_06(void **state); -static bool test_steps_mesh_open_06(void); -static void test_case_mesh_open_07(void **state); -static bool test_steps_mesh_open_07(void); - -/* State structure for meshlink_open Test Case #1 */ -static black_box_state_t test_mesh_open_01_state = { - .test_case_name = "test_case_mesh_open_01", -}; - -/* State structure for meshlink_open Test Case #2 */ -static black_box_state_t test_mesh_open_02_state = { - .test_case_name = "test_case_mesh_open_02", -}; - -/* State structure for meshlink_open Test Case #3 */ -static black_box_state_t test_mesh_open_03_state = { - .test_case_name = "test_case_mesh_open_03", -}; - -/* State structure for meshlink_open Test Case #4 */ -static black_box_state_t test_mesh_open_04_state = { - .test_case_name = "test_case_mesh_open_04", -}; - -/* State structure for meshlink_open Test Case #5 */ -static black_box_state_t test_mesh_open_05_state = { - .test_case_name = "test_case_mesh_open_05", -}; - -/* State structure for meshlink_open Test Case #6 */ -static black_box_state_t test_mesh_open_06_state = { - .test_case_name = "test_case_mesh_open_06", -}; - -/* State structure for meshlink_open Test Case #7 */ -static black_box_state_t test_mesh_open_07_state = { - .test_case_name = "test_case_mesh_open_07", -}; - -/* Execute meshlink_open Test Case # 1*/ -static void test_case_mesh_open_01(void **state) { - execute_test(test_steps_mesh_open_01, state); -} - -/* Test Steps for meshlink_open Test Case # 1 - - Test Steps: - 1. Open the node instance using meshlink_open - - Expected Result: - meshlink_open API should successfully return a mesh handle. -*/ -static bool test_steps_mesh_open_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh = meshlink_open("open_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert_int_not_equal(mesh, NULL); - - meshlink_close(mesh); - assert(meshlink_destroy("open_conf")); - return true; -} - -/* Execute meshlink_open Test Case # 2*/ -static void test_case_mesh_open_02(void **state) { - execute_test(test_steps_mesh_open_02, state); -} - -/* Test Steps for meshlink_open Test Case # 2 - - Test Steps: - 1. Open the node instance using meshlink_open with NULL as confbase argument - - Expected Result: - meshlink_open API should successfully report error by returning NULL pointer -*/ -static bool test_steps_mesh_open_02(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh = meshlink_open(NULL, "foo", "test", DEV_CLASS_STATIONARY); - assert_int_equal(mesh, NULL); - - return true; -} - -/* Execute meshlink_open Test Case # 3 */ -static void test_case_mesh_open_03(void **state) { - execute_test(test_steps_mesh_open_03, state); -} - -/* Test Steps for meshlink_open Test Case # 3 - - Test Steps: - 1. Open the node instance using meshlink_open with NULL as node name argument - - Expected Result: - meshlink_open API should successfully report error by returning NULL pointer -*/ -static bool test_steps_mesh_open_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh = meshlink_open("openconf", NULL, "test", DEV_CLASS_STATIONARY); - assert_int_equal(mesh, NULL); - - assert(meshlink_destroy("open_conf")); - return true; -} - -/* Execute meshlink_open Test Case # 4*/ -static void test_case_mesh_open_04(void **state) { - execute_test(test_steps_mesh_open_04, state); -} - -/* Test Steps for meshlink_open Test Case # 4 - - Test Steps: - 1. Open the node instance using meshlink_open with NULL as app name argument - - Expected Result: - meshlink_open API should successfully report error by returning NULL pointer -*/ -static bool test_steps_mesh_open_04(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh = meshlink_open("openconf", "foo", NULL, DEV_CLASS_STATIONARY); - assert_int_equal(mesh, NULL); - - assert(meshlink_destroy("open_conf")); - return true; -} - -/* Execute meshlink_open Test Case # 5*/ -static void test_case_mesh_open_05(void **state) { - execute_test(test_steps_mesh_open_05, state); -} - -/* Test Steps for meshlink_open Test Case # 5 - - Test Steps: - 1. Open the node instance using meshlink_open with invalid device class argument - - Expected Result: - meshlink_open API should successfully report error by returning NULL pointer -*/ -static bool test_steps_mesh_open_05(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh = meshlink_open("openconf", "foo", "test", -1); - assert_int_equal(mesh, NULL); - - assert(meshlink_destroy("open_conf")); - return true; -} - -/* Execute meshlink_open Test Case # 7 - Atomicity testing - Validate the meshlink_open behavior opened a new confbase and terminated immediately the open call. -*/ -static void test_case_mesh_open_06(void **state) { - execute_test(test_steps_mesh_open_06, state); -} - -static bool test_steps_mesh_open_06(void) { - bool status; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 6); - - // Fork a new process in which NUT opens it's instance and raises SIGINT to terminate. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_OPEN, DEV_CLASS_STATIONARY); - assert(mesh); - raise(SIGINT); - } - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_OPEN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - // Validate parameters that were used to open meshlink instance. - - assert_int_equal(strcmp(mesh->name, NUT), 0); - meshlink_node_t *self = meshlink_get_self(mesh); - assert_int_equal(strcmp(self->name, NUT), 0); - assert_int_equal(meshlink_get_node_dev_class(mesh, self), DEV_CLASS_STATIONARY); - - // Cleanup - - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* Execute meshlink_open Test Case # 7 - Atomicity testing - Validate the meshlink_open behavior opened an existing confbase and terminated immediately the open call. -*/ -static void test_case_mesh_open_07(void **state) { - execute_test(test_steps_mesh_open_07, state); -} - -static bool test_steps_mesh_open_07(void) { - bool status; - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - char peer_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 7); - create_path(peer_confbase, PEER, 7); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_OPEN, DEV_CLASS_BACKBONE); - assert_non_null(mesh); - meshlink_handle_t *mesh_peer = meshlink_open(peer_confbase, PEER, TEST_MESHLINK_OPEN, DEV_CLASS_STATIONARY); - assert_non_null(mesh_peer); - - // Exporting and Importing mutually - char *export_data = meshlink_export(mesh); - assert_non_null(export_data); - assert_true(meshlink_import(mesh_peer, export_data)); - free(export_data); - export_data = meshlink_export(mesh_peer); - assert_non_null(export_data); - assert_true(meshlink_import(mesh, export_data)); - free(export_data); - - meshlink_close(mesh); - meshlink_close(mesh_peer); - - - // Fork a new process in which NUT reopens it's instance and raises SIGINT to terminate. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_OPEN, DEV_CLASS_BACKBONE); - assert(mesh); - raise(SIGINT); - } - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Reopen the NUT instance in the same test suite - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_OPEN, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - // Validate parameters that were used to open meshlink instance. - - assert_int_equal(strcmp(mesh->name, NUT), 0); - meshlink_node_t *self = meshlink_get_self(mesh); - assert_int_equal(strcmp(self->name, NUT), 0); - assert_int_equal(meshlink_get_node_dev_class(mesh, self), DEV_CLASS_STATIONARY); - - // Cleanup - - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - assert_true(meshlink_destroy(peer_confbase)); - return true; -} - -int test_meshlink_open(void) { - const struct CMUnitTest blackbox_open_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_01, NULL, NULL, - (void *)&test_mesh_open_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_02, NULL, NULL, - (void *)&test_mesh_open_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_03, NULL, NULL, - (void *)&test_mesh_open_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_04, NULL, NULL, - (void *)&test_mesh_open_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_05, NULL, NULL, - (void *)&test_mesh_open_05_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_06, NULL, NULL, - (void *)&test_mesh_open_06_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_07, NULL, NULL, - (void *)&test_mesh_open_07_state) - - }; - total_tests += sizeof(blackbox_open_tests) / sizeof(blackbox_open_tests[0]); - - return cmocka_run_group_tests(blackbox_open_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_open.h b/test/blackbox/run_blackbox_tests/test_cases_open.h deleted file mode 100644 index 0c3f7d9..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_open.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_OPEN_H -#define TEST_CASES_OPEN_H - -/* - test_cases_open.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_open(void); -extern int total_tests; - -#endif // TEST_STEP_OPEN_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_pmtu.c b/test/blackbox/run_blackbox_tests/test_cases_pmtu.c deleted file mode 100644 index 5867596..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_pmtu.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - test_cases_pmtu.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_pmtu.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_pmtu_01(void **state); -static bool test_steps_mesh_pmtu_01(void); -static void test_case_mesh_pmtu_02(void **state); -static bool test_steps_mesh_pmtu_02(void); -static void test_case_mesh_pmtu_03(void **state); -static bool test_steps_mesh_pmtu_03(void); - -/* State structure for meshlink_get_pmtu Test Case #1 */ -static black_box_state_t test_mesh_pmtu_01_state = { - .test_case_name = "test_case_mesh_pmtu_01", -}; - -/* State structure for meshlink_get_pmtu Test Case #2 */ -static black_box_state_t test_mesh_pmtu_02_state = { - .test_case_name = "test_case_mesh_pmtu_02", -}; - -/* State structure for meshlink_get_pmtu Test Case #3 */ -static black_box_state_t test_mesh_pmtu_03_state = { - .test_case_name = "test_case_mesh_pmtu_03", -}; - -/* Execute meshlink_get_pmtu Test Case # 1 */ -static void test_case_mesh_pmtu_01(void **state) { - execute_test(test_steps_mesh_pmtu_01, state); -} - -/* Test Steps for meshlink_get_pmtu Test Case # 1 - - Test Steps: - 1. Create node instance & get self handle - 2. Obtain MTU size - - Expected Result: - meshlink_get_pmtu should return valid MTU size of a node -*/ -static bool test_steps_mesh_pmtu_01(void) { - meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - - assert(meshlink_start(mesh)); - meshlink_node_t *dest_node = meshlink_get_self(mesh); - assert(dest_node != NULL); - - ssize_t pmtu = meshlink_get_pmtu(mesh, dest_node); - assert_int_not_equal(pmtu, -1); - - meshlink_close(mesh); - assert(meshlink_destroy("pmtu_conf")); - return true; -} - -/* Execute meshlink_get_pmtu Test Case # 2 - - Test Steps: - 1. Create node instance & get self handle - 2. Try to obtain MTU size by passing NULL as mesh handle to API - - Expected Result: - meshlink_get_pmtu should return -1 reporting the error -*/ -static void test_case_mesh_pmtu_02(void **state) { - execute_test(test_steps_mesh_pmtu_02, state); -} - -/* Test Steps for meshlink_get_pmtu Test Case # 2*/ -static bool test_steps_mesh_pmtu_02(void) { - meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - - assert(meshlink_start(mesh)); - meshlink_node_t *dest_node = meshlink_get_self(mesh); - assert(dest_node != NULL); - - ssize_t pmtu = meshlink_get_pmtu(NULL, dest_node); - assert_int_equal(pmtu, -1); - - meshlink_close(mesh); - assert(meshlink_destroy("pmtu_conf")); - return true; -} - -/* Execute meshlink_get_pmtu Test Case # 3 */ -static void test_case_mesh_pmtu_03(void **state) { - execute_test(test_steps_mesh_pmtu_03, state); -} - -/* Test Steps for meshlink_get_pmtu Test Case # 3 - - Test Steps: - 1. Create node instance & get self handle - 2. Try to obtain MTU size by passing NULL as node handle to API - - Expected Result: - meshlink_get_pmtu should return -1 reporting the error -*/ -static bool test_steps_mesh_pmtu_03(void) { - meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - - assert(meshlink_start(mesh)); - - ssize_t pmtu = meshlink_get_pmtu(mesh, NULL); - assert_int_equal(pmtu, -1); - - meshlink_close(mesh); - assert(meshlink_destroy("pmtu_conf")); - return true; -} - -int test_meshlink_pmtu(void) { - const struct CMUnitTest blackbox_pmtu_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_01, NULL, NULL, - (void *)&test_mesh_pmtu_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_02, NULL, NULL, - (void *)&test_mesh_pmtu_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_03, NULL, NULL, - (void *)&test_mesh_pmtu_03_state) - }; - - total_tests += sizeof(blackbox_pmtu_tests) / sizeof(blackbox_pmtu_tests[0]); - - return cmocka_run_group_tests(blackbox_pmtu_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_pmtu.h b/test/blackbox/run_blackbox_tests/test_cases_pmtu.h deleted file mode 100644 index db9b5cd..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_pmtu.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_PMTU_H -#define TEST_CASES_PMTU_H - -/* - test_cases_pmtu.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_pmtu(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c deleted file mode 100644 index f7bead8..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - test_cases_random_port_bindings01.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -#include "execute_tests.h" -#include "test_cases_random_port_bindings01.h" -#include "../../../src/meshlink-tiny.h" -#include "../../../src/devtools.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_random_port_bindings_01(void **state); -static bool test_steps_mesh_random_port_bindings_01(void); -static void test_case_mesh_random_port_bindings_02(void **state); -static bool test_steps_mesh_random_port_bindings_02(void); -static void test_case_mesh_random_port_bindings_03(void **state); -static bool test_steps_mesh_random_port_bindings_03(void); - -/* State structure for meshlink_random_port_bindings Test Case #1 */ -static black_box_state_t test_mesh_random_port_bindings_01_state = { - .test_case_name = "test_case_mesh_random_port_bindings_01", -}; - -/* State structure for meshlink_random_port_bindings Test Case #2 */ -static black_box_state_t test_mesh_random_port_bindings_02_state = { - .test_case_name = "test_case_mesh_random_port_bindings_02", -}; - -/* State structure for meshlink_random_port_bindings Test Case #3 */ -static black_box_state_t test_mesh_random_port_bindings_03_state = { - .test_case_name = "test_case_mesh_random_port_bindings_03", -}; - -static int sockfd = -1, ipv6_fd = -1; - -static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void) mesh; - - static const char *levelstr[] = { - [MESHLINK_DEBUG] = "\x1b[34mDEBUG", - [MESHLINK_INFO] = "\x1b[32mINFO", - [MESHLINK_WARNING] = "\x1b[33mWARNING", - [MESHLINK_ERROR] = "\x1b[31mERROR", - [MESHLINK_CRITICAL] = "\x1b[31mCRITICAL", - }; - fprintf(stderr, "%s:\x1b[0m %s\n", levelstr[level], text); -} - -static void occupy_port(int port) { - int ret_val; - int mode = 1; - struct sockaddr_in servaddr; - struct sockaddr_in6 ipv6addr; - - sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - assert_int_not_equal(sockfd, -1); - memset(&servaddr, 0, sizeof(servaddr)); - - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(port); - - assert_int_equal(bind(sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)), 0); - - ipv6_fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); - assert_int_not_equal(ipv6_fd, -1); - - mode = 1; - setsockopt(ipv6_fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&mode, sizeof(mode)); - - memset(&ipv6addr, 0, sizeof(ipv6addr)); - - ipv6addr.sin6_family = AF_INET6; - ipv6addr.sin6_addr = in6addr_any; - ipv6addr.sin6_port = htons(port); - - if((ret_val = bind(ipv6_fd, (const struct sockaddr *)&ipv6addr, sizeof(ipv6addr))) < 0) { - fprintf(stderr, "Bind to ipv6 failed due to %s\n", strerror(errno)); - assert(false); - } - - listen(ipv6_fd, 5); - - return; -} - -static void occupy_trybind_port(void) { - occupy_port(10000); - return; -} - -/* Execute meshlink_random_port_bindings Test Case # 1*/ -void test_case_mesh_random_port_bindings_01(void **state) { - execute_test(test_steps_mesh_random_port_bindings_01, state); -} - -/* Test Steps for meshlink random port bindings Test Case # 1 - - Test Steps: - 1. Open a node instance - 2. Bind a Socket on port 10000 - 3. Call meshlink_set_port() with same port 10000 - - Expected Result: - The meshlink_set_port() API should fail and the Listening Port - of the instance should be unchanged. -*/ -bool test_steps_mesh_random_port_bindings_01(void) { - meshlink_handle_t *relay = NULL; - assert(meshlink_destroy("relay_conf")); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message); - - relay = meshlink_open("relay_conf", "relay", "test", DEV_CLASS_BACKBONE); - fprintf(stderr, "Got mesh handle %p\n", (void *)relay); - assert_non_null(relay); - - meshlink_set_log_cb(relay, MESHLINK_DEBUG, log_message); - meshlink_enable_discovery(relay, false); - - assert_true(meshlink_start(relay)); - - occupy_port(10000); - - meshlink_stop(relay); - fprintf(stderr, "Meshlink stop returned\n"); - - assert_int_equal(meshlink_set_port(relay, 10000), false); - fprintf(stderr, "Meshlink set port returned\n"); - - close(sockfd); - close(ipv6_fd); - - sockfd = -1; - ipv6_fd = -1; - - meshlink_close(relay); - assert(meshlink_destroy("relay_conf")); - - return true; -} - -/* Execute meshlink_blacklist Test Case # 2*/ -void test_case_mesh_random_port_bindings_02(void **state) { - execute_test(test_steps_mesh_random_port_bindings_02, state); -} - -/* Test Steps for meshlink random port bindings Test Case # 2 - - Test Steps: - 1. Open a node and start the instance. - 2. Call meshlink_set_port() with port 10000 - 3. When try bind succeeds block the port using devtool_trybind_probe() callback. - - Expected Result: - The meshlink_set_port() API should fail. -*/ -bool test_steps_mesh_random_port_bindings_02(void) { - meshlink_handle_t *relay = NULL; - assert(meshlink_destroy("relay_conf")); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message); - - relay = meshlink_open("relay_conf", "relay", "test", DEV_CLASS_BACKBONE); - fprintf(stderr, "Got mesh handle %p\n", (void *)relay); - assert_non_null(relay); - - meshlink_set_log_cb(relay, MESHLINK_DEBUG, log_message); - meshlink_enable_discovery(relay, false); - - assert_true(meshlink_start(relay)); - - sleep(1); - - devtool_trybind_probe = occupy_trybind_port; - meshlink_stop(relay); - - assert_int_equal(meshlink_set_port(relay, 10000), false); - - close(sockfd); - close(ipv6_fd); - - sockfd = -1; - ipv6_fd = -1; - - meshlink_close(relay); - assert(meshlink_destroy("relay_conf")); - return true; -} - -/* Execute meshlink_blacklist Test Case # 3*/ -void test_case_mesh_random_port_bindings_03(void **state) { - execute_test(test_steps_mesh_random_port_bindings_03, state); -} - -/* Test Steps for meshlink random port bindings Test Case # 3 - - Test Steps: - 1. Open a node and start the instance. - 2. Retrieve the port number of current instance using meshlink_get_port(). - 3. Close the instance and try to occupy the meshlink instance port. - 4. Start the instance again with same confdir. - - Expected Result: - The meshlink instance should start with a new random port different to - previous port number. -*/ -bool test_steps_mesh_random_port_bindings_03(void) { - int port, new_port; - meshlink_handle_t *relay = NULL; - assert(meshlink_destroy("relay_conf")); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message); - - relay = meshlink_open("relay_conf", "relay", "test", DEV_CLASS_BACKBONE); - fprintf(stderr, "Got mesh handle %p\n", (void *)relay); - assert_non_null(relay); - - meshlink_set_log_cb(relay, MESHLINK_DEBUG, log_message); - meshlink_enable_discovery(relay, false); - - assert_true(meshlink_start(relay)); - port = meshlink_get_port(relay); - - meshlink_close(relay); - - occupy_port(port); - - relay = meshlink_open("relay_conf", "relay", "test", DEV_CLASS_BACKBONE); - fprintf(stderr, "Got mesh handle %p\n", (void *)relay); - assert_non_null(relay); - - meshlink_set_log_cb(relay, MESHLINK_DEBUG, log_message); - meshlink_enable_discovery(relay, false); - - assert_true(meshlink_start(relay)); - - new_port = meshlink_get_port(relay); - - assert_int_not_equal(port, new_port); - - close(sockfd); - close(ipv6_fd); - - sockfd = -1; - ipv6_fd = -1; - - meshlink_close(relay); - assert(meshlink_destroy("relay_conf")); - return true; -} - -int test_meshlink_random_port_bindings01(void) { - const struct CMUnitTest blackbox_random_port_bindings_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_random_port_bindings_01, NULL, NULL, - (void *)&test_mesh_random_port_bindings_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_random_port_bindings_02, NULL, NULL, - (void *)&test_mesh_random_port_bindings_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_random_port_bindings_03, NULL, NULL, - (void *)&test_mesh_random_port_bindings_03_state) - }; - - total_tests += sizeof(blackbox_random_port_bindings_tests) / sizeof(blackbox_random_port_bindings_tests[0]); - - return cmocka_run_group_tests(blackbox_random_port_bindings_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.h b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.h deleted file mode 100644 index c79ea91..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_RANDOM_PORT_BINDINGS01_H -#define TEST_CASES_RANDOM_PORT_BINDINGS01_H - -/* - test_cases_random_port_bindings01.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_random_port_bindings01(void); -extern int total_tests; - -#endif //TEST_CASES_RANDOM_PORT_BINDINGS01_H \ No newline at end of file diff --git a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c deleted file mode 100644 index 1c6fa79..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - test_optimal_pmtu.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../../../src/meshlink-tiny.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" -#include "test_cases_random_port_bindings02.h" - -static void test_case_mesh_random_port_bindings_04(void **state); -static bool test_steps_mesh_random_port_bindings_04(void); -static void test_case_mesh_random_port_bindings_05(void **state); -static bool test_steps_mesh_random_port_bindings_05(void); - -typedef bool (*test_step_func_t)(void); -static int setup_test(void **state); - -static meshlink_handle_t *peer, *nut_instance, *relay; -static char *peer_invite, *nut_invite; -struct sync_flag test_random_port_binding_node_connected = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -struct sync_flag test_random_port_binding_node_started = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -struct sync_flag test_random_port_binding_peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -struct sync_flag test_random_port_binding_make_switch = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -struct sync_flag test_random_port_binding_relay_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -struct sync_flag test_random_port_binding_peer_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -struct sync_flag test_random_port_binding_nut_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static netns_state_t *test_random_port_bindings_state; -static bool localnode = false; - -static int setup_test(void **state) { - (void)state; - - netns_create_topology(test_random_port_bindings_state); - fprintf(stderr, "\nCreated topology\n"); - - set_sync_flag(&test_random_port_binding_node_connected, false); - set_sync_flag(&test_random_port_binding_node_started, false); - set_sync_flag(&test_random_port_binding_peer_reachable, false); - set_sync_flag(&test_random_port_binding_make_switch, false); - set_sync_flag(&test_random_port_binding_relay_closed, false); - set_sync_flag(&test_random_port_binding_peer_closed, false); - set_sync_flag(&test_random_port_binding_nut_closed, false); - - assert(meshlink_destroy("nut")); - assert(meshlink_destroy("peer")); - assert(meshlink_destroy("relay")); - - return EXIT_SUCCESS; -} - -static int teardown_test(void **state) { - (void)state; - - assert(meshlink_destroy("nut")); - assert(meshlink_destroy("peer")); - assert(meshlink_destroy("relay")); - netns_destroy_topology(test_random_port_bindings_state); - - return EXIT_SUCCESS; -} - -static void execute_test(test_step_func_t step_func, void **state) { - (void)state; - - - fprintf(stderr, "\n\x1b[32mRunning Test\x1b[0m\n"); - bool test_result = step_func(); - - if(!test_result) { - fail(); - } -} - -static void message_log(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)level; - - char *levelstr = "\x1b[32mRELAY"; - - if(strcmp(mesh->name, "peer") == 0) { - if(strcmp("Connection with nut activated", text) == 0) { - set_sync_flag(&test_random_port_binding_node_connected, true); - } - - levelstr = "\x1b[34mPEER"; - } else if(strcmp(mesh->name, "nut") == 0) { - if(strcmp("Connection with peer activated", text) == 0) { - set_sync_flag(&test_random_port_binding_node_connected, true); - } - - levelstr = "\x1b[33mNUT"; - } - - fprintf(stderr, "%s:\x1b[0m %s\n", levelstr, text); -} - -static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(reachable) { - if((strcmp(mesh->name, "nut") == 0) && (strcmp(node->name, "peer") == 0)) { - set_sync_flag(&test_random_port_binding_peer_reachable, true); - } - - fprintf(stderr, "%s: %s joined.\n", mesh->name, node->name); - } -} - -static void *relay_node(void *arg) { - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - - //system("ifconfig"); - - assert(meshlink_destroy("relay")); - - relay = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(relay); - - assert_true(meshlink_start(relay)); - fprintf(stderr, "\n\x1b[32mRelay Started\x1b[0m\n"); - - assert((peer_invite = meshlink_invite(relay, NULL, "peer"))); - assert((nut_invite = meshlink_invite(relay, NULL, "nut"))); - - set_sync_flag(&test_random_port_binding_node_started, true); - - meshlink_set_log_cb(relay, MESHLINK_DEBUG, message_log); - - if(localnode == true) { - assert(wait_sync_flag(&test_random_port_binding_make_switch, 300)); - meshlink_close(relay); - assert(meshlink_destroy("relay")); - - - set_sync_flag(&test_random_port_binding_relay_closed, true); - - return NULL; - } - - assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); - - meshlink_close(relay); - assert(meshlink_destroy("relay")); - - - set_sync_flag(&test_random_port_binding_relay_closed, true); - - return NULL; -} - -static void *peer_node(void *arg) { - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - - fprintf(stderr, "\n\x1b[32mPeer Thread Started\x1b[0m\n"); - - assert(meshlink_destroy("peer")); - - peer = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(peer); - meshlink_set_log_cb(peer, MESHLINK_DEBUG, message_log); - - fprintf(stderr, "\n\x1b[32mPeer joining relay\x1b[0m\n"); - - assert_true(meshlink_join(peer, (const char *)mesh_arg->join_invitation)); - - assert_true(meshlink_start(peer)); - - fprintf(stderr, "\n\x1b[32mPeer Started\x1b[0m\n"); - - set_sync_flag(&test_random_port_binding_node_started, true); - - assert(wait_sync_flag(&test_random_port_binding_make_switch, 300)); - - meshlink_stop(peer); - - //meshlink_set_log_cb(peer, MESHLINK_DEBUG, message_log); - - assert(meshlink_set_port(peer, 20000)); - - assert_true(meshlink_start(peer)); - - assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); - - meshlink_close(peer); - assert(meshlink_destroy("peer")); - - set_sync_flag(&test_random_port_binding_peer_closed, true); - - return NULL; -} - -static void *nut_node(void *arg) { - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - - fprintf(stderr, "\n\x1b[32mNut Thread Started\x1b[0m\n"); - - assert(meshlink_destroy("nut")); - - nut_instance = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(nut_instance); - - meshlink_set_log_cb(nut_instance, MESHLINK_DEBUG, message_log); - - fprintf(stderr, "\n\x1b[32mNut joining relay\x1b[0m\n"); - - assert_true(meshlink_join(nut_instance, (const char *)mesh_arg->join_invitation)); - - meshlink_set_node_status_cb(nut_instance, node_status); - - assert_true(meshlink_start(nut_instance)); - - fprintf(stderr, "\n\x1b[32mNut Started\x1b[0m\n"); - sleep(5); - - set_sync_flag(&test_random_port_binding_node_started, true); - - assert(wait_sync_flag(&test_random_port_binding_make_switch, 300)); - - meshlink_stop(nut_instance); - - //meshlink_set_log_cb(nut_instance, MESHLINK_DEBUG, message_log); - - assert(meshlink_set_port(nut_instance, 30000)); - - assert_true(meshlink_start(nut_instance)); - - assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); - - meshlink_close(nut_instance); - assert(meshlink_destroy("nut")); - - set_sync_flag(&test_random_port_binding_nut_closed, true); - - return NULL; -} - -/* Test Steps for Random port bindings Test Case # 4 */ -static void test_case_mesh_random_port_bindings_04(void **state) { - execute_test(test_steps_mesh_random_port_bindings_04, state); - return; -} - -/* Test Steps for Random port bindings Test Case # 4 - - Test Steps: - 1. Create three node nut, peer and relay in three different name spaces. - 2. Join nut and peer to relay with invitation. - 3. Stop the three nodes and change the ports of nut and peer. - 4. Start all the nodes again. - Expected Result: - NUT and Peer should be able to discover each others port with the help - of RELAY and form the direct meta connection. -*/ -static bool test_steps_mesh_random_port_bindings_04(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "chat", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "chat", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "chat", .dev_class = 1 }; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = relay_node, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - assert(wait_sync_flag(&test_random_port_binding_node_started, 5)); - fprintf(stderr, "\n\x1b[32mTest-04 : Relay Started\x1b[0m\n"); - - set_sync_flag(&test_random_port_binding_node_started, false); - peer_arg.join_invitation = peer_invite; - fprintf(stderr, "\n\x1b[32mTest-04: Got Invite {%s} for peer\x1b[0m\n", peer_arg.join_invitation); - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = peer_node, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - assert(wait_sync_flag(&test_random_port_binding_node_started, 20)); - fprintf(stderr, "\n\x1b[32mTest-04 : Peer Started\x1b[0m\n"); - - set_sync_flag(&test_random_port_binding_node_started, false); - nut_arg.join_invitation = nut_invite; - fprintf(stderr, "\n\x1b[32mTest-04: Got Invite {%s} for nut\x1b[0m\n", nut_arg.join_invitation); - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = nut_node, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_random_port_binding_node_started, 20)); - fprintf(stderr, "\n\x1b[32mTest-04 : Nut Started\x1b[0m\n"); - - set_sync_flag(&test_random_port_binding_make_switch, true); - fprintf(stderr, "\n\x1b[32mTest-04 : Making Switch\x1b[0m\n"); - - assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); - - fprintf(stderr, "\n\x1b[32mDone Test-04\x1b[0m\n"); - - assert(wait_sync_flag(&test_random_port_binding_relay_closed, 10)); - assert(wait_sync_flag(&test_random_port_binding_peer_closed, 10)); - assert(wait_sync_flag(&test_random_port_binding_nut_closed, 10)); - - return true; -} - -/* Test Steps for Random port bindings Test Case # 5 */ -static void test_case_mesh_random_port_bindings_05(void **state) { - execute_test(test_steps_mesh_random_port_bindings_05, state); - return; -} - -/* Test Steps for Random port bindings Test Case # 5 - - Test Steps: - 1. Create three node nut, peer and relay in same name spaces. - 2. Join nut and peer to relay with invitation. - 3. Stop the three nodes and change the ports of nut and peer. - 4. Close the relay node and start nut and peer nodes again. - Expected Result: - NUT and Peer should be able to discover each others port with the help - of CATTA and form the direct meta connection. -*/ -static bool test_steps_mesh_random_port_bindings_05(void) { - localnode = true; - - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "chat", .dev_class = 1 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "chat", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "chat", .dev_class = 1 }; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = relay_node, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - assert(wait_sync_flag(&test_random_port_binding_node_started, 20)); - - set_sync_flag(&test_random_port_binding_node_started, false); - peer_arg.join_invitation = peer_invite; - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = peer_node, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - assert(wait_sync_flag(&test_random_port_binding_node_started, 20)); - - set_sync_flag(&test_random_port_binding_node_started, false); - nut_arg.join_invitation = nut_invite; - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = nut_node, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_random_port_binding_node_started, 20)); - - assert(wait_sync_flag(&test_random_port_binding_peer_reachable, 300)); - - set_sync_flag(&test_random_port_binding_make_switch, true); - - assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); - - fprintf(stderr, "\n\x1b[32mDone Test-05\x1b[0m\n"); - - assert(wait_sync_flag(&test_random_port_binding_relay_closed, 10)); - assert(wait_sync_flag(&test_random_port_binding_peer_closed, 10)); - assert(wait_sync_flag(&test_random_port_binding_nut_closed, 10)); - - return true; -} - -// Optimal PMTU test case driver - -int test_meshlink_random_port_bindings02(void) { - interface_t nut_ifs[] = {{.if_peer = "wan_bridge"}}; - namespace_t nut = { - .name = "nut", - .type = HOST, - .interfaces = nut_ifs, - .interfaces_no = 1, - }; - - interface_t peer_ifs[] = {{.if_peer = "wan_bridge"}}; - namespace_t peer = { - .name = "peer", - .type = HOST, - .interfaces = peer_ifs, - .interfaces_no = 1, - }; - - interface_t relay_ifs[] = {{.if_peer = "wan_bridge"}}; - namespace_t relay = { - .name = "relay", - .type = HOST, - .interfaces = relay_ifs, - .interfaces_no = 1, - }; - - interface_t wan_ifs[] = { { .if_peer = "nut" }, { .if_peer = "peer" }, { .if_peer = "relay" } }; - namespace_t wan_bridge = { - .name = "wan_bridge", - .type = BRIDGE, - .interfaces = wan_ifs, - .interfaces_no = 3, - }; - - namespace_t test_random_port_bindings_02_nodes[] = {wan_bridge, nut, peer, relay }; - - netns_state_t test_port_bindings_nodes = { - .test_case_name = "test_case_random_port_bindings_02", - .namespaces = test_random_port_bindings_02_nodes, - .num_namespaces = 4, - }; - test_random_port_bindings_state = &test_port_bindings_nodes; - - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_random_port_bindings_04, setup_test, teardown_test, - (void *)&test_random_port_bindings_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_random_port_bindings_05, setup_test, teardown_test, - (void *)&test_random_port_bindings_state) - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.h b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.h deleted file mode 100644 index 03adb23..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_RANDOM_PORT_BINDINGS02_H -#define TEST_CASES_RANDOM_PORT_BINDINGS02_H - -/* - test_cases_random_port_bindings02.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_random_port_bindings02(void); -extern int total_tests; - -#endif //TEST_CASES_RANDOM_PORT_BINDINGS02_H \ No newline at end of file diff --git a/test/blackbox/run_blackbox_tests/test_cases_rec_cb.c b/test/blackbox/run_blackbox_tests/test_cases_rec_cb.c deleted file mode 100644 index e659ead..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_rec_cb.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - test_cases_rec_cb.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "test_cases_rec_cb.h" -#include -#include -#include -#include -#include -#include -#include - - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_set_rec_cb_01(void **state); -static bool test_set_rec_cb_01(void); -static void test_case_set_rec_cb_02(void **state); -static bool test_set_rec_cb_02(void); -static void test_case_set_rec_cb_03(void **state); -static bool test_set_rec_cb_03(void); - -/* Test Steps for meshlink_set_receive_cb Test Case #1 */ -static black_box_state_t test_case_set_rec_cb_01_state = { - .test_case_name = "test_case_set_rec_cb_01", -}; - -/* Test Steps for meshlink_set_receive_cb Test Case #2 */ -static black_box_state_t test_case_set_rec_cb_02_state = { - .test_case_name = "test_case_set_rec_cb_02", -}; - -/* Test Steps for meshlink_set_receive_cb Test Case #3 */ -static black_box_state_t test_case_set_rec_cb_03_state = { - .test_case_name = "test_case_set_rec_cb_03", -}; - -static bool received; - -/* mutex for the common variable */ -static pthread_mutex_t lock; - -/* receive callback function */ -static void rec_cb(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) { - (void)mesh; - (void)source; - - assert(len); - - pthread_mutex_lock(&lock); - - if(len == 5 && !memcmp(data, "test", 5)) { - received = true; - } - - pthread_mutex_unlock(&lock); -} - -/* Execute meshlink_set_receive_cb Test Case # 1 - Valid case */ -static void test_case_set_rec_cb_01(void **state) { - execute_test(test_set_rec_cb_01, state); -} -/* Test Steps for meshlink_set_receive_cb Test Case # 1 - - Test Steps: - 1. Open NUT - 2. Set receive callback for the NUT - 3. Echo NUT with some data. - - Expected Result: - Receive callback should be invoked when NUT echoes or sends data for itself. -*/ -static bool test_set_rec_cb_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("set_receive_cb_conf", "nut", "test", 1); - assert(mesh_handle); - meshlink_set_receive_cb(mesh_handle, rec_cb); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - assert(meshlink_start(mesh_handle)); - sleep(1); - - pthread_mutex_lock(&lock); - received = false; - pthread_mutex_unlock(&lock); - meshlink_node_t *node_handle = meshlink_get_self(mesh_handle); - assert(node_handle); - assert(meshlink_send(mesh_handle, node_handle, "test", 5)); - sleep(1); - - pthread_mutex_lock(&lock); - assert_int_equal(received, true); - pthread_mutex_unlock(&lock); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("set_receive_cb_conf")); - return true; -} - - -/* Execute meshlink_set_receive_cb Test Case # 2 - Invalid case */ -static void test_case_set_rec_cb_02(void **state) { - execute_test(test_set_rec_cb_02, state); -} -/* Test Steps for meshlink_set_receive_cb Test Case # 2 - - Test Steps: - 1. Call meshlink_set_receive_cb with NULL as mesh handle argument - - Expected Result: - meshlink_set_receive_cb API reports proper error accordingly. -*/ -static bool test_set_rec_cb_02(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Setting receive callback with NULL as mesh handle - meshlink_set_receive_cb(NULL, rec_cb); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - return true; -} - -/* Execute meshlink_set_receive_cb Test Case # 3 - Functionality Test, Trying to set receive call back after - starting the mesh */ -static void test_case_set_rec_cb_03(void **state) { - execute_test(test_set_rec_cb_03, state); -} -/* Test Steps for meshlink_set_receive_cb Test Case # 3 - - Test Steps: - 1. Open NUT - 2. Starting mesh - 2. Set receive callback for the NUT - 3. Echo NUT with some data. - - Expected Result: - Receive callback can be invoked when NUT echoes or sends data for itself -*/ -static bool test_set_rec_cb_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - /* Create meshlink instance */ - meshlink_handle_t *mesh_handle = meshlink_open("set_receive_cb_conf", "nut", "test", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - assert(meshlink_start(mesh_handle)); - sleep(1); - meshlink_set_receive_cb(mesh_handle, rec_cb); - - pthread_mutex_lock(&lock); - received = false; - pthread_mutex_unlock(&lock); - meshlink_node_t *node_handle = meshlink_get_self(mesh_handle); - assert(node_handle); - assert(meshlink_send(mesh_handle, node_handle, "test", 5)); - sleep(1); - - pthread_mutex_lock(&lock); - assert_int_equal(received, true); - pthread_mutex_unlock(&lock); - - meshlink_close(mesh_handle); - assert(meshlink_destroy("set_receive_cb_conf")); - return true; -} - -int test_meshlink_set_receive_cb(void) { - const struct CMUnitTest blackbox_receive_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_set_rec_cb_01, NULL, NULL, - (void *)&test_case_set_rec_cb_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_rec_cb_02, NULL, NULL, - (void *)&test_case_set_rec_cb_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_rec_cb_03, NULL, NULL, - (void *)&test_case_set_rec_cb_03_state) - }; - total_tests += sizeof(blackbox_receive_tests) / sizeof(blackbox_receive_tests[0]); - - assert(pthread_mutex_init(&lock, NULL) == 0); - int failed = cmocka_run_group_tests(blackbox_receive_tests, NULL, NULL); - assert(pthread_mutex_destroy(&lock) == 0); - - return failed; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_rec_cb.h b/test/blackbox/run_blackbox_tests/test_cases_rec_cb.h deleted file mode 100644 index c4467c8..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_rec_cb.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_SET_REC_CB_H -#define TEST_CASES_SET_REC_CB_H - -/* - test_cases_rec_cb.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_set_receive_cb(void); -extern int total_tests; - -#endif // TEST_CASES_SET_REC_CB_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_send.c b/test/blackbox/run_blackbox_tests/test_cases_send.c deleted file mode 100644 index 1cf47fc..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_send.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - test_cases_send.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_send.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_send_01(void **state); -static bool test_steps_mesh_send_01(void); -static void test_case_mesh_send_02(void **state); -static bool test_steps_mesh_send_02(void); -static void test_case_mesh_send_03(void **state); -static bool test_steps_mesh_send_03(void); - -/* State structure for meshlink_send Test Case #1 */ -static black_box_state_t test_mesh_send_01_state = { - .test_case_name = "test_case_mesh_send_01", -}; - -/* State structure for meshlink_send Test Case #2 */ -static black_box_state_t test_mesh_send_02_state = { - .test_case_name = "test_case_mesh_send_02", -}; - -/* State structure for meshlink_send Test Case #3 */ -static black_box_state_t test_mesh_send_03_state = { - .test_case_name = "test_case_mesh_send_03", -}; - -/* Execute meshlink_send Test Case # 1 */ -static void test_case_mesh_send_01(void **state) { - execute_test(test_steps_mesh_send_01, state); -} - -static bool receive_data = false; -static void receive(meshlink_handle_t *mesh, meshlink_node_t *dest_node, const void *data, size_t len) { - (void)mesh; - (void)dest_node; - - assert(len); - - if(!memcmp(data, "test", 5)) { - receive_data = true; - } -} - -/* Test Steps for meshlink_send Test Case # 1 - - Test Steps: - 1. Open instance of foo node - 2. Run and send data to itself - - Expected Result: - Node should receive data sent to itself -*/ -static bool test_steps_mesh_send_01(void) { - bool result = false; - - meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - meshlink_set_receive_cb(mesh, receive); - assert(meshlink_start(mesh)); - sleep(1); - meshlink_node_t *dest_node = meshlink_get_self(mesh); - assert(dest_node); - - receive_data = false; - result = meshlink_send(mesh, dest_node, "test", 5); - assert_int_equal(result, true); - sleep(1); - assert_int_equal(receive_data, true); - - meshlink_close(mesh); - assert(meshlink_destroy("send_conf")); - return result; -} - -/* Execute meshlink_send Test Case # 2 - - Test Steps: - 1. Open instance of foo node - 2. meshlink_send with NULL as mesh handle - - Expected Result: - meshlink_send returns false because of NULL handle -*/ -static void test_case_mesh_send_02(void **state) { - execute_test(test_steps_mesh_send_02, state); -} - -/* Test Steps for meshlink_send Test Case # 2*/ -static bool test_steps_mesh_send_02(void) { - meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "chat", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - meshlink_set_receive_cb(mesh, receive); - - assert(meshlink_start(mesh)); - meshlink_node_t *dest_node = meshlink_get_self(mesh); - assert(dest_node); - - bool ret = meshlink_send(NULL, dest_node, "test", 5); - assert_int_equal(ret, false); - - meshlink_close(mesh); - assert(meshlink_destroy("send_conf")); - return true; -} - -/* Execute meshlink_send Test Case # 3 - - Test Steps: - 1. Open instance of foo node - 2. meshlink_send with NULL as node handle - - Expected Result: - meshlink_send returns false because of NULL handle -*/ -static void test_case_mesh_send_03(void **state) { - execute_test(test_steps_mesh_send_03, state); -} - -/* Test Steps for meshlink_send Test Case # 3*/ -static bool test_steps_mesh_send_03(void) { - meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "chat", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - meshlink_set_receive_cb(mesh, receive); - - assert(meshlink_start(mesh)); - - bool ret = meshlink_send(mesh, NULL, "test", 5); - assert_int_equal(ret, false); - - meshlink_close(mesh); - assert(meshlink_destroy("send_conf")); - return true; -} - -int test_meshlink_send(void) { - const struct CMUnitTest blackbox_send_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_01, NULL, NULL, - (void *)&test_mesh_send_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_02, NULL, NULL, - (void *)&test_mesh_send_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_03, NULL, NULL, - (void *)&test_mesh_send_03_state) - }; - - total_tests += sizeof(blackbox_send_tests) / sizeof(blackbox_send_tests[0]); - - return cmocka_run_group_tests(blackbox_send_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_send.h b/test/blackbox/run_blackbox_tests/test_cases_send.h deleted file mode 100644 index 6649b8f..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_send.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_SEND_H -#define TEST_CASES_SEND_H - -/* - test_cases_send.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_send(void); -extern int total_tests; - - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c b/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c deleted file mode 100644 index 6eac857..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - test_cases_set_connection_try_cb.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_set_connection_try_cb.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include -#include -#include -#include - -static void test_case_set_connection_try_cb_01(void **state); -static bool test_set_connection_try_cb_01(void); - -static bool bar_reachable; -static int connection_attempts; -static struct sync_flag status_changed_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag connection_attempt_cond = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *source, bool reachable) { - if(!strcmp(mesh->name, "foo") && !strcmp(source->name, "bar")) { - bar_reachable = reachable; - set_sync_flag(&status_changed_cond, true); - } -} - -/* Meta-connection try callback handler */ -static void connection_try_cb(meshlink_handle_t *mesh, meshlink_node_t *source) { - (void)source; - - if(!strcmp(mesh->name, "foo")) { - ++connection_attempts; - - if(connection_attempts > 3) { - set_sync_flag(&connection_attempt_cond, true); - } - } -} - -/* Execute set meta connection try callback Test Case # 1 */ -static void test_case_set_connection_try_cb_01(void **state) { - execute_test(test_set_connection_try_cb_01, state); -} - -/* Test Steps for meshlink_set_connection_try_cb Test Case # 1 - - Test Steps: - 1. Run foo and bar nodes after exporting and importing node's keys and addresses mutually. - 2. Close bar node. Wait for connection attempts and cleanup. - - Expected Result: - Connection try callback should be invoked initially when foo and bar forms a meta-connection. - After closing bar node it should invoke 3 connection try callbacks in span of about 30 seconds. -*/ -static bool test_set_connection_try_cb_01(void) { - assert(meshlink_destroy("meshlink_conf.1")); - assert(meshlink_destroy("meshlink_conf.2")); - - // Opening foo and bar nodes - meshlink_handle_t *mesh1 = meshlink_open("meshlink_conf.1", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_enable_discovery(mesh1, false); - meshlink_handle_t *mesh2 = meshlink_open("meshlink_conf.2", "bar", "test", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - - // Set up callback for node status - meshlink_set_node_status_cb(mesh1, node_status_cb); - meshlink_set_connection_try_cb(mesh1, connection_try_cb); - - // Exporting and Importing mutually - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - assert(meshlink_import(mesh1, exp2)); - assert(meshlink_import(mesh2, exp1)); - free(exp1); - free(exp2); - - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - - // Wait for foo and bar nodes to join - assert(wait_sync_flag(&status_changed_cond, 5)); - assert(bar_reachable); - - // Joining should in this case raise one connection try callback - assert_int_equal(connection_attempts, 1); - - // Close the bar node - set_sync_flag(&status_changed_cond, false); - meshlink_close(mesh2); - assert(wait_sync_flag(&status_changed_cond, 5)); - assert(!bar_reachable); - - // Wait for additional 3 connection try callbacks - time_t attempt_time_start = time(NULL); - assert(attempt_time_start != -1); - assert_int_equal(wait_sync_flag(&connection_attempt_cond, 60), true); - - // Close bar node and assert on number of callbacks invoked and the time taken. - meshlink_close(mesh1); - time_t attempt_time_stop = time(NULL); - assert(attempt_time_stop != -1); - assert_int_equal(connection_attempts, 4); - assert_in_range(attempt_time_stop - attempt_time_start, 25, 45); - - // Cleanup - assert(meshlink_destroy("meshlink_conf.1")); - assert(meshlink_destroy("meshlink_conf.2")); - - return true; -} - -int test_cases_connection_try(void) { - black_box_state_t test_case_set_connection_try_cb_01_state = { - .test_case_name = "test_case_set_connection_try_cb_01", - }; - - const struct CMUnitTest blackbox_connection_try_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_set_connection_try_cb_01, NULL, NULL, - (void *)&test_case_set_connection_try_cb_01_state), - }; - total_tests += sizeof(blackbox_connection_try_tests) / sizeof(blackbox_connection_try_tests[0]); - - int failed = cmocka_run_group_tests(blackbox_connection_try_tests, NULL, NULL); - - return failed; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.h b/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.h deleted file mode 100644 index 8a3c0da..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef TEST_CASES_SET_CONNECTION_TRY_CB_H -#define TEST_CASES_SET_CONNECTION_TRY_CB_H - -/* - test_cases_set_connection_try_cb.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -extern int test_cases_connection_try(void); -extern int total_tests; - -#endif // TEST_CASES_SET_CONNECTION_TRY_CB_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c b/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c deleted file mode 100644 index da49558..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - test_cases_set_log_cb.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_set_log_cb.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include - - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_set_log_cb_01(void **state); -static bool test_set_log_cb_01(void); -static void test_case_set_log_cb_02(void **state); -static bool test_set_log_cb_02(void); - -/* log variable gives access to the log callback to know whether invoked or not */ -static bool log; - -/* State structure for log callback Test Case #1 */ -static black_box_state_t test_case_set_log_cb_01_state = { - .test_case_name = "test_case_set_log_cb_01", -}; - -/* State structure for log callback Test Case #2 */ -static black_box_state_t test_case_set_log_cb_02_state = { - .test_case_name = "test_case_set_log_cb_02", -}; - - -/* log callback */ -static void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - (void)level; - - fprintf(stderr, "Received log text : %s\n", text); - log = true; -} - -/* Execute meshlink_set_log_cb Test Case # 1 - Valid case */ -static void test_case_set_log_cb_01(void **state) { - execute_test(test_set_log_cb_01, state); -} -/* Test Steps for meshlink_set_receive_cb Test Case # 1 - - Test Steps: - 1. Run relay and Open NUT - 2. Set log callback for the NUT and Start NUT - - Expected Result: - log callback should be invoked when NUT joins with relay. -*/ -static bool test_set_log_cb_01(void) { - assert(meshlink_destroy("logconf")); - - // Create meshlink instance for NUT - - meshlink_handle_t *mesh = meshlink_open("logconf", "nut", "test", DEV_CLASS_STATIONARY); - assert(mesh != NULL); - - // Set up logging for Meshlink with the newly acquired Mesh Handle - - log = false; - meshlink_set_log_cb(mesh, TEST_MESHLINK_LOG_LEVEL, log_cb); - - // Starting node to log - - bool mesh_start = meshlink_start(mesh); - assert(mesh_start); - - bool ret = log; - - assert_int_equal(ret, true); - - // closing meshes and destroying confbase - - meshlink_close(mesh); - assert(meshlink_destroy("logconf")); - - return true; -} - -/* Execute meshlink_set_log_cb Test Case # 2 - Invalid case */ -static void test_case_set_log_cb_02(void **state) { - execute_test(test_set_log_cb_02, state); -} -/* Test Steps for meshlink_set_poll_cb Test Case # 2 - - Test Steps: - 1. Calling meshlink_set_poll_cb with some invalid integer other than the valid enums. - - Expected Result: - set poll callback handles the invalid parameter when called by giving proper error number. -*/ -static bool test_set_log_cb_02(void) { - - // Setting an invalid level - - meshlink_set_log_cb(NULL, 1000, NULL); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - return true; -} - - -int test_meshlink_set_log_cb(void) { - const struct CMUnitTest blackbox_log_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_set_log_cb_01, NULL, NULL, - (void *)&test_case_set_log_cb_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_log_cb_02, NULL, NULL, - (void *)&test_case_set_log_cb_02_state) - }; - total_tests += sizeof(blackbox_log_tests) / sizeof(blackbox_log_tests[0]); - - int failed = cmocka_run_group_tests(blackbox_log_tests, NULL, NULL); - - return failed; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.h b/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.h deleted file mode 100644 index 31b1aa9..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_SET_LOG_CB_H -#define TEST_CASES_SET_LOG_CB_H - -/* - test_cases_set_log_cb.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_set_log_cb(void); -extern int total_tests; - -#endif // TEST_CASES_SET_LOG_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_port.c b/test/blackbox/run_blackbox_tests/test_cases_set_port.c deleted file mode 100644 index c215399..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_set_port.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - test_cases_set_port.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_destroy.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../../utils.h" -#include "test_cases_set_port.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -#define NUT "nut" -#define PEER "peer" -#define TEST_MESHLINK_SET_PORT "test_set_port" -#define create_path(confbase, node_name, test_case_no) assert(snprintf(confbase, sizeof(confbase), TEST_MESHLINK_SET_PORT "_%ld_%s_%02d", (long) getpid(), node_name, test_case_no) > 0) - -static void test_case_set_port_01(void **state); -static bool test_set_port_01(void); -static void test_case_set_port_02(void **state); -static bool test_set_port_02(void); -static void test_case_set_port_03(void **state); -static bool test_set_port_03(void); -static void test_case_set_port_04(void **state); -static bool test_set_port_04(void); - -/* State structure for set port API Test Case #1 */ -static black_box_state_t test_case_set_port_01_state = { - .test_case_name = "test_case_set_port_01", -}; -/* State structure for set port API Test Case #2 */ -static black_box_state_t test_case_set_port_02_state = { - .test_case_name = "test_case_set_port_02", -}; -/* State structure for set port API Test Case #3 */ -static black_box_state_t test_case_set_port_03_state = { - .test_case_name = "test_case_set_port_03", -}; -/* State structure for set port API Test Case #4 */ -static black_box_state_t test_case_set_port_04_state = { - .test_case_name = "test_case_set_port_04", -}; - -static bool try_bind(int portno) { - int socket_fd = socket(AF_INET, SOCK_STREAM, 0); - assert_int_not_equal(socket_fd, -1); - - struct sockaddr_in sin; - socklen_t len = sizeof(sin); - bzero(&sin, len); - - assert_int_not_equal(getsockname(socket_fd, (struct sockaddr *)&sin, &len), -1); - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = htons(portno); - - errno = 0; - int bind_status = bind(socket_fd, (struct sockaddr *)&sin, len); - - // Exempt EADDRINUSE error only - - if(bind_status) { - assert_int_equal(errno, EADDRINUSE); - } - - assert_int_not_equal(close(socket_fd), -1); - - return !bind_status; -} - -static void wait_for_socket_free(int portno) { - - // Wait upto 20 seconds and poll every second whether the port is freed or not - - for(int i = 0; i < 20; i++) { - if(try_bind(portno)) { - return; - } else { - sleep(1); - } - } - - fail(); -} - -static int get_free_port(void) { - - // Get a free port - - int socket_fd = socket(AF_INET, SOCK_STREAM, 0); - assert_int_not_equal(socket_fd, -1); - - struct sockaddr_in sin; - socklen_t len = sizeof(sin); - bzero(&sin, len); - - assert_int_not_equal(getsockname(socket_fd, (struct sockaddr *)&sin, &len), -1); - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = 0; - - assert_int_not_equal(bind(socket_fd, (struct sockaddr *)&sin, len), -1); - - assert_int_not_equal(getsockname(socket_fd, (struct sockaddr *)&sin, &len), -1); - - assert_int_not_equal(close(socket_fd), -1); - - return (int) sin.sin_port; -} - - -/* Execute meshlink_set_port Test Case # 1 - valid case*/ -static void test_case_set_port_01(void **state) { - execute_test(test_set_port_01, state); -} -/* Test Steps for meshlink_set_port Test Case # 1 - Valid case - - Test Steps: - 1. Open NUT(Node Under Test) - 2. Set Port for NUT - - Expected Result: - Set the new port to the NUT. -*/ -static bool test_set_port_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - - mesh_handle = meshlink_open("setportconf", "nut", "test", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Get old port and set a new port number - - int port; - port = meshlink_get_port(mesh_handle); - assert(port > 0); - bool ret = meshlink_set_port(mesh_handle, 8000); - port = meshlink_get_port(mesh_handle); - - assert_int_equal(port, 8000); - assert_int_equal(ret, true); - - // Clean up - - meshlink_close(mesh_handle); - assert(meshlink_destroy("setportconf")); - return true; -} - - -/* Execute meshlink_set_port Test Case # 2 - Invalid arguments */ -static void test_case_set_port_02(void **state) { - execute_test(test_set_port_02, state); -} - -/* Test Steps for meshlink_set_port Test Case # 2 - functionality test - - Test Steps: - 1. Open and start NUT and then pass invalid arguments to the set port API - - Expected Result: - Meshlink set port API should fail and error out when invalid arguments are passed -*/ -static bool test_set_port_02(void) { - char nut_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 2); - - // Create meshlink instance - - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_SET_PORT, DEV_CLASS_STATIONARY); - meshlink_set_log_cb(mesh, TEST_MESHLINK_LOG_LEVEL, log_cb); - - // meshlink_set_port called using NULL as mesh handle - - meshlink_errno = MESHLINK_OK; - assert_false(meshlink_set_port(NULL, 8000)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Setting port after starting NUT - meshlink_errno = MESHLINK_OK; - assert_false(meshlink_set_port(mesh, -1)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - meshlink_errno = MESHLINK_OK; - assert_false(meshlink_set_port(mesh, 70000)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - assert_true(meshlink_start(mesh)); - meshlink_errno = MESHLINK_OK; - assert_false(meshlink_set_port(mesh, 8000)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Clean up - - meshlink_close(mesh); - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - -/* Execute meshlink_set_port Test Case # 3 - Synchronization testing */ -static void test_case_set_port_03(void **state) { - execute_test(test_set_port_03, state); -} - -static bool test_set_port_03(void) { - pid_t pid; - int pid_status; - char nut_confbase[PATH_MAX]; - create_path(nut_confbase, NUT, 3); - - int new_port = get_free_port(); - - // Fork a new process in which NUT opens it's instance, set's the new port and raises SIGINT to terminate. - - pid = fork(); - assert_int_not_equal(pid, -1); - - if(!pid) { - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_SET_PORT, DEV_CLASS_STATIONARY); - assert(mesh); - - assert(meshlink_set_port(mesh, new_port)); - raise(SIGINT); - } - - // Wait for child exit and verify which signal terminated it - - assert_int_not_equal(waitpid(pid, &pid_status, 0), -1); - assert_int_equal(WIFSIGNALED(pid_status), true); - assert_int_equal(WTERMSIG(pid_status), SIGINT); - - // Wait for the NUT's listening socket to be freed. (i.e, preventing meshlink from binding to a new port - // when NUT instance is reopened and the actual port is not freed due EADDRINUSE) - - wait_for_socket_free(new_port); - - // Reopen the NUT instance in the same test suite - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_handle_t *mesh = meshlink_open(nut_confbase, NUT, TEST_MESHLINK_SET_PORT, DEV_CLASS_STATIONARY); - assert_non_null(mesh); - - assert_false(try_bind(new_port)); - - // Validate the new port that's being set in the previous instance persists. - - int get_port = meshlink_get_port(mesh); - assert_int_equal(get_port, new_port); - - // Close the mesh instance and verify that the listening port is closed or not - - meshlink_close(mesh); - - wait_for_socket_free(new_port); - - assert_true(meshlink_destroy(nut_confbase)); - return true; -} - - -int test_meshlink_set_port(void) { - const struct CMUnitTest blackbox_set_port_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_set_port_01, NULL, NULL, - (void *)&test_case_set_port_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_port_02, NULL, NULL, - (void *)&test_case_set_port_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_port_03, NULL, NULL, - (void *)&test_case_set_port_03_state) - }; - total_tests += sizeof(blackbox_set_port_tests) / sizeof(blackbox_set_port_tests[0]); - return cmocka_run_group_tests(blackbox_set_port_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_port.h b/test/blackbox/run_blackbox_tests/test_cases_set_port.h deleted file mode 100644 index fa8a768..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_set_port.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_SET_PORT_H -#define TEST_CASES_SET_PORT_H - -/* - test_cases_set_port.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_set_port(void); - -#endif // TEST_CASES_SET_PORT diff --git a/test/blackbox/run_blackbox_tests/test_cases_sign.c b/test/blackbox/run_blackbox_tests/test_cases_sign.c deleted file mode 100644 index 68ae352..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_sign.c +++ /dev/null @@ -1,404 +0,0 @@ -/* - test_cases_sign.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_sign.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_sign_01(void **state); -static bool test_sign_01(void); -static void test_case_sign_02(void **state); -static bool test_sign_02(void); -static void test_case_sign_03(void **state); -static bool test_sign_03(void); -static void test_case_sign_04(void **state); -static bool test_sign_04(void); -static void test_case_sign_05(void **state); -static bool test_sign_05(void); -static void test_case_sign_06(void **state); -static bool test_sign_06(void); -static void test_case_sign_07(void **state); -static bool test_sign_07(void); - -/* State structure for sign API Test Case #1 */ -static black_box_state_t test_case_sign_01_state = { - .test_case_name = "test_case_sign_01", -}; - -/* State structure for sign API Test Case #2 */ -static black_box_state_t test_case_sign_02_state = { - .test_case_name = "test_case_sign_02", -}; - -/* State structure for sign API Test Case #3 */ -static black_box_state_t test_case_sign_03_state = { - .test_case_name = "test_case_sign_03", -}; - -/* State structure for sign API Test Case #4 */ -static black_box_state_t test_case_sign_04_state = { - .test_case_name = "test_case_sign_04", -}; - -/* State structure for sign API Test Case #5 */ -static black_box_state_t test_case_sign_05_state = { - .test_case_name = "test_case_sign_05", -}; - -/* State structure for sign API Test Case #6 */ -static black_box_state_t test_case_sign_06_state = { - .test_case_name = "test_case_sign_06", -}; - -/* State structure for sign API Test Case #7 */ -static black_box_state_t test_case_sign_07_state = { - .test_case_name = "test_case_sign_07", -}; - - -/* Execute sign_data Test Case # 1 - Valid case - sign a data successfully*/ -static void test_case_sign_01(void **state) { - execute_test(test_sign_01, state); -} - -/* Test Steps for meshlink_sign Test Case # 1 - Valid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Sign data - - Expected Result: - Signs data successfully -*/ -static bool test_sign_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - meshlink_handle_t *mesh_handle = meshlink_open("signconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - // Signing data - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, &ssize); - - // Clean up - meshlink_close(mesh_handle); - assert(meshlink_destroy("signconf")); - - return ret; -} - -/* Execute sign_data Test Case # 2 - Invalid case - meshlink_sign passing NULL as mesh handle argument*/ -static void test_case_sign_02(void **state) { - execute_test(test_sign_02, state); - return; -} - -/* Test Steps for meshlink_sign Test Case # 2 - invalid case - - Test Steps: - 1. meshlink_sign API called by passing NULL as mesh handle argument - - Expected Result: - API returns false hinting the error. -*/ -static bool test_sign_02(void) { - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - - // Calling meshlink_sign API - bool ret = meshlink_sign(NULL, data, strlen(data) + 1, sig, &ssize); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as mesh_handle arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_sign FAILED to report error on passing NULL as mesh_handle arg\n"); - return false; -} - -/* Execute sign_data Test Case # 3 - Invalid case - meshlink_sign passing data to be signed as NULL */ -static void test_case_sign_03(void **state) { - execute_test(test_sign_03, state); -} - -/* Test Steps for meshlink_sign Test Case # 3 - invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. meshlink_sign API called by passing NULL as data argument - that has to be signed. - - Expected Result: - API returns false hinting the error. -*/ -static bool test_sign_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - meshlink_handle_t *mesh_handle = meshlink_open("signconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - // Signing Data - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, NULL, strlen(data) + 1, sig, &ssize); - - // Clean up - - meshlink_close(mesh_handle); - assert(meshlink_destroy("signconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as data arg\n"); - return true; - } else { - PRINT_TEST_CASE_MSG("meshlink_sign FAILED to report error on passing NULL as data arg\n"); - return false; - } -} - -/* Execute sign_data Test Case # 4 - Invalid case - meshlink_sign passing 0 as size of data - to be signed */ -static void test_case_sign_04(void **state) { - execute_test(test_sign_04, state); -} - -/* Test Steps for meshlink_sign Test Case # 3 - invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. meshlink_sign API called by passing 0 as size of data to be signed - - Expected Result: - API returns false hinting the error. -*/ -static bool test_sign_04(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - - meshlink_handle_t *mesh_handle = meshlink_open("signconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - // Signing data - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, data, 0, sig, &ssize); - - // Clean up - - meshlink_close(mesh_handle); - assert(meshlink_destroy("signconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing 0 as size of data arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_sign FAILED to report error on passing 0 as size of data arg\n"); - return false; -} - -/* Execute sign_data Test Case # 5 - Invalid case - meshlink_sign passing NULL as - signature buffer argument*/ -static void test_case_sign_05(void **state) { - execute_test(test_sign_05, state); -} - -/* Test Steps for meshlink_sign Test Case # 5 - invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. meshlink_sign API called by passing NULL for signature buffer argument - - Expected Result: - API returns false hinting the error. -*/ -static bool test_sign_05(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - - meshlink_handle_t *mesh_handle = meshlink_open("signconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - // Signing data - - char *data = "Test"; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, NULL, &ssize); - - // Clean up - - meshlink_close(mesh_handle); - assert(meshlink_destroy("signconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as sign arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_sign FAILED to report error on passing NULL as sign arg\n"); - return false; -} - -/* Execute sign_data Test Case # 6 - Invalid case - meshlink_sign passing NULL for size of - signature argument */ -static void test_case_sign_06(void **state) { - execute_test(test_sign_06, state); -} - -/* Test Steps for meshlink_sign Test Case # 6 - invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. meshlink_sign API called by passing NULL for size of signature buffer argument - - Expected Result: - API returns false hinting the error. -*/ -static bool test_sign_06(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - meshlink_handle_t *mesh_handle = meshlink_open("signconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - // Signing data - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, NULL); - - // Clean up - - meshlink_close(mesh_handle); - assert(meshlink_destroy("signconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as signsize arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_sign FAILED to report error on passing NULL as signsize arg\n"); - return false; -} - -/* Execute sign_data Test Case # 7 - Invalid case - meshlink_sign passing size of signature < MESHLINK_SIGLEN*/ -static void test_case_sign_07(void **state) { - execute_test(test_sign_07, state); -} - -/* Test Steps for meshlink_sign Test Case # 6 - invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. meshlink_sign API called by passing size of signature < MESHLINK_SIGLEN - - Expected Result: - API returns false hinting the error. -*/ -static bool test_sign_07(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Create meshlink instance - - meshlink_handle_t *mesh_handle = meshlink_open("signconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - // Signing data - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = 5; //5 < MESHLINK_SIGLEN - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, &ssize); - - // Cleanup - - meshlink_stop(mesh_handle); - meshlink_close(mesh_handle); - assert(meshlink_destroy("signconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing signsize < MESHLINK_SIGLEN arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_sign FAILED to report error on passing signsize < MESHLINK_SIGLEN arg\n"); - return false; -} - - -int test_meshlink_sign(void) { - const struct CMUnitTest blackbox_sign_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_sign_01, NULL, NULL, - (void *)&test_case_sign_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_sign_02, NULL, NULL, - (void *)&test_case_sign_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_sign_03, NULL, NULL, - (void *)&test_case_sign_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_sign_04, NULL, NULL, - (void *)&test_case_sign_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_sign_05, NULL, NULL, - (void *)&test_case_sign_05_state), - cmocka_unit_test_prestate_setup_teardown(test_case_sign_06, NULL, NULL, - (void *)&test_case_sign_06_state), - cmocka_unit_test_prestate_setup_teardown(test_case_sign_07, NULL, NULL, - (void *)&test_case_sign_07_state) - }; - total_tests += sizeof(blackbox_sign_tests) / sizeof(blackbox_sign_tests[0]); - - return cmocka_run_group_tests(blackbox_sign_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_sign.h b/test/blackbox/run_blackbox_tests/test_cases_sign.h deleted file mode 100644 index bbb741b..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_sign.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_SIGN_H -#define TEST_CASES_SIGN_H - -/* - test_cases_sign.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int total_tests; -extern int test_meshlink_sign(void); - -#endif // TEST_CASES_SIGN_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_start.c b/test/blackbox/run_blackbox_tests/test_cases_start.c deleted file mode 100644 index be29b33..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_start.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - test_cases_start.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_start.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -static void test_case_mesh_start_01(void **state); -static bool test_steps_mesh_start_01(void); -static void test_case_mesh_start_02(void **state); -static bool test_steps_mesh_start_02(void); - -/* State structure for meshlink_start Test Case #1 */ -static black_box_state_t test_mesh_start_01_state = { - .test_case_name = "test_case_mesh_start_01", -}; - -/* State structure for meshlink_start Test Case #2 */ -static black_box_state_t test_mesh_start_02_state = { - .test_case_name = "test_case_mesh_start_02", -}; - -/* Execute meshlink_start Test Case # 1*/ -static void test_case_mesh_start_01(void **state) { - execute_test(test_steps_mesh_start_01, state); -} - -/* Test Steps for meshlink_start Test Case # 1 - - Test Steps: - 1. Open Instance & start node - - Expected Result: - Successfully node instance should be running -*/ -static bool test_steps_mesh_start_01(void) { - - // Open instance - - bool result = false; - meshlink_handle_t *mesh = meshlink_open("start_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh); - - // Run node instance - - result = meshlink_start(mesh); - - // Clean up - meshlink_close(mesh); - assert(meshlink_destroy("start_conf")); - - if(!result) { - fprintf(stderr, "meshlink_start status1: %s\n", meshlink_strerror(meshlink_errno)); - return false; - } else { - return true; - } -} - -/* Execute meshlink_start Test Case # 2*/ -static void test_case_mesh_start_02(void **state) { - execute_test(test_steps_mesh_start_02, state); -} - -/* Test Steps for meshlink_start Test Case # 2 - - Test Steps: - 1. Calling meshlink_start with NULL as mesh handle argument. - - Expected Result: - meshlink_start API handles the invalid parameter by returning false. -*/ -static bool test_steps_mesh_start_02(void) { - bool result = false; - assert(meshlink_destroy("start_conf")); - meshlink_handle_t *mesh = meshlink_open("start_conf", "foo", "test", DEV_CLASS_STATIONARY); - assert(mesh); - - // Run instance with NULL argument - - result = meshlink_start(NULL); - assert_int_equal(result, true); - - // Clean up - - meshlink_close(mesh); - assert(meshlink_destroy("start_conf")); - return true; -} - -int test_meshlink_start(void) { - const struct CMUnitTest blackbox_start_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_start_01, NULL, NULL, - (void *)&test_mesh_start_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_start_02, NULL, NULL, - (void *)&test_mesh_start_02_state) - - }; - - total_tests += sizeof(blackbox_start_tests) / sizeof(blackbox_start_tests[0]); - - return cmocka_run_group_tests(blackbox_start_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_start.h b/test/blackbox/run_blackbox_tests/test_cases_start.h deleted file mode 100644 index 835cfac..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_start.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef TEST_CASES_START_H -#define TEST_CASES_START_H - -/* - test_cases_start.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_start(void); -extern int total_tests; - - - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_status_cb.c b/test/blackbox/run_blackbox_tests/test_cases_status_cb.c deleted file mode 100644 index fedf3e6..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_status_cb.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - test_cases_status_cb.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_status_cb.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_set_status_cb_01(void **state); -static bool test_set_status_cb_01(void); -static void test_case_set_status_cb_02(void **state); -static bool test_set_status_cb_02(void); - -/* status variable gives access to the status callback to know whether invoked or not */ -static bool status; - -/* State structure for status callback Test Case #1 */ -static black_box_state_t test_case_set_status_cb_01_state = { - .test_case_name = "test_case_set_status_cb_01", -}; - -/* State structure for status callback Test Case #2 */ -static black_box_state_t test_case_set_status_cb_02_state = { - .test_case_name = "test_case_set_status_cb_02", -}; - - -static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *source, bool reach) { - (void)mesh; - - fprintf(stderr, "In status callback\n"); - - if(reach) { - fprintf(stderr, "[ %s ] node reachable\n", source->name); - } else { - fprintf(stderr, "[ %s ] node not reachable\n", source->name) ; - } - - status = reach; -} - -/* Execute status callback Test Case # 1 - valid case */ -static void test_case_set_status_cb_01(void **state) { - execute_test(test_set_status_cb_01, state); -} - -/* Test Steps for meshlink_set_status_cb Test Case # 1 - - Test Steps: - 1. Run bar and nut node instances - 2. Set status callback for the NUT and Start NUT - - Expected Result: - status callback should be invoked when NUT connects/disconnects with 'relay' node. -*/ -static bool test_set_status_cb_01(void) { - assert(meshlink_destroy("set_status_cb_conf.1")); - assert(meshlink_destroy("set_status_cb_conf.2")); - - // Opening NUT and bar nodes - meshlink_handle_t *mesh1 = meshlink_open("set_status_cb_conf.1", "nut", "test", DEV_CLASS_STATIONARY); - assert(mesh1 != NULL); - meshlink_set_log_cb(mesh1, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("set_status_cb_conf.2", "bar", "test", DEV_CLASS_STATIONARY); - assert(mesh2 != NULL); - meshlink_set_log_cb(mesh2, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - - // Set up callback for node status - meshlink_set_node_status_cb(mesh1, status_cb); - - // Exporting and Importing mutually - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - assert(meshlink_import(mesh1, exp2)); - assert(meshlink_import(mesh2, exp1)); - - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - sleep(1); - - // Test for status from status callback - assert_int_equal(status, true); - - meshlink_close(mesh2); - sleep(1); - - // Test for status from status callback - assert_int_equal(status, false); - - free(exp1); - free(exp2); - meshlink_close(mesh1); - assert(meshlink_destroy("set_status_cb_conf.1")); - assert(meshlink_destroy("set_status_cb_conf.2")); - - return true; -} - -/* Execute status callback Test Case # 2 - Invalid case */ -static void test_case_set_status_cb_02(void **state) { - execute_test(test_set_status_cb_02, state); -} - -/* Test Steps for meshlink_set_status_cb Test Case # 2 - - Test Steps: - 1. Calling meshlink_set_status_cb with NULL as mesh handle argument. - - Expected Result: - set poll callback handles the invalid parameter when called by giving proper error number. -*/ -static bool test_set_status_cb_02(void) { - - // Create meshlink instance - - assert(meshlink_destroy("set_status_cb_conf.3")); - meshlink_handle_t *mesh_handle = meshlink_open("set_status_cb_conf.3", "nut", "node_sim", 1); - assert(mesh_handle); - - // Pass NULL as meshlink_set_node_status_cb's argument - - meshlink_set_node_status_cb(NULL, status_cb); - meshlink_errno_t meshlink_errno_buff = meshlink_errno; - assert_int_equal(meshlink_errno_buff, MESHLINK_EINVAL); - - // Clean up - - meshlink_close(mesh_handle); - assert(meshlink_destroy("set_status_cb_conf.3")); - return true; -} - - -int test_meshlink_set_status_cb(void) { - const struct CMUnitTest blackbox_status_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_set_status_cb_01, NULL, NULL, - (void *)&test_case_set_status_cb_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_set_status_cb_02, NULL, NULL, - (void *)&test_case_set_status_cb_02_state) - }; - total_tests += sizeof(blackbox_status_tests) / sizeof(blackbox_status_tests[0]); - - int failed = cmocka_run_group_tests(blackbox_status_tests, NULL, NULL); - - return failed; -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_status_cb.h b/test/blackbox/run_blackbox_tests/test_cases_status_cb.h deleted file mode 100644 index 16e03e3..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_status_cb.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_SET_STATUS_CB_H -#define TEST_CASES_SET_STATUS_CB_H - -/* - test_cases_status_cb.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_set_status_cb(void); -extern int total_tests; - -#endif // TEST_CASES_SET_STATUS_CB_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_stop_close.c b/test/blackbox/run_blackbox_tests/test_cases_stop_close.c deleted file mode 100644 index 991171a..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_stop_close.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - test_cases_stop_close.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_stop_close.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include - -#define CLOSE_FILE_PATH "/home/sairoop/meshlink/test/blackbox/test_case_close/mesh_close" -#define VALGRIND_LOG "valgrind.log" - -static void test_case_mesh_close_01(void **state); -static bool test_steps_mesh_close_01(void); -static void test_case_mesh_stop_01(void **state); -static bool test_steps_mesh_stop_01(void); - -/* State structure for meshlink_close Test Case #1 */ -static black_box_state_t test_mesh_close_01_state = { - .test_case_name = "test_case_mesh_close_01", -}; - -/* State structure for meshlink_close Test Case #1 */ -static black_box_state_t test_mesh_stop_01_state = { - .test_case_name = "test_case_mesh_stop_01", -}; - -/* Execute meshlink_close Test Case # 1*/ -static void test_case_mesh_close_01(void **state) { - execute_test(test_steps_mesh_close_01, state); -} - -/* Test Steps for meshlink_close Test Case # 1*/ - -static bool test_steps_mesh_close_01(void) { - meshlink_close(NULL); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - return true; -} - -/* Execute meshlink_stop Test Case # 1*/ -static void test_case_mesh_stop_01(void **state) { - execute_test(test_steps_mesh_stop_01, state); -} - -/* Test Steps for meshlink_stop Test Case # 1*/ -static bool test_steps_mesh_stop_01(void) { - meshlink_stop(NULL); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - return true; -} - -int test_meshlink_stop_close(void) { - const struct CMUnitTest blackbox_stop_close_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_stop_01, NULL, NULL, - (void *)&test_mesh_stop_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_close_01, NULL, NULL, - (void *)&test_mesh_close_01_state) - }; - - total_tests += sizeof(blackbox_stop_close_tests) / sizeof(blackbox_stop_close_tests[0]); - - return cmocka_run_group_tests(blackbox_stop_close_tests, NULL, NULL); -} - diff --git a/test/blackbox/run_blackbox_tests/test_cases_stop_close.h b/test/blackbox/run_blackbox_tests/test_cases_stop_close.h deleted file mode 100644 index ede4e5b..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_stop_close.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_STOP_CLOSE_H -#define TEST_CASES_STOP_CLOSE_H - -/* - test_cases_stop_close.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_stop_close(void); -extern int total_tests; - - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh01.c b/test/blackbox/run_blackbox_tests/test_cases_submesh01.c deleted file mode 100644 index 9c1b432..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh01.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - test_cases_submesh.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_submesh01.h" -#include "pthread.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/mesh_event_handler.h" - -#define CORENODE1_ID "0" -#define APP1NODE1_ID "1" -#define APP2NODE1_ID "2" -#define CORENODE2_ID "3" -#define APP1NODE2_ID "4" -#define APP2NODE2_ID "5" - -#define INIT_ST 0 - -static bool test_case_status = false; - -static void test_case_submesh_01(void **state); -static bool test_steps_submesh_01(void); - -static char event_node_name[][10] = {"CORENODE1", "APP1NODE1", "APP2NODE1", "CORENODE2", - "APP1NODE2", "APP2NODE2" - }; -static const char *node_ids[] = { "corenode1", "app1node1", "app2node1", "corenode2", - "app1node2", "app2node2" - }; - -static mesh_event_t core_node1[] = { NODE_STARTED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t core_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app1_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app2_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app1_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED}; - -static mesh_event_t app2_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED}; - -/* State structure for SubMesh Test Case #1 */ -static char *test_case_submesh_1_nodes[] = { "corenode1", "app1node1", "app2node1", "corenode2", "app1node2", "app2node2" }; -static black_box_state_t test_case_submesh_1_state = { - .test_case_name = "test_cases_submesh01", - .node_names = test_case_submesh_1_nodes, - .num_nodes = 6 -}; - -static int black_box_group0_setup(void **state) { - (void)state; - - const char *nodes[] = { "corenode1", "app1node1", "app2node1", "corenode2", "app1node2", "app2node2" }; - int num_nodes = sizeof(nodes) / sizeof(nodes[0]); - - PRINT_TEST_CASE_MSG("Creating Containers\n"); - destroy_containers(); - create_containers(nodes, num_nodes); - - return 0; -} - -static int black_box_group0_teardown(void **state) { - (void)state; - - PRINT_TEST_CASE_MSG("Destroying Containers\n"); - destroy_containers(); - - return 0; -} - -static bool event_cb(mesh_event_payload_t payload) { - static node_status_t node_status[6] = { - {core_node1, 0, 3}, - {app1_node1, 0, 4}, - {app2_node1, 0, 4}, - {core_node2, 0, 4}, - {app1_node2, 0, 7}, - {app2_node2, 0, 7}, - }; - - fprintf(stderr, "%s(%lu) : %s\n", event_node_name[payload.client_id], time(NULL), event_status[payload.mesh_event]); - assert(change_state(&node_status[payload.client_id], payload.mesh_event)); - - if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 5, (char **)node_ids); - } - - if(check_nodes_finished(node_status, 6)) { - test_case_status = true; - return true; - } - - return false; -} - -/* Execute SubMesh Test Case # 1 */ -static void test_case_submesh_01(void **state) { - execute_test(test_steps_submesh_01, state); -} - -/* Test Steps for SubMesh Test Case # 1 - - Test Steps: - 1. Run corenode1, app1node1, app2node1, corenode2, app1node2 and app2node2 - 2. Generate invites to app1node1, app2node1, corenode2, app1node2 and app2node2 - from corenode1 to join corenode1. - 3. After Join is successful start channels from all nodes and exchange data on channels - 4. Try to fetch the node handle of one sub-mesh node from node in another sub-mesh - - Expected Result: - Channels should be formed between nodes of sub-mesh & coremesh, nodes with in sub-mesh - and should be able to exchange data. But node in one sub-mesh should not get the details - of node in another sub-mesh. -*/ -static bool test_steps_submesh_01(void) { - char *invite_corenode2, *invite_app1node1, *invite_app2node1, *invite_app1node2, *invite_app2node2; - char *import; - - import = mesh_event_sock_create(eth_if_name); - invite_corenode2 = invite_in_container("corenode1", "corenode2"); - invite_app1node1 = submesh_invite_in_container("corenode1", "app1node1", "app1"); - invite_app2node1 = submesh_invite_in_container("corenode1", "app2node1", "app2"); - invite_app1node2 = submesh_invite_in_container("corenode1", "app1node2", "app1"); - invite_app2node2 = submesh_invite_in_container("corenode1", "app2node2", "app2"); - - node_sim_in_container_event("corenode1", "1", NULL, CORENODE1_ID, import); - node_sim_in_container_event("corenode2", "1", invite_corenode2, CORENODE2_ID, import); - node_sim_in_container_event("app1node1", "1", invite_app1node1, APP1NODE1_ID, import); - node_sim_in_container_event("app2node1", "1", invite_app2node1, APP2NODE1_ID, import); - node_sim_in_container_event("app1node2", "1", invite_app1node2, APP1NODE2_ID, import); - node_sim_in_container_event("app2node2", "1", invite_app2node2, APP2NODE2_ID, import); - - PRINT_TEST_CASE_MSG("Waiting for nodes to get connected with corenode1\n"); - - assert(wait_for_event(event_cb, 240)); - assert(test_case_status); - - free(invite_corenode2); - free(invite_app1node1); - free(invite_app2node1); - free(invite_app1node2); - free(invite_app2node2); - - mesh_event_destroy(); - - return true; -} - -int test_cases_submesh01(void) { - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_submesh_01, setup_test, teardown_test, - (void *)&test_case_submesh_1_state) - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh01.h b/test/blackbox/run_blackbox_tests/test_cases_submesh01.h deleted file mode 100644 index d4ebcca..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh01.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef TEST_CASES_SUBMESH_H -#define TEST_CASES_SUBMESH_H - -/* - test_cases_submesh01.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include -#include "../common/mesh_event_handler.h" - -extern int total_tests; -extern int test_cases_submesh01(void); - -#endif // TEST_CASES_SUBMESH_H \ No newline at end of file diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh02.c b/test/blackbox/run_blackbox_tests/test_cases_submesh02.c deleted file mode 100644 index 9f21850..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh02.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - test_cases_submesh02.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_submesh02.h" -#include "pthread.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/mesh_event_handler.h" - -#define CORENODE1_ID "0" -#define APP1NODE1_ID "1" -#define APP2NODE1_ID "2" -#define CORENODE2_ID "3" -#define APP1NODE2_ID "4" -#define APP2NODE2_ID "5" - -#define INIT_ST 0 - -static bool test_case_status = false; - -static void test_case_submesh_02(void **state); -static bool test_steps_submesh_02(void); - -static char event_node_name[][10] = {"CORENODE1", "APP1NODE1", "APP2NODE1", "CORENODE2", - "APP1NODE2", "APP2NODE2" - }; -static const char *node_ids[] = { "corenode1", "app1node1", "app2node1", "corenode2", - "app1node2", "app2node2" - }; - -static mesh_event_t core_node1[] = { NODE_STARTED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t core_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app1_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app2_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app1_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED}; - -static mesh_event_t app2_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED}; - -/* State structure for SubMesh Test Case #1 */ -static char *test_case_submesh_2_nodes[] = { "corenode1", "app1node1", "app2node1", "corenode2", "app1node2", "app2node2" }; -static black_box_state_t test_case_submesh_2_state = { - .test_case_name = "test_cases_submesh02", - .node_names = test_case_submesh_2_nodes, - .num_nodes = 6 -}; - -static int black_box_group0_setup(void **state) { - (void)state; - - const char *nodes[] = { "corenode1", "app1node1", "app2node1", "corenode2", "app1node2", "app2node2" }; - int num_nodes = sizeof(nodes) / sizeof(nodes[0]); - - PRINT_TEST_CASE_MSG("Creating Containers\n"); - destroy_containers(); - create_containers(nodes, num_nodes); - - return 0; -} - -static int black_box_group0_teardown(void **state) { - (void)state; - - PRINT_TEST_CASE_MSG("Destroying Containers\n"); - destroy_containers(); - - return 0; -} - -static bool event_cb(mesh_event_payload_t payload) { - static node_status_t node_status[6] = { - {core_node1, 0, 3}, - {app1_node1, 0, 4}, - {app2_node1, 0, 4}, - {core_node2, 0, 4}, - {app1_node2, 0, 7}, - {app2_node2, 0, 7}, - }; - - fprintf(stderr, "%s(%lu) : %s\n", event_node_name[payload.client_id], time(NULL), event_status[payload.mesh_event]); - assert(change_state(&node_status[payload.client_id], payload.mesh_event)); - - if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 5, (char **)node_ids); - } - - if(check_nodes_finished(node_status, 6)) { - test_case_status = true; - return true; - } - - return false; -} - -/* Execute SubMesh Test Case # 2 */ -static void test_case_submesh_02(void **state) { - execute_test(test_steps_submesh_02, state); -} - -/* Test Steps for SubMesh Test Case # 2 - - Test Steps: - 1. Run corenode1, app1node1, app2node1, corenode2, app1node2 and app2node2 - 2. Generate invites to app1node1, app2node1, corenode2, app1node2 and app2node2 - from corenode1 to join corenode1. - 3. After Join is successful start channels from all nodes and exchange data on channels - 4. Try to fetch the list of all nodes and check if the nodes in other submesh does not - appear in the list. - 5. Try fetch all the nodes with a submesh handle and check only if both the nodes joining - the submesh are present. - - Expected Result: - Channels should be formed between nodes of sub-mesh & coremesh, nodes with in sub-mesh - and should be able to exchange data. Lis of all nodes should only contain four nodes - and the list of submesh should only contain two nodes of that submesh. -*/ -static bool test_steps_submesh_02(void) { - char *invite_corenode2, *invite_app1node1, *invite_app2node1, *invite_app1node2, *invite_app2node2; - char *import; - - import = mesh_event_sock_create(eth_if_name); - invite_corenode2 = invite_in_container("corenode1", "corenode2"); - invite_app1node1 = submesh_invite_in_container("corenode1", "app1node1", "app1"); - invite_app2node1 = submesh_invite_in_container("corenode1", "app2node1", "app2"); - invite_app1node2 = submesh_invite_in_container("corenode1", "app1node2", "app1"); - invite_app2node2 = submesh_invite_in_container("corenode1", "app2node2", "app2"); - - node_sim_in_container_event("corenode1", "1", NULL, CORENODE1_ID, import); - node_sim_in_container_event("corenode2", "1", invite_corenode2, CORENODE2_ID, import); - node_sim_in_container_event("app1node1", "1", invite_app1node1, APP1NODE1_ID, import); - node_sim_in_container_event("app2node1", "1", invite_app2node1, APP2NODE1_ID, import); - node_sim_in_container_event("app1node2", "1", invite_app1node2, APP1NODE2_ID, import); - node_sim_in_container_event("app2node2", "1", invite_app2node2, APP2NODE2_ID, import); - - PRINT_TEST_CASE_MSG("Waiting for nodes to get connected with corenode1\n"); - - assert(wait_for_event(event_cb, 240)); - assert(test_case_status); - - free(invite_corenode2); - free(invite_app1node1); - free(invite_app2node1); - free(invite_app1node2); - free(invite_app2node2); - - mesh_event_destroy(); - - return true; -} - -int test_cases_submesh02(void) { - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_submesh_02, setup_test, teardown_test, - (void *)&test_case_submesh_2_state) - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh02.h b/test/blackbox/run_blackbox_tests/test_cases_submesh02.h deleted file mode 100644 index a571038..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh02.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef TEST_CASES_SUBMESH02_H -#define TEST_CASES_SUBMESH02_H - -/* - test_cases_submesh02.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include -#include "../common/mesh_event_handler.h" - -extern int total_tests; -extern int test_cases_submesh02(void); - -#endif // TEST_CASES_SUBMESH02_H \ No newline at end of file diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh03.c b/test/blackbox/run_blackbox_tests/test_cases_submesh03.c deleted file mode 100644 index 18a8025..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh03.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - test_cases_submesh03.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_submesh03.h" -#include "pthread.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/mesh_event_handler.h" - -#define CORENODE1_ID "0" -#define APP1NODE1_ID "1" -#define APP1NODE2_ID "2" - -#define INIT_ST 0 - -static bool test_case_status = false; - -static void test_case_submesh_03(void **state); -static bool test_steps_submesh_03(void); - -static char event_node_name[][10] = {"CORENODE1", "APP1NODE1", "APP1NODE2"}; -static const char *node_ids[] = { "corenode1", "app1node1", "app1node2" }; - -static mesh_event_t core_node1[] = { NODE_STARTED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app1_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED}; - -static mesh_event_t app1_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED}; - -static node_status_t node_status[3] = { - {core_node1, 0, 3}, - {app1_node1, 0, 4}, - {app1_node2, 0, 7}, -}; - -/* State structure for SubMesh Test Case #3 */ -static char *test_case_submesh_3_nodes[] = { "corenode1", "app1node1", "app1node2" }; -static black_box_state_t test_case_submesh_3_state = { - .test_case_name = "test_cases_submesh03", - .node_names = test_case_submesh_3_nodes, - .num_nodes = 3 -}; - -static int black_box_group0_setup(void **state) { - (void)state; - - const char *nodes[] = { "corenode1", "app1node1", "app1node2" }; - int num_nodes = sizeof(nodes) / sizeof(nodes[0]); - - PRINT_TEST_CASE_MSG("Creating Containers\n"); - destroy_containers(); - create_containers(nodes, num_nodes); - - return 0; -} - -static int black_box_group0_teardown(void **state) { - (void)state; - - PRINT_TEST_CASE_MSG("Destroying Containers\n"); - destroy_containers(); - - return 0; -} - -static void restart_all_nodes(char *import) { - int i; - - for(i = 0; i < 3; i++) { - node_step_in_container(node_ids[i], "SIGTERM"); - node_status[i].current_index = 0; - } - - sleep(5); - - node_sim_in_container_event("corenode1", "1", NULL, CORENODE1_ID, import); - node_sim_in_container_event("app1node1", "1", NULL, APP1NODE1_ID, import); - node_sim_in_container_event("app1node2", "1", NULL, APP1NODE2_ID, import); -} - -static bool event_cb(mesh_event_payload_t payload) { - - fprintf(stderr, "%s(%lu) : %s\n", event_node_name[payload.client_id], time(NULL), event_status[payload.mesh_event]); - assert(change_state(&node_status[payload.client_id], payload.mesh_event)); - - if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 2, (char **)node_ids); - } - - if(check_nodes_finished(node_status, 3)) { - test_case_status = true; - return true; - } - - return false; -} - -/* Execute SubMesh Test Case # 3 */ -static void test_case_submesh_03(void **state) { - execute_test(test_steps_submesh_03, state); -} - -/* Test Steps for SubMesh Test Case # 3 - - Test Steps: - 1. Run corenode1, app1node1, and app1node2 - 2. Generate invites to app1node1, and app1node2 - from corenode1 to join corenode1. - 3. After Join is successful start channels from all nodes and exchange data on channels - 4. Try to restart all the nodes at the same time. - - Expected Result: - Channels should be formed between nodes of sub-mesh & coremesh, nodes with in sub-mesh - and should be able to exchange data even after restart. -*/ -static bool test_steps_submesh_03(void) { - char *invite_app1node1, *invite_app1node2; - char *import; - - import = mesh_event_sock_create(eth_if_name); - invite_app1node1 = invite_in_container("corenode1", "app1node1"); - invite_app1node2 = invite_in_container("corenode1", "app1node2"); - - node_sim_in_container_event("corenode1", "1", NULL, CORENODE1_ID, import); - node_sim_in_container_event("app1node1", "1", invite_app1node1, APP1NODE1_ID, import); - node_sim_in_container_event("app1node2", "1", invite_app1node2, APP1NODE2_ID, import); - - PRINT_TEST_CASE_MSG("Waiting for nodes to get connected with corenode1\n"); - - assert(wait_for_event(event_cb, 120)); - assert(test_case_status); - - test_case_status = false; - - restart_all_nodes(import); - PRINT_TEST_CASE_MSG("Waiting for nodes to get restarted\n"); - - assert(wait_for_event(event_cb, 120)); - assert(test_case_status); - - free(invite_app1node1); - free(invite_app1node2); - - mesh_event_destroy(); - - return true; -} - -int test_cases_submesh03(void) { - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_submesh_03, setup_test, teardown_test, - (void *)&test_case_submesh_3_state) - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh03.h b/test/blackbox/run_blackbox_tests/test_cases_submesh03.h deleted file mode 100644 index 432c1e0..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh03.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef TEST_CASES_SUBMESH03_H -#define TEST_CASES_SUBMESH03_H - -/* - test_cases_submesh03.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include -#include "../common/mesh_event_handler.h" - -extern int total_tests; -extern int test_cases_submesh03(void); - -#endif // TEST_CASES_SUBMESH03_H \ No newline at end of file diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh04.c b/test/blackbox/run_blackbox_tests/test_cases_submesh04.c deleted file mode 100644 index 5476423..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh04.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - test_cases_submesh05.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "execute_tests.h" -#include "test_cases_submesh04.h" -#include "pthread.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/mesh_event_handler.h" - -#define CORENODE1_ID "0" -#define APP1NODE1_ID "1" -#define APP1NODE2_ID "2" - -#define INIT_ST 0 - -static bool test_case_status = false; - -static void test_case_submesh_04(void **state); -static bool test_steps_submesh_04(void); - -static char event_node_name[][10] = {"CORENODE1", "APP1NODE1", "APP1NODE2"}; -static const char *node_ids[] = { "corenode1", "app1node1", "app1node2" }; - -static mesh_event_t core_node1[] = { NODE_STARTED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED }; - -static mesh_event_t app1_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED }; - -static mesh_event_t app1_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED}; - -/* State structure for SubMesh Test Case #4 */ -static char *test_case_submesh_4_nodes[] = { "corenode1", "app1node1", "app1node2" }; -static black_box_state_t test_case_submesh_4_state = { - .test_case_name = "test_cases_submesh04", - .node_names = test_case_submesh_4_nodes, - .num_nodes = 3 -}; - -static int black_box_group0_setup(void **state) { - (void)state; - - const char *nodes[] = { "corenode1", "app1node1", "app1node2" }; - int num_nodes = sizeof(nodes) / sizeof(nodes[0]); - - PRINT_TEST_CASE_MSG("Creating Containers\n"); - destroy_containers(); - create_containers(nodes, num_nodes); - - return 0; -} - -static int black_box_group0_teardown(void **state) { - (void)state; - - PRINT_TEST_CASE_MSG("Destroying Containers\n"); - destroy_containers(); - - return 0; -} - -static bool event_cb(mesh_event_payload_t payload) { - static node_status_t node_status[3] = { - {core_node1, 0, 3}, - {app1_node1, 0, 4}, - {app1_node2, 0, 7}, - }; - - fprintf(stderr, "%s(%lu) : %s\n", event_node_name[payload.client_id], time(NULL), event_status[payload.mesh_event]); - assert(change_state(&node_status[payload.client_id], payload.mesh_event)); - - if(payload.mesh_event == NODE_JOINED) { - signal_node_start(node_status, 1, 2, (char **)node_ids); - } - - if(check_nodes_finished(node_status, 3)) { - test_case_status = true; - return true; - } - - return false; -} - -/* Execute SubMesh Test Case # 4 */ -static void test_case_submesh_04(void **state) { - execute_test(test_steps_submesh_04, state); -} - -/* Test Steps for SubMesh Test Case # 4 - - Test Steps: - 1. Run corenode1, app1node1, and app1node2 - 2. Generate invites to app1node1, app1node2 - from corenode1 to join corenode1. - 3. After Join is successful start channels from all nodes and exchange data on channels - 4. Black list a node in the submesh and check if it is successful - 5. White list the node and it should be form all the connections again - - Expected Result: - Channels should be formed between nodes of sub-mesh & coremesh, nodes with in sub-mesh - and should be able to exchange data. When black listed, other node should not get any - from the black listed node. When white listed again it has to form the connections as - they were previously before black listing. -*/ -static bool test_steps_submesh_04(void) { - char *invite_app1node1, *invite_app1node2; - char *import; - - import = mesh_event_sock_create(eth_if_name); - invite_app1node1 = invite_in_container("corenode1", "app1node1"); - invite_app1node2 = invite_in_container("corenode1", "app1node2"); - - node_sim_in_container_event("corenode1", "1", NULL, CORENODE1_ID, import); - node_sim_in_container_event("app1node1", "1", invite_app1node1, APP1NODE1_ID, import); - node_sim_in_container_event("app1node2", "1", invite_app1node2, APP1NODE2_ID, import); - - PRINT_TEST_CASE_MSG("Waiting for nodes to get connected with corenode1\n"); - - assert(wait_for_event(event_cb, 120)); - assert(test_case_status); - - free(invite_app1node1); - free(invite_app1node2); - - mesh_event_destroy(); - - return true; -} - -int test_cases_submesh04(void) { - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_submesh_04, setup_test, teardown_test, - (void *)&test_case_submesh_4_state) - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh04.h b/test/blackbox/run_blackbox_tests/test_cases_submesh04.h deleted file mode 100644 index be7a22b..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_submesh04.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef TEST_CASES_SUBMESH04_H -#define TEST_CASES_SUBMESH04_H - -/* - test_cases_submesh04.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include -#include "../common/mesh_event_handler.h" - -extern int total_tests; -extern int test_cases_submesh04(void); - -#endif // TEST_CASES_SUBMESH04_H \ No newline at end of file diff --git a/test/blackbox/run_blackbox_tests/test_cases_verify.c b/test/blackbox/run_blackbox_tests/test_cases_verify.c deleted file mode 100644 index f811e16..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_verify.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - test_cases_verify.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_verify.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include - -/* Modify this to change the logging level of Meshlink */ -#define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG - -static void test_case_verify_01(void **state); -static bool test_verify_01(void); -static void test_case_verify_02(void **state); -static bool test_verify_02(void); -static void test_case_verify_03(void **state); -static bool test_verify_03(void); -static void test_case_verify_04(void **state); -static bool test_verify_04(void); -static void test_case_verify_05(void **state); -static bool test_verify_05(void); -static void test_case_verify_06(void **state); -static bool test_verify_06(void); - -/* State structure for verify API Test Case #1 */ -static black_box_state_t test_case_verify_01_state = { - .test_case_name = "test_case_verify_01", -}; - -/* State structure for verify API Test Case #2 */ -static black_box_state_t test_case_verify_02_state = { - .test_case_name = "test_case_verify_02", -}; - -/* State structure for verify API Test Case #3 */ -static black_box_state_t test_case_verify_03_state = { - .test_case_name = "test_case_verify_03", -}; - -/* State structure for verify API Test Case #4 */ -static black_box_state_t test_case_verify_04_state = { - .test_case_name = "test_case_verify_04", -}; - -/* State structure for verify API Test Case #5 */ -static black_box_state_t test_case_verify_05_state = { - .test_case_name = "test_case_verify_05", -}; - -/* State structure for verify API Test Case #6 */ -static black_box_state_t test_case_verify_06_state = { - .test_case_name = "test_case_verify_06", -}; - - - -/* Execute meshlink_verify Test Case # 1 - Valid case - verify a data successfully*/ -void test_case_verify_01(void **state) { - execute_test(test_verify_01, state); -} - -/* Test Steps for meshlink_sign Test Case # 1 - Valid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Sign data with meshlink_sign - 3. Verify data with the sign buffer used while signing - - Expected Result: - Verifies data successfully with the apt signature -*/ -bool test_verify_01(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh_handle = meshlink_open("verifyconf", "nut", "node_sim", DEV_CLASS_BACKBONE); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, &ssize); - assert(ret); - - meshlink_node_t *source = meshlink_get_node(mesh_handle, "nut"); - assert(source); - ret = meshlink_verify(mesh_handle, source, data, strlen(data) + 1, sig, ssize); - meshlink_close(mesh_handle); - assert(meshlink_destroy("verifyconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_verify FAILED to verify data\n"); - return false; - } - - PRINT_TEST_CASE_MSG("meshlink_verify Successfully verified data\n"); - return true; -} - - -/* Execute verify_data Test Case # 2 - Invalid case - meshlink_verify passing NULL args*/ -void test_case_verify_02(void **state) { - execute_test(test_verify_02, state); -} - -/* Test Steps for meshlink_sign Test Case # 2 - Invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Sign data with meshlink_sign - 3. Trying to pass NULL as mesh handle argument - and other arguments being valid - - Expected Result: - Reports error accordingly by returning false -*/ -bool test_verify_02(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh_handle = meshlink_open("verifyconf", "nut", "node_sim", DEV_CLASS_BACKBONE); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool sret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, &ssize); - assert(sret); - - meshlink_node_t *source = meshlink_get_node(mesh_handle, "nut"); - assert(source != NULL); - bool ret = meshlink_verify(NULL, source, data, strlen(data) + 1, sig, ssize); - meshlink_close(mesh_handle); - assert(meshlink_destroy("verifyconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as mesh_handle arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_sign FAILED to report error on passing NULL as mesh_handle arg\n"); - return false; -} - - -/* Execute verify_data Test Case # 3 - Invalid case - meshlink_verify passing NULL args*/ -void test_case_verify_03(void **state) { - execute_test(test_verify_03, state); -} - -/* Test Steps for meshlink_sign Test Case # 3 - Invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Sign data with meshlink_sign - 3. Trying to pass NULL as source node handle argument - and other arguments being valid - - Expected Result: - Reports error accordingly by returning false -*/ -bool test_verify_03(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh_handle = meshlink_open("verifyconf", "nut", "node_sim", DEV_CLASS_BACKBONE); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, &ssize); - assert(ret); - ret = meshlink_verify(mesh_handle, NULL, data, strlen(data) + 1, sig, ssize); - meshlink_close(mesh_handle); - assert(meshlink_destroy("verifyconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_verify successfully reported NULL as node_handle arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_verify FAILED to report NULL as node_handle arg\n"); - return false; -} - -/* Execute verify_data Test Case # 4 - Invalid case - meshlink_verify passing NULL args*/ -void test_case_verify_04(void **state) { - execute_test(test_verify_04, state); -} - -/* Test Steps for meshlink_sign Test Case # 4 - Invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Sign data with meshlink_sign - 3. Trying to pass NULL as signed data argument - and other arguments being valid - - Expected Result: - Reports error accordingly by returning false -*/ -bool test_verify_04(void) { - assert(meshlink_destroy("verifyconf")); - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh_handle = meshlink_open("verifyconf", "nut", "node_sim", DEV_CLASS_BACKBONE); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, &ssize); - assert(ret); - meshlink_node_t *source = meshlink_get_node(mesh_handle, "nut"); - assert(source != NULL); - ret = meshlink_verify(mesh_handle, source, NULL, strlen(data) + 1, sig, ssize); - meshlink_stop(mesh_handle); - meshlink_close(mesh_handle); - assert(meshlink_destroy("verifyconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_verify successfully reported NULL as data arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_verify FAILED to report NULL as data arg\n"); - return false; -} - - -/* Execute verify_data Test Case # 5 - Invalid case - meshlink_verify passing NULL args*/ -void test_case_verify_05(void **state) { - execute_test(test_verify_05, state); -} - -/* Test Steps for meshlink_sign Test Case # 5 - Invalid case - - Test Steps: - 1. Run NUT(Node Under Test) - 2. Sign data with meshlink_sign - 3. Trying to pass NULL as signature buffer argument - and other arguments being valid - - Expected Result: - Reports error accordingly by returning false -*/ -bool test_verify_05(void) { - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh_handle = meshlink_open("verifyconf", "nut", "node_sim", 1); - assert(mesh_handle); - meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - assert(meshlink_start(mesh_handle)); - - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh_handle, data, strlen(data) + 1, sig, &ssize); - assert(ret); - meshlink_node_t *source = meshlink_get_node(mesh_handle, "nut"); - assert(source != NULL); - - ret = meshlink_verify(mesh_handle, source, data, strlen(data) + 1, NULL, ssize); - meshlink_stop(mesh_handle); - meshlink_close(mesh_handle); - assert(meshlink_destroy("verifyconf")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_verify successfully NULL as sign arg\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_verify FAILED to report NULL as sign arg\n"); - return false; -} - -/* Execute verify_data Test Case # 6 - Functionality test, when a wrong source node is mentioned to verify - the signed data */ -void test_case_verify_06(void **state) { - execute_test(test_verify_06, state); -} - -/* Test Steps for meshlink_verify Test Case # 6 - Functionality Test - - Test Steps: - 1. Run NUT(Node Under Test) and peer - 2. Sign using peer as source node. - 3. Verify with NUT but passing NUT as source node rather than - 'peer' as source node - - Expected Result: - API returns false when it detects the wrong source node -*/ -bool test_verify_06(void) { - /* deleting the confbase if already exists */ - assert(meshlink_destroy("verifyconf1")); - assert(meshlink_destroy("verifyconf2")); - /* Set up logging for Meshlink */ - meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_handle_t *mesh1 = meshlink_open("verifyconf1", "nut", "chat", DEV_CLASS_STATIONARY); - assert(mesh1); - meshlink_handle_t *mesh2 = meshlink_open("verifyconf2", "bar", "chat", DEV_CLASS_STATIONARY); - assert(mesh2); - - char *exp1 = meshlink_export(mesh1); - assert(exp1 != NULL); - char *exp2 = meshlink_export(mesh2); - assert(exp2 != NULL); - assert(meshlink_import(mesh1, exp2)); - assert(meshlink_import(mesh2, exp1)); - - /* signing done by peer node */ - char *data = "Test"; - char sig[MESHLINK_SIGLEN]; - size_t ssize = MESHLINK_SIGLEN; - bool ret = meshlink_sign(mesh2, data, strlen(data) + 1, sig, &ssize); - assert(ret); - - meshlink_node_t *source_nut = meshlink_get_self(mesh1); - assert(source_nut); - ret = meshlink_verify(mesh_handle, source_nut, data, strlen(data) + 1, sig, ssize); - meshlink_close(mesh1); - meshlink_close(mesh2); - assert(meshlink_destroy("verifyconf1")); - assert(meshlink_destroy("verifyconf2")); - - if(!ret) { - PRINT_TEST_CASE_MSG("meshlink_verify successfully returned 'false' when a wrong source node used to verify the data\n"); - return true; - } - - PRINT_TEST_CASE_MSG("meshlink_verify FAILED to report error when a wrong source is mentioned\n"); - return false; -} - - -int test_meshlink_verify(void) { - const struct CMUnitTest blackbox_verify_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_verify_01, NULL, NULL, - (void *)&test_case_verify_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_verify_02, NULL, NULL, - (void *)&test_case_verify_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_verify_03, NULL, NULL, - (void *)&test_case_verify_03_state), - cmocka_unit_test_prestate_setup_teardown(test_case_verify_04, NULL, NULL, - (void *)&test_case_verify_04_state), - cmocka_unit_test_prestate_setup_teardown(test_case_verify_05, NULL, NULL, - (void *)&test_case_verify_05_state), - cmocka_unit_test_prestate_setup_teardown(test_case_verify_06, NULL, NULL, - (void *)&test_case_verify_06_state) - }; - - total_tests += sizeof(blackbox_verify_tests) / sizeof(blackbox_verify_tests[0]); - - return cmocka_run_group_tests(blackbox_verify_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_verify.h b/test/blackbox/run_blackbox_tests/test_cases_verify.h deleted file mode 100644 index 39661a0..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_verify.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEST_CASES_VERIFY_H -#define TEST_CASES_VERIFY_H - -/* - test_cases_verify.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - - -#include - -extern int total_tests; -extern int test_meshlink_verify(void); - -#endif // TEST_CASES_VERIFY_H diff --git a/test/blackbox/run_blackbox_tests/test_cases_whitelist.c b/test/blackbox/run_blackbox_tests/test_cases_whitelist.c deleted file mode 100644 index 68283a9..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_whitelist.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - test_cases_whitelist.c -- Execution of specific meshlink black box test cases - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include "execute_tests.h" -#include "test_cases_whitelist.h" -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../utils.h" - -static void test_case_mesh_whitelist_01(void **state); -static bool test_steps_mesh_whitelist_01(void); -static void test_case_mesh_whitelist_02(void **state); -static bool test_steps_mesh_whitelist_02(void); -static void test_case_mesh_whitelist_03(void **state); -static bool test_steps_mesh_whitelist_03(void); - -/* State structure for meshlink_whitelist Test Case #1 */ -static black_box_state_t test_mesh_whitelist_01_state = { - .test_case_name = "test_case_mesh_whitelist_01", -}; - -/* State structure for meshlink_whitelist Test Case #2 */ -static black_box_state_t test_mesh_whitelist_02_state = { - .test_case_name = "test_case_mesh_whitelist_02", -}; - -/* State structure for meshlink_whitelist Test Case #3 */ -static black_box_state_t test_mesh_whitelist_03_state = { - .test_case_name = "test_case_mesh_whitelist_03", -}; - -static bool rec_stat; -static bool reachable; -static pthread_mutex_t lock_receive = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t receive_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t reachable_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t reachable_cond = PTHREAD_COND_INITIALIZER; - - -/* Execute meshlink_whitelist Test Case # 1*/ -static void test_case_mesh_whitelist_01(void **state) { - execute_test(test_steps_mesh_whitelist_01, state); -} - - -static void receive(meshlink_handle_t *mesh, meshlink_node_t *src, const void *data, size_t len) { - (void)mesh; - (void)src; - (void)data; - - assert(len); - - pthread_mutex_lock(& lock_receive); - rec_stat = true; - assert(!pthread_cond_broadcast(&receive_cond)); - pthread_mutex_unlock(& lock_receive); - -} - -static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reach) { - (void)mesh; - - if(!strcmp(node->name, "bar")) { - pthread_mutex_lock(&reachable_lock); - reachable = reach; - assert(!pthread_cond_broadcast(&reachable_cond)); - pthread_mutex_unlock(&reachable_lock); - } -} - - -/* Test Steps for meshlink_whitelist Test Case # 1 - - Test Steps: - 1. Run 2 node instances - 2. Blacklist one node and again whitelist the blacklisted node - - Expected Result: - meshlink_whitelist API whitelists the blacklisted node -*/ -static bool test_steps_mesh_whitelist_01(void) { - struct timespec timeout = {0}; - - // Open two new meshlink instance. - - assert(meshlink_destroy("whitelist_conf.1")); - assert(meshlink_destroy("whitelist_conf.2")); - meshlink_handle_t *mesh1 = meshlink_open("whitelist_conf.1", "foo", "test", DEV_CLASS_BACKBONE); - assert(mesh1); - meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_handle_t *mesh2 = meshlink_open("whitelist_conf.2", "bar", "test", DEV_CLASS_BACKBONE); - assert(mesh2); - meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_receive_cb(mesh2, receive); - meshlink_set_receive_cb(mesh1, receive); - - // Export & Import to join the mesh - - reachable = false; - char *data = meshlink_export(mesh1); - assert(data); - assert(meshlink_import(mesh2, data)); - free(data); - data = meshlink_export(mesh2); - assert(data); - assert(meshlink_import(mesh1, data)); - free(data); - - // Start both instances - - meshlink_set_node_status_cb(mesh1, status_cb); - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - - // Nodes should know each other - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&reachable_lock); - - while(reachable == false) { - assert(!pthread_cond_timedwait(&reachable_cond, &reachable_lock, &timeout)); - } - - pthread_mutex_unlock(&reachable_lock); - sleep(1); - - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar); - meshlink_node_t *foo = meshlink_get_node(mesh2, "foo"); - assert(foo); - - rec_stat = false; - assert(meshlink_send(mesh1, bar, "test", 5)); - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(& lock_receive); - - if(rec_stat == false) { - assert(pthread_cond_timedwait(&receive_cond, &lock_receive, &timeout) == 0); - } - - pthread_mutex_unlock(& lock_receive); - - - assert(meshlink_blacklist(mesh1, foo)); - - rec_stat = false; - assert(meshlink_send(mesh1, bar, "test", 5)); - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(& lock_receive); - - if(rec_stat == false) { - int err = pthread_cond_timedwait(&receive_cond, &lock_receive, &timeout); - assert(err == ETIMEDOUT); - } - - pthread_mutex_unlock(& lock_receive); - assert(meshlink_whitelist(mesh1, foo)); - - rec_stat = false; - bool result = meshlink_send(mesh2, foo, "test", 5); - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(& lock_receive); - - if(rec_stat == false) { - assert(pthread_cond_timedwait(&receive_cond, &lock_receive, &timeout) == 0); - } - - pthread_mutex_unlock(& lock_receive); - - // Clean up. - - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("whitelist_conf.1")); - assert(meshlink_destroy("whitelist_conf.2")); - - return result; -} - -/* Test Steps for meshlink_whitelist Test Case # 2 - - Test Steps: - 1. Calling meshlink_whitelist with NULL as mesh handle argument. - - Expected Result: - meshlink_whitelist API handles the invalid parameter when called by giving proper error number. -*/ -static void test_case_mesh_whitelist_02(void **state) { - execute_test(test_steps_mesh_whitelist_02, state); -} - -/* Test Steps for meshlink_whitelist Test Case # 2*/ -static bool test_steps_mesh_whitelist_02(void) { - struct timespec timeout = {0}; - - // Open two new meshlink instance. - - assert(meshlink_destroy("whitelist_conf.3")); - assert(meshlink_destroy("whitelist_conf.4")); - meshlink_handle_t *mesh1 = meshlink_open("whitelist_conf.3", "foo", "test", DEV_CLASS_BACKBONE); - assert(mesh1); - meshlink_handle_t *mesh2 = meshlink_open("whitelist_conf.4", "bar", "test", DEV_CLASS_BACKBONE); - assert(mesh2); - meshlink_set_receive_cb(mesh2, receive); - meshlink_set_receive_cb(mesh1, receive); - - char *data = meshlink_export(mesh1); - assert(data); - assert(meshlink_import(mesh2, data)); - free(data); - data = meshlink_export(mesh2); - assert(data); - assert(meshlink_import(mesh1, data)); - free(data); - - // Start both instances - - reachable = false; - meshlink_set_node_status_cb(mesh1, status_cb); - assert(meshlink_start(mesh1)); - assert(meshlink_start(mesh2)); - - // Nodes should know each other - timeout.tv_sec = time(NULL) + 10; - pthread_mutex_lock(&reachable_lock); - - while(reachable == false) { - assert(!pthread_cond_timedwait(&reachable_cond, &reachable_lock, &timeout)); - } - - pthread_mutex_unlock(&reachable_lock); - - meshlink_node_t *bar = meshlink_get_node(mesh1, "bar"); - assert(bar); - meshlink_node_t *foo = meshlink_get_node(mesh2, "foo"); - assert(foo); - - assert(meshlink_send(mesh1, bar, "test", 5)); - - assert(meshlink_blacklist(mesh1, foo)); - - // Passing NULL as mesh handle but with valid node handle 'foo' - - assert(!meshlink_whitelist(NULL, foo)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Clean up. - - meshlink_close(mesh2); - meshlink_close(mesh1); - assert(meshlink_destroy("whitelist_conf.3")); - assert(meshlink_destroy("whitelist_conf.4")); - - return true; -} - -/* Execute meshlink_whitelist Test Case # 3*/ -static void test_case_mesh_whitelist_03(void **state) { - execute_test(test_steps_mesh_whitelist_03, state); -} - -/* Test Steps for meshlink_whitelist Test Case # 3 - - Test Steps: - 1. Calling meshlink_whitelist with NULL as node handle argument. - - Expected Result: - meshlink_whitelist API handles the invalid parameter when called by giving proper error number. -*/ -static bool test_steps_mesh_whitelist_03(void) { - // Open meshlink instance. - - assert(meshlink_destroy("whitelist_conf")); - meshlink_handle_t *mesh = meshlink_open("whitelist_conf", "foo", "test", DEV_CLASS_BACKBONE); - assert(mesh); - - // Start instance - assert(meshlink_start(mesh)); - - assert(!meshlink_whitelist(mesh, NULL)); - assert_int_equal(meshlink_errno, MESHLINK_EINVAL); - - // Clean up. - - meshlink_close(mesh); - assert(meshlink_destroy("whitelist_conf")); - return true; -} - -int test_meshlink_whitelist(void) { - const struct CMUnitTest blackbox_whitelist_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_whitelist_01, NULL, NULL, - (void *)&test_mesh_whitelist_01_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_whitelist_02, NULL, NULL, - (void *)&test_mesh_whitelist_02_state), - cmocka_unit_test_prestate_setup_teardown(test_case_mesh_whitelist_03, NULL, NULL, - (void *)&test_mesh_whitelist_03_state) - }; - - total_tests += sizeof(blackbox_whitelist_tests) / sizeof(blackbox_whitelist_tests[0]); - - return cmocka_run_group_tests(blackbox_whitelist_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_cases_whitelist.h b/test/blackbox/run_blackbox_tests/test_cases_whitelist.h deleted file mode 100644 index f7f79c4..0000000 --- a/test/blackbox/run_blackbox_tests/test_cases_whitelist.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_CASES_WHITELIST_H -#define TEST_CASES_WHITELIST_H - -/* - test_cases_whitelist.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_meshlink_whitelist(void); -extern int total_tests; - -#endif diff --git a/test/blackbox/run_blackbox_tests/test_optimal_pmtu.c b/test/blackbox/run_blackbox_tests/test_optimal_pmtu.c deleted file mode 100644 index 1d74089..0000000 --- a/test/blackbox/run_blackbox_tests/test_optimal_pmtu.c +++ /dev/null @@ -1,651 +0,0 @@ -/* - test_optimal_pmtu.c -- Execution of specific meshlink black box test cases - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/containers.h" -#include "../common/test_step.h" -#include "../common/common_handlers.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" -#include "../test_case_optimal_pmtu_01/test_case_optimal_pmtu.h" -#include "test_optimal_pmtu.h" - -static void test_case_optimal_pmtu_01(void **state); -static bool test_steps_optimal_pmtu_01(void); -static void test_case_optimal_pmtu_02(void **state); -static bool test_steps_optimal_pmtu_02(void); -static void test_case_optimal_pmtu_03(void **state); -static bool test_steps_optimal_pmtu_03(void); -static void test_case_optimal_pmtu_04(void **state); -static bool test_steps_optimal_pmtu_04(void); -static void test_case_optimal_pmtu_05(void **state); -static bool test_steps_optimal_pmtu_05(void); -static void test_case_optimal_pmtu_06(void **state); -static bool test_steps_optimal_pmtu_06(void); -static void test_case_optimal_pmtu_07(void **state); -static bool test_steps_optimal_pmtu_07(void); - -extern void *node_sim_relay_01(void *arg); -extern void *node_sim_peer_01(void *arg); -extern void *node_sim_nut_01(void *arg); -extern pmtu_attr_t node_pmtu[2]; - -typedef bool (*test_step_func_t)(void); -static int setup_test(void **state); -bool test_pmtu_relay_running = true; -bool test_pmtu_peer_running = true; -bool test_pmtu_nut_running = true; -bool ping_channel_enable_07 = false; - -struct sync_flag test_pmtu_nut_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static netns_state_t *test_pmtu_state; - -static int setup_test(void **state) { - (void)state; - - netns_create_topology(test_pmtu_state); - fprintf(stderr, "\nCreated topology\n"); - - test_pmtu_relay_running = true; - test_pmtu_peer_running = true; - test_pmtu_nut_running = true; - ping_channel_enable_07 = false; - memset(node_pmtu, 0, sizeof(node_pmtu)); - set_sync_flag(&test_pmtu_nut_closed, false); - assert(meshlink_destroy("nut")); - assert(meshlink_destroy("peer")); - assert(meshlink_destroy("relay")); - - return EXIT_SUCCESS; -} - -static int teardown_test(void **state) { - (void)state; - - assert(meshlink_destroy("nut")); - assert(meshlink_destroy("peer")); - assert(meshlink_destroy("relay")); - netns_destroy_topology(test_pmtu_state); - - return EXIT_SUCCESS; -} - -static void execute_test(test_step_func_t step_func, void **state) { - (void)state; - - - fprintf(stderr, "\n\x1b[32mRunning Test\x1b[0m\n"); - bool test_result = step_func(); - - if(!test_result) { - fail(); - } -} - -static void *gen_inv(void *arg) { - mesh_invite_arg_t *mesh_invite_arg = (mesh_invite_arg_t *)arg; - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_invite_arg->mesh_arg->node_name, mesh_invite_arg->mesh_arg->confbase, mesh_invite_arg->mesh_arg->app_name, mesh_invite_arg->mesh_arg->dev_class); - assert(mesh); - - char *invitation = meshlink_invite(mesh, NULL, mesh_invite_arg->invitee_name); - assert(invitation); - mesh_invite_arg->invite_str = invitation; - meshlink_close(mesh); - - return NULL; -} - -/* Test Steps for optimal PMTU discovery Test Case # 1 - - Validating NUT MTU parameters without blocking ICMP under designed - network topology */ -static void test_case_optimal_pmtu_01(void **state) { - execute_test(test_steps_optimal_pmtu_01, state); - return; -} - -/* Test Steps for optimal PMTU discovery Test Case # 1 - Success case - - Test Steps: - 1. Create NAT setup and run each node instances in discrete namespace. - 2. Open a channel from NUT to peer and hence triggering Peer to peer connection - 3. Send the analyzed MTU parameters mesh event information to test driver - Expected Result: - NUT and Peer should be able to hole puch the NATs and MTU parameters should be in - the expected range -*/ -static bool test_steps_optimal_pmtu_01(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; - - - mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; - netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; - netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = node_sim_pmtu_relay_01, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = node_sim_pmtu_peer_01, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = node_sim_pmtu_nut_01, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_pmtu_nut_closed, 300)); - test_pmtu_relay_running = false; - test_pmtu_peer_running = false; - - sleep(1); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_size, 1450, 1501); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_discovery.probes, 120, 160); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_size, 1450, 1501); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_discovery.probes, 120, 160); - - return true; -} - -/* Test Steps for optimal PMTU discovery Test Case # 2 - - Validating NUT MTU parameters blocking ICMP under designed - network topology */ -static void test_case_optimal_pmtu_02(void **state) { - execute_test(test_steps_optimal_pmtu_02, state); - return; -} - -/* Test Steps for optimal PMTU discovery Test Case # 2 - - Test Steps: - 1. Create NAT setup and run each node instances in discrete namespace, - 2. Block ICMP protocol at NUT's NAT - 3. Open a channel from NUT to peer and hence triggering Peer to peer connection - 4. Send the analyzed MTU parameters mesh event information to test driver - Expected Result: - NUT and Peer should be able to hole puch the NATs and MTU parameters should be in - the expected range -*/ -static bool test_steps_optimal_pmtu_02(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; - - assert(system("ip netns exec peer_nat iptables -A FORWARD -p icmp -j DROP") == 0); - assert(system("ip netns exec nut_nat iptables -A FORWARD -p icmp -j DROP") == 0); - - mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; - netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; - netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = node_sim_pmtu_relay_01, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = node_sim_pmtu_peer_01, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = node_sim_pmtu_nut_01, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_pmtu_nut_closed, 300)); - test_pmtu_relay_running = false; - test_pmtu_peer_running = false; - - sleep(1); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_size, 1450, 1501); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_discovery.probes, 120, 160); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_size, 1450, 1501); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_discovery.probes, 120, 160); - - return true; -} - -/* Test Steps for optimal PMTU discovery Test Case # 3 - - Validating NUT MTU parameters with MTU size of NAT = 1250 under designed - network topology */ -static void test_case_optimal_pmtu_03(void **state) { - execute_test(test_steps_optimal_pmtu_03, state); - return; -} - -/* Test Steps for optimal PMTU discovery Test Case # 3 - - Test Steps: - 1. Create NAT setup and run each node instances in discrete namespace, - 2. Change the MTU size of NUT's NAT to 1250 - 3. Open a channel from NUT to peer and hence triggering Peer to peer connection - 4. Send the analyzed MTU parameters mesh event information to test driver - Expected Result: - NUT and Peer should be able to hole puch the NATs and MTU parameters should be in - the expected range -*/ -static bool test_steps_optimal_pmtu_03(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; - - assert(system("ip netns exec nut_nat ifconfig eth_nut mtu 1250") == 0); - - mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; - netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; - netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = node_sim_pmtu_relay_01, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = node_sim_pmtu_peer_01, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = node_sim_pmtu_nut_01, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_pmtu_nut_closed, 300)); - test_pmtu_relay_running = false; - test_pmtu_peer_running = false; - - sleep(1); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_size, 1200, 1250); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_size, 1200, 1250); - - return true; -} - -/* Test Steps for optimal PMTU discovery Test Case # 4 - - Validating NUT MTU parameters with MTU size of NAT = 1000 under designed - network topology */ -static void test_case_optimal_pmtu_04(void **state) { - execute_test(test_steps_optimal_pmtu_04, state); - return; -} - -/* Test Steps for optimal PMTU discovery Test Case # 4 - - Test Steps: - 1. Create NAT setup and run each node instances in discrete namespace, - 2. Change the MTU size of NUT's NAT to 1000 - 3. Open a channel from NUT to peer and hence triggering Peer to peer connection - 4. Send the analyzed MTU parameters mesh event information to test driver - Expected Result: - NUT and Peer should be able to hole puch the NATs and MTU parameters should be in - the expected range -*/ -static bool test_steps_optimal_pmtu_04(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; - - assert(system("ip netns exec nut_nat ifconfig eth_nut mtu 1000") == 0); - - mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; - netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; - netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = node_sim_pmtu_relay_01, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = node_sim_pmtu_peer_01, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = node_sim_pmtu_nut_01, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_pmtu_nut_closed, 300)); - test_pmtu_relay_running = false; - test_pmtu_peer_running = false; - - sleep(1); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_size, 925, 1000); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_size, 925, 1000); - - return true; -} - -/* Test Steps for optimal PMTU discovery Test Case # 5 - - Validating NUT MTU parameters with MTU size of NAT = 800 under designed - network topology */ -static void test_case_optimal_pmtu_05(void **state) { - execute_test(test_steps_optimal_pmtu_05, state); - return; -} - -/* Test Steps for optimal PMTU discovery Test Case # 5 - - Test Steps: - 1. Create NAT setup and run each node instances in discrete namespace, - 2. Change the MTU size of NUT's NAT to 800 - 3. Open a channel from NUT to peer and hence triggering Peer to peer connection - 4. Send the analyzed MTU parameters mesh event information to test driver - Expected Result: - NUT and Peer should be able to hole puch the NATs and MTU parameters should be in - the expected range -*/ -static bool test_steps_optimal_pmtu_05(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; - - assert(system("ip netns exec nut_nat ifconfig eth_nut mtu 750") == 0); - - mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; - netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; - netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = node_sim_pmtu_relay_01, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = node_sim_pmtu_peer_01, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = node_sim_pmtu_nut_01, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_pmtu_nut_closed, 300)); - test_pmtu_relay_running = false; - test_pmtu_peer_running = false; - - sleep(1); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_size, 700, 750); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_size, 700, 750); - - return true; -} - -/* Test Steps for optimal PMTU discovery Test Case # 6 - - Flushing the tracked connections via NUT NAT for every 60 seconds */ -static void test_case_optimal_pmtu_06(void **state) { - execute_test(test_steps_optimal_pmtu_06, state); - return; -} - -static bool run_conntrack; -static pthread_t pmtu_test_case_conntrack_thread; -static void *conntrack_flush(void *arg) { - (void)arg; - - // flushes mappings for every 60 seconds - - while(run_conntrack) { - sleep(100); - assert(system("ip netns exec nut_nat conntrack -F") == 0); - assert(system("ip netns exec peer_nat conntrack -F") == 0); - } - - pthread_exit(NULL); -} - -/* Test Steps for optimal PMTU discovery Test Case # 6 - - Test Steps: - 1. Create NAT setup and Launch conntrack thread which flushes the tracked connections for every 90 seconds - 2. Run each node instances in discrete namespace, - 3. Open a channel from NUT to peer and hence triggering Peer to peer connection - 4. Send the analyzed MTU parameters mesh event information to test driver - Expected Result: - NUT and Peer should be able to hole puch the NATs and MTU parameters should be in - the expected range -*/ -static bool test_steps_optimal_pmtu_06(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; - - run_conntrack = true; - assert(!pthread_create(&pmtu_test_case_conntrack_thread, NULL, conntrack_flush, NULL)); - - mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; - netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; - netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = node_sim_pmtu_relay_01, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = node_sim_pmtu_peer_01, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = node_sim_pmtu_nut_01, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_pmtu_nut_closed, 300)); - test_pmtu_relay_running = false; - test_pmtu_peer_running = false; - run_conntrack = false; - pthread_join(pmtu_test_case_conntrack_thread, NULL); - - sleep(1); - - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_size, 1440, 1500); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_size, 1440, 1500); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_ping.probes, 38, 42); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_ping.probes, 38, 42); - - return true; -} - -/* Test Steps for optimal PMTU discovery Test Case # 7 - - NUT sending data to peer node via channel for every 30 seconds - */ -static void test_case_optimal_pmtu_07(void **state) { - execute_test(test_steps_optimal_pmtu_07, state); - return; -} - -/* Test Steps for optimal PMTU discovery Test Case # 7 - - Test Steps: - 1. Create NAT setup and run each node instances in discrete namespace. - 2. Open a channel from NUT to peer and hence triggering Peer to peer connection - 3. Send data periodically via channel from NUT to peer node. - 4. Send the analyzed MTU parameters mesh event information to test driver - Expected Result: - NUT and Peer should be able to hole puch the NATs and MTU parameters should be in - the expected range -*/ -static bool test_steps_optimal_pmtu_07(void) { - mesh_arg_t relay_arg = {.node_name = "relay", .confbase = "relay", .app_name = "relay", .dev_class = 0 }; - mesh_arg_t peer_arg = {.node_name = "peer", .confbase = "peer", .app_name = "peer", .dev_class = 1 }; - mesh_arg_t nut_arg = {.node_name = "nut", .confbase = "nut", .app_name = "nut", .dev_class = 1 }; - - ping_channel_enable_07 = true; - - mesh_invite_arg_t relay_nut_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "nut" }; - netns_thread_t netns_relay_nut_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_nut_invite_arg}; - run_node_in_namespace_thread(&netns_relay_nut_invite); - sleep(1); - assert(relay_nut_invite_arg.invite_str); - nut_arg.join_invitation = relay_nut_invite_arg.invite_str; - - mesh_invite_arg_t relay_peer_invite_arg = {.mesh_arg = &relay_arg, .invitee_name = "peer" }; - netns_thread_t netns_relay_peer_invite = {.namespace_name = "relay", .netns_thread = gen_inv, .arg = &relay_peer_invite_arg}; - run_node_in_namespace_thread(&netns_relay_peer_invite); - sleep(1); - assert(relay_peer_invite_arg.invite_str); - peer_arg.join_invitation = relay_peer_invite_arg.invite_str; - - netns_thread_t netns_relay_handle = {.namespace_name = "relay", .netns_thread = node_sim_pmtu_relay_01, .arg = &relay_arg}; - run_node_in_namespace_thread(&netns_relay_handle); - - netns_thread_t netns_peer_handle = {.namespace_name = "peer", .netns_thread = node_sim_pmtu_peer_01, .arg = &peer_arg}; - run_node_in_namespace_thread(&netns_peer_handle); - - netns_thread_t netns_nut_handle = {.namespace_name = "nut", .netns_thread = node_sim_pmtu_nut_01, .arg = &nut_arg}; - run_node_in_namespace_thread(&netns_nut_handle); - - assert(wait_sync_flag(&test_pmtu_nut_closed, 300)); - test_pmtu_relay_running = false; - test_pmtu_peer_running = false; - - sleep(1); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_size, 1450, 1501); - assert_in_range(node_pmtu[NODE_PMTU_PEER].mtu_discovery.probes, 120, 160); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_size, 1450, 1501); - assert_in_range(node_pmtu[NODE_PMTU_RELAY].mtu_discovery.probes, 120, 160); - - return true; -} - -// Optimal PMTU test case driver - -int test_optimal_pmtu(void) { - interface_t nut_ifs[] = { { .if_peer = "nut_nat", .fetch_ip_netns_name = "nut_nat" } }; - namespace_t nut = { - .name = "nut", - .type = HOST, - .interfaces = nut_ifs, - .interfaces_no = 1, - }; - - interface_t peer_ifs[] = { { .if_peer = "peer_nat", .fetch_ip_netns_name = "peer_nat" } }; - namespace_t peer = { - .name = "peer", - .type = HOST, - .interfaces = peer_ifs, - .interfaces_no = 1, - }; - - interface_t relay_ifs[] = { { .if_peer = "wan_bridge" } }; - namespace_t relay = { - .name = "relay", - .type = HOST, - .interfaces = relay_ifs, - .interfaces_no = 1, - }; - - netns_fullcone_handle_t nut_nat_fullcone = { .snat_to_source = "wan_bridge", .dnat_to_destination = "nut" }; - netns_fullcone_handle_t *nut_nat_args[] = { &nut_nat_fullcone, NULL }; - interface_t nut_nat_ifs[] = { { .if_peer = "nut", .fetch_ip_netns_name = "nut_nat" }, { .if_peer = "wan_bridge" } }; - namespace_t nut_nat = { - .name = "nut_nat", - .type = FULL_CONE, - .nat_arg = nut_nat_args, - .static_config_net_addr = "192.168.1.0/24", - .interfaces = nut_nat_ifs, - .interfaces_no = 2, - }; - - netns_fullcone_handle_t peer_nat_fullcone = { .snat_to_source = "wan_bridge", .dnat_to_destination = "peer" }; - netns_fullcone_handle_t *peer_nat_args[] = { &peer_nat_fullcone, NULL }; - interface_t peer_nat_ifs[] = { { .if_peer = "peer", .fetch_ip_netns_name = "peer_nat" }, { .if_peer = "wan_bridge" } }; - namespace_t peer_nat = { - .name = "peer_nat", - .type = FULL_CONE, - .nat_arg = peer_nat_args, - .static_config_net_addr = "192.168.1.0/24", - .interfaces = peer_nat_ifs, - .interfaces_no = 2, - }; - - interface_t wan_ifs[] = { { .if_peer = "peer_nat" }, { .if_peer = "nut_nat" }, { .if_peer = "relay" } }; - namespace_t wan_bridge = { - .name = "wan_bridge", - .type = BRIDGE, - .interfaces = wan_ifs, - .interfaces_no = 3, - }; - - namespace_t test_optimal_pmtu_1_nodes[] = { nut_nat, peer_nat, wan_bridge, nut, peer, relay }; - - netns_state_t test_pmtu_nodes = { - .test_case_name = "test_case_optimal_pmtu", - .namespaces = test_optimal_pmtu_1_nodes, - .num_namespaces = 6, - }; - test_pmtu_state = &test_pmtu_nodes; - - const struct CMUnitTest blackbox_group0_tests[] = { - cmocka_unit_test_prestate_setup_teardown(test_case_optimal_pmtu_01, setup_test, teardown_test, - (void *)&test_pmtu_state), - cmocka_unit_test_prestate_setup_teardown(test_case_optimal_pmtu_02, setup_test, teardown_test, - (void *)&test_pmtu_state), - cmocka_unit_test_prestate_setup_teardown(test_case_optimal_pmtu_03, setup_test, teardown_test, - (void *)&test_pmtu_state), - cmocka_unit_test_prestate_setup_teardown(test_case_optimal_pmtu_04, setup_test, teardown_test, - (void *)&test_pmtu_state), - cmocka_unit_test_prestate_setup_teardown(test_case_optimal_pmtu_05, setup_test, teardown_test, - (void *)&test_pmtu_state), - cmocka_unit_test_prestate_setup_teardown(test_case_optimal_pmtu_06, setup_test, teardown_test, - (void *)&test_pmtu_state), - cmocka_unit_test_prestate_setup_teardown(test_case_optimal_pmtu_07, setup_test, teardown_test, - (void *)&test_pmtu_state), - }; - total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]); - - return cmocka_run_group_tests(blackbox_group0_tests, NULL, NULL); -} diff --git a/test/blackbox/run_blackbox_tests/test_optimal_pmtu.h b/test/blackbox/run_blackbox_tests/test_optimal_pmtu.h deleted file mode 100644 index 3ee68f7..0000000 --- a/test/blackbox/run_blackbox_tests/test_optimal_pmtu.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef TEST_CASES_OPTIMAL_PMTU_H -#define TEST_CASES_OPTIMAL_PMTU_H - -/* - test_optimal_pmtu.h -- Declarations for Individual Test Case implementation functions - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include - -extern int test_optimal_pmtu(void); -extern int total_tests; -extern char *lxc_path; - -typedef struct pmtu_attr_para { - int probes; - int probes_total_len; - int count; - time_t time; - time_t time_l; - time_t time_h; -} pmtu_attr_para_t; - -typedef struct pmtu_attr { - pmtu_attr_para_t mtu_sent_probes; - pmtu_attr_para_t mtu_recv_probes; - pmtu_attr_para_t mtu_discovery; - pmtu_attr_para_t mtu_ping; - pmtu_attr_para_t mtu_increase; - pmtu_attr_para_t mtu_start; - int mtu_size; -} pmtu_attr_t; - -#define NODE_PMTU_RELAY 0 -#define NODE_PMTU_PEER 1 - -#define find_node_index(i, node_name) if(!strcasecmp(node_name, "peer")) { \ - i = NODE_PMTU_PEER; \ - } else if(!strcasecmp(node_name, "relay")) { \ - i = NODE_PMTU_RELAY; \ - } else { \ - abort(); \ - } - -#define PING_TRACK_TIMEOUT 100 -#define CHANNEL_PORT 1234 - -#endif // TEST_CASES_OPTIMAL_PMTU_H diff --git a/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c b/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c deleted file mode 100644 index 9e04a8b..0000000 --- a/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for channel connections with respective to blacklisting their nodes - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" -#include "node_sim_nut_01.h" - -#define CHANNEL_PORT 1234 - -static bool blacklist_set; -int total_reachable_callbacks_01; -int total_unreachable_callbacks_01; -int total_channel_closure_callbacks_01; -bool channel_discon_case_ping; -bool channel_discon_network_failure_01; -bool channel_discon_network_failure_02; -bool test_blacklist_whitelist_01; -bool test_channel_restart_01; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag peer_unreachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channels_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - fprintf(stderr, "Node %s %s\n", node->name, reachable ? "reachable" : "unreachable"); - - if(!strcmp(node->name, "peer")) { - if(reachable) { - set_sync_flag(&peer_reachable, true); - - if(blacklist_set) { - ++total_reachable_callbacks_01; - } - } else { - set_sync_flag(&peer_unreachable, true); - - if(blacklist_set) { - ++total_unreachable_callbacks_01; - } - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - fprintf(stderr, "%s poll cb invoked\n", (char *)channel->priv); - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(len == 0) { - fprintf(stderr, "Closed channel with %s\n", (char *)channel->priv); - - if(blacklist_set) { - ++total_channel_closure_callbacks_01; - } - - if(total_channel_closure_callbacks_01 == 2) { - set_sync_flag(&channels_closed, true); - } - } - - if(!strcmp(channel->node->name, "peer")) { - if(len == 5 && !memcmp(dat, "reply", 5)) { - fprintf(stderr, "Channel opened with %s\n", (char *)channel->priv); - set_sync_flag(&channel_opened, true); - } - } - - return; -} - -static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)level; - - (void)mesh; - - fprintf(stderr, "\x1b[32m nut:\x1b[0m %s\n", text); -} - -void *test_channel_blacklist_disonnection_nut_01(void *arg) { - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - total_reachable_callbacks_01 = 0; - total_unreachable_callbacks_01 = 0; - total_channel_closure_callbacks_01 = 0; - - set_sync_flag(&peer_reachable, false); - set_sync_flag(&peer_unreachable, false); - set_sync_flag(&channel_opened, false); - blacklist_set = false; - - assert(!channel_discon_network_failure_01 || !channel_discon_network_failure_02); - - // Run relay node instance - - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_message); - meshlink_set_node_status_cb(mesh, node_status_cb); - - // Join relay node and if fails to join then try few more attempts - - if(mesh_arg->join_invitation) { - assert(meshlink_join(mesh, mesh_arg->join_invitation)); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 30)); - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel1 = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - channel1->priv = "channel1"; - meshlink_set_channel_poll_cb(mesh, channel1, poll_cb); - - assert(wait_sync_flag(&channel_opened, 15)); - - set_sync_flag(&channel_opened, false); - - meshlink_channel_t *channel2 = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - channel2->priv = "channel2"; - meshlink_set_channel_poll_cb(mesh, channel2, poll_cb); - - assert(wait_sync_flag(&channel_opened, 15)); - - blacklist_set = true; - - if(channel_discon_network_failure_01) { - fprintf(stderr, "Simulating network failure before blacklisting\n"); - assert(system("iptables -A INPUT -m statistic --mode random --probability 0.9 -j DROP") == 0); - assert(system("iptables -A OUTPUT -m statistic --mode random --probability 0.9 -j DROP") == 0); - sleep(1); - } - - fprintf(stderr, "Node blacklisted\n"); - set_sync_flag(&channels_closed, false); - assert(meshlink_blacklist(mesh, peer_node)); - - sleep(10); - - if(channel_discon_network_failure_02) { - fprintf(stderr, "Simulating network failure after blacklisting\n"); - assert(system("iptables -A INPUT -m statistic --mode random --probability 0.9 -j DROP") == 0); - assert(system("iptables -A OUTPUT -m statistic --mode random --probability 0.9 -j DROP") == 0); - sleep(1); - } - - if(channel_discon_case_ping) { - fprintf(stderr, "Sending data through channels after blacklisting\n"); - assert(meshlink_channel_send(mesh, channel1, "ping", 5) >= 0); - assert(meshlink_channel_send(mesh, channel2, "ping", 5) >= 0); - } - - if(wait_sync_flag(&channels_closed, 120) == false) { - set_sync_flag(&test_channel_discon_nut_close, true); - return NULL; - } - - if(channel_discon_network_failure_01 || channel_discon_network_failure_02) { - fprintf(stderr, "Simulating network failure after blacklisting\n"); - assert(system("iptables -D INPUT -m statistic --mode random --probability 0.9 -j DROP") == 0); - assert(system("iptables -D OUTPUT -m statistic --mode random --probability 0.9 -j DROP") == 0); - } - - set_sync_flag(&peer_reachable, false); - - assert(meshlink_whitelist(mesh, peer_node)); - fprintf(stderr, "Node whitelisted\n"); - - wait_sync_flag(&peer_reachable, 70); - - fprintf(stderr, "Closing NUT instance\n"); - blacklist_set = false; - - set_sync_flag(&test_channel_discon_nut_close, true); - - meshlink_close(mesh); - return NULL; -} diff --git a/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.h b/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.h deleted file mode 100644 index e5dc0ac..0000000 --- a/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CHANNEL_BLACKLIST_NUT_01_H -#define CHANNEL_BLACKLIST_NUT_01_H - -/* - test_case_channel_disconnection.h -- Implementation of Node Simulation for Meshlink Testing - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -extern void *test_channel_blacklist_disonnection_peer_01(void *arg); -extern void *test_channel_blacklist_disonnection_nut_01(void *arg); -extern void *test_channel_blacklist_disonnection_relay_01(void *arg); -extern int total_blacklist_callbacks_01; -extern int total_whitelist_callbacks_01; -extern struct sync_flag test_channel_discon_nut_close; -extern bool test_case_signal_peer_restart_01; - -#endif diff --git a/test/blackbox/test_case_channel_blacklist_01/node_sim_peer_01.c b/test/blackbox/test_case_channel_blacklist_01/node_sim_peer_01.c deleted file mode 100644 index 4e36933..0000000 --- a/test/blackbox/test_case_channel_blacklist_01/node_sim_peer_01.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for channel connections with respective to blacklisting their nodes - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" - -#define CHANNEL_PORT 1234 - -bool test_channel_blacklist_disonnection_peer_01_running; -bool test_case_signal_peer_restart_01; - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - - if(len == 0) { - fprintf(stderr, "Channel closure\n"); - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - } - - return; -} - -void *test_channel_blacklist_disonnection_peer_01(void *arg) { - struct timeval main_loop_wait = { 2, 0 }; - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - test_channel_blacklist_disonnection_peer_01_running = true; - - // Run relay node instance - - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(mesh); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - // Join relay node and if fails to join then try few more attempts - - if(mesh_arg->join_invitation) { - assert(meshlink_join(mesh, mesh_arg->join_invitation)); - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_channel_blacklist_disonnection_peer_01_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - - if(test_case_signal_peer_restart_01) { - meshlink_stop(mesh); - assert(meshlink_start(mesh)); - test_case_signal_peer_restart_01 = false; - } - } - - meshlink_close(mesh); - - return NULL; -} diff --git a/test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c b/test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c deleted file mode 100644 index a6c293a..0000000 --- a/test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing - for channel connections with respective to blacklisting their nodes - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/network_namespace_framework.h" - -bool test_channel_blacklist_disonnection_relay_01_running; - -void *test_channel_blacklist_disonnection_relay_01(void *arg) { - struct timeval main_loop_wait = { 2, 0 }; - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - test_channel_blacklist_disonnection_relay_01_running = true; - - // Run relay node instance - - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(mesh); - - assert(meshlink_start(mesh)); - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_channel_blacklist_disonnection_relay_01_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return NULL; -} diff --git a/test/blackbox/test_case_channel_conn_01/Makefile.am b/test/blackbox/test_case_channel_conn_01/Makefile.am deleted file mode 100644 index 177c575..0000000 --- a/test/blackbox/test_case_channel_conn_01/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE \ No newline at end of file diff --git a/test/blackbox/test_case_channel_conn_01/node_sim_nut.c b/test/blackbox/test_case_channel_conn_01/node_sim_nut.c deleted file mode 100644 index 25b187f..0000000 --- a/test/blackbox/test_case_channel_conn_01/node_sim_nut.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag sigusr_received = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr_received, true); - - return; -} - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - fprintf(stderr, "SENT EVENT\n"); - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "peer") && reachable) { - set_sync_flag(&peer_reachable, true); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(len == 0) { - send_event(ERR_NETWORK); - assert(false); - } - - if(!strcmp(channel->node->name, "peer")) { - if(len == 5 && !memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 30)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&sigusr_received, 30)); - - sleep(10); - - assert(meshlink_channel_send(mesh, channel, "after", 6) >= 0); - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_01/node_sim_peer.c b/test/blackbox/test_case_channel_conn_01/node_sim_peer.c deleted file mode 100644 index ed74626..0000000 --- a/test/blackbox/test_case_channel_conn_01/node_sim_peer.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - if(len == 0) { - mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0); - assert(false); - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } else if(!memcmp(dat, "after", 6)) { - assert(mesh_event_sock_send(client_id, CHANNEL_DATA_RECIEVED, NULL, 0)); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - - // Run peer node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_02/Makefile.am b/test/blackbox/test_case_channel_conn_02/Makefile.am deleted file mode 100644 index 4cca831..0000000 --- a/test/blackbox/test_case_channel_conn_02/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_channel_conn_02/node_sim_nut.c b/test/blackbox/test_case_channel_conn_02/node_sim_nut.c deleted file mode 100644 index f6b1668..0000000 --- a/test/blackbox/test_case_channel_conn_02/node_sim_nut.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag sigusr_received = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr_received, true); - return; -} - -static void send_event(mesh_event_t event) { - bool send_ret = false; - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - send_ret = mesh_event_sock_send(client_id, event, NULL, 0); - - if(send_ret) { - break; - } - } - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "peer") && reachable) { - set_sync_flag(&peer_reachable, true); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(len == 0) { - set_sync_flag(&channel_closed, true); - send_event(ERR_NETWORK); - return; - } - - if(!strcmp(channel->node->name, "peer")) { - if(len == 5 && !memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 30)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&sigusr_received, 10)); - - assert(meshlink_channel_send(mesh, channel, "after", 6) >= 0); - - assert(wait_sync_flag(&channel_closed, 180)); - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_02/node_sim_peer.c b/test/blackbox/test_case_channel_conn_02/node_sim_peer.c deleted file mode 100644 index dc85304..0000000 --- a/test/blackbox/test_case_channel_conn_02/node_sim_peer.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - if(len == 0) { - assert(mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0)); - return; - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Run peer node instance - - setup_signals(); - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_03/Makefile.am b/test/blackbox/test_case_channel_conn_03/Makefile.am deleted file mode 100644 index 4cca831..0000000 --- a/test/blackbox/test_case_channel_conn_03/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_channel_conn_03/node_sim_nut.c b/test/blackbox/test_case_channel_conn_03/node_sim_nut.c deleted file mode 100644 index 4bd8d28..0000000 --- a/test/blackbox/test_case_channel_conn_03/node_sim_nut.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag peer_unreachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag sigusr_received = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr_received, true); - return; -} - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "peer")) { - if(reachable) { - set_sync_flag(&peer_reachable, true); - } else { - set_sync_flag(&peer_unreachable, true); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(!strcmp(channel->node->name, "peer")) { - if(len == 5 && !memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 30)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - peer_unreachable.flag = false; - peer_reachable.flag = false; - assert(wait_sync_flag(&sigusr_received, 10)); - - assert(wait_sync_flag(&peer_unreachable, 100)); - send_event(NODE_UNREACHABLE); - - assert(wait_sync_flag(&peer_reachable, 100)); - send_event(NODE_REACHABLE); - - assert(meshlink_channel_send(mesh, channel, "after", 6) >= 0); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_03/node_sim_peer.c b/test/blackbox/test_case_channel_conn_03/node_sim_peer.c deleted file mode 100644 index 19c96f8..0000000 --- a/test/blackbox/test_case_channel_conn_03/node_sim_peer.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - if(len == 0) { - assert(mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0)); - return; - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } else if(!memcmp(dat, "after", 5)) { - assert(mesh_event_sock_send(client_id, CHANNEL_DATA_RECIEVED, NULL, 0)); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Run peer node instance - - setup_signals(); - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_04/Makefile.am b/test/blackbox/test_case_channel_conn_04/Makefile.am deleted file mode 100644 index 4cca831..0000000 --- a/test/blackbox/test_case_channel_conn_04/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_channel_conn_04/node_sim_nut.c b/test/blackbox/test_case_channel_conn_04/node_sim_nut.c deleted file mode 100644 index 9579f01..0000000 --- a/test/blackbox/test_case_channel_conn_04/node_sim_nut.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable); - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "peer")) { - if(reachable) { - set_sync_flag(&peer_reachable, true); - } else { - peer_reachable.flag = false; - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(len == 0) { - //send_event(ERR_NETWORK); - return; - } - - if(!strcmp(channel->node->name, "peer")) { - if(!memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - setup_signals(); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 10)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - // Restarting the node instance - - meshlink_stop(mesh); - assert(meshlink_start(mesh)); - - assert(wait_sync_flag(&peer_reachable, 60)); - send_event(NODE_RESTARTED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_04/node_sim_peer.c b/test/blackbox/test_case_channel_conn_04/node_sim_peer.c deleted file mode 100644 index b087341..0000000 --- a/test/blackbox/test_case_channel_conn_04/node_sim_peer.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static struct sync_flag sigusr = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static int client_id = -1; - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr, true); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - if(len == 0) { - mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0); - return; - } - - if(!strcmp(channel->node->name, "nut") && !memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Run peer node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - assert(wait_sync_flag(&sigusr, 140)); - meshlink_channel_t *channel = mesh->priv; - assert(meshlink_channel_send(mesh, channel, "failure", 7)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_05/Makefile.am b/test/blackbox/test_case_channel_conn_05/Makefile.am deleted file mode 100644 index 8bde53d..0000000 --- a/test/blackbox/test_case_channel_conn_05/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_channel_conn_05/node_sim_nut.c b/test/blackbox/test_case_channel_conn_05/node_sim_nut.c deleted file mode 100644 index f520699..0000000 --- a/test/blackbox/test_case_channel_conn_05/node_sim_nut.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag sigusr_received = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr_received, true); - - return; -} - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "peer") && reachable) { - set_sync_flag(&peer_reachable, true); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(len == 0) { - send_event(ERR_NETWORK); - assert(false); - } - - if(!strcmp(channel->node->name, "peer")) { - if(len == 5 && !memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 30)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&sigusr_received, 10)); - - sleep(10); - - assert(meshlink_channel_send(mesh, channel, "after", 6) >= 0); - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_05/node_sim_peer.c b/test/blackbox/test_case_channel_conn_05/node_sim_peer.c deleted file mode 100644 index ed74626..0000000 --- a/test/blackbox/test_case_channel_conn_05/node_sim_peer.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - if(len == 0) { - mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0); - assert(false); - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } else if(!memcmp(dat, "after", 6)) { - assert(mesh_event_sock_send(client_id, CHANNEL_DATA_RECIEVED, NULL, 0)); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - - // Run peer node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_05/node_sim_relay.c b/test/blackbox/test_case_channel_conn_05/node_sim_relay.c deleted file mode 100644 index 8e5e66e..0000000 --- a/test/blackbox/test_case_channel_conn_05/node_sim_relay.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Setup required signals - - setup_signals(); - - // Run relay node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - - assert(meshlink_start(mesh)); - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_case_channel_conn_06/Makefile.am b/test/blackbox/test_case_channel_conn_06/Makefile.am deleted file mode 100644 index 8bde53d..0000000 --- a/test/blackbox/test_case_channel_conn_06/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_channel_conn_06/node_sim_nut.c b/test/blackbox/test_case_channel_conn_06/node_sim_nut.c deleted file mode 100644 index cabd82e..0000000 --- a/test/blackbox/test_case_channel_conn_06/node_sim_nut.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_closed = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag sigusr_received = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr_received, true); - return; -} - -static void send_event(mesh_event_t event) { - bool send_ret = false; - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - send_ret = mesh_event_sock_send(client_id, event, NULL, 0); - - if(send_ret) { - break; - } - } - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - - if(!strcasecmp(node->name, "peer") && reachable) { - set_sync_flag(&peer_reachable, true); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - - if(len == 0) { - set_sync_flag(&channel_closed, true); - send_event(ERR_NETWORK); - return; - } - - if(!strcmp(channel->node->name, "peer")) { - if(len == 5 && !memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 30)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - assert(wait_sync_flag(&sigusr_received, 10)); - - sleep(40); - assert(meshlink_channel_send(mesh, channel, "after", 6) >= 0); - - - assert(wait_sync_flag(&channel_closed, 140)); - - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_06/node_sim_peer.c b/test/blackbox/test_case_channel_conn_06/node_sim_peer.c deleted file mode 100644 index 5575c0e..0000000 --- a/test/blackbox/test_case_channel_conn_06/node_sim_peer.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - - if(len == 0) { - assert(mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0)); - return; - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Run peer node instance - - setup_signals(); - - meshlink_set_log_cb(NULL, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_06/node_sim_relay.c b/test/blackbox/test_case_channel_conn_06/node_sim_relay.c deleted file mode 100644 index 8e5e66e..0000000 --- a/test/blackbox/test_case_channel_conn_06/node_sim_relay.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Setup required signals - - setup_signals(); - - // Run relay node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - - assert(meshlink_start(mesh)); - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_case_channel_conn_07/Makefile.am b/test/blackbox/test_case_channel_conn_07/Makefile.am deleted file mode 100644 index 8bde53d..0000000 --- a/test/blackbox/test_case_channel_conn_07/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_channel_conn_07/node_sim_nut.c b/test/blackbox/test_case_channel_conn_07/node_sim_nut.c deleted file mode 100644 index 9be80b6..0000000 --- a/test/blackbox/test_case_channel_conn_07/node_sim_nut.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag peer_unreachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag sigusr_received = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr_received, true); - return; -} - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - - if(!strcasecmp(node->name, "peer")) { - if(reachable) { - set_sync_flag(&peer_reachable, true); - } else { - set_sync_flag(&peer_unreachable, true); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - if(!strcmp(channel->node->name, "peer")) { - if(len == 5 && !memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - assert(wait_sync_flag(&peer_reachable, 30)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - peer_unreachable.flag = false; - peer_reachable.flag = false; - assert(wait_sync_flag(&sigusr_received, 10)); - - assert(wait_sync_flag(&peer_unreachable, 100)); - send_event(NODE_UNREACHABLE); - - assert(wait_sync_flag(&peer_reachable, 100)); - send_event(NODE_REACHABLE); - - assert(meshlink_channel_send(mesh, channel, "after", 6) >= 0); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - assert(meshlink_channel_send(mesh, channel, "ping", 6) >= 0); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_07/node_sim_peer.c b/test/blackbox/test_case_channel_conn_07/node_sim_peer.c deleted file mode 100644 index 19c96f8..0000000 --- a/test/blackbox/test_case_channel_conn_07/node_sim_peer.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - if(len == 0) { - assert(mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0)); - return; - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } else if(!memcmp(dat, "after", 5)) { - assert(mesh_event_sock_send(client_id, CHANNEL_DATA_RECIEVED, NULL, 0)); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Run peer node instance - - setup_signals(); - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_07/node_sim_relay.c b/test/blackbox/test_case_channel_conn_07/node_sim_relay.c deleted file mode 100644 index 8e5e66e..0000000 --- a/test/blackbox/test_case_channel_conn_07/node_sim_relay.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Setup required signals - - setup_signals(); - - // Run relay node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - - assert(meshlink_start(mesh)); - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_case_channel_conn_08/Makefile.am b/test/blackbox/test_case_channel_conn_08/Makefile.am deleted file mode 100644 index 8bde53d..0000000 --- a/test/blackbox/test_case_channel_conn_08/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_channel_conn_08/node_sim_nut.c b/test/blackbox/test_case_channel_conn_08/node_sim_nut.c deleted file mode 100644 index 9579f01..0000000 --- a/test/blackbox/test_case_channel_conn_08/node_sim_nut.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void send_event(mesh_event_t event); -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable); - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "peer")) { - if(reachable) { - set_sync_flag(&peer_reachable, true); - } else { - peer_reachable.flag = false; - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - if(len == 0) { - //send_event(ERR_NETWORK); - return; - } - - if(!strcmp(channel->node->name, "peer")) { - if(!memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - setup_signals(); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 10)); - send_event(NODE_JOINED); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - // Restarting the node instance - - meshlink_stop(mesh); - assert(meshlink_start(mesh)); - - assert(wait_sync_flag(&peer_reachable, 60)); - send_event(NODE_RESTARTED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_channel_conn_08/node_sim_peer.c b/test/blackbox/test_case_channel_conn_08/node_sim_peer.c deleted file mode 100644 index b087341..0000000 --- a/test/blackbox/test_case_channel_conn_08/node_sim_peer.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static struct sync_flag sigusr = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static int client_id = -1; - -static void mesh_siguser1_signal_handler(int sig_num) { - (void)sig_num; - - set_sync_flag(&sigusr, true); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - (void)channel; - (void)dat; - (void)len; - - if(len == 0) { - mesh_event_sock_send(client_id, ERR_NETWORK, NULL, 0); - return; - } - - if(!strcmp(channel->node->name, "nut") && !memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGUSR1, mesh_siguser1_signal_handler); - - // Run peer node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - assert(wait_sync_flag(&sigusr, 140)); - meshlink_channel_t *channel = mesh->priv; - assert(meshlink_channel_send(mesh, channel, "failure", 7)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_channel_conn_08/node_sim_relay.c b/test/blackbox/test_case_channel_conn_08/node_sim_relay.c deleted file mode 100644 index 8e5e66e..0000000 --- a/test/blackbox/test_case_channel_conn_08/node_sim_relay.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Setup required signals - - setup_signals(); - - // Run relay node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - - assert(meshlink_start(mesh)); - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_case_meta_conn_01/Makefile.am b/test/blackbox/test_case_meta_conn_01/Makefile.am deleted file mode 100644 index 28fa44b..0000000 --- a/test/blackbox/test_case_meta_conn_01/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_relay node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_meta_conn_01/node_sim_nut.c b/test/blackbox/test_case_meta_conn_01/node_sim_nut.c deleted file mode 100644 index 5cf624f..0000000 --- a/test/blackbox/test_case_meta_conn_01/node_sim_nut.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -static bool conn_status = false; - -static void callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - (void)level; - - char connection_match_msg[100]; - - fprintf(stderr, "meshlink>> %s\n", text); - - if(strstr(text, "Connection") || strstr(text, "connection")) { - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection with peer") >= 0); - - if(strstr(text, connection_match_msg) && strstr(text, "activated")) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Already connected to peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection closed by peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Closing connection with peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - execute_open(argv[1], argv[2]); - meshlink_set_log_cb(mesh_handle, MESHLINK_DEBUG, callback_logger); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - /* Connectivity of peer */ - while(!conn_status) { - sleep(1); - } - - fprintf(stderr, "Connected with Peer\n"); - assert(mesh_event_sock_send(client_id, META_CONN_SUCCESSFUL, NULL, 0)); - - /* Connectivity of peer */ - while(conn_status) { - sleep(1); - } - - fprintf(stderr, "Closed connection with Peer\n"); - assert(mesh_event_sock_send(client_id, META_CONN_CLOSED, NULL, 0)); - - /* Connectivity of peer */ - while(!conn_status) { - sleep(1); - } - - fprintf(stderr, "Connected with Peer\n"); - assert(mesh_event_sock_send(client_id, META_RECONN_SUCCESSFUL, NULL, 0)); - - execute_close(); - assert(meshlink_destroy(argv[1])); - return 0; -} diff --git a/test/blackbox/test_case_meta_conn_01/node_sim_peer.c b/test/blackbox/test_case_meta_conn_01/node_sim_peer.c deleted file mode 100644 index 5dd8807..0000000 --- a/test/blackbox/test_case_meta_conn_01/node_sim_peer.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - - if(client_id != -1) { - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_01/node_sim_relay.c b/test/blackbox/test_case_meta_conn_01/node_sim_relay.c deleted file mode 100644 index cde644c..0000000 --- a/test/blackbox/test_case_meta_conn_01/node_sim_relay.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - execute_start(); - - if(client_id != -1) { - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_01/test/node_step.sh b/test/blackbox/test_case_meta_conn_01/test/node_step.sh deleted file mode 100755 index fe28423..0000000 --- a/test/blackbox/test_case_meta_conn_01/test/node_step.sh +++ /dev/null @@ -1,25 +0,0 @@ -# node_step.sh -- Script to send signal to control Mesh Node Simulation -# Copyright (C) 2018 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments -prog_name=$1 -signal=$2 - -# Find instance of running program and send the named signal to it -pid=`/bin/pidof -s ${prog_name}` -kill -${signal} ${pid} -exit $? diff --git a/test/blackbox/test_case_meta_conn_02/Makefile.am b/test/blackbox/test_case_meta_conn_02/Makefile.am deleted file mode 100644 index 28fa44b..0000000 --- a/test/blackbox/test_case_meta_conn_02/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_relay node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_meta_conn_02/node_sim_nut.c b/test/blackbox/test_case_meta_conn_02/node_sim_nut.c deleted file mode 100644 index c197c58..0000000 --- a/test/blackbox/test_case_meta_conn_02/node_sim_nut.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -static bool conn_status = false; - -static void callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - (void)level; - - char connection_match_msg[100]; - - fprintf(stderr, "meshlink>> %s\n", text); - - if(strstr(text, "Connection") || strstr(text, "connection")) { - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection with peer") >= 0); - - if(strstr(text, connection_match_msg) && strstr(text, "activated")) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Already connected to peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection closed by peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Closing connection with peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - execute_open(argv[1], argv[2]); - meshlink_set_log_cb(mesh_handle, MESHLINK_INFO, callback_logger); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - /* Connectivity of peer */ - while(!conn_status) { - sleep(1); - } - - fprintf(stderr, "Connected with Peer\n"); - assert(mesh_event_sock_send(client_id, META_CONN_SUCCESSFUL, NULL, 0)); - - execute_close(); - assert(meshlink_destroy(argv[1])); - - return 0; -} diff --git a/test/blackbox/test_case_meta_conn_02/node_sim_peer.c b/test/blackbox/test_case_meta_conn_02/node_sim_peer.c deleted file mode 100644 index 91ac601..0000000 --- a/test/blackbox/test_case_meta_conn_02/node_sim_peer.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - - if(client_id != -1) { - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_02/node_sim_relay.c b/test/blackbox/test_case_meta_conn_02/node_sim_relay.c deleted file mode 100644 index 57ea254..0000000 --- a/test/blackbox/test_case_meta_conn_02/node_sim_relay.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - int client_id = -1; - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[CMD_LINE_ARG_NODENAME], argv[CMD_LINE_ARG_DEVCLASS]); - execute_start(); - - if(client_id != -1) { - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_03/Makefile.am b/test/blackbox/test_case_meta_conn_03/Makefile.am deleted file mode 100644 index 28fa44b..0000000 --- a/test/blackbox/test_case_meta_conn_03/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_relay node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_meta_conn_03/node_sim_nut.c b/test/blackbox/test_case_meta_conn_03/node_sim_nut.c deleted file mode 100644 index 4038d24..0000000 --- a/test/blackbox/test_case_meta_conn_03/node_sim_nut.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -static bool conn_status = false; - -void callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - (void)level; - - char connection_match_msg[100]; - - fprintf(stderr, "meshlink>> %s\n", text); - - if(strstr(text, "Connection") || strstr(text, "connection")) { - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection with peer") >= 0); - - if(strstr(text, connection_match_msg) && strstr(text, "activated")) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Already connected to peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection closed by peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Closing connection with peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - int client_id = -1; - bool result = false; - int i; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - execute_open(argv[1], argv[2]); - meshlink_set_log_cb(mesh_handle, MESHLINK_DEBUG, callback_logger); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0); - - /* Connectivity of peer is checked using meshlink_get_node API */ - while(!conn_status) { - sleep(1); - } - - sleep(1); - fprintf(stderr, "Connected with Peer\n"); - mesh_event_sock_send(client_id, META_CONN_SUCCESSFUL, NULL, 0); - - conn_status = false; - fprintf(stderr, "Waiting 120 sec for peer to be re-connected\n"); - - for(i = 0; i < 120; i++) { - if(conn_status) { - result = true; - break; - } - - sleep(1); - } - - if(result) { - fprintf(stderr, "Re-connected with Peer\n"); - mesh_event_sock_send(client_id, META_RECONN_SUCCESSFUL, NULL, 0); - } else { - fprintf(stderr, "Failed to reconnect with Peer\n"); - mesh_event_sock_send(client_id, META_RECONN_FAILURE, NULL, 0); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); - - return 0; -} diff --git a/test/blackbox/test_case_meta_conn_03/node_sim_peer.c b/test/blackbox/test_case_meta_conn_03/node_sim_peer.c deleted file mode 100644 index 91ac601..0000000 --- a/test/blackbox/test_case_meta_conn_03/node_sim_peer.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - - if(client_id != -1) { - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_03/node_sim_relay.c b/test/blackbox/test_case_meta_conn_03/node_sim_relay.c deleted file mode 100644 index a6f9177..0000000 --- a/test/blackbox/test_case_meta_conn_03/node_sim_relay.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - execute_start(); - - if(client_id != -1) { - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_04/Makefile.am b/test/blackbox/test_case_meta_conn_04/Makefile.am deleted file mode 100644 index 28fa44b..0000000 --- a/test/blackbox/test_case_meta_conn_04/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_relay node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_meta_conn_04/node_sim_nut.c b/test/blackbox/test_case_meta_conn_04/node_sim_nut.c deleted file mode 100644 index e208572..0000000 --- a/test/blackbox/test_case_meta_conn_04/node_sim_nut.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -static bool conn_status = false; - -void callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - (void)level; - - char connection_match_msg[100]; - - fprintf(stderr, "meshlink>> %s\n", text); - - if(strstr(text, "Connection") || strstr(text, "connection")) { - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection with peer") >= 0); - - if(strstr(text, connection_match_msg) && strstr(text, "activated")) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Already connected to peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection closed by peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Closing connection with peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - int clientId = -1; - char *invite_peer; - - if((argv[3]) && (argv[4])) { - clientId = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - execute_open(argv[1], argv[2]); - meshlink_set_log_cb(mesh_handle, MESHLINK_INFO, callback_logger); - - execute_start(); - - if(!mesh_event_sock_send(clientId, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - if(!argv[CMD_LINE_ARG_INVITEURL]) { - fprintf(stderr, "Generating Invitation to PEER\n"); - invite_peer = execute_invite("peer", NULL); - assert(invite_peer != NULL); - - if(!mesh_event_sock_send(clientId, NODE_INVITATION, invite_peer, strlen(invite_peer) + 1)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - fprintf(stderr, "Waiting for PEER to be connected\n"); - - /* Connectivity of peer is checked */ - while(!conn_status) { - sleep(1); - } - - fprintf(stderr, "Connected with Peer\n"); - - if(!mesh_event_sock_send(clientId, META_CONN_SUCCESSFUL, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_04/node_sim_peer.c b/test/blackbox/test_case_meta_conn_04/node_sim_peer.c deleted file mode 100644 index b003e06..0000000 --- a/test/blackbox/test_case_meta_conn_04/node_sim_peer.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - - if(client_id != -1) { - while(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_04/node_sim_relay.c b/test/blackbox/test_case_meta_conn_04/node_sim_relay.c deleted file mode 100644 index 37bb11d..0000000 --- a/test/blackbox/test_case_meta_conn_04/node_sim_relay.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - int clientid = -1; - - if((argv[3]) && (argv[4])) { - clientid = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - execute_start(); - - if(clientid != -1) { - mesh_event_sock_send(clientid, NODE_STARTED, NULL, 0); - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_05/Makefile.am b/test/blackbox/test_case_meta_conn_05/Makefile.am deleted file mode 100644 index 28fa44b..0000000 --- a/test/blackbox/test_case_meta_conn_05/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_relay node_sim_nut - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_meta_conn_05/node_sim_nut.c b/test/blackbox/test_case_meta_conn_05/node_sim_nut.c deleted file mode 100644 index 1581ceb..0000000 --- a/test/blackbox/test_case_meta_conn_05/node_sim_nut.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -static bool conn_status = false; - -void callback_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - (void)level; - - char connection_match_msg[100]; - - fprintf(stderr, "meshlink>> %s\n", text); - - if(strstr(text, "Connection") || strstr(text, "connection")) { - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection with peer") >= 0); - - if(strstr(text, connection_match_msg) && strstr(text, "activated")) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Already connected to peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = true; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Connection closed by peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - - assert(snprintf(connection_match_msg, sizeof(connection_match_msg), - "Closing connection with peer") >= 0); - - if(strstr(text, connection_match_msg)) { - conn_status = false; - return; - } - } - - return; -} - -int main(int argc, char *argv[]) { - (void)argc; - - int clientId = -1; - char *invite_peer; - - if((argv[3]) && (argv[4])) { - clientId = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - execute_open(argv[1], argv[2]); - meshlink_set_log_cb(mesh_handle, MESHLINK_INFO, callback_logger); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - execute_join(argv[CMD_LINE_ARG_INVITEURL]); - } - - execute_start(); - - if(!mesh_event_sock_send(clientId, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - fprintf(stderr, "Generating Invitation to PEER\n"); - invite_peer = execute_invite("peer", NULL); - assert(invite_peer != NULL); - - if(!mesh_event_sock_send(clientId, NODE_INVITATION, invite_peer, strlen(invite_peer) + 1)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - fprintf(stderr, "Waiting for PEER to be connected\n"); - - /* Connectivity of peer is checked */ - while(!conn_status) { - sleep(1); - } - - fprintf(stderr, "Connected with Peer\n"); - - if(!mesh_event_sock_send(clientId, META_CONN_SUCCESSFUL, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - conn_status = false; - fprintf(stderr, "Waiting for PEER to be re-connected\n"); - - /* Connectivity of peer */ - while(!conn_status) { - sleep(1); - } - - fprintf(stderr, "Re-connected with Peer\n"); - - if(!mesh_event_sock_send(clientId, META_CONN_SUCCESSFUL, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_05/node_sim_peer.c b/test/blackbox/test_case_meta_conn_05/node_sim_peer.c deleted file mode 100644 index 91ac601..0000000 --- a/test/blackbox/test_case_meta_conn_05/node_sim_peer.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - int client_id = -1; - - if((argv[3]) && (argv[4])) { - client_id = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - - if(argv[5]) { - execute_join(argv[5]); - } - - execute_start(); - - if(client_id != -1) { - if(!mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0)) { - fprintf(stderr, "Trying to resend mesh event\n"); - sleep(1); - } - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_meta_conn_05/node_sim_relay.c b/test/blackbox/test_case_meta_conn_05/node_sim_relay.c deleted file mode 100644 index 37bb11d..0000000 --- a/test/blackbox/test_case_meta_conn_05/node_sim_relay.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - int clientid = -1; - - if((argv[3]) && (argv[4])) { - clientid = atoi(argv[3]); - mesh_event_sock_connect(argv[4]); - } - - /* Setup required signals */ - setup_signals(); - - /* Execute test steps */ - execute_open(argv[1], argv[2]); - execute_start(); - - if(clientid != -1) { - mesh_event_sock_send(clientid, NODE_STARTED, NULL, 0); - } - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - execute_close(); - assert(meshlink_destroy(argv[1])); -} diff --git a/test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c b/test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c deleted file mode 100644 index 6e745b7..0000000 --- a/test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" -#include "../run_blackbox_tests/test_optimal_pmtu.h" - -extern bool test_pmtu_nut_running; -extern bool test_pmtu_peer_running; -extern bool test_pmtu_relay_running; -extern struct sync_flag test_pmtu_nut_closed; -extern bool ping_channel_enable_07; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable); -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); - -pmtu_attr_t node_pmtu[2]; -static time_t node_shutdown_time = 0; -static bool mtu_set = true; - -static void print_mtu_calc(pmtu_attr_t node_pmtu) { - fprintf(stderr, "MTU size : %d\n", node_pmtu.mtu_size); - fprintf(stderr, "Probes took for calculating PMTU discovery : %d\n", node_pmtu.mtu_discovery.probes); - fprintf(stderr, "Probes total length took for calculating PMTU discovery : %d\n", node_pmtu.mtu_discovery.probes_total_len); - fprintf(stderr, "Time took for calculating PMTU discovery : %lu\n", node_pmtu.mtu_discovery.time); - fprintf(stderr, "Total MTU ping probes : %d\n", node_pmtu.mtu_ping.probes); - fprintf(stderr, "Total MTU ping probes length : %d\n", node_pmtu.mtu_ping.probes_total_len); - float avg = 0; - - if(node_pmtu.mtu_ping.probes) { - avg = (float)node_pmtu.mtu_ping.time / (float)node_pmtu.mtu_ping.probes; - } - - fprintf(stderr, "Average MTU ping probes ping time : %f\n", avg); - fprintf(stderr, "Total probes received %d\n", node_pmtu.mtu_recv_probes.probes); - fprintf(stderr, "Total probes sent %d\n", node_pmtu.mtu_sent_probes.probes); -} - -// Node status callback -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - // Signal pthread_cond_wait if peer is reachable - if(!strcasecmp(node->name, "peer") && reachable) { - set_sync_flag(&peer_reachable, true); - } - - return; -} - -// Channel poll callback -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - - // Send data via channel to trigger UDP peer to peer hole punching - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - if(len == 0) { - fail(); - return; - } - - if(!strcmp(channel->node->name, "peer")) { - if(!memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } else if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - } - - return; -} - -// Meshlink log handler -static void meshlink_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, - const char *text) { - (void)mesh; - (void)level; - int probe_len; - int mtu_len; - int probes; - char node_name[100]; - int i = -1; - - time_t cur_time; - time_t probe_interval; - - cur_time = time(NULL); - assert(cur_time != -1); - - if(node_shutdown_time && cur_time >= node_shutdown_time) { - test_pmtu_nut_running = false; - } - - if(level == MESHLINK_INFO) { - fprintf(stderr, "\x1b[32m nut:\x1b[0m %s\n", text); - } - - /* Calculate the MTU parameter values from the meshlink logs */ - if(sscanf(text, "Sending MTU probe length %d to %s", &probe_len, node_name) == 2) { - find_node_index(i, node_name); - node_pmtu[i].mtu_sent_probes.probes += 1; - node_pmtu[i].mtu_sent_probes.probes_total_len += probe_len; - - if(node_pmtu[i].mtu_size) { - if(node_pmtu[i].mtu_sent_probes.time > node_pmtu[i].mtu_recv_probes.time) { - probe_interval = cur_time - node_pmtu[i].mtu_sent_probes.time; - } else { - probe_interval = cur_time - node_pmtu[i].mtu_recv_probes.time; - } - - node_pmtu[i].mtu_ping.probes += 1; - node_pmtu[i].mtu_ping.time += probe_interval; - node_pmtu[i].mtu_ping.probes_total_len += probe_len; - } - - node_pmtu[i].mtu_sent_probes.time = cur_time; - - } else if(sscanf(text, "Got MTU probe length %d from %s", &probe_len, node_name) == 2) { - find_node_index(i, node_name); - node_pmtu[i].mtu_recv_probes.probes += 1; - node_pmtu[i].mtu_recv_probes.probes_total_len += probe_len; - - if(node_pmtu[i].mtu_size) { - if(node_pmtu[i].mtu_sent_probes.time > node_pmtu[i].mtu_recv_probes.time) { - probe_interval = cur_time - node_pmtu[i].mtu_sent_probes.time; - } else { - probe_interval = cur_time - node_pmtu[i].mtu_recv_probes.time; - } - - node_pmtu[i].mtu_ping.probes += 1; - node_pmtu[i].mtu_ping.time += probe_interval; - node_pmtu[i].mtu_ping.probes_total_len += probe_len; - } - - node_pmtu[i].mtu_recv_probes.time = cur_time; - - } else if(sscanf(text, "Fixing MTU of %s to %d after %d probes", node_name, &mtu_len, &probes) == 3) { - - if(!node_shutdown_time && !strcasecmp("peer", node_name) && mtu_set) { - node_shutdown_time = cur_time + PING_TRACK_TIMEOUT; - mtu_set = false; - } - - find_node_index(i, node_name); - node_pmtu[i].mtu_discovery.probes = node_pmtu[i].mtu_recv_probes.probes + node_pmtu[i].mtu_sent_probes.probes; - node_pmtu[i].mtu_discovery.probes_total_len = node_pmtu[i].mtu_sent_probes.probes_total_len + node_pmtu[i].mtu_recv_probes.probes_total_len; - node_pmtu[i].mtu_discovery.time = cur_time - node_pmtu[i].mtu_start.time; - node_pmtu[i].mtu_discovery.count += 1; - node_pmtu[i].mtu_size = mtu_len; - - } else if(sscanf(text, "SPTPS key exchange with %s successful", node_name) == 1) { - find_node_index(i, node_name); - node_pmtu[i].mtu_start.time = cur_time; - node_pmtu[i].mtu_start.count += 1; - memset(&node_pmtu[i].mtu_discovery, 0, sizeof(struct pmtu_attr_para)); - memset(&node_pmtu[i].mtu_ping, 0, sizeof(struct pmtu_attr_para)); - memset(&node_pmtu[i].mtu_increase, 0, sizeof(struct pmtu_attr_para)); - - } else if(sscanf(text, "Increase in PMTU to %s detected, restarting PMTU discovery", node_name) == 1) { - find_node_index(i, node_name); - node_pmtu[i].mtu_increase.time = cur_time - node_pmtu[i].mtu_start.time; - node_pmtu[i].mtu_increase.count += 1; - - } else if(sscanf(text, "Trying to send MTU probe to unreachable or rekeying node %s", node_name) == 1) { - - } else if(sscanf(text, "%s did not respond to UDP ping, restarting PMTU discovery", node_name) == 1) { - - } else if(sscanf(text, "No response to MTU probes from %s", node_name) == 1) { - - } else if((sscanf(text, "Connection with %s activated", node_name) == 1) || (sscanf(text, "Already connected to %s", node_name) == 1)) { - - } else if((sscanf(text, "Connection closed by %s", node_name) == 1) || (sscanf(text, "Closing connection with %s", node_name) == 1)) { - } -} - -void *node_sim_pmtu_nut_01(void *arg) { - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - struct timeval main_loop_wait = { 5, 0 }; - - set_sync_flag(&peer_reachable, false); - set_sync_flag(&channel_opened, false); - node_shutdown_time = 0; - mtu_set = true; - - // Run relay node instance - - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - sleep(1); - - // Join relay node and if fails to join then try few more attempts - - if(mesh_arg->join_invitation) { - int attempts; - bool join_ret; - - for(attempts = 0; attempts < 10; attempts++) { - join_ret = meshlink_join(mesh, mesh_arg->join_invitation); - - if(join_ret) { - break; - } - - sleep(1); - } - - if(attempts == 10) { - fail(); - } - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 10)); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 30)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - time_t time_stamp, send_time; - - time_stamp = time(NULL); - send_time = time_stamp + 10; - - while(test_pmtu_nut_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - - // Ping the channel for every 10 seconds if ping_channel_enable_07 is enabled - - if(ping_channel_enable_07) { - time_stamp = time(NULL); - - if(time_stamp >= send_time) { - send_time = time_stamp + 10; - assert(meshlink_channel_send(mesh, channel, "ping", 5) == 5); - } - } - } - - // Send MTU probe parameters data to the test driver - meshlink_close(mesh); - - set_sync_flag(&test_pmtu_nut_closed, true); - fprintf(stderr, "NODE_PMTU_PEER :\n"); - print_mtu_calc(node_pmtu[NODE_PMTU_PEER]); - fprintf(stderr, "\nNODE_PMTU_RELAY :\n"); - print_mtu_calc(node_pmtu[NODE_PMTU_RELAY]); - - return NULL; -} diff --git a/test/blackbox/test_case_optimal_pmtu_01/node_sim_peer.c b/test/blackbox/test_case_optimal_pmtu_01/node_sim_peer.c deleted file mode 100644 index 597f44c..0000000 --- a/test/blackbox/test_case_optimal_pmtu_01/node_sim_peer.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" -#include "../run_blackbox_tests/test_optimal_pmtu.h" - -extern bool test_pmtu_peer_running; - -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - //channel->node->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - if(len == 0) { - // channel closed - fail(); - return; - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } else if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - } - - return; -} - -static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { - (void)mesh; - - if(level == MESHLINK_INFO) { - fprintf(stderr, "\x1b[34m peer:\x1b[0m %s\n", text); - } -} - -void *node_sim_pmtu_peer_01(void *arg) { - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - struct timeval main_loop_wait = { 5, 0 }; - - // Run relay node instance - - - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(mesh); - - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_message); - meshlink_set_channel_accept_cb(mesh, channel_accept); - - if(mesh_arg->join_invitation) { - int attempts; - bool join_ret; - - for(attempts = 0; attempts < 10; attempts++) { - join_ret = meshlink_join(mesh, mesh_arg->join_invitation); - - if(join_ret) { - break; - } - - sleep(1); - } - - if(attempts == 10) { - abort(); - } - } - - assert(meshlink_start(mesh)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_pmtu_peer_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return NULL; -} diff --git a/test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c b/test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c deleted file mode 100644 index 7823f4b..0000000 --- a/test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/network_namespace_framework.h" -#include "../../utils.h" -#include "../run_blackbox_tests/test_optimal_pmtu.h" - -extern bool test_pmtu_relay_running; - -void *node_sim_pmtu_relay_01(void *arg) { - mesh_arg_t *mesh_arg = (mesh_arg_t *)arg; - struct timeval main_loop_wait = { 5, 0 }; - - // Run relay node instance - - - meshlink_handle_t *mesh; - mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); - assert(mesh); - - //meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_enable_discovery(mesh, false); - - assert(meshlink_start(mesh)); - //send_event(NODE_STARTED); - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_pmtu_relay_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_case_optimal_pmtu_01/test_case_optimal_pmtu.h b/test/blackbox/test_case_optimal_pmtu_01/test_case_optimal_pmtu.h deleted file mode 100644 index 655324b..0000000 --- a/test/blackbox/test_case_optimal_pmtu_01/test_case_optimal_pmtu.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - test_case_optimal_pmtu.h -- Implementation of Node Simulation for Meshlink Testing - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -extern void *node_sim_pmtu_nut_01(void *arg); -extern void *node_sim_pmtu_peer_01(void *arg); -extern void *node_sim_pmtu_relay_01(void *arg); diff --git a/test/blackbox/test_case_optimal_pmtu_02/Makefile.am b/test/blackbox/test_case_optimal_pmtu_02/Makefile.am deleted file mode 100644 index fc9b98f..0000000 --- a/test/blackbox/test_case_optimal_pmtu_02/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = ../test_case_optimal_pmtu_01/node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = ../test_case_optimal_pmtu_01/node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = ../test_case_optimal_pmtu_01/node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_optimal_pmtu_03/Makefile.am b/test/blackbox/test_case_optimal_pmtu_03/Makefile.am deleted file mode 100644 index fc9b98f..0000000 --- a/test/blackbox/test_case_optimal_pmtu_03/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = ../test_case_optimal_pmtu_01/node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = ../test_case_optimal_pmtu_01/node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = ../test_case_optimal_pmtu_01/node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_optimal_pmtu_04/Makefile.am b/test/blackbox/test_case_optimal_pmtu_04/Makefile.am deleted file mode 100644 index fc9b98f..0000000 --- a/test/blackbox/test_case_optimal_pmtu_04/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = ../test_case_optimal_pmtu_01/node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = ../test_case_optimal_pmtu_01/node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = ../test_case_optimal_pmtu_01/node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_optimal_pmtu_05/Makefile.am b/test/blackbox/test_case_optimal_pmtu_05/Makefile.am deleted file mode 100644 index fc9b98f..0000000 --- a/test/blackbox/test_case_optimal_pmtu_05/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = ../test_case_optimal_pmtu_01/node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = ../test_case_optimal_pmtu_01/node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = ../test_case_optimal_pmtu_01/node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_optimal_pmtu_06/Makefile.am b/test/blackbox/test_case_optimal_pmtu_06/Makefile.am deleted file mode 100644 index fc9b98f..0000000 --- a/test/blackbox/test_case_optimal_pmtu_06/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = ../test_case_optimal_pmtu_01/node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = ../test_case_optimal_pmtu_01/node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = ../test_case_optimal_pmtu_01/node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_optimal_pmtu_07/Makefile.am b/test/blackbox/test_case_optimal_pmtu_07/Makefile.am deleted file mode 100644 index 8bde53d..0000000 --- a/test/blackbox/test_case_optimal_pmtu_07/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_peer node_sim_nut node_sim_relay - -node_sim_peer_SOURCES = node_sim_peer.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_peer_LDADD = ../../../src/libmeshlink.la -node_sim_peer_CFLAGS = -D_GNU_SOURCE - -node_sim_nut_SOURCES = node_sim_nut.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_nut_LDADD = ../../../src/libmeshlink.la -node_sim_nut_CFLAGS = -D_GNU_SOURCE - -node_sim_relay_SOURCES = node_sim_relay.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_relay_LDADD = ../../../src/libmeshlink.la -node_sim_relay_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_case_optimal_pmtu_07/node_sim_nut.c b/test/blackbox/test_case_optimal_pmtu_07/node_sim_nut.c deleted file mode 100644 index 06332e4..0000000 --- a/test/blackbox/test_case_optimal_pmtu_07/node_sim_nut.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - node_sim_nut.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" -#include "../run_blackbox_tests/test_optimal_pmtu.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -#pragma pack(1) - -static int client_id = -1; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable); -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static pmtu_attr_t node_pmtu[2]; - -static void print_mtu_calc(pmtu_attr_t node_pmtu) { - fprintf(stderr, "MTU size : %d\n", node_pmtu.mtu_size); - fprintf(stderr, "Probes took for calculating PMTU discovery : %d\n", node_pmtu.mtu_discovery.probes); - fprintf(stderr, "Probes total length took for calculating PMTU discovery : %d\n", node_pmtu.mtu_discovery.probes_total_len); - fprintf(stderr, "Time took for calculating PMTU discovery : %lu\n", node_pmtu.mtu_discovery.time); - fprintf(stderr, "Total MTU ping probes : %d\n", node_pmtu.mtu_ping.probes); - fprintf(stderr, "Total MTU ping probes length : %d\n", node_pmtu.mtu_ping.probes_total_len); - float avg = 0; - - if(node_pmtu.mtu_ping.probes) { - avg = (float)node_pmtu.mtu_ping.time / (float)node_pmtu.mtu_ping.probes; - } - - fprintf(stderr, "Average MTU ping probes ping time : %f\n", avg); - fprintf(stderr, "Total probes received %d\n", node_pmtu.mtu_recv_probes.probes); - fprintf(stderr, "Total probes sent %d\n", node_pmtu.mtu_sent_probes.probes); -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable) { - if(!strcasecmp(node->name, "peer") && reachable) { - set_sync_flag(&peer_reachable, true); - } - - mesh_event_sock_send(client_id, reachable ? NODE_JOINED : NODE_LEFT, node->name, 100); - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "peer")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - if(len == 0) { - mesh_event_sock_send(client_id, ERR_NETWORK, channel->node->name, 100); - return; - } - - if(!strcmp(channel->node->name, "peer")) { - if(!memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - fprintf(stderr, "GOT REPLY FROM PEER\n"); - } else if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - } - - return; -} - -void meshlink_logger(meshlink_handle_t *mesh, meshlink_log_level_t level, - const char *text) { - (void)mesh; - (void)level; - int probe_len; - int mtu_len; - int probes; - char node_name[100]; - int i = -1; - - time_t cur_time; - time_t probe_interval; - - cur_time = time(NULL); - assert(cur_time != -1); - - static time_t node_shutdown_time = 0; - bool mtu_probe = false; - - if(node_shutdown_time && cur_time >= node_shutdown_time) { - test_running = false; - } - - static const char *levelstr[] = { - [MESHLINK_DEBUG] = "\x1b[34mDEBUG", - [MESHLINK_INFO] = "\x1b[32mINFO", - [MESHLINK_WARNING] = "\x1b[33mWARNING", - [MESHLINK_ERROR] = "\x1b[31mERROR", - [MESHLINK_CRITICAL] = "\x1b[31mCRITICAL", - }; - - fprintf(stderr, "%s:\x1b[0m %s\n", levelstr[level], text); - - if(sscanf(text, "Sending MTU probe length %d to %s", &probe_len, node_name) == 2) { - find_node_index(i, node_name); - node_pmtu[i].mtu_sent_probes.probes += 1; - node_pmtu[i].mtu_sent_probes.probes_total_len += probe_len; - - if(node_pmtu[i].mtu_size) { - if(node_pmtu[i].mtu_sent_probes.time > node_pmtu[i].mtu_recv_probes.time) { - probe_interval = cur_time - node_pmtu[i].mtu_sent_probes.time; - } else { - probe_interval = cur_time - node_pmtu[i].mtu_recv_probes.time; - } - - node_pmtu[i].mtu_ping.probes += 1; - node_pmtu[i].mtu_ping.time += probe_interval; - node_pmtu[i].mtu_ping.probes_total_len += probe_len; - } - - node_pmtu[i].mtu_sent_probes.time = cur_time; - - } else if(sscanf(text, "Got MTU probe length %d from %s", &probe_len, node_name) == 2) { - find_node_index(i, node_name); - node_pmtu[i].mtu_recv_probes.probes += 1; - node_pmtu[i].mtu_recv_probes.probes_total_len += probe_len; - - if(node_pmtu[i].mtu_size) { - if(node_pmtu[i].mtu_sent_probes.time > node_pmtu[i].mtu_recv_probes.time) { - probe_interval = cur_time - node_pmtu[i].mtu_sent_probes.time; - } else { - probe_interval = cur_time - node_pmtu[i].mtu_recv_probes.time; - } - - node_pmtu[i].mtu_ping.probes += 1; - node_pmtu[i].mtu_ping.time += probe_interval; - node_pmtu[i].mtu_ping.probes_total_len += probe_len; - } - - node_pmtu[i].mtu_recv_probes.time = cur_time; - - } else if(sscanf(text, "Fixing MTU of %s to %d after %d probes", node_name, &mtu_len, &probes) == 3) { - static bool mtu_set = true; - - if(!node_shutdown_time && !strcasecmp("relay", node_name) && mtu_set) { - node_shutdown_time = cur_time + PING_TRACK_TIMEOUT; - mtu_set = false; - } - - find_node_index(i, node_name); - node_pmtu[i].mtu_discovery.probes = node_pmtu[i].mtu_recv_probes.probes + node_pmtu[i].mtu_sent_probes.probes; - node_pmtu[i].mtu_discovery.probes_total_len = node_pmtu[i].mtu_sent_probes.probes_total_len + node_pmtu[i].mtu_recv_probes.probes_total_len; - node_pmtu[i].mtu_discovery.time = cur_time - node_pmtu[i].mtu_start.time; - node_pmtu[i].mtu_discovery.count += 1; - node_pmtu[i].mtu_size = mtu_len; - - } else if(sscanf(text, "SPTPS key exchange with %s successful", node_name) == 1) { - find_node_index(i, node_name); - node_pmtu[i].mtu_start.time = cur_time; - node_pmtu[i].mtu_start.count += 1; - memset(&node_pmtu[i].mtu_discovery, 0, sizeof(struct pmtu_attr_para)); - memset(&node_pmtu[i].mtu_ping, 0, sizeof(struct pmtu_attr_para)); - memset(&node_pmtu[i].mtu_increase, 0, sizeof(struct pmtu_attr_para)); - - } else if(sscanf(text, "Increase in PMTU to %s detected, restarting PMTU discovery", node_name) == 1) { - find_node_index(i, node_name); - node_pmtu[i].mtu_increase.time = cur_time - node_pmtu[i].mtu_start.time; - node_pmtu[i].mtu_increase.count += 1; - - } else if(sscanf(text, "Trying to send MTU probe to unreachable or rekeying node %s", node_name) == 1) { - - } else if(sscanf(text, "%s did not respond to UDP ping, restarting PMTU discovery", node_name) == 1) { - - } else if(sscanf(text, "No response to MTU probes from %s", node_name) == 1) { - - } else if((sscanf(text, "Connection with %s activated", node_name) == 1) || (sscanf(text, "Already connected to %s", node_name) == 1)) { - mesh_event_sock_send(client_id, META_CONN_SUCCESSFUL, node_name, sizeof(node_name)); - - } else if((sscanf(text, "Connection closed by %s", node_name) == 1) || (sscanf(text, "Closing connection with %s", node_name) == 1)) { - mesh_event_sock_send(client_id, META_CONN_CLOSED, node_name, sizeof(node_name)); - - } -} - -int main(int argc, char *argv[]) { - struct timeval main_loop_wait = { 5, 0 }; - int i; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - setup_signals(); - - // Execute test steps - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_logger); - meshlink_set_node_status_cb(mesh, node_status_cb); - meshlink_enable_discovery(mesh, false); - sleep(1); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - int attempts; - bool join_ret; - - for(attempts = 0; attempts < 10; attempts++) { - join_ret = meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL]); - - if(join_ret) { - break; - } - - sleep(1); - } - - if(attempts == 10) { - abort(); - } - } - - assert(meshlink_start(mesh)); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 10)); - - // Open a channel to peer node - - meshlink_node_t *peer_node = meshlink_get_node(mesh, "peer"); - assert(peer_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, peer_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 30)); - assert(mesh_event_sock_send(client_id, CHANNEL_OPENED, NULL, 0)); - - // All test steps executed - wait for signals to stop/start or close the mesh - - time_t time_stamp, send_time; - - time_stamp = time(NULL); - send_time = time_stamp + 10; - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - - time_stamp = time(NULL); - - if(time_stamp >= send_time) { - send_time = time_stamp + 10; - meshlink_channel_send(mesh, channel, "ping", 5); - } - } - - pmtu_attr_t send_mtu_data; - send_mtu_data = node_pmtu[NODE_PMTU_PEER]; - print_mtu_calc(send_mtu_data); - assert(mesh_event_sock_send(client_id, OPTIMAL_PMTU_PEER, &send_mtu_data, sizeof(send_mtu_data))); - send_mtu_data = node_pmtu[NODE_PMTU_RELAY]; - print_mtu_calc(send_mtu_data); - assert(mesh_event_sock_send(client_id, OPTIMAL_PMTU_RELAY, &send_mtu_data, sizeof(send_mtu_data))); - - meshlink_close(mesh); -} diff --git a/test/blackbox/test_case_optimal_pmtu_07/node_sim_peer.c b/test/blackbox/test_case_optimal_pmtu_07/node_sim_peer.c deleted file mode 100644 index 6a9ec47..0000000 --- a/test/blackbox/test_case_optimal_pmtu_07/node_sim_peer.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static struct sync_flag nut_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER}; - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, - bool reachable) { - if(!strcasecmp(node->name, "nut") && reachable) { - //set_sync_flag(&nut_reachable, true); - mesh_event_sock_send(client_id, reachable ? NODE_JOINED : NODE_LEFT, node->name, 100); - } - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - if(!strcmp(channel->node->name, "nut")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - //channel->node->priv = channel; - - return true; - } - - return false; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - assert(meshlink_channel_send(mesh, channel, "test", 5) >= 0); - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - if(len == 0) { - mesh_event_sock_send(client_id, ERR_NETWORK, channel->node->name, 100); - return; - } - - if(!strcmp(channel->node->name, "nut")) { - if(!memcmp(dat, "reply", 5)) { - set_sync_flag(&channel_opened, true); - } else if(!memcmp(dat, "test", 5)) { - assert(meshlink_channel_send(mesh, channel, "reply", 5) >= 0); - } - } - - return; -} - -int main(int argc, char *argv[]) { - struct timeval main_loop_wait = { 2, 0 }; - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - - // Run peer node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_enable_discovery(mesh, false); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - int attempts; - bool join_ret; - - for(attempts = 0; attempts < 10; attempts++) { - join_ret = meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL]); - - if(join_ret) { - break; - } - - sleep(1); - } - - if(attempts == 10) { - abort(); - } - } - - assert(meshlink_start(mesh)); - mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0); - - //assert(wait_sync_flag(&nut_reachable, 10)); - - /*meshlink_node_t *nut_node = meshlink_get_node(mesh, "nut"); - assert(nut_node); - meshlink_channel_t *channel = meshlink_channel_open(mesh, nut_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - - assert(wait_sync_flag(&channel_opened, 20)); - mesh_event_sock_send(client_id, NODE_STARTED, NULL, 0);*/ - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_case_optimal_pmtu_07/node_sim_relay.c b/test/blackbox/test_case_optimal_pmtu_07/node_sim_relay.c deleted file mode 100644 index dd62209..0000000 --- a/test/blackbox/test_case_optimal_pmtu_07/node_sim_relay.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - node_sim_relay.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 - -int main(int argc, char *argv[]) { - struct timeval main_loop_wait = { 5, 0 }; - - // Setup required signals - - setup_signals(); - - // Run relay node instance - - meshlink_handle_t *mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_enable_discovery(mesh, false); - - meshlink_start(mesh); - //send_event(NODE_STARTED); - - /* All test steps executed - wait for signals to stop/start or close the mesh */ - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_cases_submesh01/Makefile.am b/test/blackbox/test_cases_submesh01/Makefile.am deleted file mode 100644 index bb0ff44..0000000 --- a/test/blackbox/test_cases_submesh01/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -check_PROGRAMS = node_sim_corenode1 node_sim_corenode2 node_sim_app1node1 node_sim_app1node2 node_sim_app2node1 node_sim_app2node2 - -node_sim_corenode1_SOURCES = node_sim_corenode1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_corenode1_LDADD = ../../../src/libmeshlink.la -node_sim_corenode1_CFLAGS = -D_GNU_SOURCE - -node_sim_corenode2_SOURCES = node_sim_corenode2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_corenode2_LDADD = ../../../src/libmeshlink.la -node_sim_corenode2_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node1_SOURCES = node_sim_app1node1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node1_LDADD = ../../../src/libmeshlink.la -node_sim_app1node1_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node2_SOURCES = node_sim_app1node2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node2_LDADD = ../../../src/libmeshlink.la -node_sim_app1node2_CFLAGS = -D_GNU_SOURCE - -node_sim_app2node1_SOURCES = node_sim_app2node1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app2node1_LDADD = ../../../src/libmeshlink.la -node_sim_app2node1_CFLAGS = -D_GNU_SOURCE - -node_sim_app2node2_SOURCES = node_sim_app2node2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app2node2_LDADD = ../../../src/libmeshlink.la -node_sim_app2node2_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_cases_submesh01/node_sim_app1node1.c b/test/blackbox/test_cases_submesh01/node_sim_app1node1.c deleted file mode 100644 index 8c2655e..0000000 --- a/test/blackbox/test_cases_submesh01/node_sim_app1node1.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node1 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } else if(!strcmp(channel->node->name, "app1node2")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - fprintf(stderr, "\tapp1node1 rejecting channel request from %s at %lu\n", channel->node->name, time(NULL)); - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - char data[100] = {0}; - char *message = "Channel Message"; - - if(len == 0) { - fprintf(stderr, "\tapp1node1 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node1 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node2")) { - if(!memcmp(dat, "Channel Message", len)) { - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("corenode1", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node1\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app1node1' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node1 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 100)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 100)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh01/node_sim_app1node2.c b/test/blackbox/test_cases_submesh01/node_sim_app1node2.c deleted file mode 100644 index 051ebc3..0000000 --- a/test/blackbox/test_cases_submesh01/node_sim_app1node2.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag app_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node2 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - fprintf(stderr, "\tapp1node2 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node2 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else { - assert(false); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node2's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } else if(!strcasecmp(node->name, "app1node1")) { - if(reachable) { - fprintf(stderr, "\tNode app1node1 became reachable\n"); - set_sync_flag(&app_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app1node2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node2conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // Open a channel to peer node - channel_opened.flag = false; - channel_data_recieved.flag = false; - - assert(wait_sync_flag(&app_reachable, 60)); - - core_node = meshlink_get_node(mesh, "app1node1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to app1node1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 100)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 100)); - send_event(CHANNEL_DATA_RECIEVED); - - core_node = meshlink_get_node(mesh, "app2node1"); - - if(NULL != core_node) { - send_event(SIG_ABORT); - assert(false); - } - - send_event(MESH_EVENT_COMPLETED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh01/node_sim_app2node1.c b/test/blackbox/test_cases_submesh01/node_sim_app2node1.c deleted file mode 100644 index d50a10c..0000000 --- a/test/blackbox/test_cases_submesh01/node_sim_app2node1.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp2node1 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } else if(!strcmp(channel->node->name, "app2node2")) { - fprintf(stderr, "\tapp2node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - fprintf(stderr, "\tapp2node1 rejecting channel request from %s at %lu\n", channel->node->name, time(NULL)); - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - char *message = "Channel Message"; - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp2node1 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app2node2")) { - if(!memcmp(dat, "Channel Message", len)) { - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp2node1's Channel request has been accepted by corenode1 at : %lu\n", time(NULL)); - - if(0 == strcmp("corenode1", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app2node1\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app2node1' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app2node1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp2node1 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh01/node_sim_app2node2.c b/test/blackbox/test_cases_submesh01/node_sim_app2node2.c deleted file mode 100644 index a7a2d1d..0000000 --- a/test/blackbox/test_cases_submesh01/node_sim_app2node2.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag app_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp2node2 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - fprintf(stderr, "\tapp2node2 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp2node2 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app2node1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else { - assert(false); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp2node2's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } else if(!strcasecmp(node->name, "app2node1")) { - if(reachable) { - fprintf(stderr, "\tNode app2node1 became reachable\n"); - set_sync_flag(&app_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app2node2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app2node2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app2node2conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp2node2 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 30)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // Open a channel to peer node - channel_opened.flag = false; - channel_data_recieved.flag = false; - - assert(wait_sync_flag(&app_reachable, 60)); - - core_node = meshlink_get_node(mesh, "app2node1"); - assert(core_node); - fprintf(stderr, "\tapp2node2 Sending Channel request to app2node1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 30)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - core_node = meshlink_get_node(mesh, "app1node1"); - - if(NULL != core_node) { - send_event(SIG_ABORT); - assert(false); - } - - send_event(MESH_EVENT_COMPLETED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh01/node_sim_corenode1.c b/test/blackbox/test_cases_submesh01/node_sim_corenode1.c deleted file mode 100644 index 8c8eb7c..0000000 --- a/test/blackbox/test_cases_submesh01/node_sim_corenode1.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static meshlink_handle_t *mesh = NULL; - -static void mesh_send_message_handler(const char *destination); - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "corenode1 got message from %s as %s\n", channel->node->name, data); - - if(!memcmp(dat, "Channel Message", len)) { - mesh_send_message_handler(channel->node->name); - - if(0 == strcmp("corenode2", channel->node->name)) { - set_sync_flag(&channel_data_recieved, true); - } - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(reachable) { - fprintf(stderr, "Node %s became reachable\n", node->name); - } else { - fprintf(stderr, "Node %s is unreachable\n", node->name); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - const char *message = "Channel Message"; - const char *node = channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "corenode1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("corenode2", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - -/* channel receive callback */ -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "corenode1 got channel request from %s\n", channel->node->name); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - - return true; -} - -static void mesh_send_message_handler(const char *destination) { - meshlink_channel_t *channel = NULL; - meshlink_node_t *target_node = NULL; - - // Open a channel to destination node - target_node = meshlink_get_node(mesh, destination); - assert(target_node); - fprintf(stderr, "corenode1 Sending Channel request to %s at : %lu\n", destination, time(NULL)); - channel = meshlink_channel_open(mesh, target_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - fprintf(stderr, "Mesh node 'corenode1' starting up........\n"); - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - setup_signals(); - - // Execute test steps - - mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 10)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_cases_submesh01/node_sim_corenode2.c b/test/blackbox/test_cases_submesh01/node_sim_corenode2.c deleted file mode 100644 index d996272..0000000 --- a/test/blackbox/test_cases_submesh01/node_sim_corenode2.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "corenode2 got channel request from %s", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "corenode2 got message from %s as %s", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "corenode2's Channel request has been accepted by corenode1 at : %lu", time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "Node corenode2 became reachable"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in corenode2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "Mesh node 'corenode2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("corenode1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "corenode2 Sending Channel request to corenode1 at : %lu", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 10)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh02/Makefile.am b/test/blackbox/test_cases_submesh02/Makefile.am deleted file mode 100644 index bb0ff44..0000000 --- a/test/blackbox/test_cases_submesh02/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -check_PROGRAMS = node_sim_corenode1 node_sim_corenode2 node_sim_app1node1 node_sim_app1node2 node_sim_app2node1 node_sim_app2node2 - -node_sim_corenode1_SOURCES = node_sim_corenode1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_corenode1_LDADD = ../../../src/libmeshlink.la -node_sim_corenode1_CFLAGS = -D_GNU_SOURCE - -node_sim_corenode2_SOURCES = node_sim_corenode2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_corenode2_LDADD = ../../../src/libmeshlink.la -node_sim_corenode2_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node1_SOURCES = node_sim_app1node1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node1_LDADD = ../../../src/libmeshlink.la -node_sim_app1node1_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node2_SOURCES = node_sim_app1node2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node2_LDADD = ../../../src/libmeshlink.la -node_sim_app1node2_CFLAGS = -D_GNU_SOURCE - -node_sim_app2node1_SOURCES = node_sim_app2node1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app2node1_LDADD = ../../../src/libmeshlink.la -node_sim_app2node1_CFLAGS = -D_GNU_SOURCE - -node_sim_app2node2_SOURCES = node_sim_app2node2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app2node2_LDADD = ../../../src/libmeshlink.la -node_sim_app2node2_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_cases_submesh02/node_sim_app1node1.c b/test/blackbox/test_cases_submesh02/node_sim_app1node1.c deleted file mode 100644 index 42ffe4f..0000000 --- a/test/blackbox/test_cases_submesh02/node_sim_app1node1.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node1 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } else if(!strcmp(channel->node->name, "app1node2")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - fprintf(stderr, "\tapp1node1 rejecting channel request from %s at %lu\n", channel->node->name, time(NULL)); - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - char data[100] = {0}; - char *message = "Channel Message"; - - if(len == 0) { - fprintf(stderr, "\tapp1node1 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node1 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node2")) { - if(!memcmp(dat, "Channel Message", len)) { - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("corenode1", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node1\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app1node1' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node1 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh02/node_sim_app1node2.c b/test/blackbox/test_cases_submesh02/node_sim_app1node2.c deleted file mode 100644 index 46a1010..0000000 --- a/test/blackbox/test_cases_submesh02/node_sim_app1node2.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag app_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node2 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - fprintf(stderr, "\tapp1node2 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node2 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else { - assert(false); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node2's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } else if(!strcasecmp(node->name, "app1node1")) { - if(reachable) { - fprintf(stderr, "\tNode app1node1 became reachable\n"); - set_sync_flag(&app_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - size_t num_nodes, i; - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - meshlink_node_t **node_handles = NULL; - meshlink_submesh_t *submesh = NULL; - - fprintf(stderr, "\tMesh node 'app1node2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node2conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // Open a channel to peer node - channel_opened.flag = false; - channel_data_recieved.flag = false; - - assert(wait_sync_flag(&app_reachable, 60)); - - core_node = meshlink_get_node(mesh, "app1node1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to app1node1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 30)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - num_nodes = 0; - node_handles = meshlink_get_all_nodes(mesh, NULL, &num_nodes); - fprintf(stderr, "\tGot %d nodes in list with error : %s\n", (int)num_nodes, meshlink_strerror(meshlink_errno)); - assert(node_handles); - assert((num_nodes == 4)); - - for(i = 0; i < num_nodes; i++) { - fprintf(stderr, "\tChecking the node : %s\n", node_handles[i]->name); - - if((0 == strcmp(node_handles[i]->name, "app2node1")) || (0 == strcmp(node_handles[i]->name, "app2node2"))) { - send_event(SIG_ABORT); - assert(false); - } - } - - meshlink_node_t *node = meshlink_get_self(mesh); - assert(node); - submesh = meshlink_get_node_submesh(mesh, node); - assert(submesh); - - node_handles = meshlink_get_all_nodes_by_submesh(mesh, submesh, node_handles, &num_nodes); - assert(node_handles); - assert((num_nodes == 2)); - - for(i = 0; i < num_nodes; i++) { - fprintf(stderr, "\tChecking the node : %s\n", node_handles[i]->name); - - if((0 == strcmp(node_handles[i]->name, "app2node1")) || (0 == strcmp(node_handles[i]->name, "app2node2"))) { - send_event(SIG_ABORT); - assert(false); - } - } - - submesh = meshlink_get_submesh(mesh, "app1"); - - if(submesh == NULL) { - fprintf(stderr, "\tapp1node2 Got invalid submesh handle\n"); - send_event(ERR_NETWORK); - } - - submesh = meshlink_get_submesh(mesh, "app2"); - - if(submesh != NULL) { - fprintf(stderr, "\tapp1node2 Submesh handle should be NULL\n"); - send_event(ERR_NETWORK); - } - - send_event(MESH_EVENT_COMPLETED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh02/node_sim_app2node1.c b/test/blackbox/test_cases_submesh02/node_sim_app2node1.c deleted file mode 100644 index d50a10c..0000000 --- a/test/blackbox/test_cases_submesh02/node_sim_app2node1.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp2node1 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } else if(!strcmp(channel->node->name, "app2node2")) { - fprintf(stderr, "\tapp2node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - fprintf(stderr, "\tapp2node1 rejecting channel request from %s at %lu\n", channel->node->name, time(NULL)); - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - char *message = "Channel Message"; - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp2node1 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app2node2")) { - if(!memcmp(dat, "Channel Message", len)) { - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp2node1's Channel request has been accepted by corenode1 at : %lu\n", time(NULL)); - - if(0 == strcmp("corenode1", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app2node1\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app2node1' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app2node1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp2node1 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh02/node_sim_app2node2.c b/test/blackbox/test_cases_submesh02/node_sim_app2node2.c deleted file mode 100644 index d29350f..0000000 --- a/test/blackbox/test_cases_submesh02/node_sim_app2node2.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag app_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp2node2 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - fprintf(stderr, "\tapp2node2 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp2node2 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app2node1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else { - assert(false); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp2node2's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } else if(!strcasecmp(node->name, "app2node1")) { - if(reachable) { - fprintf(stderr, "\tNode app2node1 became reachable\n"); - set_sync_flag(&app_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app2node2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - size_t num_nodes, i; - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - meshlink_node_t **node_handles = NULL; - meshlink_submesh_t *submesh = NULL; - - fprintf(stderr, "\tMesh node 'app2node2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app2node2conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp2node2 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 30)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // Open a channel to peer node - channel_opened.flag = false; - channel_data_recieved.flag = false; - - assert(wait_sync_flag(&app_reachable, 60)); - - core_node = meshlink_get_node(mesh, "app2node1"); - assert(core_node); - fprintf(stderr, "\tapp2node2 Sending Channel request to app2node1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - num_nodes = 0; - node_handles = meshlink_get_all_nodes(mesh, NULL, &num_nodes); - fprintf(stderr, "\tGot %d nodes in list with error : %s\n", (int)num_nodes, meshlink_strerror(meshlink_errno)); - assert(node_handles); - assert((num_nodes == 4)); - - for(i = 0; i < num_nodes; i++) { - fprintf(stderr, "\tChecking the node : %s\n", node_handles[i]->name); - - if(0 == strcmp(node_handles[i]->name, "app1node1")) { - send_event(SIG_ABORT); - assert(false); - } else if(0 == strcmp(node_handles[i]->name, "app1node2")) { - send_event(SIG_ABORT); - assert(false); - } - } - - meshlink_node_t *node = meshlink_get_self(mesh); - assert(node); - submesh = meshlink_get_node_submesh(mesh, node); - assert(submesh); - - node_handles = meshlink_get_all_nodes_by_submesh(mesh, submesh, node_handles, &num_nodes); - assert(node_handles); - assert((num_nodes == 2)); - - for(i = 0; i < num_nodes; i++) { - fprintf(stderr, "\tChecking the node : %s\n", node_handles[i]->name); - - if((0 == strcmp(node_handles[i]->name, "app1node1")) || (0 == strcmp(node_handles[i]->name, "app1node2"))) { - send_event(SIG_ABORT); - assert(false); - } - } - - submesh = meshlink_get_submesh(mesh, "app2"); - - if(submesh == NULL) { - fprintf(stderr, "\tapp2node2 Got invalid submesh handle\n"); - send_event(ERR_NETWORK); - } - - submesh = meshlink_get_submesh(mesh, "app1"); - - if(submesh != NULL) { - fprintf(stderr, "\tapp2node2 Submesh handle should be NULL\n"); - send_event(ERR_NETWORK); - } - - send_event(MESH_EVENT_COMPLETED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh02/node_sim_corenode1.c b/test/blackbox/test_cases_submesh02/node_sim_corenode1.c deleted file mode 100644 index 8c8eb7c..0000000 --- a/test/blackbox/test_cases_submesh02/node_sim_corenode1.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static meshlink_handle_t *mesh = NULL; - -static void mesh_send_message_handler(const char *destination); - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "corenode1 got message from %s as %s\n", channel->node->name, data); - - if(!memcmp(dat, "Channel Message", len)) { - mesh_send_message_handler(channel->node->name); - - if(0 == strcmp("corenode2", channel->node->name)) { - set_sync_flag(&channel_data_recieved, true); - } - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(reachable) { - fprintf(stderr, "Node %s became reachable\n", node->name); - } else { - fprintf(stderr, "Node %s is unreachable\n", node->name); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - const char *message = "Channel Message"; - const char *node = channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "corenode1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("corenode2", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - -/* channel receive callback */ -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "corenode1 got channel request from %s\n", channel->node->name); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - - return true; -} - -static void mesh_send_message_handler(const char *destination) { - meshlink_channel_t *channel = NULL; - meshlink_node_t *target_node = NULL; - - // Open a channel to destination node - target_node = meshlink_get_node(mesh, destination); - assert(target_node); - fprintf(stderr, "corenode1 Sending Channel request to %s at : %lu\n", destination, time(NULL)); - channel = meshlink_channel_open(mesh, target_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - fprintf(stderr, "Mesh node 'corenode1' starting up........\n"); - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - setup_signals(); - - // Execute test steps - - mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 10)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_cases_submesh02/node_sim_corenode2.c b/test/blackbox/test_cases_submesh02/node_sim_corenode2.c deleted file mode 100644 index d996272..0000000 --- a/test/blackbox/test_cases_submesh02/node_sim_corenode2.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "corenode2 got channel request from %s", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "corenode2 got message from %s as %s", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "corenode2's Channel request has been accepted by corenode1 at : %lu", time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "Node corenode2 became reachable"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in corenode2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "Mesh node 'corenode2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("corenode1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "corenode2 Sending Channel request to corenode1 at : %lu", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 10)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh03/Makefile.am b/test/blackbox/test_cases_submesh03/Makefile.am deleted file mode 100644 index 7a7004a..0000000 --- a/test/blackbox/test_cases_submesh03/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_corenode1 node_sim_app1node1 node_sim_app1node2 - -node_sim_corenode1_SOURCES = node_sim_corenode1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_corenode1_LDADD = ../../../src/libmeshlink.la -node_sim_corenode1_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node1_SOURCES = node_sim_app1node1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node1_LDADD = ../../../src/libmeshlink.la -node_sim_app1node1_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node2_SOURCES = node_sim_app1node2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node2_LDADD = ../../../src/libmeshlink.la -node_sim_app1node2_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_cases_submesh03/node_sim_app1node1.c b/test/blackbox/test_cases_submesh03/node_sim_app1node1.c deleted file mode 100644 index 42ffe4f..0000000 --- a/test/blackbox/test_cases_submesh03/node_sim_app1node1.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node1 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } else if(!strcmp(channel->node->name, "app1node2")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - fprintf(stderr, "\tapp1node1 rejecting channel request from %s at %lu\n", channel->node->name, time(NULL)); - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - char data[100] = {0}; - char *message = "Channel Message"; - - if(len == 0) { - fprintf(stderr, "\tapp1node1 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node1 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node2")) { - if(!memcmp(dat, "Channel Message", len)) { - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("corenode1", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node1\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app1node1' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node1 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh03/node_sim_app1node2.c b/test/blackbox/test_cases_submesh03/node_sim_app1node2.c deleted file mode 100644 index 65fb80b..0000000 --- a/test/blackbox/test_cases_submesh03/node_sim_app1node2.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag app_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node2 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - fprintf(stderr, "\tapp1node2 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node2 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else { - assert(false); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node2's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } else if(!strcasecmp(node->name, "app1node1")) { - if(reachable) { - fprintf(stderr, "\tNode app1node1 became reachable\n"); - set_sync_flag(&app_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - size_t num_nodes, i; - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - meshlink_node_t **node_handles = NULL; - - fprintf(stderr, "\tMesh node 'app1node2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node2conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // Open a channel to peer node - channel_opened.flag = false; - channel_data_recieved.flag = false; - - assert(wait_sync_flag(&app_reachable, 60)); - - core_node = meshlink_get_node(mesh, "app1node1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to app1node1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - num_nodes = 0; - node_handles = meshlink_get_all_nodes(mesh, NULL, &num_nodes); - fprintf(stderr, "\tGot %lu nodes in list with error : %s\n", num_nodes, meshlink_strerror(meshlink_errno)); - assert(node_handles); - - for(i = 0; i < num_nodes; i++) { - fprintf(stderr, "\tChecking the node : %s\n", node_handles[i]->name); - - if(0 == strcmp(node_handles[i]->name, "app2node1")) { - send_event(SIG_ABORT); - assert(false); - } else if(0 == strcmp(node_handles[i]->name, "app2node2")) { - send_event(SIG_ABORT); - assert(false); - } - } - - send_event(MESH_EVENT_COMPLETED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh03/node_sim_corenode1.c b/test/blackbox/test_cases_submesh03/node_sim_corenode1.c deleted file mode 100644 index 6d6c94d..0000000 --- a/test/blackbox/test_cases_submesh03/node_sim_corenode1.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static meshlink_handle_t *mesh = NULL; - -static void mesh_send_message_handler(const char *destination); - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "corenode1 got message from %s as %s\n", channel->node->name, data); - - if(!memcmp(dat, "Channel Message", len)) { - mesh_send_message_handler(channel->node->name); - - if(0 == strcmp("app1node1", channel->node->name)) { - set_sync_flag(&channel_data_recieved, true); - } - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(reachable) { - fprintf(stderr, "Node %s became reachable\n", node->name); - } else { - fprintf(stderr, "Node %s is unreachable\n", node->name); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - const char *message = "Channel Message"; - const char *node = channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "corenode1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("app1node1", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - -/* channel receive callback */ -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "corenode1 got channel request from %s\n", channel->node->name); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - - return true; -} - -static void mesh_send_message_handler(const char *destination) { - meshlink_channel_t *channel = NULL; - meshlink_node_t *target_node = NULL; - - // Open a channel to destination node - target_node = meshlink_get_node(mesh, destination); - assert(target_node); - fprintf(stderr, "corenode1 Sending Channel request to %s at : %lu\n", destination, time(NULL)); - channel = meshlink_channel_open(mesh, target_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - fprintf(stderr, "Mesh node 'corenode1' starting up........\n"); - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - setup_signals(); - - // Execute test steps - - mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - assert(wait_sync_flag(&channel_opened, 10)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 10)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/test_cases_submesh04/Makefile.am b/test/blackbox/test_cases_submesh04/Makefile.am deleted file mode 100644 index 7a7004a..0000000 --- a/test/blackbox/test_cases_submesh04/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -check_PROGRAMS = node_sim_corenode1 node_sim_app1node1 node_sim_app1node2 - -node_sim_corenode1_SOURCES = node_sim_corenode1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_corenode1_LDADD = ../../../src/libmeshlink.la -node_sim_corenode1_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node1_SOURCES = node_sim_app1node1.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node1_LDADD = ../../../src/libmeshlink.la -node_sim_app1node1_CFLAGS = -D_GNU_SOURCE - -node_sim_app1node2_SOURCES = node_sim_app1node2.c ../common/common_handlers.c ../common/test_step.c ../common/mesh_event_handler.c ../../utils.c -node_sim_app1node2_LDADD = ../../../src/libmeshlink.la -node_sim_app1node2_CFLAGS = -D_GNU_SOURCE diff --git a/test/blackbox/test_cases_submesh04/node_sim_app1node1.c b/test/blackbox/test_cases_submesh04/node_sim_app1node1.c deleted file mode 100644 index 42ffe4f..0000000 --- a/test/blackbox/test_cases_submesh04/node_sim_app1node1.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node1 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } else if(!strcmp(channel->node->name, "app1node2")) { - fprintf(stderr, "\tapp1node1 accepting channel request from %s at %lu\n", channel->node->name, time(NULL)); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - fprintf(stderr, "\tapp1node1 rejecting channel request from %s at %lu\n", channel->node->name, time(NULL)); - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - char data[100] = {0}; - char *message = "Channel Message"; - - if(len == 0) { - fprintf(stderr, "\tapp1node1 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node1 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node2")) { - if(!memcmp(dat, "Channel Message", len)) { - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("corenode1", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node1\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - - fprintf(stderr, "\tMesh node 'app1node1' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node1conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node1 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh04/node_sim_app1node2.c b/test/blackbox/test_cases_submesh04/node_sim_app1node2.c deleted file mode 100644 index 8e47d7e..0000000 --- a/test/blackbox/test_cases_submesh04/node_sim_app1node2.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - node_sim_peer.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len); -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len); - -static int client_id = -1; -static meshlink_handle_t *mesh = NULL; - -static struct sync_flag peer_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag start_test = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag app_reachable = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static meshlink_channel_t *ch_app1node1 = NULL; - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "\tapp1node2 got channel request from %s\n", channel->node->name); - - if(!strcmp(channel->node->name, "corenode1")) { - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - mesh->priv = channel; - - return true; - } - - return false; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - fprintf(stderr, "\tapp1node2 got error from %s at %lu\n", channel->node->name, time(NULL)); - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "\tapp1node2 got message from %s as %s\n", channel->node->name, data); - - if(!strcmp(channel->node->name, "corenode1")) { - if(!memcmp(dat, "Channel Message", len)) { - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else if(!strcmp(channel->node->name, "app1node1")) { - if(!memcmp(dat, "Channel Message", len)) { - ch_app1node1 = channel; - set_sync_flag(&channel_data_recieved, true); - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - } else { - assert(false); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - char *message = "Channel Message"; - char *node = (char *)channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "\tapp1node2's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - set_sync_flag(&channel_opened, true); - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(!strcasecmp(node->name, "corenode1")) { - if(reachable) { - fprintf(stderr, "\tNode corenode1 became reachable\n"); - set_sync_flag(&peer_reachable, true); - } - } else if(!strcasecmp(node->name, "app1node1")) { - if(reachable) { - fprintf(stderr, "\tNode app1node1 became reachable\n"); - set_sync_flag(&app_reachable, true); - } - } - - return; -} - -void mesh_start_test_handler(int signum) { - (void)signum; - - fprintf(stderr, "Starting test in app1node2\n"); - set_sync_flag(&start_test, true); -} - -int main(int argc, char *argv[]) { - (void)argc; - - size_t num_nodes, i; - struct timeval main_loop_wait = { 2, 0 }; - meshlink_channel_t *channel = NULL; - meshlink_node_t *core_node = NULL; - meshlink_node_t **node_handles = NULL; - - fprintf(stderr, "\tMesh node 'app1node2' starting up........\n"); - - // Import mesh event handler - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - // Setup required signals - - setup_signals(); - signal(SIGIO, mesh_start_test_handler); - - // Run peer node instance - - mesh = meshlink_open("app1node2conf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - // Wait for peer node to join - - assert(wait_sync_flag(&peer_reachable, 15)); - send_event(NODE_JOINED); - - while(false == wait_sync_flag(&start_test, 10)); - - // Open a channel to peer node - core_node = meshlink_get_node(mesh, "corenode1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to corenode1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - // Open a channel to peer node - channel_opened.flag = false; - channel_data_recieved.flag = false; - - assert(wait_sync_flag(&app_reachable, 60)); - - core_node = meshlink_get_node(mesh, "app1node1"); - assert(core_node); - fprintf(stderr, "\tapp1node2 Sending Channel request to app1node1 at : %lu\n", time(NULL)); - channel = meshlink_channel_open(mesh, core_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); - assert(wait_sync_flag(&channel_opened, 15)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 30)); - send_event(CHANNEL_DATA_RECIEVED); - - num_nodes = 0; - node_handles = meshlink_get_all_nodes(mesh, NULL, &num_nodes); - fprintf(stderr, "\tGot %lu nodes in list with error : %s\n", num_nodes, meshlink_strerror(meshlink_errno)); - assert(node_handles); - - for(i = 0; i < num_nodes; i++) { - fprintf(stderr, "\tChecking the node : %s\n", node_handles[i]->name); - - if(0 == strcmp(node_handles[i]->name, "app2node1")) { - send_event(SIG_ABORT); - assert(false); - } else if(0 == strcmp(node_handles[i]->name, "app2node2")) { - send_event(SIG_ABORT); - assert(false); - } - } - - meshlink_node_t *app1_node1 = meshlink_get_node(mesh, "app1node1"); - - if(!app1_node1) { - send_event(SIG_ABORT); - assert(app1_node1); - } - - channel_data_recieved.flag = false; - assert(meshlink_blacklist(mesh, app1_node1)); - - sleep(2); - - assert(meshlink_channel_send(mesh, ch_app1node1, "test", 5) == 5); - - wait_sync_flag(&channel_data_recieved, 30); - - if(true == channel_data_recieved.flag) { - send_event(SIG_ABORT); - assert(false); - } - - channel_data_recieved.flag = false; - assert(meshlink_whitelist(mesh, app1_node1)); - - sleep(2); - - assert(meshlink_channel_send(mesh, ch_app1node1, "Channel Message", strlen("Channel Message")) == strlen("Channel Message")); - - assert(wait_sync_flag(&channel_data_recieved, 60)); - - send_event(MESH_EVENT_COMPLETED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/test_cases_submesh04/node_sim_corenode1.c b/test/blackbox/test_cases_submesh04/node_sim_corenode1.c deleted file mode 100644 index a2ff3ce..0000000 --- a/test/blackbox/test_cases_submesh04/node_sim_corenode1.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - node_sim.c -- Implementation of Node Simulation for Meshlink Testing - for meta connection test case 01 - re-connection of - two nodes when relay node goes down - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include -#include -#include -#include -#include -#include "../common/common_handlers.h" -#include "../common/test_step.h" -#include "../common/mesh_event_handler.h" -#include "../../utils.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_DEVCLASS 2 -#define CMD_LINE_ARG_CLIENTID 3 -#define CMD_LINE_ARG_IMPORTSTR 4 -#define CMD_LINE_ARG_INVITEURL 5 -#define CHANNEL_PORT 1234 - -static int client_id = -1; - -static struct sync_flag channel_opened = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; -static struct sync_flag channel_data_recieved = {.mutex = PTHREAD_MUTEX_INITIALIZER, .cond = PTHREAD_COND_INITIALIZER, .flag = false}; - -static meshlink_handle_t *mesh = NULL; - -static void mesh_send_message_handler(const char *destination); - -static void send_event(mesh_event_t event) { - int attempts; - - for(attempts = 0; attempts < 5; attempts += 1) { - if(mesh_event_sock_send(client_id, event, NULL, 0)) { - break; - } - } - - assert(attempts < 5); - - return; -} - -/* channel receive callback */ -static void channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *dat, size_t len) { - (void)mesh; - - char data[100] = {0}; - - if(len == 0) { - send_event(ERR_NETWORK); - return; - } - - memcpy(data, dat, len); - - fprintf(stderr, "corenode1 got message from %s as %s\n", channel->node->name, data); - - if(!memcmp(dat, "Channel Message", len)) { - mesh_send_message_handler(channel->node->name); - - if(0 == strcmp("app1node2", channel->node->name)) { - set_sync_flag(&channel_data_recieved, true); - } - } else if(!memcmp(dat, "failure", 7)) { - assert(false); - } - - return; -} - -static void node_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - (void)mesh; - - if(reachable) { - fprintf(stderr, "Node %s became reachable\n", node->name); - } else { - fprintf(stderr, "Node %s is unreachable\n", node->name); - } - - return; -} - -static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) { - const char *message = "Channel Message"; - const char *node = channel->node->name; - (void)len; - meshlink_set_channel_poll_cb(mesh, channel, NULL); - fprintf(stderr, "corenode1's Channel request has been accepted by %s at : %lu\n", node, time(NULL)); - - if(0 == strcmp("app1node2", node)) { - set_sync_flag(&channel_opened, true); - } - - assert(meshlink_channel_send(mesh, channel, message, strlen(message)) >= 0); - return; -} - -/* channel receive callback */ -static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *dat, size_t len) { - (void)dat; - (void)len; - - assert(port == CHANNEL_PORT); - - fprintf(stderr, "corenode1 got channel request from %s\n", channel->node->name); - meshlink_set_channel_receive_cb(mesh, channel, channel_receive_cb); - - return true; -} - -static void mesh_send_message_handler(const char *destination) { - meshlink_channel_t *channel = NULL; - meshlink_node_t *target_node = NULL; - - // Open a channel to destination node - target_node = meshlink_get_node(mesh, destination); - assert(target_node); - fprintf(stderr, "corenode1 Sending Channel request to %s at : %lu\n", destination, time(NULL)); - channel = meshlink_channel_open(mesh, target_node, CHANNEL_PORT, - channel_receive_cb, NULL, 0); - meshlink_set_channel_poll_cb(mesh, channel, poll_cb); -} - -int main(int argc, char *argv[]) { - (void)argc; - - struct timeval main_loop_wait = { 5, 0 }; - - // Import mesh event handler - - fprintf(stderr, "Mesh node 'corenode1' starting up........\n"); - - if((argv[CMD_LINE_ARG_CLIENTID]) && (argv[CMD_LINE_ARG_IMPORTSTR])) { - client_id = atoi(argv[CMD_LINE_ARG_CLIENTID]); - mesh_event_sock_connect(argv[CMD_LINE_ARG_IMPORTSTR]); - } - - setup_signals(); - - // Execute test steps - - mesh = meshlink_open("testconf", argv[CMD_LINE_ARG_NODENAME], - "test_channel_conn", atoi(argv[CMD_LINE_ARG_DEVCLASS])); - assert(mesh); - meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_set_channel_accept_cb(mesh, channel_accept); - meshlink_set_node_status_cb(mesh, node_status_cb); - - if(argv[CMD_LINE_ARG_INVITEURL]) { - assert(meshlink_join(mesh, argv[CMD_LINE_ARG_INVITEURL])); - } - - assert(meshlink_start(mesh)); - - send_event(NODE_STARTED); - - assert(wait_sync_flag(&channel_opened, 50)); - send_event(CHANNEL_OPENED); - - assert(wait_sync_flag(&channel_data_recieved, 50)); - send_event(CHANNEL_DATA_RECIEVED); - - // All test steps executed - wait for signals to stop/start or close the mesh - - while(test_running) { - select(1, NULL, NULL, NULL, &main_loop_wait); - } - - meshlink_close(mesh); - - return 0; -} diff --git a/test/blackbox/util/build_container.sh b/test/blackbox/util/build_container.sh deleted file mode 100755 index e03b018..0000000 --- a/test/blackbox/util/build_container.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/sh -# build_container.sh -- Script to populate an LXC Container with the files -# required to run a Meshlink Node Simulation. -# Designed to run on unprivileged Containers. -# Copyright (C) 2018 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments -testcase=$1 -nodename=$2 -meshlinkrootpath=$3 -setx=$4 - -# Set configuration for required folders, programs and scripts -# Folder Paths -ltlibfolder=".libs" -meshlinksrclibpath="${meshlinkrootpath}/src/${ltlibfolder}" -blackboxpath="${meshlinkrootpath}/test/blackbox" -blackboxlibpath="${meshlinkrootpath}/test/blackbox/${ltlibfolder}" -blackboxutilpath="${blackboxpath}/util" -testcasepath="${blackboxpath}/${testcase}" -testcaselibpath="${blackboxpath}/${testcase}/${ltlibfolder}" -mirrorfolder="test" -mirrorfolderpath="${testcasepath}/${mirrorfolder}" -mirrorfolderlibpath="${mirrorfolderpath}/${ltlibfolder}" -containerdstpath="/home/ubuntu/${mirrorfolder}" -containerconfbase="/testconf" -containerlogpath="" -# Program/Script Names -ltprefix="lt-" -nodestepscript="node_step.sh" -nodesimpgm="node_sim_${nodename}" -nodesimltscript="${ltprefix}${nodesimpgm}" -geninvitepgm="gen_invite" -geninviteltscript="${ltprefix}${geninvitepgm}" -lxccopydirscript="lxc_copy_dir.sh" -lxccopyfilescript="lxc_copy_file.sh" -lxcrunscript="lxc_run.sh" -# Container Name -containername="${testcase}_${nodename}" - -# Run Libtool Wrapper Scripts once in their built paths in order to generate lt- script inside .libs directory -${blackboxpath}/${geninvitepgm} >/dev/null 2>/dev/null -${testcasepath}/${nodesimpgm} >/dev/null 2>/dev/null - -set ${setx} - -# Create Meshlink Container Mirror Folder (Delete any existing folder before creating new folder) -rm -rf ${mirrorfolderpath} >/dev/null 2>/dev/null -mkdir ${mirrorfolderpath} - -# Populate Mirror Folder -# Copy Wrapper Scripts for Utility Programs -cp ${blackboxpath}/${geninvitepgm} ${mirrorfolderpath} -cp ${testcasepath}/${nodesimpgm} ${mirrorfolderpath} -# Copy Utility Scripts -cp ${blackboxutilpath}/${nodestepscript} ${mirrorfolderpath} -# Set Script Permissions -chmod 755 ${mirrorfolderpath}/* -# Copy Binaries, lt- Scripts and Required Libraries -mkdir ${mirrorfolderlibpath} -cp ${blackboxlibpath}/* ${mirrorfolderlibpath} -cp ${testcaselibpath}/*${nodesimpgm}* ${mirrorfolderlibpath} -cp ${meshlinksrclibpath}/* ${mirrorfolderlibpath} - -# Copy mirror folder into LXC Container -# Delete Destination Folder -${blackboxutilpath}/${lxcrunscript} "rm -rf ${containerdstpath}" ${containername} -# Delete Meshlink confbase folder and logs from Container - every new test case starts on a clean slate -${blackboxutilpath}/${lxcrunscript} "rm -rf ${containerconfbase}" ${containername} -${blackboxutilpath}/${lxcrunscript} "rm ${containerlogpath}/*.log" ${containername} -# Create Destination Folder and Copy Files -${blackboxutilpath}/${lxccopydirscript} ${mirrorfolderpath} ${containername} ${containerdstpath} -# Kill any running instances of the Node Simulation Program -${blackboxutilpath}/${lxcrunscript} "${containerdstpath}/${nodestepscript} ${ltprefix}${nodesimpgm} SIGTERM 2>/dev/null" ${containername} -# Restore the 'interfaces' file in the Container -echo "auto lo" > interfaces -echo "iface lo inet loopback" >> interfaces -echo "" >> interfaces -echo "auto eth0" >> interfaces -echo "iface eth0 inet dhcp" >> interfaces -${blackboxutilpath}/${lxccopyfilescript} interfaces ${containername} /etc/network/interfaces - -set +x diff --git a/test/blackbox/util/gen_invite.c b/test/blackbox/util/gen_invite.c deleted file mode 100644 index dda2641..0000000 --- a/test/blackbox/util/gen_invite.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - gen_invite.c -- Black Box Test Utility to generate a meshlink invite - Copyright (C) 2018 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifdef NDEBUG -#undef NDEBUG -#endif - -#include -#include -#include -#include "../../../src/meshlink-tiny.h" -#include "../common/test_step.h" - -#define CMD_LINE_ARG_NODENAME 1 -#define CMD_LINE_ARG_INVITEE 2 -#define CMD_LINE_ARG_SUBMESH 3 - -int main(int argc, char *argv[]) { - char *invite = NULL; - meshlink_submesh_t *s = NULL; - - /* Start mesh, generate an invite and print out the invite */ - meshlink_handle_t *mesh = execute_open(argv[CMD_LINE_ARG_NODENAME], "1"); - execute_start(); - - if(argc > CMD_LINE_ARG_SUBMESH) { - s = meshlink_submesh_open(mesh, argv[CMD_LINE_ARG_SUBMESH]); - } - - invite = execute_invite(argv[CMD_LINE_ARG_INVITEE], s); - printf("%s\n", invite); - execute_close(); - - return EXIT_SUCCESS; -} diff --git a/test/blackbox/util/install_node_sim_copy.sh b/test/blackbox/util/install_node_sim_copy.sh deleted file mode 100755 index af1175d..0000000 --- a/test/blackbox/util/install_node_sim_copy.sh +++ /dev/null @@ -1,3 +0,0 @@ -cp ../${1}/node_sim_${2} . -mkdir .libs 2>/dev/null -cp ../${1}/.libs/*node_sim_${2}* .libs diff --git a/test/blackbox/util/install_packages.sh b/test/blackbox/util/install_packages.sh deleted file mode 100755 index f427b22..0000000 --- a/test/blackbox/util/install_packages.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# nat.sh - Script to create a NAT using LXC Container -# Designed to work on unprivileged Containers -# Copyright (C) 2019 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments - -if [ $# -le 1 ] - then - echo "enter valid arguments" - exit 1 -fi - -container=$1 -update_cmd="apt-get update -y >> /dev/null" -echo "${update_cmd}" | lxc-attach -n ${container} -- - -while test $# -gt 1 -do - shift - pkg_name=$1 - install_cmd="apt-get install ${pkg_name} -y >> /dev/null" - echo "${install_cmd}" | lxc-attach -n ${container} -- - if [ $? -ne 0 ] - then - echo "${pkg_name} installation failed in ${container} retrying to install again" - sleep 1 - echo "${update_cmd}" | lxc-attach -n ${container} -- - sleep 1 - echo "${install_cmd}" | lxc-attach -n ${container} -- - if [ $? -ne 0 ] - then - echo "${pkg_name} installation failed in ${container} container" - exit 1 - fi - fi - echo "Installed ${pkg_name} in container ${container}" -done - -exit 0 diff --git a/test/blackbox/util/lxc_copy_dir.sh b/test/blackbox/util/lxc_copy_dir.sh deleted file mode 100755 index d9be5f9..0000000 --- a/test/blackbox/util/lxc_copy_dir.sh +++ /dev/null @@ -1,27 +0,0 @@ -# lxc_copy.sh -- Script to transfer multiple files into an LXC Container -# Designed to work on unprivileged Containers -# Copyright (C) 2018 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments -srcdir=$1 -containername=$2 -containerdstdir=$3 - -# Create destination directory inside container and copy source directory contents into it -# by 'tar'ing the source directory and un'tar'ing it inside the container -lxc-attach -n ${containername} -- mkdir ${containerdstdir} -tar -C ${srcdir} -c . | lxc-attach -n ${containername} -- tar -C ${containerdstdir} -xvp diff --git a/test/blackbox/util/lxc_copy_file.sh b/test/blackbox/util/lxc_copy_file.sh deleted file mode 100755 index c833681..0000000 --- a/test/blackbox/util/lxc_copy_file.sh +++ /dev/null @@ -1,25 +0,0 @@ -# lxc_copy.sh -- Script to transfer multiple files into an LXC Container -# Designed to work on unprivileged Containers -# Copyright (C) 2018 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read Command-line arguments -srcfilepath=$1 -containername=$2 -dstfilepath=$3 - -# Copy file into Container -cat ${srcfilepath} | lxc-attach -n ${containername} -- sh -c "cat > ${dstfilepath}" diff --git a/test/blackbox/util/lxc_rename.sh b/test/blackbox/util/lxc_rename.sh deleted file mode 100755 index 31c0bcf..0000000 --- a/test/blackbox/util/lxc_rename.sh +++ /dev/null @@ -1,29 +0,0 @@ -# lxc_rename.sh - Script to rename an LXC Container -# Designed to work on unprivileged Containers -# Copyright (C) 2018 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments -lxcpath=$1 -oldname=$2 -newname=$3 - -# Run command inside Container by attaching to the Container and sending it the command -mv ${lxcpath}/${oldname} ${lxcpath}/${newname} -sed {s/${oldname}/${newname}/} ${lxcpath}/${newname}/config > ${lxcpath}/${newname}/config1 -mv ${lxcpath}/${newname}/config1 ${lxcpath}/${newname}/config -#lxc-copy -n ${oldname} -P lxcpath -N ${newname} -p lxcpath -R -exit $? diff --git a/test/blackbox/util/lxc_run.sh b/test/blackbox/util/lxc_run.sh deleted file mode 100755 index 4a2456e..0000000 --- a/test/blackbox/util/lxc_run.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# lxc_run.sh - Script to run a command inside an LXC Container -# Designed to work on unprivileged Containers -# Copyright (C) 2018 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments -cmd=${1} -containername=${2} - -# Run command inside Container by attaching to the Container and sending it the command -echo "${cmd}" | lxc-attach -n ${containername} -- -exit $? diff --git a/test/blackbox/util/nat.sh b/test/blackbox/util/nat.sh deleted file mode 100755 index 314eff0..0000000 --- a/test/blackbox/util/nat.sh +++ /dev/null @@ -1,130 +0,0 @@ -#!/bin/bash - -# nat.sh - Script to create a NAT using LXC Container -# Designed to work on unprivileged Containers -# Copyright (C) 2019 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments -if [ $# -ne 3 ] - then - echo "enter valid arguments" - exit 1 -fi -router_container=$1 -router_bridge="${router_container}_bridge" -router_conf_path="${2}/${router_container}/config" -meshlinkrootpath=$3 - -MAXCOUNT=10 -RANGE=16 -number1_1=$RANDOM -number1_2=$RANDOM -number2_1=$RANDOM -number2_2=$RANDOM - -let "number1_1 %= $RANGE" -let "number1_2 %= $RANGE" -let "number2_1 %= $RANGE" -let "number2_2 %= $RANGE" - -number1_1="$((echo "obase=16; ${number1_1}") | bc)" -number1_2="$((echo "obase=16; ${number1_2}") | bc)" -number2_1="$((echo "obase=16; ${number2_1}") | bc)" -number2_2="$((echo "obase=16; ${number2_2}") | bc)" - -echo + Creating nat bridge -ifconfig ${router_bridge} down >/dev/null 2>/dev/null -brctl delbr ${router_bridge} >/dev/null 2>/dev/null -brctl addbr ${router_bridge} -ifconfig ${router_bridge} up - -# Destroying the existing router if already exists -lxc-stop -n ${router_container} >/dev/null 2>/dev/null -lxc-destroy -n ${router_container} >/dev/null 2>/dev/null - -echo + Creating router -lxc-create -t download -n ${router_container} -- -d ubuntu -r trusty -a amd64 >> /dev/null -echo + Creating config file for router -echo "lxc.net.0.name = eth0" >> ${router_conf_path} -echo " " >> ${router_conf_path} -echo "lxc.net.1.type = veth" >> ${router_conf_path} -echo "lxc.net.1.flags = up" >> ${router_conf_path} -echo "lxc.net.1.link = ${router_bridge}" >> ${router_conf_path} -echo "lxc.net.1.name = eth1" >> ${router_conf_path} -echo "lxc.net.1.hwaddr = 00:16:3e:ab:32:2a" >> ${router_conf_path} - -echo + Starting Router -lxc-start -n ${router_container} - -echo + Waiting for IP address.. -while [ -z `lxc-info -n ${router_container} -iH` ] -do - sleep 1 -done -eth0_ip=`lxc-info -n ${router_container} -iH` -echo "Obtained IP address: ${eth0_ip}" - -############################################################################################################### - -echo "Installing and Configuring iptables, dnsmasq conntrack packages in ${1}" -${meshlinkrootpath}/test/blackbox/util/install_packages.sh ${1} iptables dnsmasq conntrack -if [ $? -ne 0 ] -then - exit 1 -fi - -cmd="echo \"interface=eth1\" >> /etc/dnsmasq.conf" -echo "${cmd}" | lxc-attach -n ${router_container} -- -cmd="echo \"bind-interfaces\" >> /etc/dnsmasq.conf" -echo "${cmd}" | lxc-attach -n ${router_container} -- -cmd="echo \"listen-address=172.16.0.1\" >> /etc/dnsmasq.conf" -echo "${cmd}" | lxc-attach -n ${router_container} -- -cmd="echo \"dhcp-range=172.16.0.2,172.16.0.254,12h\" >> /etc/dnsmasq.conf" -echo "${cmd}" | lxc-attach -n ${router_container} -- -cmd="ifconfig eth1 172.16.0.1 netmask 255.255.255.0 up" -echo "${cmd}" | lxc-attach -n ${router_container} -- -if [ $? -ne 0 ] -then - echo "Failed to configure eth1 interface" - exit 1 -fi -cmd="service dnsmasq restart >> /dev/null" -echo "${cmd}" | lxc-attach -n ${router_container} -- -if [ $? -ne 0 ] -then - echo "Failed to restart service" - exit 1 -fi - -echo + Configuring NAT for ${1}.... -cmd="iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source ${eth0_ip} " -echo "${cmd}" | sudo lxc-attach -n ${router_container} -- -if [ $? -ne 0 ] -then - echo "Failed to apply NAT rule" - exit 1 -fi -cmd="iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-destination 172.16.0.1 " -echo "${cmd}" | sudo lxc-attach -n ${router_container} -- -if [ $? -ne 0 ] -then - echo "Failed to apply NAT rule" - exit 1 -fi -echo "Router created and configured with Full-cone NAT" - -exit 0 diff --git a/test/blackbox/util/nat_destroy.sh b/test/blackbox/util/nat_destroy.sh deleted file mode 100755 index 2fa0f20..0000000 --- a/test/blackbox/util/nat_destroy.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -router=${1} -router_bridge="${1}_bridge" - -echo + Stopping router...... -lxc-stop -n ${router} - -echo + Removing NATs bridge.... - -ifconfig ${router_bridge} down - -brctl delbr ${router_bridge} - -echo + Destroing the routers..... - -lxc-destroy -n ${router} >> /dev/null diff --git a/test/blackbox/util/node_step.sh b/test/blackbox/util/node_step.sh deleted file mode 100755 index fe28423..0000000 --- a/test/blackbox/util/node_step.sh +++ /dev/null @@ -1,25 +0,0 @@ -# node_step.sh -- Script to send signal to control Mesh Node Simulation -# Copyright (C) 2018 Guus Sliepen -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# Read command-line arguments -prog_name=$1 -signal=$2 - -# Find instance of running program and send the named signal to it -pid=`/bin/pidof -s ${prog_name}` -kill -${signal} ${pid} -exit $? -- 2.39.2