]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_pmtu.c
Add the blackbox container based test suite.
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_pmtu.c
1 /*
2     test_cases_pmtu.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
20 #include "execute_tests.h"
21 #include "test_cases_pmtu.h"
22 #include "../common/containers.h"
23 #include "../common/test_step.h"
24 #include "../common/common_handlers.h"
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <setjmp.h>
28 #include <cmocka.h>
29 #include <assert.h>
30 #include <string.h>
31
32 static void test_case_mesh_pmtu_01(void **state);
33 static bool test_steps_mesh_pmtu_01(void);
34 static void test_case_mesh_pmtu_02(void **state);
35 static bool test_steps_mesh_pmtu_02(void);
36 static void test_case_mesh_pmtu_03(void **state);
37 static bool test_steps_mesh_pmtu_03(void);
38
39 /* State structure for meshlink_get_pmtu Test Case #1 */
40 static black_box_state_t test_mesh_pmtu_01_state = {
41         .test_case_name = "test_case_mesh_pmtu_01",
42 };
43
44 /* State structure for meshlink_get_pmtu Test Case #2 */
45 static black_box_state_t test_mesh_pmtu_02_state = {
46         .test_case_name = "test_case_mesh_pmtu_02",
47 };
48
49 /* State structure for meshlink_get_pmtu Test Case #3 */
50 static black_box_state_t test_mesh_pmtu_03_state = {
51         .test_case_name = "test_case_mesh_pmtu_03",
52 };
53
54 /* Execute meshlink_get_pmtu Test Case # 1 */
55 static void test_case_mesh_pmtu_01(void **state) {
56         execute_test(test_steps_mesh_pmtu_01, state);
57 }
58
59 /* Test Steps for meshlink_get_pmtu Test Case # 1
60
61     Test Steps:
62     1. Create node instance & get self handle
63     2. Obtain MTU size
64
65     Expected Result:
66     meshlink_get_pmtu should return valid MTU size of a node
67 */
68 static bool test_steps_mesh_pmtu_01(void) {
69         meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
70         assert(mesh != NULL);
71
72         assert(meshlink_start(mesh));
73         meshlink_node_t *dest_node = meshlink_get_self(mesh);
74         assert(dest_node != NULL);
75
76         ssize_t pmtu = meshlink_get_pmtu(mesh, dest_node);
77         assert_int_not_equal(pmtu, -1);
78
79         meshlink_close(mesh);
80         meshlink_destroy("pmtu_conf");
81         return true;
82 }
83
84 /* Execute meshlink_get_pmtu Test Case # 2
85
86     Test Steps:
87     1. Create node instance & get self handle
88     2. Try to obtain MTU size by passing NULL as mesh handle to API
89
90     Expected Result:
91     meshlink_get_pmtu should return -1 reporting the error
92 */
93 static void test_case_mesh_pmtu_02(void **state) {
94         execute_test(test_steps_mesh_pmtu_02, state);
95 }
96
97 /* Test Steps for meshlink_get_pmtu Test Case # 2*/
98 static bool test_steps_mesh_pmtu_02(void) {
99         meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
100         assert(mesh != NULL);
101
102         assert(meshlink_start(mesh));
103         meshlink_node_t *dest_node = meshlink_get_self(mesh);
104         assert(dest_node != NULL);
105
106         ssize_t pmtu = meshlink_get_pmtu(NULL, dest_node);
107         assert_int_equal(pmtu, -1);
108
109         meshlink_close(mesh);
110         meshlink_destroy("pmtu_conf");
111         return true;
112 }
113
114 /* Execute meshlink_get_pmtu Test Case # 3 */
115 static void test_case_mesh_pmtu_03(void **state) {
116         execute_test(test_steps_mesh_pmtu_03, state);
117 }
118
119 /* Test Steps for meshlink_get_pmtu Test Case # 3
120
121     Test Steps:
122     1. Create node instance & get self handle
123     2. Try to obtain MTU size by passing NULL as node handle to API
124
125     Expected Result:
126     meshlink_get_pmtu should return -1 reporting the error
127 */
128 static bool test_steps_mesh_pmtu_03(void) {
129         meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
130         assert(mesh != NULL);
131
132         assert(meshlink_start(mesh));
133
134         ssize_t pmtu = meshlink_get_pmtu(mesh, NULL);
135         assert_int_equal(pmtu, -1);
136
137         meshlink_close(mesh);
138         meshlink_destroy("pmtu_conf");
139         return true;
140 }
141
142 int test_meshlink_pmtu(void) {
143         const struct CMUnitTest blackbox_pmtu_tests[] = {
144                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_01, NULL, NULL,
145                                 (void *)&test_mesh_pmtu_01_state),
146                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_02, NULL, NULL,
147                                 (void *)&test_mesh_pmtu_02_state),
148                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_03, NULL, NULL,
149                                 (void *)&test_mesh_pmtu_03_state)
150         };
151
152         total_tests += sizeof(blackbox_pmtu_tests) / sizeof(blackbox_pmtu_tests[0]);
153
154         return cmocka_run_group_tests(blackbox_pmtu_tests, NULL, NULL);
155 }