2 test_cases_pmtu.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.
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"
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);
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",
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",
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",
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);
59 /* Test Steps for meshlink_get_pmtu Test Case # 1
62 1. Create node instance & get self handle
66 meshlink_get_pmtu should return valid MTU size of a node
68 static bool test_steps_mesh_pmtu_01(void) {
69 meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
72 assert(meshlink_start(mesh));
73 meshlink_node_t *dest_node = meshlink_get_self(mesh);
74 assert(dest_node != NULL);
76 ssize_t pmtu = meshlink_get_pmtu(mesh, dest_node);
77 assert_int_not_equal(pmtu, -1);
80 meshlink_destroy("pmtu_conf");
84 /* Execute meshlink_get_pmtu Test Case # 2
87 1. Create node instance & get self handle
88 2. Try to obtain MTU size by passing NULL as mesh handle to API
91 meshlink_get_pmtu should return -1 reporting the error
93 static void test_case_mesh_pmtu_02(void **state) {
94 execute_test(test_steps_mesh_pmtu_02, state);
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);
102 assert(meshlink_start(mesh));
103 meshlink_node_t *dest_node = meshlink_get_self(mesh);
104 assert(dest_node != NULL);
106 ssize_t pmtu = meshlink_get_pmtu(NULL, dest_node);
107 assert_int_equal(pmtu, -1);
109 meshlink_close(mesh);
110 meshlink_destroy("pmtu_conf");
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);
119 /* Test Steps for meshlink_get_pmtu Test Case # 3
122 1. Create node instance & get self handle
123 2. Try to obtain MTU size by passing NULL as node handle to API
126 meshlink_get_pmtu should return -1 reporting the error
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);
132 assert(meshlink_start(mesh));
134 ssize_t pmtu = meshlink_get_pmtu(mesh, NULL);
135 assert_int_equal(pmtu, -1);
137 meshlink_close(mesh);
138 meshlink_destroy("pmtu_conf");
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)
152 total_tests += sizeof(blackbox_pmtu_tests) / sizeof(blackbox_pmtu_tests[0]);
154 return cmocka_run_group_tests(blackbox_pmtu_tests, NULL, NULL);