Skip to content

Commit 673002e

Browse files
committed
testing/nuts: NuttX Unit Test Selection (NUTS) application.
Introduces a collection of unit tests for NuttX, built on top of the cmocka framework. Tests are organized into suites/groups which can be individually included/excluded from the build using Kconfig. Output is easily legible and separated with headers including the test group name. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
1 parent c4da1b5 commit 673002e

File tree

16 files changed

+2061
-0
lines changed

16 files changed

+2061
-0
lines changed

testing/nuts/CMakeLists.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ##############################################################################
2+
# apps/testing/nuts/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
if(CONFIG_TESTING_NUTS)
24+
25+
set(SRCS)
26+
27+
if(CONFIG_TESTING_NUTS_DSTRUCTS)
28+
29+
if(CONFIG_TESTING_NUTS_DSTRUCTS_LIST)
30+
list(APPEND SRCS dstructs/list.c)
31+
endif()
32+
33+
if(CONFIG_TESTING_NUTS_DSTRUCTS_CBUF)
34+
list(APPEND SRCS dstructs/cbuf.c)
35+
endif()
36+
37+
endif() # CONFIG_TESTING_NUTS_DSTRUCTS
38+
39+
if(CONFIG_TESTING_NUTS_DEVICES)
40+
41+
if(CONFIG_TESTING_NUTS_DEVICES_DEVNULL)
42+
list(APPEND SRCS devices/devnull.c)
43+
endif()
44+
45+
if(CONFIG_TESTING_NUTS_DEVICES_DEVZERO)
46+
list(APPEND SRCS devices/devzero.c)
47+
endif()
48+
49+
if(CONFIG_TESTING_NUTS_DEVICES_DEVASCII)
50+
list(APPEND SRCS devices/devascii.c)
51+
endif()
52+
53+
if(CONFIG_TESTING_NUTS_DEVICES_DEVCONSOLE)
54+
list(APPEND SRCS devices/devconsole.c)
55+
endif()
56+
57+
if(CONFIG_TESTING_NUTS_DEVICES_DEVURANDOM)
58+
list(APPEND SRCS devices/devurandom.c)
59+
endif()
60+
61+
endif() # CONFIG_TESTING_NUTS_DEVICES
62+
63+
set(NUTS_SRCS nuts_main.c ${SRCS})
64+
nuttx_add_application(NAME ${CONFIG_TESTING_NUTS_PROGNAME} SRCS ${NUTS_SRCS})
65+
66+
endif()

testing/nuts/Kconfig

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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_NUTS
7+
tristate "NuttX Unit Test Selection (NUTS)"
8+
depends on TESTING_CMOCKA
9+
default n
10+
---help---
11+
Enable the NuttX unit test selection, based on the cmocka test framework.
12+
13+
if TESTING_NUTS
14+
15+
comment "Program options"
16+
17+
config TESTING_NUTS_PROGNAME
18+
string "Program name"
19+
default "nuts"
20+
---help---
21+
The name of the program.
22+
23+
config TESTING_NUTS_STACKSIZE
24+
int "Stack size"
25+
default 1024
26+
---help---
27+
Size of the stack used to create the task.
28+
29+
comment "Test Suites"
30+
31+
comment "Data structures"
32+
33+
config TESTING_NUTS_DSTRUCTS
34+
bool "Collections tests"
35+
default n
36+
---help---
37+
Enable test suites for collections.
38+
39+
if TESTING_NUTS_DSTRUCTS
40+
41+
config TESTING_NUTS_DSTRUCTS_LIST
42+
bool "List testing"
43+
default y
44+
---help---
45+
Enable list test cases.
46+
47+
config TESTING_NUTS_DSTRUCTS_CBUF
48+
bool "Circular buffer testing"
49+
default y
50+
---help---
51+
Enable circular buffer test cases.
52+
53+
endif # TESTING_NUTS_DSTRUCTS
54+
55+
comment "Devices"
56+
57+
config TESTING_NUTS_DEVICES
58+
bool "Device tests"
59+
default n
60+
---help---
61+
Enable test suites for devices.
62+
63+
if TESTING_NUTS_DEVICES
64+
65+
config TESTING_NUTS_DEVICES_DEVNULL
66+
bool "/dev/null test"
67+
depends on DEV_NULL
68+
default y
69+
---help---
70+
Enable test cases for /dev/null device.
71+
72+
config TESTING_NUTS_DEVICES_DEVZERO
73+
bool "/dev/zero test"
74+
depends on DEV_ZERO
75+
default y
76+
---help---
77+
Enable test cases for /dev/zero device.
78+
79+
config TESTING_NUTS_DEVICES_DEVASCII
80+
bool "/dev/ascii test"
81+
depends on DEV_ASCII
82+
default y
83+
---help---
84+
Enable test cases for /dev/ascii device.
85+
86+
config TESTING_NUTS_DEVICES_DEVCONSOLE
87+
bool "/dev/console test"
88+
depends on DEV_CONSOLE
89+
default y
90+
---help---
91+
Enable test cases for /dev/console device.
92+
93+
config TESTING_NUTS_DEVICES_DEVURANDOM
94+
bool "/dev/urandom test"
95+
depends on DEV_URANDOM
96+
default y
97+
---help---
98+
Enable test cases for /dev/urandom device.
99+
100+
endif # TESTING_NUTS_DEVICES
101+
102+
endif # TESTING_NUTS

testing/nuts/Make.defs

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

testing/nuts/Makefile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
############################################################################
2+
# apps/testing/nuts/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
include $(APPDIR)/Make.defs
24+
25+
# Application info
26+
27+
PROGNAME = $(CONFIG_TESTING_NUTS_PROGNAME)
28+
PRIORITY = SCHED_PRIORITY_DEFAULT
29+
STACKSIZE = $(CONFIG_TESTING_NUTS_STACKSIZE)
30+
MODULE = $(CONFIG_TESTING_OSTEST)
31+
32+
# Source inclusion
33+
34+
MAINSRC = nuts_main.c
35+
CSRCS =
36+
37+
ifeq ($(CONFIG_TESTING_NUTS_DSTRUCTS),y)
38+
39+
ifeq ($(CONFIG_TESTING_NUTS_DSTRUCTS_LIST),y)
40+
CSRCS += dstructs/list.c
41+
endif
42+
43+
ifeq ($(CONFIG_TESTING_NUTS_DSTRUCTS_CBUF),y)
44+
CSRCS += dstructs/cbuf.c
45+
endif
46+
47+
ifeq ($(CONFIG_TESTING_NUTS_DSTRUCTS_HMAP),y)
48+
CSRCS += dstructs/hmap.c
49+
endif
50+
51+
endif # CONFIG_TESTING_NUTS_DSTRUCTS
52+
53+
ifeq ($(CONFIG_TESTING_NUTS_DEVICES),y)
54+
55+
ifeq ($(CONFIG_TESTING_NUTS_DEVICES_DEVNULL),y)
56+
CSRCS += devices/devnull.c
57+
endif
58+
59+
ifeq ($(CONFIG_TESTING_NUTS_DEVICES_DEVZERO),y)
60+
CSRCS += devices/devzero.c
61+
endif
62+
63+
ifeq ($(CONFIG_TESTING_NUTS_DEVICES_DEVASCII),y)
64+
CSRCS += devices/devascii.c
65+
endif
66+
67+
ifeq ($(CONFIG_TESTING_NUTS_DEVICES_DEVCONSOLE),y)
68+
CSRCS += devices/devconsole.c
69+
endif
70+
71+
ifeq ($(CONFIG_TESTING_NUTS_DEVICES_DEVURANDOM),y)
72+
CSRCS += devices/devurandom.c
73+
endif
74+
75+
endif # CONFIG_TESTING_NUTS_DEVICES
76+
77+
include $(APPDIR)/Application.mk

0 commit comments

Comments
 (0)