From 151b85678fa36dc2f3c888dda220f2ee99b483ff Mon Sep 17 00:00:00 2001 From: zhangshuai39 Date: Mon, 25 Nov 2024 17:36:52 +0800 Subject: [PATCH] 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 --- testing/nettest/CMakeLists.txt | 42 +++++++++++++++++++ testing/nettest/Kconfig | 28 +++++++++++++ testing/nettest/Make.defs | 23 ++++++++++ testing/nettest/Makefile | 36 ++++++++++++++++ testing/nettest/tcp/test_tcp.c | 47 +++++++++++++++++++++ testing/nettest/tcp/test_tcp.h | 51 +++++++++++++++++++++++ testing/nettest/tcp/test_tcp_common.c | 47 +++++++++++++++++++++ testing/nettest/tcp/test_tcp_connect_01.c | 46 ++++++++++++++++++++ 8 files changed, 320 insertions(+) create mode 100644 testing/nettest/CMakeLists.txt create mode 100644 testing/nettest/Kconfig create mode 100644 testing/nettest/Make.defs create mode 100644 testing/nettest/Makefile create mode 100644 testing/nettest/tcp/test_tcp.c create mode 100644 testing/nettest/tcp/test_tcp.h create mode 100644 testing/nettest/tcp/test_tcp_common.c create mode 100644 testing/nettest/tcp/test_tcp_connect_01.c diff --git a/testing/nettest/CMakeLists.txt b/testing/nettest/CMakeLists.txt new file mode 100644 index 000000000..8f650fbe7 --- /dev/null +++ b/testing/nettest/CMakeLists.txt @@ -0,0 +1,42 @@ +# ############################################################################## +# apps/testing/nettest/CMakeLists.txt +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +if(CONFIG_TESTING_NET_TEST) + if(CONFIG_TESTING_NET_TCP) + set(SRCS ${CMAKE_CURRENT_LIST_DIR}/tcp/test_tcp.c + ${CMAKE_CURRENT_LIST_DIR}/tcp/test_tcp_common.c + ${CMAKE_CURRENT_LIST_DIR}/tcp/test_tcp_connect_01.c) + + nuttx_add_application( + NAME + cmocka_net_tcp + PRIORITY + ${CONFIG_TESTING_NET_TEST_PRIORITY} + STACKSIZE + ${CONFIG_TESTING_NET_TEST_STACKSIZE} + MODULE + ${CONFIG_TESTING_NET_TEST} + DEPENDS + cmocka + SRCS + ${SRCS}) + endif() + +endif() \ No newline at end of file diff --git a/testing/nettest/Kconfig b/testing/nettest/Kconfig new file mode 100644 index 000000000..b5332469d --- /dev/null +++ b/testing/nettest/Kconfig @@ -0,0 +1,28 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config TESTING_NET_TEST + tristate "vela cmocka net test" + default n + depends on TESTING_CMOCKA + ---help--- + Enable the cmocka net test + +if TESTING_NET_TEST + +config TESTING_NET_TEST_PRIORITY + int "Task priority" + default 100 + +config TESTING_NET_TEST_STACKSIZE + int "Stack size" + default DEFAULT_TASK_STACKSIZE + +config TESTING_NET_TCP + bool "Enable cmocka net tcp test" + depends on NET_TCP && NET_TCPBACKLOG + default y + +endif diff --git a/testing/nettest/Make.defs b/testing/nettest/Make.defs new file mode 100644 index 000000000..2f2595325 --- /dev/null +++ b/testing/nettest/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# apps/testing/nettest/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifneq ($(CONFIG_TESTING_NET_TEST),) +CONFIGURED_APPS += $(APPDIR)/testing/nettest +endif diff --git a/testing/nettest/Makefile b/testing/nettest/Makefile new file mode 100644 index 000000000..6d61714d6 --- /dev/null +++ b/testing/nettest/Makefile @@ -0,0 +1,36 @@ +############################################################################ +# apps/testing/nettest/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +PRIORITY = $(CONFIG_TESTING_NET_TEST_PRIORITY) +STACKSIZE = $(CONFIG_TESTING_NET_TEST_STACKSIZE) +MODULE = $(CONFIG_TESTING_NET_TEST) + +ifeq ($(CONFIG_TESTING_NET_TEST),y) + +ifeq ($(CONFIG_TESTING_NET_TCP),y) +MAINSRC += tcp/test_tcp.c +PROGNAME += cmocka_net_tcp +CSRCS += tcp/test_tcp_common.c tcp/test_tcp_connect_01.c +endif + +endif +include $(APPDIR)/Application.mk diff --git a/testing/nettest/tcp/test_tcp.c b/testing/nettest/tcp/test_tcp.c new file mode 100644 index 000000000..c4d2f6ef4 --- /dev/null +++ b/testing/nettest/tcp/test_tcp.c @@ -0,0 +1,47 @@ +/**************************************************************************** + * apps/testing/nettest/tcp/test_tcp.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "test_tcp.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + const struct CMUnitTest tcp_tests[] = + { + cmocka_unit_test_setup(test_tcp_connect_ipv4_01, + tcp_connect_setup_01), + }; + + return cmocka_run_group_tests(tcp_tests, tcp_group_setup, + tcp_group_teardown); +} diff --git a/testing/nettest/tcp/test_tcp.h b/testing/nettest/tcp/test_tcp.h new file mode 100644 index 000000000..46d22a15e --- /dev/null +++ b/testing/nettest/tcp/test_tcp.h @@ -0,0 +1,51 @@ +/**************************************************************************** + * apps/testing/nettest/tcp/test_tcp.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Name: tcp_group_setup + ****************************************************************************/ + +int tcp_group_setup(FAR void **state); + +/**************************************************************************** + * Name: tcp_group_teardown + ****************************************************************************/ + +int tcp_group_teardown(FAR void **state); + +/**************************************************************************** + * Name: tcp_connect_setup_01 + ****************************************************************************/ + +int tcp_connect_setup_01(FAR void **state); + +/**************************************************************************** + * Name: test_tcp_connect_ipv4_01 + ****************************************************************************/ + +void test_tcp_connect_ipv4_01(FAR void **state); diff --git a/testing/nettest/tcp/test_tcp_common.c b/testing/nettest/tcp/test_tcp_common.c new file mode 100644 index 000000000..f78648721 --- /dev/null +++ b/testing/nettest/tcp/test_tcp_common.c @@ -0,0 +1,47 @@ +/**************************************************************************** + * apps/testing/nettest/tcp/test_tcp_common.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "test_tcp.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tcp_group_setup + ****************************************************************************/ + +int tcp_group_setup(FAR void **state) +{ + return 0; +} + +/**************************************************************************** + * Name: tcp_group_teardown + ****************************************************************************/ + +int tcp_group_teardown(FAR void **state) +{ + return 0; +} diff --git a/testing/nettest/tcp/test_tcp_connect_01.c b/testing/nettest/tcp/test_tcp_connect_01.c new file mode 100644 index 000000000..3058fde32 --- /dev/null +++ b/testing/nettest/tcp/test_tcp_connect_01.c @@ -0,0 +1,46 @@ +/**************************************************************************** + * apps/testing/nettest/tcp/test_tcp_connect_01.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "test_tcp.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tcp_connect_setup_01 + ****************************************************************************/ + +int tcp_connect_setup_01(FAR void **state) +{ + return 0; +} + +/**************************************************************************** + * Name: test_tcp_connect_ipv4_01 + ****************************************************************************/ + +void test_tcp_connect_ipv4_01(FAR void **state) +{ +}