Skip to content

Commit

Permalink
apps/testing: Add a cmocka framework for network testing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
zs39 authored and xiaoxiang781216 committed Jan 9, 2025
1 parent 121205f commit f2b0437
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 0 deletions.
45 changes: 45 additions & 0 deletions testing/nettest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ##############################################################################
# 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)

if(CONFIG_NET_IPv4)
list(APPEND SRCS ${CMAKE_CURRENT_LIST_DIR}/tcp/test_tcp_connect_ipv4.c)
endif()

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()
28 changes: 28 additions & 0 deletions testing/nettest/Kconfig
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions testing/nettest/Make.defs
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions testing/nettest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
############################################################################
# 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

ifeq ($(CONFIG_NET_IPv4), y)
CSRCS += tcp/test_tcp_connect_ipv4.c
endif

endif

endif
include $(APPDIR)/Application.mk
49 changes: 49 additions & 0 deletions testing/nettest/tcp/test_tcp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/****************************************************************************
* 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 <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>

#include "test_tcp.h"

/****************************************************************************
* Public Functions
****************************************************************************/

int main(int argc, FAR char *argv[])
{
const struct CMUnitTest tcp_tests[] =
{
#ifdef CONFIG_NET_IPv4
cmocka_unit_test_setup(test_tcp_connect_ipv4,
test_tcp_connect_ipv4_setup),
#endif
};

return cmocka_run_group_tests(tcp_tests, test_tcp_group_setup,
test_tcp_group_teardown);
}
57 changes: 57 additions & 0 deletions testing/nettest/tcp/test_tcp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/****************************************************************************
* 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.
*
****************************************************************************/

#ifndef __APPS_TESTING_NETTEST_TCP_TEST_TCP_H
#define __APPS_TESTING_NETTEST_TCP_TEST_TCP_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#include <nuttx/compiler.h>

/****************************************************************************
* Name: test_tcp_group_setup
****************************************************************************/

int test_tcp_group_setup(FAR void **state);

/****************************************************************************
* Name: test_tcp_group_teardown
****************************************************************************/

int test_tcp_group_teardown(FAR void **state);

/****************************************************************************
* Name: test_tcp_connect_ipv4_setup
****************************************************************************/

#ifdef CONFIG_NET_IPv4
int test_tcp_connect_ipv4_setup(FAR void **state);

/****************************************************************************
* Name: test_tcp_connect_ipv4
****************************************************************************/

void test_tcp_connect_ipv4(FAR void **state);
#endif /* CONFIG_NET_IPv4 */
#endif /* __APPS_TESTING_NETTEST_TCP_TEST_TCP_H */
47 changes: 47 additions & 0 deletions testing/nettest/tcp/test_tcp_common.c
Original file line number Diff line number Diff line change
@@ -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: test_tcp_group_setup
****************************************************************************/

int test_tcp_group_setup(FAR void **state)
{
return 0;
}

/****************************************************************************
* Name: test_tcp_group_teardown
****************************************************************************/

int test_tcp_group_teardown(FAR void **state)
{
return 0;
}
46 changes: 46 additions & 0 deletions testing/nettest/tcp/test_tcp_connect_ipv4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/****************************************************************************
* apps/testing/nettest/tcp/test_tcp_connect_ipv4.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: test_tcp_connect_ipv4_setup
****************************************************************************/

int test_tcp_connect_ipv4_setup(FAR void **state)
{
return 0;
}

/****************************************************************************
* Name: test_tcp_connect_ipv4
****************************************************************************/

void test_tcp_connect_ipv4(FAR void **state)
{
}

0 comments on commit f2b0437

Please sign in to comment.