Skip to content

Commit f2b0437

Browse files
zs39xiaoxiang781216
authored andcommitted
apps/testing: Add a cmocka framework for network testing
Provides a network automated testing framework, including the main directory structure and Makefile, CMakeLists, Kconfig and other files such as tcp. Signed-off-by: zhangshuai39 <[email protected]>
1 parent 121205f commit f2b0437

File tree

8 files changed

+336
-0
lines changed

8 files changed

+336
-0
lines changed

testing/nettest/CMakeLists.txt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ##############################################################################
2+
# apps/testing/nettest/CMakeLists.txt
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
5+
# license agreements. See the NOTICE file distributed with this work for
6+
# additional information regarding copyright ownership. The ASF licenses this
7+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
8+
# use this file except in compliance with the License. You may obtain a copy of
9+
# the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations under
17+
# the License.
18+
#
19+
# ##############################################################################
20+
21+
if(CONFIG_TESTING_NET_TEST)
22+
if(CONFIG_TESTING_NET_TCP)
23+
set(SRCS ${CMAKE_CURRENT_LIST_DIR}/tcp/test_tcp.c
24+
${CMAKE_CURRENT_LIST_DIR}/tcp/test_tcp_common.c)
25+
26+
if(CONFIG_NET_IPv4)
27+
list(APPEND SRCS ${CMAKE_CURRENT_LIST_DIR}/tcp/test_tcp_connect_ipv4.c)
28+
endif()
29+
30+
nuttx_add_application(
31+
NAME
32+
cmocka_net_tcp
33+
PRIORITY
34+
${CONFIG_TESTING_NET_TEST_PRIORITY}
35+
STACKSIZE
36+
${CONFIG_TESTING_NET_TEST_STACKSIZE}
37+
MODULE
38+
${CONFIG_TESTING_NET_TEST}
39+
DEPENDS
40+
cmocka
41+
SRCS
42+
${SRCS})
43+
endif()
44+
45+
endif()

testing/nettest/Kconfig

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config TESTING_NET_TEST
7+
tristate "vela cmocka net test"
8+
default n
9+
depends on TESTING_CMOCKA
10+
---help---
11+
Enable the cmocka net test
12+
13+
if TESTING_NET_TEST
14+
15+
config TESTING_NET_TEST_PRIORITY
16+
int "Task priority"
17+
default 100
18+
19+
config TESTING_NET_TEST_STACKSIZE
20+
int "Stack size"
21+
default DEFAULT_TASK_STACKSIZE
22+
23+
config TESTING_NET_TCP
24+
bool "Enable cmocka net tcp test"
25+
depends on NET_TCP && NET_TCPBACKLOG
26+
default y
27+
28+
endif

testing/nettest/Make.defs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
############################################################################
2+
# apps/testing/nettest/Make.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
ifneq ($(CONFIG_TESTING_NET_TEST),)
22+
CONFIGURED_APPS += $(APPDIR)/testing/nettest
23+
endif

testing/nettest/Makefile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
############################################################################
2+
# apps/testing/nettest/Makefile
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
include $(APPDIR)/Make.defs
22+
23+
PRIORITY = $(CONFIG_TESTING_NET_TEST_PRIORITY)
24+
STACKSIZE = $(CONFIG_TESTING_NET_TEST_STACKSIZE)
25+
MODULE = $(CONFIG_TESTING_NET_TEST)
26+
27+
ifeq ($(CONFIG_TESTING_NET_TEST),y)
28+
29+
ifeq ($(CONFIG_TESTING_NET_TCP),y)
30+
MAINSRC += tcp/test_tcp.c
31+
PROGNAME += cmocka_net_tcp
32+
CSRCS += tcp/test_tcp_common.c
33+
34+
ifeq ($(CONFIG_NET_IPv4), y)
35+
CSRCS += tcp/test_tcp_connect_ipv4.c
36+
endif
37+
38+
endif
39+
40+
endif
41+
include $(APPDIR)/Application.mk

testing/nettest/tcp/test_tcp.c

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/****************************************************************************
2+
* apps/testing/nettest/tcp/test_tcp.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <stdarg.h>
26+
#include <stddef.h>
27+
#include <stdint.h>
28+
#include <setjmp.h>
29+
#include <cmocka.h>
30+
31+
#include "test_tcp.h"
32+
33+
/****************************************************************************
34+
* Public Functions
35+
****************************************************************************/
36+
37+
int main(int argc, FAR char *argv[])
38+
{
39+
const struct CMUnitTest tcp_tests[] =
40+
{
41+
#ifdef CONFIG_NET_IPv4
42+
cmocka_unit_test_setup(test_tcp_connect_ipv4,
43+
test_tcp_connect_ipv4_setup),
44+
#endif
45+
};
46+
47+
return cmocka_run_group_tests(tcp_tests, test_tcp_group_setup,
48+
test_tcp_group_teardown);
49+
}

testing/nettest/tcp/test_tcp.h

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/****************************************************************************
2+
* apps/testing/nettest/tcp/test_tcp.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef __APPS_TESTING_NETTEST_TCP_TEST_TCP_H
22+
#define __APPS_TESTING_NETTEST_TCP_TEST_TCP_H
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <nuttx/config.h>
29+
30+
#include <nuttx/compiler.h>
31+
32+
/****************************************************************************
33+
* Name: test_tcp_group_setup
34+
****************************************************************************/
35+
36+
int test_tcp_group_setup(FAR void **state);
37+
38+
/****************************************************************************
39+
* Name: test_tcp_group_teardown
40+
****************************************************************************/
41+
42+
int test_tcp_group_teardown(FAR void **state);
43+
44+
/****************************************************************************
45+
* Name: test_tcp_connect_ipv4_setup
46+
****************************************************************************/
47+
48+
#ifdef CONFIG_NET_IPv4
49+
int test_tcp_connect_ipv4_setup(FAR void **state);
50+
51+
/****************************************************************************
52+
* Name: test_tcp_connect_ipv4
53+
****************************************************************************/
54+
55+
void test_tcp_connect_ipv4(FAR void **state);
56+
#endif /* CONFIG_NET_IPv4 */
57+
#endif /* __APPS_TESTING_NETTEST_TCP_TEST_TCP_H */

testing/nettest/tcp/test_tcp_common.c

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/****************************************************************************
2+
* apps/testing/nettest/tcp/test_tcp_common.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include "test_tcp.h"
26+
27+
/****************************************************************************
28+
* Public Functions
29+
****************************************************************************/
30+
31+
/****************************************************************************
32+
* Name: test_tcp_group_setup
33+
****************************************************************************/
34+
35+
int test_tcp_group_setup(FAR void **state)
36+
{
37+
return 0;
38+
}
39+
40+
/****************************************************************************
41+
* Name: test_tcp_group_teardown
42+
****************************************************************************/
43+
44+
int test_tcp_group_teardown(FAR void **state)
45+
{
46+
return 0;
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/****************************************************************************
2+
* apps/testing/nettest/tcp/test_tcp_connect_ipv4.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include "test_tcp.h"
26+
27+
/****************************************************************************
28+
* Public Functions
29+
****************************************************************************/
30+
31+
/****************************************************************************
32+
* Name: test_tcp_connect_ipv4_setup
33+
****************************************************************************/
34+
35+
int test_tcp_connect_ipv4_setup(FAR void **state)
36+
{
37+
return 0;
38+
}
39+
40+
/****************************************************************************
41+
* Name: test_tcp_connect_ipv4
42+
****************************************************************************/
43+
44+
void test_tcp_connect_ipv4(FAR void **state)
45+
{
46+
}

0 commit comments

Comments
 (0)