]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_submesh04.c
Add meshlink_get_submesh API
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_submesh04.c
1 /*
2     test_cases_submesh05.c -- Execution of specific meshlink black box test cases
3     Copyright (C) 2018  Guus Sliepen <guus@meshlink.io>
4
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.
9
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.
14
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.
18 */
19 #include <stdlib.h>
20 #include <stdarg.h>
21 #include <setjmp.h>
22 #include <cmocka.h>
23 #include <assert.h>
24 #include "execute_tests.h"
25 #include "test_cases_submesh04.h"
26 #include "pthread.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"
31
32 #define CORENODE1_ID  "0"
33 #define APP1NODE1_ID  "1"
34 #define APP1NODE2_ID  "2"
35
36 #define INIT_ST         0
37
38 static bool test_case_status = false;
39
40 static void test_case_submesh_04(void **state);
41 static bool test_steps_submesh_04(void);
42
43 static char event_node_name[][10] = {"CORENODE1", "APP1NODE1", "APP1NODE2"};
44 static const char *node_ids[] = { "corenode1", "app1node1", "app1node2" };
45
46 static mesh_event_t core_node1[] = { NODE_STARTED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED };
47
48 static mesh_event_t app1_node1[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED };
49
50 static mesh_event_t app1_node2[] = { NODE_STARTED, NODE_JOINED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, CHANNEL_OPENED, CHANNEL_DATA_RECIEVED, MESH_EVENT_COMPLETED};
51
52 /* State structure for SubMesh Test Case #4 */
53 static char *test_case_submesh_4_nodes[] = { "corenode1", "app1node1", "app1node2" };
54 static black_box_state_t test_case_submesh_4_state = {
55         .test_case_name =  "test_cases_submesh04",
56         .node_names =  test_case_submesh_4_nodes,
57         .num_nodes =  3
58 };
59
60 static int black_box_group0_setup(void **state) {
61         const char *nodes[] = { "corenode1", "app1node1", "app1node2" };
62         int num_nodes = sizeof(nodes) / sizeof(nodes[0]);
63
64         PRINT_TEST_CASE_MSG("Creating Containers\n");
65         destroy_containers();
66         create_containers(nodes, num_nodes);
67
68         return 0;
69 }
70
71 static int black_box_group0_teardown(void **state) {
72         PRINT_TEST_CASE_MSG("Destroying Containers\n");
73         destroy_containers();
74
75         return 0;
76 }
77
78 static int black_box_all_nodes_setup(void **state) {
79         const char *nodes[] = { "corenode1" };
80         int num_nodes = sizeof(nodes) / sizeof(nodes[0]);
81
82         PRINT_TEST_CASE_MSG("Creating Containers\n");
83         destroy_containers();
84         create_containers(nodes, num_nodes);
85         PRINT_TEST_CASE_MSG("Created Containers\n");
86         return 0;
87 }
88
89 static bool event_cb(mesh_event_payload_t payload) {
90         static node_status_t node_status[3] = {
91                 {core_node1, 0, 3, false},
92                 {app1_node1, 0, 4, false},
93                 {app1_node2, 0, 7, false}
94         };
95
96         fprintf(stderr, "%s(%lu) : %s\n", event_node_name[payload.client_id], time(NULL), event_status[payload.mesh_event]);
97         assert(change_state(&node_status[payload.client_id], payload.mesh_event));
98
99         if(payload.mesh_event == NODE_JOINED) {
100                 signal_node_start(node_status, 1, 2, (char **)node_ids);
101         }
102
103         if(check_nodes_finished(node_status, 3)) {
104                 test_case_status = true;
105                 return true;
106         }
107
108         return false;
109 }
110
111 /* Execute SubMesh Test Case # 4 */
112 static void test_case_submesh_04(void **state) {
113         execute_test(test_steps_submesh_04, state);
114 }
115
116 /* Test Steps for SubMesh Test Case # 4
117
118     Test Steps:
119     1. Run corenode1, app1node1, and app1node2
120     2. Generate invites to app1node1, app1node2
121         from corenode1 to join corenode1.
122     3. After Join is successful start channels from all nodes and exchange data on channels
123     4. Black list a node in the submesh and check if it is successful
124     5. White list the node and it should be form all the connections again
125
126     Expected Result:
127     Channels should be formed between nodes of sub-mesh & coremesh, nodes with in sub-mesh
128     and should be able to exchange data. When black listed, other node should not get any
129     from the black listed node. When white listed again it has to form the connections as
130     they were previously before black listing.
131 */
132 static bool test_steps_submesh_04(void) {
133         char *invite_app1node1, *invite_app1node2;
134         bool result = false;
135         int i;
136         char *import;
137         pthread_t thread1, thread2;
138
139         import = mesh_event_sock_create(eth_if_name);
140         invite_app1node1 = invite_in_container("corenode1", "app1node1");
141         invite_app1node2 = invite_in_container("corenode1", "app1node2");
142
143         node_sim_in_container_event("corenode1", "1", NULL, CORENODE1_ID, import);
144         node_sim_in_container_event("app1node1", "1", invite_app1node1, APP1NODE1_ID, import);
145         node_sim_in_container_event("app1node2", "1", invite_app1node2, APP1NODE2_ID, import);
146
147         PRINT_TEST_CASE_MSG("Waiting for nodes to get connected with corenode1\n");
148
149         assert(wait_for_event(event_cb, 120));
150         assert(test_case_status);
151
152         free(invite_app1node1);
153         free(invite_app1node2);
154
155         mesh_event_destroy();
156
157         return true;
158 }
159
160 int test_cases_submesh04(void) {
161         const struct CMUnitTest blackbox_group0_tests[] = {
162                 cmocka_unit_test_prestate_setup_teardown(test_case_submesh_04, setup_test, teardown_test,
163                                 (void *)&test_case_submesh_4_state)
164         };
165         total_tests += sizeof(blackbox_group0_tests) / sizeof(blackbox_group0_tests[0]);
166
167         return cmocka_run_group_tests(blackbox_group0_tests, black_box_group0_setup, black_box_group0_teardown);
168 }