1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hctest.h"
17 #include "lwip/sockets.h"
18 #include "lwip/inet.h"
19 #include "lwip/tcp.h"
20 #include "securec.h"
21 #include "cmsis_os2.h"
22 #include <string.h>
23 #include <errno.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <stdio.h>
27
28 #define LOCAL_HOST "127.0.0.1"
29 #define STACK_PORT 2277
30 #define STACK_IP LOCAL_HOST
31 #define PEER_PORT STACK_PORT
32 #define PEER_IP LOCAL_HOST
33 #define UDP_MSG "Hi, I am UDP"
34 #define SRV_MSG "Hi, I am TCP server"
35 #define CLI_MSG "Hi, I am TCP client"
36 #define BUF_SIZE (1024 * 8)
37 #define LWIP_TEST_SUCCESS 0
38 #define LWIP_TEST_FAIL (-1)
39 #define DEF_TASK_STACK 2000
40 #define DEF_TASK_PRIORITY 20
41 #define ONE_SECOND 1
42 #define TIMEOUT 4
43 #define TEST_FD_COUNT 10
44
45 static char g_buf[BUF_SIZE + 1] = {0};
46 static int g_clientWait = 0;
47 static int g_clientWaitOver = 0;
48 static int g_serverWait = 0;
49 static int g_serverWaitOver = 0;
50 static int g_clientResult = 0;
51 static int g_serverResult = 0;
52 static int g_selectResult = 0;
53 static int g_selectFlag = 1;
54 static int g_selectTimeout = 2;
55
WaitClient(void)56 static void WaitClient(void)
57 {
58 while (1) {
59 sleep(ONE_SECOND);
60 if (g_clientWait) {
61 break;
62 }
63 }
64 g_clientWaitOver = 1;
65 g_clientWait = 0;
66 }
67
WaitServer(void)68 static void WaitServer(void)
69 {
70 while (1) {
71 sleep(ONE_SECOND);
72 if (g_serverWait) {
73 break;
74 }
75 }
76 g_serverWaitOver = 1;
77 g_serverWait = 0;
78 }
79
CommInitTcpServer(int port)80 static int CommInitTcpServer(int port)
81 {
82 int srvFd = socket(AF_INET, SOCK_STREAM, 0);
83 if (srvFd == -1) {
84 printf("CommInitTcpServer]socket fail!, errinfo[%s]\n", strerror(errno));
85 return -1;
86 }
87 int flag = 1;
88 int ret = setsockopt(srvFd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(int));
89 if (ret != 0) {
90 printf("[CommInitTcpServer]setsockopt fail, ret[%d]!\n", ret);
91 }
92 struct sockaddr_in srvAddr = {0};
93 srvAddr.sin_family = AF_INET;
94 srvAddr.sin_addr.s_addr = inet_addr(LOCAL_HOST);
95 srvAddr.sin_port = htons(port);
96 ret = bind(srvFd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
97 if (ret != 0) {
98 printf("[CommInitTcpServer]::bind fail!\n");
99 lwip_close(srvFd);
100 return -1;
101 }
102 int backlog = 5;
103 ret = listen(srvFd, backlog);
104 if (ret != 0) {
105 printf("[CommInitTcpServer]listen fail!\n");
106 lwip_close(srvFd);
107 return -1;
108 }
109 printf("[CommInitTcpServer]success,Fd[%d]\n", srvFd);
110 return srvFd;
111 }
112
CommTcpClientTask(void)113 static void CommTcpClientTask(void)
114 {
115 int clnFd = socket(AF_INET, SOCK_STREAM, 0);
116 TEST_ASSERT_NOT_EQUAL(-1, clnFd);
117 if (clnFd == -1) {
118 printf("[comm client]socket fail, errinfo[%s]\n", strerror(errno));
119 return;
120 }
121 struct sockaddr_in srvAddr = {0};
122 srvAddr.sin_family = AF_INET;
123 srvAddr.sin_addr.s_addr = inet_addr(LOCAL_HOST);
124 srvAddr.sin_port = htons(PEER_PORT+1);
125 int rst = connect(clnFd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
126 TEST_ASSERT_EQUAL_INT(0, rst);
127 if (rst != 0) {
128 printf("[comm client]connect fail\n");
129 lwip_close(clnFd);
130 return;
131 }
132 int count = 4;
133 char dataBuf[50] = {0};
134 char sendMsgList[5][50] = {"Hi, I'm client,FD:[%d]", "client:123456789abcdefg,FD:[%d]",
135 "client:!!@@##$$%%^^&&**(()),FD:[%d]", "client:(((112233445566778899))),FD:[%d]", "bye"};
136 for (int i = 0; i < count; i++) {
137 sleep(ONE_SECOND);
138 (void) memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf));
139 rst = sprintf_s(dataBuf, sizeof(dataBuf), sendMsgList[i], clnFd);
140 if (rst < 0) {
141 printf("[comm client]sprintf_s error!\n");
142 continue;
143 }
144 rst = send(clnFd, dataBuf, strlen(dataBuf), 0);
145 TEST_ASSERT_TRUE(rst > 0);
146 if (rst <= 0) {
147 printf("[comm client][%d]send fail\n", clnFd);
148 }
149 (void) memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf));
150 rst = recv(clnFd, dataBuf, sizeof(dataBuf), 0);
151 if (rst > 0) {
152 printf("[comm client][%d]recv msg[%s]\n", clnFd, dataBuf);
153 } else {
154 printf("[comm client][%d]recv no data\n", clnFd);
155 }
156 }
157 // send 'bye', finish
158 rst = send(clnFd, sendMsgList[count], strlen(sendMsgList[count]), 0);
159 TEST_ASSERT_TRUE(rst > 0);
160 if (rst <= 0) {
161 printf("[comm client][%d]send fail\n", clnFd);
162 }
163 rst = lwip_close(clnFd);
164 TEST_ASSERT_EQUAL_INT(0, rst);
165 if (rst != 0) {
166 printf("[comm client][%d]close fd fail\n", clnFd);
167 }
168 }
169
SampleTcpServerTask(void)170 static void SampleTcpServerTask(void)
171 {
172 int ret;
173 struct msghdr msg = {0};
174 struct iovec iov[2] = {};
175 struct sockaddr_in clnAddr = {0};
176 socklen_t clnAddrLen = sizeof(clnAddr);
177 static char buf[BUF_SIZE + 1] = {0};
178
179 int srvFd = CommInitTcpServer(STACK_PORT);
180 TEST_ASSERT_NOT_EQUAL(-1, srvFd);
181
182 WaitServer();
183 int clientFd = accept(srvFd, (struct sockaddr*)&clnAddr, &clnAddrLen);
184 printf("[tcp server]accept <%s:%d>\n", inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
185 TEST_ASSERT_NOT_EQUAL(LWIP_TEST_FAIL, clientFd);
186
187 int srvMsgLen = strlen(SRV_MSG);
188 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
189 ret = strcpy_s(buf, BUF_SIZE, SRV_MSG);
190 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
191 ret = send(clientFd, buf, srvMsgLen, 0);
192 printf("[tcp server]send, ret=%d\n", ret);
193 TEST_ASSERT_EQUAL_INT(srvMsgLen, ret);
194
195 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
196 ret = recv(clientFd, buf, sizeof(buf), 0);
197 printf("[tcp server]recv, ret=%d\n", ret);
198 TEST_ASSERT_EQUAL_INT(strlen(CLI_MSG), ret);
199
200 WaitServer();
201 int len = 2;
202 clnAddr.sin_family = AF_INET;
203 clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
204 clnAddr.sin_port = htons(PEER_PORT);
205 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
206 ret = strcpy_s(buf, BUF_SIZE, SRV_MSG);
207 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
208 msg.msg_name = &clnAddr;
209 msg.msg_namelen = sizeof(clnAddr);
210 msg.msg_iov = iov;
211 msg.msg_iovlen = len;
212 iov[0].iov_base = buf;
213 iov[0].iov_len = srvMsgLen;
214 iov[1].iov_base = buf;
215 iov[1].iov_len = srvMsgLen;
216 ret = sendmsg(clientFd, &msg, 0);
217 printf("[tcp server]sendmsg, ret=%d\n", ret);
218 TEST_ASSERT_EQUAL_INT(len * srvMsgLen, ret);
219
220 WaitServer();
221 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
222 int recvSum = 0;
223 int recvTimes = 50;
224 while (recvTimes > 0) {
225 ret = recv(clientFd, buf, sizeof(buf), 0);
226 recvSum += ret;
227 if ((unsigned int)recvSum == (len * strlen(SRV_MSG)) || ret <= 0) {
228 break;
229 }
230 recvTimes--;
231 }
232 printf("[tcp server]recv, recvSum=%d,recvTimes=%d\n", recvSum, recvTimes);
233 TEST_ASSERT_EQUAL_INT(len * strlen(CLI_MSG), recvSum);
234
235 ret = shutdown(clientFd, SHUT_RDWR);
236 printf("[tcp server]shutdown, ret=%d\n", ret);
237 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
238
239 lwip_close(clientFd);
240 lwip_close(srvFd);
241 g_serverResult = 1;
242 WaitServer();
243 }
244
SampleTcpClientTask(void)245 static void SampleTcpClientTask(void)
246 {
247 int ret;
248 struct msghdr msg = {0};
249 struct iovec iov[2] = {};
250 struct sockaddr addr;
251 socklen_t addrLen = sizeof(addr);
252 struct sockaddr_in srvAddr = {0};
253 struct sockaddr_in clnAddr = {0};
254 static char buf[BUF_SIZE+1] = {0};
255
256 int clientFd = socket(AF_INET, SOCK_STREAM, 0);
257 TEST_ASSERT_NOT_EQUAL(LWIP_TEST_FAIL, clientFd);
258 if (clientFd == -1) {
259 printf("[tcp client]socket fail, errinfo[%s]\n", strerror(errno));
260 }
261
262 WaitClient();
263 srvAddr.sin_family = AF_INET;
264 srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
265 srvAddr.sin_port = htons(PEER_PORT);
266 ret = connect(clientFd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
267 printf("[tcp client]connect %s:%d, ret=%d\n", inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
268 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
269
270 ret = getpeername(clientFd, &addr, &addrLen);
271 printf("[tcp client]getpeername %s:%d, ret=%d\n", inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr),
272 ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
273 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
274 TEST_ASSERT_EQUAL_INT(sizeof(struct sockaddr_in), addrLen);
275 TEST_ASSERT_EQUAL_INT(inet_addr(PEER_IP), ((struct sockaddr_in*)&addr)->sin_addr.s_addr);
276
277 ret = getsockname(clientFd, &addr, &addrLen);
278 printf("[tcp client]getsockname %s:%d, ret=%d\n", inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr),
279 ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
280 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
281 TEST_ASSERT_EQUAL_INT(sizeof(struct sockaddr_in), addrLen);
282 TEST_ASSERT_EQUAL_INT(inet_addr(STACK_IP), ((struct sockaddr_in*)&addr)->sin_addr.s_addr);
283
284 int cliMsgLen = strlen(CLI_MSG);
285 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
286 ret = strcpy_s(buf, BUF_SIZE, CLI_MSG);
287 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
288 ret = send(clientFd, buf, cliMsgLen, 0);
289 printf("[tcp client]send, ret=%d\n", ret);
290 TEST_ASSERT_EQUAL_INT(cliMsgLen, ret);
291
292 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
293 ret = recv(clientFd, buf, sizeof(buf), 0);
294 printf("[tcp client]recv,ret=%d\n", ret);
295 TEST_ASSERT_EQUAL_INT(strlen(SRV_MSG), ret);
296
297 WaitClient();
298 int len = 2;
299 clnAddr.sin_family = AF_INET;
300 clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
301 clnAddr.sin_port = htons(PEER_PORT);
302 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
303 ret = strcpy_s(buf, BUF_SIZE, CLI_MSG);
304 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
305 msg.msg_name = &clnAddr;
306 msg.msg_namelen = sizeof(clnAddr);
307 msg.msg_iov = iov;
308 msg.msg_iovlen = len;
309 iov[0].iov_base = buf;
310 iov[0].iov_len = cliMsgLen;
311 iov[1].iov_base = buf;
312 iov[1].iov_len = cliMsgLen;
313 ret = sendmsg(clientFd, &msg, 0);
314 printf("[tcp client]sendmsg, ret=%d\n", ret);
315 TEST_ASSERT_EQUAL_INT(len * cliMsgLen, ret);
316
317 WaitClient();
318 (void) memset_s(buf, BUF_SIZE, 0, BUF_SIZE);
319 int recvSum = 0;
320 int recvTimes = 50;
321 while (recvTimes > 0) {
322 ret = recv(clientFd, buf, sizeof(buf), 0);
323 recvSum += ret;
324 if ((unsigned int)recvSum == (len * strlen(SRV_MSG)) || ret <= 0) {
325 break;
326 }
327 recvTimes--;
328 }
329 printf("[tcp client]recv, recvSum=%d,recvTimes=%d\n", recvSum, recvTimes);
330 TEST_ASSERT_EQUAL_INT(len * strlen(SRV_MSG), recvSum);
331
332 ret = shutdown(clientFd, SHUT_RDWR);
333 printf("[tcp client]shutdown, ret=%d\n", ret);
334 TEST_ASSERT_EQUAL_INT(0, ret);
335
336 lwip_close(clientFd);
337 g_clientResult = 1;
338 WaitClient();
339 }
340
SelectServerTask(void)341 static void SelectServerTask(void)
342 {
343 int srvFd = CommInitTcpServer(STACK_PORT + 1);
344 if (srvFd == -1) {
345 g_selectResult = -1;
346 g_selectFlag = 0;
347 return;
348 }
349 int ret;
350 int cliCount = 0;
351 int maxFd = srvFd;
352 fd_set readSet;
353 char dataBuf[50] = {0};
354 int fds[TEST_FD_COUNT] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
355 fds[0] = srvFd;
356 struct timeval timev = {
357 .tv_sec = g_selectTimeout,
358 .tv_usec = 0
359 };
360 struct sockaddr_in clnAddr = {0};
361 socklen_t clnAddrLen = sizeof(clnAddr);
362 while (1) {
363 FD_ZERO(&readSet);
364 for (int i = 0; i < TEST_FD_COUNT; i++) {
365 if (fds[i] != -1) {
366 FD_SET(fds[i], &readSet);
367 if (maxFd < fds[i]) {
368 maxFd = fds[i];
369 }
370 printf("[select process]fd info[%d:%d]\n", i, fds[i]);
371 }
372 }
373 ret = select(maxFd + 1, &readSet, NULL, NULL, &timev);
374 if (ret == 0) {
375 printf("[select process]select timeout!\n");
376 int retTimeout = -2;
377 g_selectResult = retTimeout;
378 break;
379 }
380 if (ret == -1) {
381 g_selectResult = -1;
382 printf("[select process]select fail, errinfo[%s]!\n", strerror(errno));
383 break;
384 }
385 if (FD_ISSET(srvFd, &readSet)) {
386 int cliFd = accept(srvFd, (struct sockaddr*)&clnAddr, &clnAddrLen);
387 if (cliFd == -1) {
388 printf("[select process]accept fail!\n");
389 g_selectResult = -1;
390 break;
391 } else {
392 for (int i = 0; i < TEST_FD_COUNT; i++) {
393 if (fds[i] == -1) {
394 fds[i] = cliFd;
395 break;
396 }
397 }
398 cliCount++;
399 printf("[select process]accept success, cliCount[%d]\n", cliCount);
400 }
401 continue;
402 }
403 for (int i = 0; i < TEST_FD_COUNT; i++) {
404 if (fds[i] == -1) {
405 continue;
406 }
407 if (FD_ISSET(fds[i], &readSet)) {
408 (void) memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf));
409 int len = recv(fds[i], dataBuf, sizeof(dataBuf), 0);
410 if (len > 0) {
411 printf("[select process][%d]recv msg[%s]\n", fds[i], dataBuf);
412 if (strcmp(dataBuf, "bye") == 0) {
413 printf("[select process][%d]client bye,cliCount[%d]\n", fds[i], cliCount);
414 FD_CLR(fds[i], &readSet);
415 lwip_close(fds[i]);
416 fds[i] = -1;
417 cliCount--;
418 continue;
419 }
420 len = send(fds[i], dataBuf, strlen(dataBuf), 0);
421 if (len > 0) {
422 printf("[select process][%d]send success\n", fds[i]);
423 } else {
424 printf("[select process][%d]send fail\n", fds[i]);
425 }
426 }
427 }
428 }
429 if (cliCount == 0) {
430 g_selectResult = 0;
431 printf("[select process]cliCount=0, over!\n");
432 break;
433 }
434 }
435 lwip_close(srvFd);
436 g_selectFlag = 0;
437 }
438
439 /**
440 * @tc.desc : register a test suite, this suite is used to test function
441 * @param : subsystem name is communication
442 * @param : module name is lwip
443 * @param : test suit name is LwipFuncTestSuite
444 */
445 LITE_TEST_SUIT(communication, lwip, LwipFuncTestSuite);
446
447 /**
448 * @tc.setup : setup for every testcase
449 * @return : setup result, TRUE is success, FALSE is fail
450 */
LwipFuncTestSuiteSetUp(void)451 static BOOL LwipFuncTestSuiteSetUp(void)
452 {
453 return TRUE;
454 }
455
456 /**
457 * @tc.teardown : teardown for every testcase
458 * @return : teardown result, TRUE is success, FALSE is fail
459 */
LwipFuncTestSuiteTearDown(void)460 static BOOL LwipFuncTestSuiteTearDown(void)
461 {
462 printf("+----------------------------------------------------------+\n");
463 return TRUE;
464 }
465
466 /**
467 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0100
468 * @tc.name : sample test tcp
469 * @tc.desc : [C- SOFTWARE -0200]
470 */
471 LITE_TEST_CASE(LwipFuncTestSuite, testTcp, Function | MediumTest | Level2)
472 {
473 osThreadAttr_t attrServer;
474 attrServer.name = "SampleTcpServerTask";
475 attrServer.attr_bits = 0U;
476 attrServer.cb_mem = NULL;
477 attrServer.cb_size = 0U;
478 attrServer.stack_mem = NULL;
479 attrServer.stack_size = DEF_TASK_STACK;
480 attrServer.priority = DEF_TASK_PRIORITY;
481
482 osThreadAttr_t attrClient;
483 attrClient.name = "SampleTcpClientTask";
484 attrClient.attr_bits = 0U;
485 attrClient.cb_mem = NULL;
486 attrClient.cb_size = 0U;
487 attrClient.stack_mem = NULL;
488 attrClient.stack_size = DEF_TASK_STACK;
489 attrClient.priority = DEF_TASK_PRIORITY;
490
491 osThreadId_t serverTaskId = osThreadNew((osThreadFunc_t)SampleTcpServerTask, NULL, &attrServer);
492 TEST_ASSERT_NOT_NULL(serverTaskId);
493 if (serverTaskId == NULL) {
494 printf("[testTcp]create server task fail!\n");
495 }
496 osThreadId_t clientTaskId = osThreadNew((osThreadFunc_t)SampleTcpClientTask, NULL, &attrClient);
497 TEST_ASSERT_NOT_NULL(clientTaskId);
498 if (clientTaskId == NULL) {
499 printf("[testTcp]create client task fail!\n");
500 }
501
502 sleep(ONE_SECOND);
503 int timeout = TIMEOUT;
504 g_serverWait = 1;
505 g_clientWait = 1;
506 while (timeout > 0) {
507 if (g_serverWaitOver == 1 && g_clientWaitOver == 1) {
508 printf("[testTcp] wait success[1]!\n");
509 break;
510 }
511 timeout--;
512 sleep(ONE_SECOND);
513 printf("[testTcp] wait[1]...\n");
514 }
515
516 sleep(ONE_SECOND);
517 timeout = TIMEOUT;
518 g_serverWait = 1;
519 g_clientWait = 1;
520 while (timeout > 0) {
521 if (g_serverWaitOver == 1 && g_clientWaitOver == 1) {
522 printf("[testTcp] wait success[2]!\n");
523 break;
524 }
525 timeout--;
526 sleep(ONE_SECOND);
527 printf("[testTcp] wait[2]...\n");
528 }
529
530 sleep(ONE_SECOND);
531 timeout = TIMEOUT;
532 g_serverWait = 1;
533 g_clientWait = 1;
534 while (timeout > 0) {
535 if (g_serverWaitOver == 1 && g_clientWaitOver == 1) {
536 printf("[testTcp] wait success[3]!\n");
537 break;
538 }
539 timeout--;
540 sleep(ONE_SECOND);
541 printf("[testTcp] wait[3]...\n");
542 }
543 sleep(ONE_SECOND);
544 timeout = TIMEOUT;
545 g_serverWait = 1;
546 g_clientWait = 1;
547 while (timeout > 0) {
548 if (g_serverWaitOver == 1 && g_clientWaitOver == 1) {
549 printf("[testTcp] wait success[4]!\n");
550 break;
551 }
552 timeout--;
553 sleep(ONE_SECOND);
554 printf("[testTcp] wait[4]...\n");
555 }
556 TEST_ASSERT_EQUAL_INT(1, g_clientResult);
557 TEST_ASSERT_EQUAL_INT(1, g_serverResult);
558
559 sleep(ONE_SECOND);
560 g_serverWait = 1;
561 g_clientWait = 1;
562 }
563
564 /**
565 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0200
566 * @tc.name : sample test udp
567 * @tc.desc : [C- SOFTWARE -0200]
568 */
569 LITE_TEST_CASE(LwipFuncTestSuite, testUdp, Function | MediumTest | Level2)
570 {
571 int ret;
572 int len = 2;
573 struct msghdr msg = {0};
574 struct iovec iov[2] = {0};
575 struct sockaddr_in srvAddr = {0};
576 struct sockaddr_in clnAddr = {0};
577 socklen_t clnAddrLen = sizeof(clnAddr);
578
579 int fd = socket(AF_INET, SOCK_DGRAM, 0);
580 TEST_ASSERT_NOT_EQUAL(LWIP_TEST_FAIL, ret);
581
582 srvAddr.sin_family = AF_INET;
583 srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
584 srvAddr.sin_port = htons(STACK_PORT);
585 ret = bind(fd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
586 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
587
588 clnAddr.sin_family = AF_INET;
589 clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
590 clnAddr.sin_port = htons(PEER_PORT);
591 (void) memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE);
592 ret = strcpy_s(g_buf, BUF_SIZE, UDP_MSG);
593 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
594 ret = sendto(fd, g_buf, strlen(UDP_MSG), 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr));
595 TEST_ASSERT_NOT_EQUAL(LWIP_TEST_FAIL, ret);
596
597 (void) memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE);
598 ret = recvfrom(fd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr, &clnAddrLen);
599 TEST_ASSERT_EQUAL_INT(strlen(UDP_MSG), ret);
600
601 clnAddr.sin_family = AF_INET;
602 clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
603 clnAddr.sin_port = htons(PEER_PORT);
604 (void) memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE);
605 ret = strcpy_s(g_buf, BUF_SIZE, UDP_MSG);
606 TEST_ASSERT_EQUAL_INT(LWIP_TEST_SUCCESS, ret);
607 msg.msg_name = &clnAddr;
608 msg.msg_namelen = sizeof(clnAddr);
609 msg.msg_iov = iov;
610 msg.msg_iovlen = len;
611 iov[0].iov_base = g_buf;
612 iov[0].iov_len = strlen(UDP_MSG);
613 iov[1].iov_base = g_buf;
614 iov[1].iov_len = strlen(UDP_MSG);
615 ret = sendmsg(fd, &msg, 0);
616 TEST_ASSERT_EQUAL_INT(len * strlen(UDP_MSG), ret);
617
618 ret = lwip_close(fd);
619 TEST_ASSERT_NOT_EQUAL(LWIP_TEST_FAIL, ret);
620 }
621
622 /**
623 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0400
624 * @tc.name : test select timeout
625 * @tc.desc : [C- SOFTWARE -0200]
626 */
627 LITE_TEST_CASE(LwipFuncTestSuite, testSelectTimeout, Function | MediumTest | Level2)
628 {
629 osThreadAttr_t tSelect;
630 tSelect.name = "SelectServerTask";
631 tSelect.attr_bits = 0U;
632 tSelect.cb_mem = NULL;
633 tSelect.cb_size = 0U;
634 tSelect.stack_mem = NULL;
635 tSelect.stack_size = DEF_TASK_STACK;
636 tSelect.priority = DEF_TASK_PRIORITY;
637
638 g_selectFlag = 1;
639 g_selectTimeout = 2;
640 osThreadId_t serverTaskId = osThreadNew((osThreadFunc_t)SelectServerTask, NULL, &tSelect);
641 TEST_ASSERT_NOT_NULL(serverTaskId);
642 if (serverTaskId == NULL) {
643 printf("create select server task fail!\n");
644 } else {
645 while (g_selectFlag) {
646 sleep(ONE_SECOND);
647 printf("wait select server finish...\n");
648 }
649 TEST_ASSERT_EQUAL_INT(-2, g_selectResult);
650 }
651 }
652
653 /**
654 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0500
655 * @tc.name : test select with one clients
656 * @tc.desc : [C- SOFTWARE -0200]
657 */
658 LITE_TEST_CASE(LwipFuncTestSuite, testSelectOneClient, Function | MediumTest | Level2)
659 {
660 osThreadAttr_t tSelect;
661 tSelect.name = "SelectServerTask";
662 tSelect.attr_bits = 0U;
663 tSelect.cb_mem = NULL;
664 tSelect.cb_size = 0U;
665 tSelect.stack_mem = NULL;
666 tSelect.stack_size = DEF_TASK_STACK;
667 tSelect.priority = DEF_TASK_PRIORITY;
668
669 g_selectTimeout = 5;
670 osThreadId_t serverTaskId = osThreadNew((osThreadFunc_t)SelectServerTask, NULL, &tSelect);
671 TEST_ASSERT_NOT_NULL(serverTaskId);
672 sleep(ONE_SECOND);
673 if (serverTaskId == NULL) {
674 printf("create select server task fail!\n");
675 } else {
676 osThreadAttr_t tClient;
677 osThreadId_t clientTaskId;
678 tClient.name = "CommTcpClientTask";
679 tClient.attr_bits = 0U;
680 tClient.cb_mem = NULL;
681 tClient.cb_size = 0U;
682 tClient.stack_mem = NULL;
683 tClient.stack_size = DEF_TASK_STACK;
684 tClient.priority = DEF_TASK_PRIORITY;
685 clientTaskId = osThreadNew((osThreadFunc_t)CommTcpClientTask, NULL, &tClient);
686 TEST_ASSERT_NOT_NULL(clientTaskId);
687 }
688
689 g_selectFlag = 1;
690 while (g_selectFlag) {
691 sleep(ONE_SECOND);
692 printf("wait select server finish...\n");
693 }
694 TEST_ASSERT_EQUAL_INT(0, g_selectResult);
695 }
696
697 /**
698 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0700
699 * @tc.name : test socket operation
700 * @tc.desc : [C- SOFTWARE -0200]
701 */
702 LITE_TEST_CASE(LwipFuncTestSuite, testSocketOpt, Function | MediumTest | Level2)
703 {
704 socklen_t len;
705 struct timeval timeout;
706 int fd = socket(AF_INET, SOCK_STREAM, 0);
707 TEST_ASSERT_NOT_EQUAL(-1, fd);
708
709 int error = -1;
710 len = sizeof(error);
711 int ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
712 TEST_ASSERT_EQUAL_INT(0, ret);
713 TEST_ASSERT_EQUAL_INT(0, error);
714
715 len = sizeof(timeout);
716 ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len);
717 TEST_ASSERT_EQUAL_INT(0, ret);
718
719 timeout.tv_sec = 1000;
720 len = sizeof(timeout);
721 ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len);
722 TEST_ASSERT_EQUAL_INT(0, ret);
723
724 (void) memset_s(&timeout, len, 0, len);
725 ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len);
726 TEST_ASSERT_EQUAL_INT(0, ret);
727 TEST_ASSERT_EQUAL_INT(1000, timeout.tv_sec);
728
729 int flag = 1;
730 ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
731 TEST_ASSERT_EQUAL_INT(0, ret);
732
733 flag = 0;
734 len = sizeof(flag);
735 ret = getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, &len);
736 TEST_ASSERT_EQUAL_INT(0, ret);
737 TEST_ASSERT_EQUAL_INT(1, flag);
738
739 error = -1;
740 len = sizeof(error);
741 ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
742 TEST_ASSERT_EQUAL_INT(0, ret);
743 TEST_ASSERT_EQUAL_INT(0, error);
744
745 ret = lwip_close(fd);
746 TEST_ASSERT_EQUAL_INT(0, ret);
747 }
748
749 /**
750 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0800
751 * @tc.name : test getsockname and getpeername invalid input
752 * @tc.desc : [C- SOFTWARE -0200]
753 */
754 LITE_TEST_CASE(LwipFuncTestSuite, testGetSocketNameInvalidInput, Function | MediumTest | Level3)
755 {
756 struct sockaddr addr;
757 socklen_t addrLen = sizeof(addr);
758 int ret = getsockname(-1, &addr, &addrLen);
759 TEST_ASSERT_EQUAL_INT(-1, ret);
760 ret = getpeername(-1, &addr, &addrLen);
761 TEST_ASSERT_EQUAL_INT(-1, ret);
762 ret = getsockname(0, &addr, &addrLen);
763 TEST_ASSERT_EQUAL_INT(-1, ret);
764 ret = getpeername(0, &addr, &addrLen);
765 TEST_ASSERT_EQUAL_INT(-1, ret);
766 ret = getsockname(1, &addr, &addrLen);
767 TEST_ASSERT_EQUAL_INT(-1, ret);
768 ret = getpeername(1, &addr, &addrLen);
769 TEST_ASSERT_EQUAL_INT(-1, ret);
770 ret = getsockname(130, &addr, &addrLen);
771 TEST_ASSERT_EQUAL_INT(-1, ret);
772 ret = getpeername(130, &addr, &addrLen);
773 TEST_ASSERT_EQUAL_INT(-1, ret);
774 ret = getsockname(10, NULL, &addrLen);
775 TEST_ASSERT_EQUAL_INT(-1, ret);
776 ret = getpeername(10, NULL, &addrLen);
777 TEST_ASSERT_EQUAL_INT(-1, ret);
778 ret = getsockname(10, &addr, NULL);
779 TEST_ASSERT_EQUAL_INT(-1, ret);
780 ret = getpeername(10, &addr, NULL);
781 TEST_ASSERT_EQUAL_INT(-1, ret);
782 }
783
784 /**
785 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0900
786 * @tc.name : test inet_pton IPv4 normal
787 * @tc.desc : [C- SOFTWARE -0200]
788 */
789 LITE_TEST_CASE(LwipFuncTestSuite, testInetPtonIpv4Normal, Function | MediumTest | Level2)
790 {
791 int ret;
792 struct in_addr rst;
793 char cpAddrs[4][16] = {"10.58.212.100", "0.0.0.0", "255.0.0.0", "255.255.255.255"};
794 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
795 unsigned int expectLittle[4] = {1691630090, 0, 255, 4294967295};
796 #else
797 unsigned int expectBig[4] = {171627620, 0, 4278190080, 4294967295};
798 #endif
799
800 for (int i = 0; i < 4; i++) {
801 ret = inet_pton(AF_INET, cpAddrs[i], &rst);
802 TEST_ASSERT_EQUAL_INT(1, ret);
803 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
804 TEST_ASSERT_EQUAL_INT(expectLittle[i], rst.s_addr);
805 #else
806 TEST_ASSERT_EQUAL_INT(expectBig[i], rst.s_addr);
807 #endif
808 printf("inet_pton %s: un[%u],s[%d],hex[%x]\n", cpAddrs[i], rst.s_addr, rst.s_addr, rst.s_addr);
809 }
810 }
811
812 /**
813 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1000
814 * @tc.name : test inet_pton IPv4 abnormal
815 * @tc.desc : [C- SOFTWARE -0200]
816 */
817 LITE_TEST_CASE(LwipFuncTestSuite, testInetPtonIpv4Abnormal, Function | MediumTest | Level2)
818 {
819 int ret;
820 struct in_addr rst;
821 char cpAddrs[6][16] = {"256.0.0.1", "a.a.a.a", "....", "#", "127.0.0.f", "0:0:0:0:0:0:0:1"};
822 for (int i = 0; i < 6; i++) {
823 ret = inet_pton(AF_INET, cpAddrs[i], &rst);
824 TEST_ASSERT_EQUAL_INT(0, ret);
825 printf("inet_pton error, cpAddr[%s]\n", cpAddrs[i]);
826 }
827 }
828
829 /**
830 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1100
831 * @tc.name : test inet_pton IPv6 normal
832 * @tc.desc : [C- SOFTWARE -0200]
833 */
834 LITE_TEST_CASE(LwipFuncTestSuite, testInetPtonIpv6Normal, Function | MediumTest | Level2)
835 {
836 int ret;
837 struct in6_addr rst;
838 char cpAddrs[6][40] = {"fc00:0101:0011:0011:0011:0011:0011:0011", "0:0:0:0:0:0:0:0",
839 "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "::", "1::", "fc00:0011:0011:0011:11:11:11:11"};
840 for (int i = 0; i < 6; i++) {
841 ret = inet_pton(AF_INET6, cpAddrs[i], &rst);
842 TEST_ASSERT_EQUAL_INT(1, ret);
843 printf("inet_pton error, cpAddr[%s]\n", cpAddrs[i]);
844 }
845 }
846
847 /**
848 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1200
849 * @tc.name : test inet_pton IPv6 abnormal
850 * @tc.desc : [C- SOFTWARE -0200]
851 */
852 LITE_TEST_CASE(LwipFuncTestSuite, testInetPtonIpv6Abnormal, Function | MediumTest | Level2)
853 {
854 int ret;
855 struct in6_addr rst;
856 char cpAddrs[7][40] = {"127.0.0.1", "f", ":", "0:0", "1:::", ":::::::",
857 "1111:1111:1111:1111:1111:1111:1111:111G"};
858 for (int i = 0; i < 7; i++) {
859 ret = inet_pton(AF_INET6, cpAddrs[i], &rst);
860 TEST_ASSERT_EQUAL_INT(0, ret);
861 printf("inet_pton error, cpAddr[%s]\n", cpAddrs[i]);
862 }
863 }
864
865 /**
866 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1300
867 * @tc.name : test inet_pton with invalid family
868 * @tc.desc : [C- SOFTWARE -0200]
869 */
870 LITE_TEST_CASE(LwipFuncTestSuite, testInetPtonInvalidFamily, Function | MediumTest | Level2)
871 {
872 struct in_addr rst;
873 int ret = inet_pton(AF_IPX, "127.0.0.1", &rst);
874 TEST_ASSERT_EQUAL_INT(-1, ret);
875 ret = inet_pton(-1, "127.0.0.1", &rst);
876 TEST_ASSERT_EQUAL_INT(-1, ret);
877 }
878
879 /**
880 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1400
881 * @tc.name : test inet_ntop IPv4 normal
882 * @tc.desc : [C- SOFTWARE -0200]
883 */
884 LITE_TEST_CASE(LwipFuncTestSuite, testInetNtopIpv4Normal, Function | MediumTest | Level2)
885 {
886 const char* ret = NULL;
887 struct in_addr inputAddr;
888 char rstBuff[INET_ADDRSTRLEN];
889 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
890 unsigned int inputLittle[4] = {0x64d43a0a, 0, 255, 4294967295};
891 #else
892 unsigned int inputBig[4] = {171627620, 0, 4278190080, 4294967295};
893 #endif
894
895 char expectAddrs[4][16] = {"10.58.212.100", "0.0.0.0", "255.0.0.0", "255.255.255.255"};
896 for (int i = 0; i < 4; i++) {
897 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
898 inputAddr.s_addr = inputLittle[i];
899 #else
900 inputAddr.s_addr = inputBig[i];
901 #endif
902 ret = inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
903 if (ret == NULL) {
904 TEST_ASSERT_TRUE(ret != NULL);
905 printf("inet_ntop error, cpAddr[%s]\n", expectAddrs[i]);
906 } else {
907 printf("inet_ntop expect [%s]: ret[%s], buf[%s]\n", expectAddrs[i], ret, rstBuff);
908 TEST_ASSERT_EQUAL_STRING(expectAddrs[i], ret);
909 TEST_ASSERT_EQUAL_STRING(expectAddrs[i], rstBuff);
910 }
911 }
912 }
913
914 /**
915 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1500
916 * @tc.name : test inet_ntop IPv4 boundary input
917 * @tc.desc : [C- SOFTWARE -0200]
918 */
919 LITE_TEST_CASE(LwipFuncTestSuite, testInetNtopIpv4Abnormal, Function | MediumTest | Level2)
920 {
921 const char* ret = NULL;
922 struct in_addr inputAddr;
923 char rstBuff[INET_ADDRSTRLEN];
924 char expectStr[2][16] = {"255.255.255.255", "0.0.0.0"};
925 for (int i = 0; i < 2; i++) {
926 inputAddr.s_addr = (i == 0 ? -1 : 4294967296);
927 ret = inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
928 TEST_ASSERT_TRUE(ret != NULL);
929 TEST_ASSERT_EQUAL_STRING(expectStr[i], ret);
930 TEST_ASSERT_EQUAL_STRING(expectStr[i], rstBuff);
931 }
932 }
933
934 /**
935 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1600
936 * @tc.name : test inet_ntop IPv6 normal
937 * @tc.desc : [C- SOFTWARE -0200]
938 */
939 LITE_TEST_CASE(LwipFuncTestSuite, testInetNtopIpv6Normal, Function | MediumTest | Level2)
940 {
941 int iret;
942 const char* ret = NULL;
943 struct in6_addr inputAddr;
944 char rstBuff[INET6_ADDRSTRLEN];
945 char inputAddrs[6][40] = {"fc00:0101:0011:0011:0011:0011:0011:0011", "0:0:0:0:0:0:0:0",
946 "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "::", "1::", "fc00:0011:0011:0011:1100:11:11:11"};
947 char expectAddrs[6][40] = {"FC00:101:11:11:11:11:11:11", "::",
948 "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "::", "1::", "FC00:11:11:11:1100:11:11:11"};
949 for (int i = 0; i < 6; i++) {
950 iret = inet_pton(AF_INET6, inputAddrs[i], &inputAddr);
951 TEST_ASSERT_EQUAL_INT(1, iret);
952 ret = inet_ntop(AF_INET6, &inputAddr, rstBuff, sizeof(rstBuff));
953 if (ret == NULL) {
954 TEST_ASSERT_TRUE(ret != NULL);
955 printf("inet_ntop error, cpAddr[%s]\n", expectAddrs[i]);
956 } else {
957 printf("inet_ntop expect [%s]: ret[%s], buf[%s]\n", expectAddrs[i], ret, rstBuff);
958 TEST_ASSERT_EQUAL_STRING(expectAddrs[i], ret);
959 TEST_ASSERT_EQUAL_STRING(expectAddrs[i], rstBuff);
960 }
961 }
962 }
963
964 /**
965 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1700
966 * @tc.name : test inet_ntop IPv6 boundary input
967 * @tc.desc : [C- SOFTWARE -0200]
968 */
969 LITE_TEST_CASE(LwipFuncTestSuite, testInetNtopIpv6Abnormal, Function | MediumTest | Level2)
970 {
971 const char* ret = NULL;
972 struct in6_addr inputAddr;
973 char rstBuff[INET6_ADDRSTRLEN];
974 char expectStr[2][40] = {"FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "::"};
975 for (int i = 0; i < 2; i++) {
976 for (int j = 0; j < 16; j++) {
977 inputAddr.s6_addr[j] = (i == 0 ? -1 : 256);
978 }
979 ret = inet_ntop(AF_INET6, &inputAddr, rstBuff, sizeof(rstBuff));
980 TEST_ASSERT_TRUE(ret != NULL);
981 TEST_ASSERT_EQUAL_STRING(expectStr[i], ret);
982 TEST_ASSERT_EQUAL_STRING(expectStr[i], rstBuff);
983 }
984 }
985
986 /**
987 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_1800
988 * @tc.name : test inet_ntop with invalid family
989 * @tc.desc : [C- SOFTWARE -0200]
990 */
991 LITE_TEST_CASE(LwipFuncTestSuite, testInetNtopInvalidFamily, Function | MediumTest | Level2)
992 {
993 int iret;
994 const char* ret = NULL;
995 struct in6_addr inputAddr;
996 char rstBuff[INET6_ADDRSTRLEN];
997
998 iret = inet_pton(AF_INET6, "1::", &inputAddr);
999 TEST_ASSERT_EQUAL_INT(1, iret);
1000 ret = inet_ntop(AF_IPX, &inputAddr, rstBuff, sizeof(rstBuff));
1001 TEST_ASSERT_TRUE(ret == NULL);
1002 ret = inet_ntop(-1, &inputAddr, rstBuff, sizeof(rstBuff));
1003 TEST_ASSERT_TRUE(ret == NULL);
1004 }
1005 /**
1006 * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0500
1007 * @tc.name : test invalid parameter
1008 * @tc.desc : [C- SOFTWARE -0200]
1009 */
1010 LITE_TEST_CASE(LwipFuncTestSuite, testInvalidParameter, Function | MediumTest | Level2)
1011 {
1012 int ret;
1013 int fdFail = -1;
1014 int fdSuccess = -1;
1015
1016 fdFail = socket(0, 0, 0);
1017 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, fdFail);
1018 fdSuccess = socket(AF_INET, SOCK_STREAM, 0);
1019 TEST_ASSERT_NOT_EQUAL(LWIP_TEST_FAIL, fdSuccess);
1020
1021 ret = bind(fdFail, NULL, sizeof(struct sockaddr_in));
1022 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1023 ret = bind(fdSuccess, NULL, sizeof(struct sockaddr_in));
1024 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1025
1026 ret = connect(fdFail, NULL, sizeof(struct sockaddr));
1027 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1028 ret = connect(fdSuccess, NULL, sizeof(struct sockaddr));
1029 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1030
1031 ret = accept(fdFail, NULL, NULL);
1032 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1033 ret = accept(fdSuccess, NULL, NULL);
1034 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1035
1036 ret = getsockname(fdFail, NULL, NULL);
1037 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1038 ret = getsockname(fdSuccess, NULL, NULL);
1039 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1040
1041 ret = getpeername(fdFail, NULL, NULL);
1042 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1043 ret = getpeername(fdSuccess, NULL, NULL);
1044 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1045
1046 ret = send(fdFail, NULL, strlen(SRV_MSG), 0);
1047 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1048 ret = send(fdSuccess, NULL, strlen(SRV_MSG), 0);
1049 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1050
1051 ret = sendto(fdFail, NULL, strlen(SRV_MSG), 0, NULL, (socklen_t)sizeof(struct sockaddr_in));
1052 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1053 ret = sendto(fdSuccess, NULL, strlen(SRV_MSG), 0, NULL, (socklen_t)sizeof(struct sockaddr_in));
1054 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1055
1056 ret = recv(fdFail, NULL, sizeof(SRV_MSG), 0);
1057 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1058 ret = recv(fdSuccess, NULL, sizeof(SRV_MSG), 0);
1059 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1060
1061 ret = recvfrom(fdFail, NULL, sizeof(SRV_MSG), 0, NULL, NULL);
1062 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1063 ret = recvfrom(fdSuccess, NULL, sizeof(SRV_MSG), 0, NULL, NULL);
1064 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1065
1066 ret = setsockopt(fdFail, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t)sizeof(struct timeval));
1067 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1068 ret = setsockopt(fdSuccess, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t)sizeof(struct timeval));
1069 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1070
1071 ret = getsockopt(fdFail, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t*)sizeof(struct timeval));
1072 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1073 ret = getsockopt(fdSuccess, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t*)sizeof(struct timeval));
1074 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1075
1076 ret = sendmsg(fdFail, NULL, 0);
1077 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1078 ret = sendmsg(fdSuccess, NULL, 0);
1079 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1080
1081 ret = listen(fdFail, 0);
1082 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1083 ret = listen(fdSuccess, -1);
1084 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1085
1086 ret = select(fdFail, NULL, NULL, NULL, NULL);
1087 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1088
1089 ret = shutdown(fdFail, SHUT_RD);
1090 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1091 ret = shutdown(fdSuccess, -1);
1092 TEST_ASSERT_EQUAL_INT(LWIP_TEST_FAIL, ret);
1093
1094 ret = lwip_close(fdSuccess);
1095 TEST_ASSERT_EQUAL_INT(0, ret);
1096 }
1097
1098 RUN_TEST_SUITE(LwipFuncTestSuite);
1099