X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fblackbox%2Frun_blackbox_tests%2Ftest_cases_submesh03.c;fp=test%2Fblackbox%2Frun_blackbox_tests%2Ftest_cases_submesh03.c;h=76b6ef9e852e05467359c45f9b0073168beb9f76;hb=4108810af455f463dfbcdac0e2e0b2ba0312bf26;hp=0000000000000000000000000000000000000000;hpb=026aa799bdccd860575e4ce228b750f47abd31e2;p=meshlink diff --git a/test/blackbox/run_blackbox_tests/test_cases_submesh03.c b/test/blackbox/run_blackbox_tests/test_cases_submesh03.c new file mode 100644 index 00000000..76b6ef9e --- /dev/null +++ b/test/blackbox/run_blackbox_tests/test_cases_submesh03.c @@ -0,0 +1,189 @@ +/* + 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. +*/ +#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, false}, + {app1_node1, 0, 4, false}, + {app1_node2, 0, 7, false} +}; + +/* 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) { + 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) { + PRINT_TEST_CASE_MSG("Destroying Containers\n"); + destroy_containers(); + + return 0; +} + +static int black_box_all_nodes_setup(void **state) { + const char *nodes[] = { "corenode1" }; + 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 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, 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; + bool result = false; + int i; + char *import; + pthread_t thread1, thread2; + + 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); +} \ No newline at end of file