📄 t_socket.c
字号:
/* * Copyright (C) 1999-2003 MITSUBISHI ELECTRIC CORPORATION and * RENESAS SOLUTIONS CORPORATION and * RENESAS TECHNOLOGY CORPORATION * All rights reserved. * * TCP/IP Test Application program [API]. */#include <tk/tkernel.h>#include <renesas_tcpip.h>#include <renesas_tcpip_common.h>#include "config.h"voidtest_task(int stacd, void *exinf){ int i, af, type, s; int maxfdno, maxs, sd[NDFILE +1]; int testno, testno2, result[15]; testno = 0; memset((char *)result, 0, sizeof(result)); /* Test 1 */ printf("Socket Test 1: AF check \n"); for (af = -1; af <= 29; af++) { /* AF_UNSPEC to AF_MAX */ /* change address family from -1 to 18 */ errno = 0; /* Create SOCK_STREAM socket */ s = unix_socket(af, SOCK_STREAM, 0); switch(af) { case AF_INET:testno = 1; printf("AF_INET: %d\n",af); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_INET SOCK_STREAM socket \n"); result[testno] = 0; } break; default:testno = 2; printf("AF: %d\n",af); if (s < 0) { printf("OK! : AF %d not support \n",af); result[testno] = 0; } else { printf("Fail! : AF %d , errno= %d \n",af,errno); result[testno] = 1; } } if (s >= 0) unix_close(s); errno = 0; s = unix_socket(af, SOCK_DGRAM, 0); switch(af) { case AF_INET:testno = 3; printf("AF_INET: %d\n",af); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_INET SOCK_DGRAM socket \n"); result[testno] = 0; } break; default:testno = 4; printf("AF: %d\n",af); if (s < 0) { printf("OK! : AF %d not support \n",af); result[testno] = 0; } else { printf("Fail! : AF %d not support \n",af); result[testno] = 1; } } if (s >= 0) unix_close(s); errno = 0; s = unix_socket(af, SOCK_RAW, 0); switch(af) { case AF_INET:testno = 5; printf("AF_INET \n"); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_INET SOCK_RAW socket \n"); result[testno] = 0; } break; case AF_ROUTE:testno = 6; printf("AF_ROUTE \n"); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_ROUTE SOCK_RAW socket \n"); result[testno] = 0; } break; default:testno = 7; printf("AF: %d\n",af); if (s < 0) { printf("OK! : AF %d not support \n",af); result[testno] = 0; } else { printf("Fail! : AF %d , errno= %d \n",af,errno); result[testno] = 1; } } if (s >= 0) unix_close(s); } /* Test 2 */ printf("Socket Test 2: Socket Type check \n"); for (type = -1; type <= 7; type++) { errno = 0; s = unix_socket(AF_INET, type, 0); switch(type) { case SOCK_STREAM:testno = 8; printf("SOCK_STREAM \n"); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_INET SOCK_STREAM socket \n"); result[testno] = 0; } break; case SOCK_DGRAM:testno = 9; printf("SOCK_DGRAM \n"); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_INET SOCK_DGRAM socket \n"); result[testno] = 0; } break; case SOCK_RAW:testno = 10; printf("SOCK_RAW \n"); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_INET SOCK_RAW socket \n"); result[testno] = 0; } break; default:testno = 11; printf("TYPE: %d\n",type); if (s < 0) { printf("OK! : TYPE %d not support \n",type); result[testno] = 0; } else { printf("Fail! : TYPE %d , errno= %d \n",type,errno); result[testno] = 1; } } if (s >= 0) unix_close(s); } /* Test 3 */ printf("Socket Test 3: Socket Type check \n"); for (type = -1; type <= 7; type++) { errno = 0; s = unix_socket(AF_ROUTE, type, 0); switch(type) { case SOCK_RAW:testno = 12; printf("SOCK_RAW \n"); if (s < 0) { printf("Fail! : errno = %d\n",errno); result[testno] = 1; } else { printf("OK! : AF_ROUTE SOCK_RAW socket \n"); result[testno] = 0; } break; default:testno = 13; printf("TYPE: %d\n",type); if (s < 0) { printf("OK! : TYPE %d not support \n",type); result[testno] = 0; } else { printf("Fail! : TYPE %d , errno= %d \n",type,errno); result[testno] = 1; } } if (s >= 0) unix_close(s); } /* Test 4 */ printf("Socket Test 4: Socket FD exhaust check \n");testno = 14; maxfdno = NDFILE; for (i = 0; i <= maxfdno; i++) { errno = 0; sd[i] = unix_socket(AF_INET, SOCK_STREAM, 0); if (sd[i] < 0) break; maxs = i; } if (i >= maxfdno) { printf("OK! : FD exhaust \n"); result[testno] = 0; } else { printf("Fail! : FD don't exhaust errno= %d\n",errno); result[testno] = 1; } errno = 0; for (i = 0; i <= maxs; i++) { if (unix_close(sd[i]) < 0) { break; } } /* check the results */ testno2 = 14; for (i=1; i <= testno; i++) { if (result[i] == 1) break; } if (i > testno2) printf("Pass.\n"); else printf("Error.\n");#if defined(T_KERNEL) tk_slp_tsk(TMO_FEVR);#endif}/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -