Changeset 89ba88c in mainline for uspace/srv/net/udp/test/assoc.c
- Timestamp:
- 2019-10-14T11:16:24Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1cd4b0
- Parents:
- 25525133
- git-author:
- Jiri Svoboda <jiri@…> (2019-10-13 18:08:59)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-10-14 11:16:24)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/test/assoc.c
r25525133 r89ba88c 46 46 }; 47 47 48 static errno_t test_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *); 49 static errno_t test_transmit_msg(inet_ep2_t *, udp_msg_t *); 50 51 static udp_assocs_dep_t test_assocs_dep = { 52 .get_srcaddr = test_get_srcaddr, 53 .transmit_msg = test_transmit_msg 54 }; 55 56 static inet_ep2_t *sent_epp; 57 static udp_msg_t *sent_msg; 58 48 59 PCUT_TEST_BEFORE 49 60 { … … 54 65 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 55 66 56 rc = udp_assocs_init( );67 rc = udp_assocs_init(&test_assocs_dep); 57 68 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 58 69 } … … 129 140 } 130 141 131 PCUT_TEST(send_recv) 132 { 142 /** Sending message with destination not set in association and NULL 143 * destination argument should fail with EINVAL. 144 */ 145 PCUT_TEST(send_null_dest) 146 { 147 udp_assoc_t *assoc; 148 inet_ep2_t epp; 149 inet_ep_t dest; 150 errno_t rc; 151 udp_msg_t *msg; 152 const char *msgstr = "Hello"; 153 154 msg = udp_msg_new(); 155 PCUT_ASSERT_NOT_NULL(msg); 156 msg->data_size = str_size(msgstr) + 1; 157 msg->data = str_dup(msgstr); 158 159 inet_ep2_init(&epp); 160 inet_ep_init(&dest); 161 162 assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL); 163 PCUT_ASSERT_NOT_NULL(assoc); 164 165 rc = udp_assoc_add(assoc); 166 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 167 168 rc = udp_assoc_send(assoc, &dest, msg); 169 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc); 170 171 udp_msg_delete(msg); 172 173 udp_assoc_remove(assoc); 174 udp_assoc_delete(assoc); 175 } 176 177 /** Sending message with destination not set in association and unset 178 * destination argument should fail with EINVAL. 179 */ 180 PCUT_TEST(send_unset_dest) 181 { 182 udp_assoc_t *assoc; 183 inet_ep2_t epp; 184 inet_ep_t dest; 185 errno_t rc; 186 udp_msg_t *msg; 187 const char *msgstr = "Hello"; 188 189 msg = udp_msg_new(); 190 PCUT_ASSERT_NOT_NULL(msg); 191 msg->data_size = str_size(msgstr) + 1; 192 msg->data = str_dup(msgstr); 193 194 inet_ep2_init(&epp); 195 inet_ep_init(&dest); 196 197 assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL); 198 PCUT_ASSERT_NOT_NULL(assoc); 199 200 rc = udp_assoc_add(assoc); 201 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 202 203 rc = udp_assoc_send(assoc, &dest, msg); 204 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc); 205 206 udp_msg_delete(msg); 207 208 udp_assoc_remove(assoc); 209 udp_assoc_delete(assoc); 210 } 211 212 /** Sending message with explicit destination */ 213 PCUT_TEST(send_explicit_dest) 214 { 215 udp_assoc_t *assoc; 216 inet_ep2_t epp; 217 inet_ep_t dest; 218 errno_t rc; 219 udp_msg_t *msg; 220 const char *msgstr = "Hello"; 221 222 msg = udp_msg_new(); 223 PCUT_ASSERT_NOT_NULL(msg); 224 msg->data_size = str_size(msgstr) + 1; 225 msg->data = str_dup(msgstr); 226 227 inet_ep2_init(&epp); 228 inet_addr(&dest.addr, 127, 0, 0, 1); 229 dest.port = 42; 230 231 assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL); 232 PCUT_ASSERT_NOT_NULL(assoc); 233 234 rc = udp_assoc_add(assoc); 235 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 236 237 sent_epp = NULL; 238 sent_msg = NULL; 239 240 rc = udp_assoc_send(assoc, &dest, msg); 241 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 242 PCUT_ASSERT_EQUALS(msg, sent_msg); 243 PCUT_ASSERT_TRUE(inet_addr_compare(&dest.addr, &sent_epp->remote.addr)); 244 PCUT_ASSERT_EQUALS(dest.port, sent_epp->remote.port); 245 246 udp_msg_delete(msg); 247 248 udp_assoc_remove(assoc); 249 udp_assoc_delete(assoc); 250 } 251 252 /** Sending message with destination set in association and NULL destination 253 * argument 254 */ 255 PCUT_TEST(send_assoc_null_dest) 256 { 257 udp_assoc_t *assoc; 258 inet_ep2_t epp; 259 errno_t rc; 260 udp_msg_t *msg; 261 const char *msgstr = "Hello"; 262 263 msg = udp_msg_new(); 264 PCUT_ASSERT_NOT_NULL(msg); 265 msg->data_size = str_size(msgstr) + 1; 266 msg->data = str_dup(msgstr); 267 268 inet_ep2_init(&epp); 269 inet_addr(&epp.remote.addr, 127, 0, 0, 1); 270 epp.remote.port = 42; 271 inet_addr(&epp.local.addr, 127, 0, 0, 1); 272 epp.local.port = 1; 273 274 assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL); 275 PCUT_ASSERT_NOT_NULL(assoc); 276 277 rc = udp_assoc_add(assoc); 278 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 279 280 sent_epp = NULL; 281 sent_msg = NULL; 282 283 rc = udp_assoc_send(assoc, NULL, msg); 284 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 285 PCUT_ASSERT_EQUALS(msg, sent_msg); 286 PCUT_ASSERT_TRUE(inet_addr_compare(&epp.remote.addr, &sent_epp->remote.addr)); 287 PCUT_ASSERT_EQUALS(epp.remote.port, sent_epp->remote.port); 288 289 udp_msg_delete(msg); 290 291 udp_assoc_remove(assoc); 292 udp_assoc_delete(assoc); 293 } 294 295 /** Sending message with destination set in association and unset destination 296 * argument should return EINVAL 297 */ 298 PCUT_TEST(send_assoc_unset_dest) 299 { 300 udp_assoc_t *assoc; 301 inet_ep2_t epp; 302 inet_ep_t dest; 303 errno_t rc; 304 udp_msg_t *msg; 305 const char *msgstr = "Hello"; 306 307 msg = udp_msg_new(); 308 PCUT_ASSERT_NOT_NULL(msg); 309 msg->data_size = str_size(msgstr) + 1; 310 msg->data = str_dup(msgstr); 311 312 inet_ep2_init(&epp); 313 inet_addr(&epp.remote.addr, 127, 0, 0, 1); 314 epp.remote.port = 42; 315 inet_addr(&epp.local.addr, 127, 0, 0, 1); 316 epp.local.port = 1; 317 inet_ep_init(&dest); 318 319 assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL); 320 PCUT_ASSERT_NOT_NULL(assoc); 321 322 rc = udp_assoc_add(assoc); 323 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 324 325 rc = udp_assoc_send(assoc, &dest, msg); 326 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc); 327 328 udp_msg_delete(msg); 329 330 udp_assoc_remove(assoc); 331 udp_assoc_delete(assoc); 332 } 333 334 PCUT_TEST(recv) 335 { 336 // XXX Looks like currently udp_assoc_recv() is not used at all 133 337 } 134 338 … … 189 393 } 190 394 395 static errno_t test_get_srcaddr(inet_addr_t *remote, uint8_t tos, 396 inet_addr_t *local) 397 { 398 inet_addr(local, 127, 0, 0, 1); 399 return EOK; 400 } 401 402 static errno_t test_transmit_msg(inet_ep2_t *epp, udp_msg_t *msg) 403 { 404 sent_epp = epp; 405 sent_msg = msg; 406 return EOK; 407 } 408 191 409 PCUT_EXPORT(assoc);
Note:
See TracChangeset
for help on using the changeset viewer.