1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "sys/socket.h"
33 #include "hos_cmsis_adp.h"
34
35 #define LWIP_TEST_TIMEOUT 1000 // timeout 1s
36 #define LWIP_TEST_COUNT_FLAG 100
37
38 #define SOCKET_TEST 310
39 #define UDP_TEST 320
40 #define TCP_TEST 330
41 #define OPT_TEST 340
42 #define ORDER_TEST 350
43 #define INET_TEST 360
44 #define UDP_MORE_TEST 370
45 #define TCP_MORE_TEST 380
46 #define TCP_SELECT_TEST 390
47 #define TCP_POLL_TEST 400
48 #define NETIF_TEST 410
49 #define TCP_DUP_TEST 420
50 #define TCP_LONG_TEST 430
51
52 int g_lwipTimerCount = 0;
53 int g_testCase = LWIP_TEST_COUNT_FLAG;
54 int g_testError = 0;
55 int g_testTemp = LWIP_TEST_COUNT_FLAG;
56 extern void abort(void);
57 extern int SocketTest(void);
58 extern int UdpTest(void);
59 extern void TcpTest();
60 extern int SockOptTest();
61 extern int ByteOrderTest(void);
62 extern int InetTest();
63 extern int UdpTestMore(void);
64 extern void TcpTestMore();
65 extern void TcpTestSelect();
66 extern void TcpTestPoll();
67 extern int UdpTestNetif(void);
68 extern void TcpTestDup();
69 extern void TcpTestLong();
70
71 // time out 1s
LwipTestTimeoutCallback(void const * argument)72 static void LwipTestTimeoutCallback(void const *argument)
73 {
74 g_lwipTimerCount++;
75 switch (g_lwipTimerCount) {
76 case SOCKET_TEST:
77 SocketTest();
78 break;
79 case UDP_TEST:
80 UdpTest();
81 break;
82 case TCP_TEST:
83 TcpTest();
84 break;
85 case OPT_TEST:
86 SockOptTest();
87 break;
88 case ORDER_TEST:
89 ByteOrderTest();
90 break;
91 case INET_TEST:
92 InetTest();
93 break;
94 case UDP_MORE_TEST:
95 UdpTestMore();
96 break;
97 case TCP_MORE_TEST:
98 TcpTestMore();
99 break;
100 case TCP_SELECT_TEST:
101 TcpTestSelect();
102 break;
103 case TCP_POLL_TEST:
104 TcpTestPoll();
105 break;
106 case NETIF_TEST:
107 UdpTestNetif();
108 break;
109 case TCP_DUP_TEST:
110 TcpTestDup();
111 break;
112 case TCP_LONG_TEST:
113 TcpTestLong();
114 break;
115 default:
116 break;
117 }
118 }
119
120 osTimerId_t g_lwipTestTimerId = NULL;
121
LwipTestStartTimer(uint32_t timeout)122 void LwipTestStartTimer(uint32_t timeout)
123 {
124 osStatus_t status;
125 if (g_lwipTestTimerId != NULL) {
126 status = osTimerStart(g_lwipTestTimerId, timeout);
127 if (status != osOK) {
128 return;
129 }
130 } else {
131 g_lwipTestTimerId = osTimerNew((osTimerFunc_t)LwipTestTimeoutCallback, osTimerPeriodic, NULL, NULL);
132 if (g_lwipTestTimerId == NULL) {
133 return;
134 }
135 status = osTimerStart(g_lwipTestTimerId, timeout);
136 if (status != osOK) {
137 return;
138 }
139 }
140 }
141
LwipTestEnter()142 void LwipTestEnter()
143 {
144 LwipTestStartTimer(LWIP_TEST_TIMEOUT);
145 }
146