Skip to content

Commit 871f0bb

Browse files
committed
tests: net: config: Add tests for yaml based configuration
Add simple unit tests that verify that options specified in yaml file can be used to configure network stack. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 761a84c commit 871f0bb

File tree

6 files changed

+1411
-0
lines changed

6 files changed

+1411
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(iface)
6+
7+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/net/ip)
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# This is a network configuration data that is used to validate that the
2+
# configuration can be applied automatically when the device boots.
3+
#
4+
# In this test, we have multiple devices and network interface. The test
5+
# enables the network config library, it reads the configuration when the
6+
# device boots, and then the test checks that the configuration is applied
7+
# correctly to the network stack.
8+
#
9+
# Some of the network interfaces are dummy ones and some Ethernet ones.
10+
# The Ethernet devices are needed to validate the VLAN configuration.
11+
# The virtual interface is used to verity that it can be bound to some
12+
# other network interface.
13+
#
14+
networking:
15+
interfaces:
16+
# First Ethernet interface in the system. We change its name in the
17+
# testing process.
18+
- &main-interface
19+
name: eth0
20+
set_name: test-eth0
21+
set_default: true
22+
ipv6:
23+
status: true
24+
ipv6_addresses:
25+
- 2001:db8:110::1
26+
ipv6_multicast_addresses:
27+
- ff05::114
28+
- ff15::115
29+
prefixes:
30+
- address: "2001:db8::"
31+
len: 64
32+
lifetime: 1024
33+
hop_limit: 48
34+
multicast_hop_limit: 2
35+
dhcpv6:
36+
status: true
37+
do_request_address: true
38+
do_request_prefix: false
39+
ipv4:
40+
status: true
41+
ipv4_addresses:
42+
- 192.0.2.10/24
43+
ipv4_multicast_addresses:
44+
- 234.0.0.10
45+
gateway: 192.0.2.1
46+
time_to_live: 128
47+
multicast_time_to_live: 3
48+
dhcpv4:
49+
status: true
50+
ipv4_autoconf:
51+
status: true
52+
53+
# For this interface we do not know its name, but we know what device
54+
# it is bound to.
55+
- &device-interface
56+
device_name: eth_2
57+
set_name: test-eth1
58+
flags:
59+
- NET_IF_NO_AUTO_START
60+
- NET_IF_PROMISC
61+
ipv4:
62+
status: true
63+
ipv4_addresses:
64+
- 192.0.2.22/24
65+
gateway: 192.0.2.2
66+
time_to_live: 10
67+
multicast_time_to_live: 1
68+
dhcpv4:
69+
status: false
70+
dhcpv4_server:
71+
status: true
72+
base_address: 192.0.2.32
73+
74+
# This virtual interface bound to the first one
75+
- name: virt0
76+
bind_to: *main-interface
77+
flags:
78+
- NET_IF_IPV6_NO_MLD
79+
- NET_IF_NO_AUTO_START
80+
- ^NET_IF_PROMISC
81+
ipv6:
82+
status: true
83+
ipv6_addresses:
84+
- 2001:db8:111::2
85+
ipv4:
86+
status: false
87+
88+
# This VLAN interface that attaches to second Ethernet interface
89+
- &vlan-interface
90+
set_name: vlan0
91+
bind_to: *device-interface
92+
vlan:
93+
status: true
94+
tag: 2432
95+
ipv4:
96+
status: true
97+
dhcpv4:
98+
status: true
99+
100+
# This 2nd VLAN interface is attached to one of the Ethernet interfaces
101+
- set_name: vlan1
102+
bind_to: *main-interface
103+
vlan:
104+
status: true
105+
tag: 1234
106+
ipv4:
107+
status: true
108+
dhcpv4:
109+
status: true
110+
111+
# This virtual interface bound to the VLAN interface
112+
- name: virt1
113+
set_name: virt-over-vlan
114+
bind_to: *vlan-interface
115+
ipv6:
116+
status: true
117+
ipv6_addresses:
118+
- 2001:db8:abcd::11
119+
120+
# This interface IPv4 configuration is set to disabled
121+
# in which case its IPv4 configuration is skipped
122+
- name: dummy0
123+
ipv6:
124+
status: true
125+
ipv4:
126+
status: false
127+
ipv4_addresses:
128+
- 192.2.0.2
129+
gateway: 192.2.0.1
130+
time_to_live: 10
131+
multicast_time_to_live: 2
132+
133+
# This interface IPv4 and IPv6 configuration are both disabled.
134+
# Basically the interface is non functional for IP connectivity.
135+
- name: dummy1
136+
ipv6:
137+
status: false
138+
ipv4:
139+
status: false
140+
141+
ieee_802_15_4:
142+
status: true
143+
pan_id: 0xabcd
144+
channel: 26
145+
tx_power: 1
146+
security_key: [0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
147+
0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf]
148+
security_key_mode: 0
149+
security_level: 1
150+
ack_required: true
151+
bind_to: *device-interface
152+
153+
sntp:
154+
server: sntp.foo.bar
155+
timeout: 30
156+
bind_to: *vlan-interface

tests/net/lib/config/prj.conf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
CONFIG_NETWORKING=y
2+
CONFIG_NET_TEST=y
3+
CONFIG_ZTEST=y
4+
CONFIG_NET_LOG=y
5+
CONFIG_LOG=y
6+
CONFIG_MAIN_STACK_SIZE=2048
7+
8+
CONFIG_NET_IPV6=y
9+
CONFIG_NET_IPV4=y
10+
CONFIG_NET_IPV6_DAD=n
11+
CONFIG_NET_IPV6_MLD=n
12+
CONFIG_NET_IPV6_MAX_NEIGHBORS=8
13+
CONFIG_NET_IPV6_ND=n
14+
CONFIG_NET_MAX_NEXTHOPS=8
15+
CONFIG_NET_IPV4_AUTO=n
16+
CONFIG_NET_IPV4_ACD=n
17+
CONFIG_NET_DHCPV4=y
18+
CONFIG_NET_DHCPV4_SERVER=y
19+
CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT=32
20+
CONFIG_NET_DHCPV6=y
21+
22+
CONFIG_NET_UDP=y
23+
CONFIG_NET_TCP=y
24+
25+
CONFIG_NET_MAX_CONTEXTS=4
26+
27+
CONFIG_NET_L2_DUMMY=y
28+
CONFIG_NET_L2_ETHERNET=y
29+
CONFIG_NET_L2_ETHERNET_MGMT=y
30+
CONFIG_NET_L2_VIRTUAL=y
31+
CONFIG_NET_INTERFACE_NAME_LEN=15
32+
33+
CONFIG_NET_VLAN=y
34+
CONFIG_NET_VLAN_COUNT=2
35+
36+
CONFIG_ENTROPY_GENERATOR=y
37+
CONFIG_TEST_RANDOM_GENERATOR=y
38+
39+
CONFIG_NET_PKT_TX_COUNT=10
40+
CONFIG_NET_PKT_RX_COUNT=10
41+
CONFIG_NET_BUF_RX_COUNT=10
42+
CONFIG_NET_BUF_TX_COUNT=10
43+
44+
CONFIG_NET_IF_MAX_IPV6_COUNT=8
45+
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=6
46+
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
47+
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=2
48+
CONFIG_NET_IF_MAX_IPV4_COUNT=8
49+
50+
CONFIG_NET_CONFIG_SETTINGS=y
51+
CONFIG_NET_CONFIG_AUTO_INIT=y

0 commit comments

Comments
 (0)