Skip to content

Commit 3d837f2

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 6b27eb5 commit 3d837f2

File tree

6 files changed

+1384
-0
lines changed

6 files changed

+1384
-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: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
net_init_config:
15+
network_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_enabled: true
49+
ipv4_autoconf_enabled: true
50+
51+
# For this interface we do not know its name, but we know what device
52+
# it is bound to.
53+
- &device-interface
54+
device_name: eth_2
55+
set_name: test-eth1
56+
flags:
57+
- NET_IF_NO_AUTO_START
58+
- NET_IF_PROMISC
59+
ipv4:
60+
status: true
61+
ipv4_addresses:
62+
- 192.0.2.22/24
63+
gateway: 192.0.2.2
64+
time_to_live: 10
65+
multicast_time_to_live: 1
66+
dhcpv4_enabled: false
67+
dhcpv4_server:
68+
status: true
69+
base_address: 192.0.2.32
70+
71+
# This virtual interface bound to the first one
72+
- name: virt0
73+
bind_to: *main-interface
74+
flags:
75+
- NET_IF_IPV6_NO_MLD
76+
- NET_IF_NO_AUTO_START
77+
- ^NET_IF_PROMISC
78+
ipv6:
79+
status: true
80+
ipv6_addresses:
81+
- 2001:db8:111::2
82+
ipv4:
83+
status: false
84+
85+
# This VLAN interface that attaches to second Ethernet interface
86+
- &vlan-interface
87+
set_name: vlan0
88+
bind_to: *device-interface
89+
vlan:
90+
status: true
91+
tag: 2432
92+
ipv4:
93+
status: true
94+
dhcpv4_enabled: true
95+
96+
# This 2nd VLAN interface is attached to one of the Ethernet interfaces
97+
- set_name: vlan1
98+
bind_to: *main-interface
99+
vlan:
100+
status: true
101+
tag: 1234
102+
ipv4:
103+
status: true
104+
dhcpv4_enabled: true
105+
106+
# This virtual interface bound to the VLAN interface
107+
- name: virt1
108+
set_name: virt-over-vlan
109+
bind_to: *vlan-interface
110+
ipv6:
111+
status: true
112+
ipv6_addresses:
113+
- 2001:db8:abcd::11
114+
115+
# This interface IPv4 configuration is set to disabled
116+
# in which case its IPv4 configuration is skipped
117+
- name: dummy0
118+
ipv6:
119+
status: true
120+
ipv4:
121+
status: false
122+
ipv4_addresses:
123+
- 192.2.0.2
124+
gateway: 192.2.0.1
125+
time_to_live: 10
126+
multicast_time_to_live: 2
127+
128+
# This interface IPv4 and IPv6 configuration are both disabled.
129+
# Basically the interface is non functional for IP connectivity.
130+
- name: dummy1
131+
ipv6:
132+
status: false
133+
ipv4:
134+
status: false
135+
136+
ieee_802_15_4:
137+
status: true
138+
pan_id: 0xabcd
139+
channel: 26
140+
tx_power: 1
141+
security_key: [0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
142+
0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf]
143+
security_key_mode: 0
144+
security_level: 1
145+
ack_required: true
146+
bind_to: *device-interface
147+
148+
sntp:
149+
server: sntp.foo.bar
150+
timeout: 30
151+
bind_to: *vlan-interface

tests/net/lib/config/prj.conf

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

0 commit comments

Comments
 (0)