2 test_cases_submesh.c -- Execution of specific meshlink black box test cases
3 Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "execute_tests.h"
25 #include "test_cases_submesh01.h"
27 #include "../common/containers.h"
28 #include "../common/test_step.h"
29 #include "../common/common_handlers.h"
30 #include "../common/mesh_event_handler.h"
32 #define CORENODE1_ID "0"
33 #define APP1NODE1_ID "1"
34 #define APP2NODE1_ID "2"
35 #define CORENODE2_ID "3"
36 #define APP1NODE2_ID "4"
37 #define APP2NODE2_ID "5"
41 static bool test_case_status = false;
43 static void test_case_submesh_01(void **state);
44 static bool test_steps_submesh_01(void);
46 static char event_node_name[][10] = {"CORENODE1", "APP1NODE1", "APP2NODE1", "CORENODE2",
47 "APP1NODE2", "APP2NODE2"
49 static const char *node_ids[] = { "corenode1", "app1node1", "app2node1", "corenode2",
50 "app1node2", "app2node2"
53 static mesh_event_t core_node1[] = { NODE_STARTED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED};
55 static mesh_event_t core_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED};
57 static mesh_event_t app1_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED};
59 static mesh_event_t app2_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED};
61 static mesh_event_t app1_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED};
63 static mesh_event_t app2_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED};
65 /* State structure for SubMesh Test Case #1 */
66 static char *test_case_submesh_1_nodes[] = { "corenode1", "app1node1", "app2node1", "corenode2", "app1node2", "app2node2" };
67 static black_box_state_t test_case_submesh_1_state = {
68 .test_case_name = "test_cases_submesh01",
69 .node_names = test_case_submesh_1_nodes,
73 static int black_box_group0_setup(void **state) {
76 const char *nodes[] = { "corenode1", "app1node1", "app2node1", "corenode2", "app1node2", "app2node2" };
77 int num_nodes = sizeof(nodes) / sizeof(nodes[0]);
79 PRINT_TEST_CASE_MSG("Creating Containers\n");
81 create_containers(nodes, num_nodes);
86 static int black_box_group0_teardown(void **state) {
89 PRINT_TEST_CASE_MSG("Destroying Containers\n");
95 static bool event_cb(mesh_event_payload_t payload) {
96 static node_status_t node_status[6] = {
105 fprintf(stderr, "%s(%lu) : %s\n", event_node_name[payload.client_id], time(NULL), event_status[payload.mesh_event]);
106 assert(change_state(&node_status[payload.client_id], payload.mesh_event));
108 if(payload.mesh_event == NODE_JOINED) {
109 signal_node_start(node_status, 1, 5, (char **)node_ids);
112 if(check_nodes_finished(node_status, 6)) {
113 test_case_status = true;
120 /* Execute SubMesh Test Case # 1 */
121 static void test_case_submesh_01(void **state) {
122 execute_test(test_steps_submesh_01, state);
125 /* Test Steps for SubMesh Test Case # 1
128 1. Run corenode1, app1node1, app2node1, corenode2, app1node2 and app2node2
129 2. Generate invites to app1node1, app2node1, corenode2, app1node2 and app2node2
130 from corenode1 to join corenode1.
131 3. After Join is successful start channels from all nodes and exchange data on channels
132 4. Try to fetch the node handle of one sub-mesh node from node in another sub-mesh
135 Channels should be formed between nodes of sub-mesh & coremesh, nodes with in sub-mesh
136 and should be able to exchange data. But node in one sub-mesh should not get the details
137 of node in another sub-mesh.
139 static bool test_steps_submesh_01(void) {
140 char *invite_corenode2, *invite_app1node1, *invite_app2node1, *invite_app1node2, *invite_app2node2;
143 import = mesh_event_sock_create(eth_if_name);
144 invite_corenode2 = invite_in_container("corenode1", "corenode2");
145 invite_app1node1 = submesh_invite_in_container("corenode1", "app1node1", "app1");
146 invite_app2node1 = submesh_invite_in_container("corenode1", "app2node1", "app2");
147 invite_app1node2 = submesh_invite_in_container("corenode1", "app1node2", "app1");
148 invite_app2node2 = submesh_invite_in_container("corenode1", "app2node2", "app2");
150 node_sim_in_container_event("corenode1", "1", NULL, CORENODE1_ID, import);
151 node_sim_in_container_event("corenode2", "1", invite_corenode2, CORENODE2_ID, import);
152 node_sim_in_container_event("app1node1", "1", invite_app1node1, APP1NODE1_ID, import);
153 node_sim_in_container_event("app2node1", "1", invite_app2node1, APP2NODE1_ID, import);
154 node_sim_in_container_event("app1node2", "1", invite_app1node2, APP1NODE2_ID, import);
155 node_sim_in_container_event("app2node2", "1", invite_app2node2, APP2NODE2_ID, import);
157 PRINT_TEST_CASE_MSG("Waiting for nodes to get connected with corenode1\n");
159 assert(wait_for_event(event_cb, 240));
160 assert(test_case_status);
162 free(invite_corenode2);
163 free(invite_app1node1);
164 free(invite_app2node1);
165 free(invite_app1node2);
166 free(invite_app2node2);
168 mesh_event_destroy();
173 int test_cases_submesh01(void) {
174 const struct CMUnitTest blackbox_group0_tests[] = {
175 cmocka_unit_test_prestate_setup_teardown(test_case_submesh_01, setup_test, teardown_test,
176 (void *)&test_case_submesh_1_state)
178 total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]);
180 return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown);