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.
24 #include "execute_tests.h"
25 #include "test_cases_pmtu.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
36 static void test_case_mesh_pmtu_01(void **state);
37 static bool test_steps_mesh_pmtu_01(void);
38 static void test_case_mesh_pmtu_02(void **state);
39 static bool test_steps_mesh_pmtu_02(void);
40 static void test_case_mesh_pmtu_03(void **state);
41 static bool test_steps_mesh_pmtu_03(void);
43 /* State structure for meshlink_get_pmtu Test Case #1 */
44 static black_box_state_t test_mesh_pmtu_01_state = {
45 .test_case_name = "test_case_mesh_pmtu_01",
48 /* State structure for meshlink_get_pmtu Test Case #2 */
49 static black_box_state_t test_mesh_pmtu_02_state = {
50 .test_case_name = "test_case_mesh_pmtu_02",
53 /* State structure for meshlink_get_pmtu Test Case #3 */
54 static black_box_state_t test_mesh_pmtu_03_state = {
55 .test_case_name = "test_case_mesh_pmtu_03",
58 /* Execute meshlink_get_pmtu Test Case # 1 */
59 static void test_case_mesh_pmtu_01(void **state) {
60 execute_test(test_steps_mesh_pmtu_01, state);
63 /* Test Steps for meshlink_get_pmtu Test Case # 1
66 1. Create node instance & get self handle
70 meshlink_get_pmtu should return valid MTU size of a node
72 static bool test_steps_mesh_pmtu_01(void) {
73 meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
76 assert(meshlink_start(mesh));
77 meshlink_node_t *dest_node = meshlink_get_self(mesh);
78 assert(dest_node != NULL);
80 ssize_t pmtu = meshlink_get_pmtu(mesh, dest_node);
81 assert_int_not_equal(pmtu, -1);
84 assert(meshlink_destroy("pmtu_conf"));
88 /* Execute meshlink_get_pmtu Test Case # 2
91 1. Create node instance & get self handle
92 2. Try to obtain MTU size by passing NULL as mesh handle to API
95 meshlink_get_pmtu should return -1 reporting the error
97 static void test_case_mesh_pmtu_02(void **state) {
98 execute_test(test_steps_mesh_pmtu_02, state);
101 /* Test Steps for meshlink_get_pmtu Test Case # 2*/
102 static bool test_steps_mesh_pmtu_02(void) {
103 meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
104 assert(mesh != NULL);
106 assert(meshlink_start(mesh));
107 meshlink_node_t *dest_node = meshlink_get_self(mesh);
108 assert(dest_node != NULL);
110 ssize_t pmtu = meshlink_get_pmtu(NULL, dest_node);
111 assert_int_equal(pmtu, -1);
113 meshlink_close(mesh);
114 assert(meshlink_destroy("pmtu_conf"));
118 /* Execute meshlink_get_pmtu Test Case # 3 */
119 static void test_case_mesh_pmtu_03(void **state) {
120 execute_test(test_steps_mesh_pmtu_03, state);
123 /* Test Steps for meshlink_get_pmtu Test Case # 3
126 1. Create node instance & get self handle
127 2. Try to obtain MTU size by passing NULL as node handle to API
130 meshlink_get_pmtu should return -1 reporting the error
132 static bool test_steps_mesh_pmtu_03(void) {
133 meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
134 assert(mesh != NULL);
136 assert(meshlink_start(mesh));
138 ssize_t pmtu = meshlink_get_pmtu(mesh, NULL);
139 assert_int_equal(pmtu, -1);
141 meshlink_close(mesh);
142 assert(meshlink_destroy("pmtu_conf"));
146 int test_meshlink_pmtu(void) {
147 const struct CMUnitTest blackbox_pmtu_tests[] = {
148 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_01, NULL, NULL,
149 (void *)&test_mesh_pmtu_01_state),
150 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_02, NULL, NULL,
151 (void *)&test_mesh_pmtu_02_state),
152 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_03, NULL, NULL,
153 (void *)&test_mesh_pmtu_03_state)
156 total_tests += sizeof(blackbox_pmtu_tests) / sizeof(blackbox_pmtu_tests[0]);
158 return cmocka_run_group_tests(blackbox_pmtu_tests, NULL, NULL);