Commit graph

1722 commits

Author SHA1 Message Date
Robert Lubos e836427f97 tests: net: socket: reuseaddr_reuseport: Fix userspace testing
net_context_foreach() is not a systemcall, therefore should not be used
from userspace threads. Usage of this API made SO_REUSADDR/SO_REUSEPORT
userspace tests unfunctional (crashing).

Fix this by using CONFIG_NET_TCP_TIME_WAIT_DELAY instead for tests that
involve TCP connections. Other tests don't really need to wait as
there's no teardown delay on UDP or unconnected TCP contexts.

Additionally, remove the platform exclude for qemu_x86 platform, as this
was the sole reason the tests were crashing on that platform.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-28 15:15:44 +02:00
Jukka Rissanen 729a8e622b tests: net: mld: Fix ICMP usage in the test
Convert the test to use new ICMP API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen 274f5d9a4b tests: net: ipv6_fragment: Fix ICMP usage in the test
Convert the test to use new ICMP API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen 8f74148bdd tests: net: icmpv6: Convert to use new ICMP API
Converting the ICMPv6 tests to use the new ICMP API so that
the tests pass.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen fe5638cf0f tests: net: icmpv4: Convert to use new ICMP API
Converting the ICMPv4 tests to use the new ICMP API so that
the tests pass.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen 44151d5ccd tests: net: icmp: Add offloaded ICMP API tests
Add some tests that verify that offloaded ICMP API works
as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Jukka Rissanen 19d1dd747f tests: net: icmp: Add test cases for new ICMP API
Tests cases for new ICMP API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Robert Lubos d9f4c1cff0 tests: net: dhcpv6: Add tests
Add tests for the DHCPv6 library. The tests verify that:
* message format is valid for the outgoing messages
* incoming messages are only processed in respective states
* processing through standard DHCPv6 transactions is correct
  (Solicit/Confirm/Renew/Rebind)

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-28 09:31:20 +02:00
Florian Grandel a12a6ab5b9 drivers: ieee802154: introduce channel pages
Replaces the previous approach to define bands via hardware capabilities
by the standard conforming concept of channel pages.

In the short term this allows us to correctly calculate the PHY specific
symbol rate and several parameters that directly depend from the symbol
rate and were previously not being correctly calculated for some of the
drivers whose channel pages could not be represented previously:
* We now support sub-nanosecond precision symbol rates for UWB. Rounding
  errors are being minimized by switching from a divide-then-multiply
  approach to a multiply-then-divide approach.
* UWB HRP: symbol rate depends on channel page specific preamble symbol
  rate which again requires the pulse repetition value to be known
* Several MAC timings are being corrected based on the now correctly
  calculated symbol rates, namely aTurnaroundTime, aUnitBackoffPeriod,
  aBaseSuperframeDuration.

In the long term, this change unlocks such highly promising functional
areas as UWB ranging and SUN-PHY channel hopping in the SubG area (plus
of course any other PHY specific feature).

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-27 12:44:15 -04:00
Seppo Takalo b9028bb722 net: lwm2m: Remove unneeded function pointer parameter
lwm2m_udp_receive() is only called with same function
pointer, so there no need to carry that in the parameter.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo f227b56792 net: lwm2m: Separate opaque content format into its own
Opaque content format is not part of clear-text, so it
should be separated into its own file.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-27 15:44:30 +02:00
Seppo Takalo 7b4f22edd1 net: lwm2m: Add functional tests for LwM2M against Leshan
Use the new Pytest integration to run testcases against Leshan.

Test with:
twister -T tests/net/lib/lwm2m/functional -p native_posix -vv

This requires Leshan running in localhost using following setup:
tcp/8080 Leshan web interface and REST API
tcp/8081 Leshan bootstrap server REST API
udp/5683 Leshan non-secure CoAP
udp/5684 Leshan DTLS CoAP
udp/5783 non-secure Bootstrap CoAP
udp/5684 DTLS Bootstrap CoAP

Leshan and Boostrap server must be reachable from native_posix
run using IP address 192.0.2.2 as in most of the examples.

Tests are written from test spec;
OMA Enabler Test Specification (Interoperability) for
Lightweight M2M

Following tests are implemented in this commit:
* LightweightM2M-1.1-int-0 – Client Initiated Bootstrap
* LightweightM2M-1.1-int-1 – Client Initiated Bootstrap Full (PSK)
* LightweightM2M-1.1-int-101 – Initial Registration
* LightweightM2M-1.1-int-102 – Registration Update
* LightweightM2M-1.1-int-104 – Registration Update Trigge
* LightweightM2M-1.1-int-105 - Discarded Register Update
* LightweightM2M-1.1-int-107 – Extending the lifetime of a registration
* LightweightM2M-1.1-int-108 – Turn on Queue Mode
* LightweightM2M-1.1-int-109 – Behavior in Queue Mode
* LightweightM2M-1.1-int-201 – Querying basic information in Plain Text
* LightweightM2M-1.1-int-203 – Querying basic information in TLV format
* LightweightM2M-1.1-int-204 – Querying basic information in JSON format
* LightweightM2M-1.1-int-205 – Setting basic information in Plain Text
* LightweightM2M-1.1-int-211 – Querying basic information in CBOR format
* LightweightM2M-1.1-int-212 – Setting basic information in CBOR format
* LightweightM2M-1.1-int-215 – Setting basic information in TLV format
* LightweightM2M-1.1-int-220 – Setting basic information in JSON format
* LightweightM2M-1.1-int-221 – Attempt to perform operations on Security
* LightweightM2M-1.1-int-401 – UDP Channel Security – PSK Mode

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-26 16:53:16 +02:00
Pieter De Gendt 09e58e1ecc test: http_server: Fix copy-paste references
Fixed HTTP resource references in test_HTTP_RESOURCE_DEFINE.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-09-22 13:44:13 +02:00
Marcin Gasiorek 4ebf6e5fac tests: net: Add missing tests to net_pkt_clone
Add tests for flag cloning and couple extra.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2023-09-21 13:36:20 +02:00
Tobias Frauenschläger 1de4e73e6d tests: net: sockets: add tests for SO_REUSEPORT
This commit adds unit tests for the SO_REUSEPORT sockets option. It also
fixes some bugs in other tests triggered by the new features.

Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
2023-09-20 08:56:31 +02:00
Tobias Frauenschläger 795c96494a tests: net: sockets: add tests for SO_REUSEADDR
This commit adds unit tests for the SO_REUSEADDR socket option to test
the different possible scenarios for the option to work correctly.

There is also a fix for the TCP testsuite to make a now failing test
pass again due to a TIME_WAIT socket.

Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
2023-09-20 08:56:31 +02:00
Chaitanya Tata 40ee8791f2 net: socketpair: Fix use after free
In low memory conditions, its possible for socketpair memory allocation
to fail and then the socketpair is freed but after that the remote
semaphore is released causing a crash.

Fix this by freeing the socketpair after releasing the semaphore. Add a
test case to induce low memory conditions (low HEAP and high socketpair
buffer size), with the fix issue is not seen.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-18 20:34:12 +02:00
Manuel Argüelles 2d49ab6623 tests: mqtt: disable debug log level
Avoid to use debug log level for all modules and keep it only for MQTT
and NET related modules.

mr_canhubk3 board will fail to initialize the on-board watchdog within
the expected window causing a board reset, due to the amount of log
messages being printed. Other boards may also be affected.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-09-12 10:56:35 +02:00
Huifeng Zhang 662a14a25e tests: net: lib: lwm2m: fix the missing float support
The tests `content_json` and `content_plain_test` depend on the float
support of libc. After PR##57340, Picolibc would be selected in
these two tests and the `PICOLIBC_IO_FLOAT` won't be selected if
the platform doesn't select `FPU`.

This commit select `CONFIG_PICOLIBC` and `CONFIG_PICOLIBC_IO_FLOAT`
for these two tests.

Signed-off-by: Huifeng Zhang <Huifeng.Zhang@arm.com>
2023-09-11 16:58:10 -04:00
Seppo Takalo 4798187801 test: lwm2m: Fix minor timing issue
RD client tests work well on emulated (fast) environments
but tend to fail on real HW with real time sleeps.
This change refactors wait_for_service() to be a bit more
syncronous on background service, instead of relying hardcoded
sleeps.

Fixes #61824

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-09-11 19:56:08 +02:00
Robert Lubos 16870cd664 tests: net: tcp: Add test case for SYN/RST+ACK scenario
Add TCP test case which verifies that if RST+ACK packet is received
during TCP handshake, the connection is brought down and
net_context_connect() fails.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-09-07 11:41:52 +02:00
Florian Grandel fa4f15a7d5 tests: net: conn_mgr_monitor: increase stack size
Fixes the broken conn_mgr_monitor test.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-09-06 09:32:36 +02:00
Alberto Escolar Piedras 4f0b2a0bf6 tests lwm2m_rd_client: Allow only on native_posix
This test is too dependent on the exact order of events,
and known to fail in most platforms but native_posix.
To mitigate the issue and avoid blocking development
due to failed CI tests, let's only allow the test in
native_posix.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-09-01 13:59:12 +02:00
Jukka Rissanen 7aa4904b5a net: socket: Change SO_BINDTODEVICE to use interface name
Make sure we use the network interface name (if configured)
instead of device name when binding to certain network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-08-31 14:43:36 +02:00
Jukka Rissanen bb5885580f tests: net: iface: Add unit test for interface name support
Check that we can set and get the network interface name.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-08-31 14:43:36 +02:00
Georges Oates_Larsen b25ea4742e net: conn_mgr: Rename connectivity monitor
The connectivity monitoring subfeature of conn_mgr is currently also
named conn_mgr, which is confusing.

This commit renames it to conn_mgr_monitor, or conn_mgr_mon for short,
for clarity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Georges Oates_Larsen 6d2ce0b30b net: conn_mgr: Create separate connectivity implementation API.
Splits many definitions from conn_mgr_connectivity.h off into their own
header, conn_mgr_connectivity_impl.h

conn_mgr_connectivity.h now focuses solely on user/application-facing
APIs, and conn_mgr_connectivity_impl now contains all functions, utils,
definitions intended for use by connectivity implementations, including
conn_mgr_if_get_binding, which is now available for use by connectivity
implementations.

This lays the foundation for allowing connectivity implementations
easier and safer access to their internal state through internal APIs.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Robert Lubos 9a90440226 tests: net: sockets: misc: Add getsockname() tests
Add tests which verify that getsockname() function works as expected.

Additionally, add a teardown delay in tests involving TCP, to make sure
all resources are released before the test ends, not to interfere with
other tests.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-27 07:35:34 -04:00
Georgij Cernysiov 986fb1e85d tests: net: lib: coap: test coap_packet_set_path
Adds testing of 'coap_packet_set_path'.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2023-08-25 13:15:12 +02:00
Robert Lubos e8a00b7ef6 tests: net: socket: udp: Add test to verify connected socket behavior
Add test cases which verify that when UDP socket is connected, it only
accepts datagrams from a remote peer it was connected to, and not
others.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-25 10:31:19 +02:00
Seppo Takalo e977fde7ee tests: lwm2m: Add more tests to LwM2M registry
Add module tests for all data types and most of deprecated
functions as well.

Refactor event wainting to expect_lwm2m_rd_client_event() which
does not care about the index, just the order.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-24 22:07:32 +01:00
Seppo Takalo 0da806736e tests: lwm2m: Add engine tests on security and socket opts
Add tests regarding socket options and various security
options.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-24 22:07:32 +01:00
Seppo Takalo 40dd0c1fa0 tests: lwm2m: Add bootstrap tests into RD client tests
Add bootstrap and few corner cases into RD client tests
to improve code coverage.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-24 22:07:32 +01:00
Sjors Hettinga 2adc95ae7a tests: net: tcp: Add testcase for validating retransmitted FIN seq
Implemented testcase to check if the retransmitted FIN packet
from the FIN1 state has the correct sequence number.
Also fix the endianness conversion of sequence numbers in the
tests to use 32-bit as it should instead of 16-bit.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-22 10:00:14 +02:00
Sjors Hettinga 330561e47a tests: net: tcp: Add a testcase for data beyond TCP socket closure
After the TCP socket has been closed, it should not accept any new data
and send a RST packet if it does receive some.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-22 10:00:14 +02:00
Christopher Friedt 9d16fbb70c tests: net: socket: tcp: reduce number of file descriptors
For some reason, tests/net/socket/tcp/net.socket.tcp.preempt
was failing to link for vmu_rt1170 with these changes, and
for some reason reducing CONFIG_POSIX_MAX_FDS from 20 to 10
resolves that issue.

ld.bfd: scripts/build/gen_kobject_placeholders.py \
  did not reserve enough space for kobject rodata.
Memory region         Used Size  Region Size  %age Used
           FLASH:      287860 B        64 MB      0.43%
             RAM:       86460 B       512 KB     16.49%
           OCRAM:          0 GB       256 KB      0.00%
          OCRAM1:          0 GB       512 KB      0.00%
          OCRAM2:          0 GB       512 KB      0.00%
            ITCM:          0 GB       256 KB      0.00%
            DTCM:       13908 B       256 KB      5.31%
        IDT_LIST:          0 GB         2 KB      0.00%
collect2: error: ld returned 1 exit status

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt 4cc5102225 net: sockets: udp: test FIONREAD with ipv4 and ipv6 sockets
The FIONREAD ioctl (or rather ZFD_IOCTL_FIONREAD) returns the
number of bytes available on the socket that can be read
immediately.

Test that the ioctl behaves according to the expectation.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt 0f139736f3 tests: net: socket: udp: clear fdtable in after()
Add an `after()` function that is executed after each test in
the testsuite.

Previously, even if one one test failed, it would calls almost
all subsequent tests to fail. This way, other tests can still
succeed.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt e7182beb40 tests: net: socket: tcp: clear fdtable in after()
Add an `after()` function that is executed after each test in
the testsuite.

Previously, even if one one test failed, it would calls almost
all subsequent tests to fail. This way, other tests can still
succeed.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt 37ca8e0697 net: sockets: tcp: test FIONREAD with ipv4 and ipv6 TCP sockets
The FIONREAD ioctl (or rather ZFD_IOCTL_FIONREAD) returns the
number of bytes available on the socket that can be read
immediately.

Test that the ioctl behaves according to the expectation.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt f1d7c0b196 tests: net: socketpair: use a test fixture to deduplicate code
A fair bit of setup / teardown code was being duplicated in many
test cases in the socketpair testsuite.

Take advantage of the `setup()`, `before()`, and `after()`
functions in the new ZTest API.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt 2116c553a1 tests: net: socketpair: add fionread test
Add a test to exercise
`zsock_ioctl(fd, ZFD_IOCTL_FIONREAD, &avail)`.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Christopher Friedt 0f143c9ec9 tests: net: socketpair: reduce requirements for test
Reduce additional requirements for the socketpair testsuite.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Lukas Woodtli 6277a3904a net: coap: Add function for removing CoAP options
The provided function allows to remove a CoAP option in a
message. This is useful for reusing parts of a message.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-08-16 17:06:41 +02:00
Seppo Takalo fbabc0cd3d test: lwm2m: Allow longer waits and stop properly
RD-client tests should wait longer for expected events.
Also the stubbed service worker should be stopped properly
after tests.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-16 10:21:46 +02:00
Seppo Takalo 01dab8690a net: lwm2m: Do not immediately close connection at Bootstrap
When BOOTSTRAP FINNISH message was received, it caused
engine to immediately switch to BOOTSTRAP_TRANS_DONE state
which then closed the connection.
Ack packet was still on the send-queue so it never got send before close().

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-16 10:21:46 +02:00
Daniel Leung efeb2d13a7 tests: net: renames shadow variables
Renames	shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:43 +00:00
Robert Lubos 68be56d282 tests: net: tcp: Fix server tests
Fixing the bug with shadowed ret variable (and hence not returning
timeout error) reveled another bug in TCP server tests. Here, the
listening context was incorrectly used to receive new data, and since it
never arrived, the function timed out.

This commits fixes that issue, and limits the retransmission timeout to
ensure that Nagle's algorithm impact does not affect test timings.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-08-09 20:01:39 -04:00
Sjors Hettinga 9d2c17dee2 tests: net: tcp: Default disable logging in TCP socket test
Accidentally statements to enable logging in the TCP socket test
where pushed. This broke some tests running on real devices due
to the additional code size.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-09 08:34:06 +00:00
Benjamin Perseghetti 79796d5c74 tests: net/socket/socketpair: exclude vmu and 1160
This has failed in repeated CI runs. Filed an issue
for having it checked. Excluding it until it's
fixed.

Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
2023-08-08 12:09:10 -05:00
Sjors Hettinga 5b640ec9db net: tcp: Implement TCP new Reno collision avoidance
To avoid a TCP connection from collapsing a link, implement a collision
avoidance algorithm. Initially TCP new Reno is implemented for its
simplicity.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-08-04 15:05:17 +02:00
Alberto Escolar Piedras 957ea755bb test lwm2m/engine: Fix build warning
Fix a build warning that is generated by new
enough compilers, when they detect the sprintf()
may overflow the destination buffer lenght.

The code which was generating the warnig was
actually not used, so we just remove it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-08-02 23:33:37 +02:00
Jaxson Han 3509f8b977 tests: net: lib: lwm2m: Use 1 cpu only as a workaround
These testcases are not SMP-safe, will fail on all SMP boards. Simply
turning them to 1cpu test  can not fix the issue.

So, setting CONFIG_MP_MAX_NUM_CPUS to 1 as a workaround.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
2023-08-02 16:34:04 +02:00
Seppo Takalo 518bbc1303 net: lwm2m: Refactor RD client to be tickless
Call RD client service only when there is state transitioning.
Remove periodic 500 ms timer.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-01 12:07:12 +02:00
Seppo Takalo 1dfa711167 net: lwm2m: Create socketpair that can wake up zsock_poll()
Allow socket-loop to wake up immediately, if there are changes,
instead of waiting for zsock_poll() to timeout.
This change makes engine more reactive and removes
hard coded timeout from zsock_poll().

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-08-01 12:07:12 +02:00
Florian Grandel a4cd5cee40 drivers: ieee802154: consistent high res timestamps
The IEEE 802.15.4 API and networking subsystem were using several
inconsistent timestamp resolutions and types. This change defines all
timestamps with nanosecond resolution and reduces the number of
available types to represent timestamps to two:
* `struct net_ptp_time` for PTP timestamps
* `net_time_t` for all other high resolution timestamps

All timestamps (including PTP timestamps) are now referred to a
"virtual" local network subsystem clock source based on the well-defined
types above. It is the responsibility of network subsystem L2/driver
implementations (notably Ethernet and IEEE 802.15.4 L2 stacks) to ensure
consistency of all timestamps and radio timer values exposed by the
driver API to such a network subsystem uptime reference clock
independent of internal implementation details.

The "virtual" network clock source may be implemented based on arbitrary
hardware peripherals (e.g. a coarse low power RTC counter during sleep
time plus a high resolution/high precision radio timer while receiving
or sending). Such implementation details must be hidden from API
clients, as if the driver used a single high resolution clock source
instead.

For IEEE 802.15.4, whenever timestamps refer to packet send or receive
times, they are measured when the end of the IEEE 802.15.4 SFD (message
timestamp point) is present at the local antenna (reference plane).

Due to its limited range of ~290 years, net_time_t timestamps (and
therefore net_pkt timestamps and times) must not be used to represent
absolute points in time referred to an external epoch independent of
system uptime (e.g.  UTC, TAI, PTP, NTP, ...).

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-28 09:06:35 +00:00
Robert Lubos ea9d8b7295 tests: net: if: Add tests to verify net_if_ipv4/6_addr_foreach()
Add tests cases which verify that net_if_ipv4/6_addr_foreach() executes
callbacks properly on assigned addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-25 14:18:54 +02:00
Seppo Takalo 27a695dda0 tests: coap_client: Zero-initialize address structures
Even though tests don't use the address, it causes warnings
on static analyzers.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-07-18 16:22:10 +02:00
Florian Grandel b106c21acd net: l2: ieee802154: unified assertion order
Small refactoring that unifies the assertion order for improved
consistency across tests - placing the SUT before the expected value
everywhere.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-14 09:38:01 +02:00
Florian Grandel cffb1a448e net: l2: ieee802154: test disassociation from coordinator
Introduces an integration test that simulates an incoming disassociaton
notification from a coordinator.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-14 09:38:01 +02:00
Florian Grandel 111a87efb1 net: l2: ieee802154: test enddevice disassociation
Adds test coverage for the disassociation shell command that
disassociates the enddevice by notifying its coordinator.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-14 09:38:01 +02:00
Florian Grandel 81c1f19f1b net: l2: ieee802154: shell set_ext_addr test coverage
Introduces an integration test that covers the set_ext_addr shell
command.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-14 09:38:01 +02:00
Chaitanya Tata 980ad00f10 tests: wifi: Add Wi-Fi test suite
This adds Wi-Fi tests for both offloaded and newly introduced network
manager managed interface. Only scan op is used to verify the network
manager code.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-07-11 14:55:30 +02:00
Florian Grandel 27bfe68204 net: l2: ieee802154: mgmt: improve association procedure spec compliance
This change introduces test coverage for association request and
response. Based on this coverage, several closely related issues were
found in the association process which cannot be split into separate
changes without breaking the build.

Most notably did the associate and disassociate net_mgmt commands send
already encoded IEEE 802.15.4 MPDUs to L3 rather than L2. L3 treated
them as payload and made L2 wrap them with another LL header/footer
which produced invalid packets.

The tests also enforce better aligment of the association process with
the IEEE 802.15.4-2020 standard:

* Association requests now ask for ACK as required by the standard. The
  fake driver was enhanced to produce ACK packages when requested.
* macPanId and macCoordinator* MAC PIB attributes are set in the right
  order for improved filtering of association responses.
* The coordinator may decide not to assign a short address to the end
  device even when associated. This is now supported.
* The coordinator may or may not use a short address. Coordinators
  choosing not to support short addresses are now supported.
* Updating the association will now remove any previously added short
  address from the hardware filter.
* The short address may no longer be changed by the user while
  associated to a PAN. Only the coordinator is allowed to allocate short
  addresses.
* Validation of outgoing and incoming association request/response
  packets is improved.

All changes are documented by pointers into the spec.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:29:10 +02:00
Marcin Gasiorek eb16ab551f tests: net: pkt_filter: Add TCs for new hooks
Add new TCs to cover new hooks functionality.
These tests implement simple IP filter.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2023-07-10 09:27:47 +02:00
Georges Oates_Larsen ad6fdaf2c2 net: conn_mgr: Bulk convenience functions
To further reduce the need for networking boilerplate in applications,
provide bulk versions of net_if_up, net_if_down, conn_mgr_if_connect,
and conn_mgr_if_disconnect that affect all available / eligible ifaces
at once.

Since it is not intuitive whether these functions should affect ifaces
which conn_mgr is ignoring, these functions take an argument that allows
this to be specified by the application.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Georges Oates_Larsen b65613e79c net: conn_mgr: Support Auto-Down
To reduce the amount of boiler-plate needed in applications, this commit
grants conn_mgr the ability to automatically take ifaces that have given
up on connecting into the admin-down state.

Tests adjusted as appropriate.

This behavior can be disabled globally by disabling
NET_CONNECTION_MANAGER_AUTO_IF_DOWN, or disabled per-iface using the
CONN_MGR_IF_NO_AUTO_DOWN flag.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Georges Oates_Larsen f3d75c4c65 net: conn_mgr: Support Auto-Connect
To reduce the need for boilerplate in application code, conn_mgr now
supports an auto-connect feature on all ifaces with connectivity
bindings.

conn_mgr will automatically call conn_mgr_if_connect on any iface with a
connectivity binding that enters the admin-up state, unless the newly
added CONN_MGR_IF_NO_AUTO_CONNECT flag has been set for that iface.

Also adjust automated tests to account for and take advantage of this
behavior.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Georges Oates_Larsen 8785a9f424 net: conn_mgr: Minor fixes
- Add missing event sleep after taking all ifaces up in
  test_connect_disconnect.
- Add missing event sleep after resetting ifaces in conn_mgr_conn_before
- Fix typo in comment for internal state flags.
- Add missing NET_MGMT_EVENT_BIT to conn_mgr_connectivity event
  definitions.
- Missing net_mgmt.h include in conn_mgr_connectivity.h
- Split conn_mgr_conn iface reset into network and state resets, before
  and after event sleep, so that triggered events do not corrupt the
  state reset.
- Reduce SIMULATED_EVENT_DELAY to 100ms to avoid timeouts on real-time
  targets.
- Use macro for simulated event wait times.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-06-30 16:10:23 +02:00
Jarno Lämsä 7ae4e24728 net: lib: lwm2m: Use int16_t for signal strength
The signal strength for the connectivity monitor was
defined as int8_t, however this was too small for
LTE RSRP values, which has range [-140,-44].

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-06-29 10:04:14 +00:00
Jarno Lämsä a3612c70c8 tests: Ztest tests for coap client
Test handling multiple requests.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-06-28 15:19:34 +02:00
Florian Vaussard 90355f143f tests: net: iface: verify multicast address not removed if used
If two IPv6 addresses have the same solicited-node multicast address
because they derive from the same EUI-64 interface identifier, make sure
that the solicited-node multicast address is not removed when one of the
IPV6 address is removed but only when both addresses are removed.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2023-06-28 06:51:21 +00:00
Florian Vaussard 6837229ff2 tests: net: iface: remove useless assignment
The value of in6addr_mcast is overwritten in iface_setup() before being
assigned to the interface. Remove the useless initial value since it is
never used, in order to avoid misleading information.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2023-06-28 06:51:21 +00:00
Seppo Takalo 6050a10f8b net: lwm2m: Allow setting string to zero length
Lwm2m firmware object have defined a write of zero length
string as a cancel operation.
So allow lwm2m_set_opaque(path, NULL, 0);

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-27 12:18:35 +00:00
Seppo Takalo a7498c39e2 tests: net: lwm2m: Remove unnecessary filtering
Content-format tests do not require network or
Newlibc, so by removing these filters.
Defined a native_posix as the only integration platform
because all simulated arm-zephyr-eabi platforms are
filtered out by Twister.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-27 00:52:31 +02:00
Seppo Takalo e92f8acff9 tests: net: lwm2m: Remove timing sensitive assert
As the lwm2m_reset_message() is stubbed, it does not remove
a message from rettry queue. Therefore depending on the
simulation speed, retries can happen one or many times.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-27 00:52:31 +02:00
Seppo Takalo 0f6ded7989 test: net: lwm2m: Fix build warning about unitialized vars
Few variables were uninitialized on certain cases.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-27 00:52:31 +02:00
Seppo Takalo 14573fcbf6 tests: lwm2m: Fix too small test buffer
ZTEST(lwm2m_registry, test_strings) is using opaque resource
0/0/3 to write a test string "coap://127.0.0.1" which
happens to be same length as default key size.
Need more room to add end marker and verify it.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-26 14:18:06 +00:00
Seppo Takalo dc7fbc5d2e net: lwm2m: Fix pause and resume on non-closed sockets
Pause and resume functionality was written into assumption
that sockets are closed before resuming.

With use new options CONFIG_LWM2M_RD_CLIENT_STOP_POLLING_AT_IDLE
or CONFIG_LWM2M_RD_CLIENT_LISTEN_AT_IDLE this is not always true.
Fix the state machine, so that on those cases, sockets are not
closed and resume is always similar like from the QUEUE mode.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-26 12:37:13 +00:00
Seppo Takalo 5c1228770e net: lwm2m: Add support for X509 certificates
Add support for using X509 certificates.
Default settings use ECDSA certificates with SHA256 hash.

When different settings are required clients should overwrite
struct lwm2m_ctx->load_credentials() and
struct lwm2m_ctx->set_socketoptions()

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-26 12:35:29 +00:00
Seppo Takalo 95cef5f3ab net: lwm2m: Ensure string termination
When writing string data to resources which are string types,
we should count in the terminating character into the data length.

Corner cases exist where LwM2M resource type is opaque but
lwm2m_get_string() or lwm2m_set_string() are used to read/write
the data. We must ensure string termination on those case, but
terminating character must not be stored in the engine buffer
or counted in the data length as this might be considered
as part of the binary data.

Fixes #59196

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-06-21 10:42:31 +02:00
Florian Grandel 267db64f39 net: l2: ieee802154: fix acknowledgment procedure
The ACK procedure had the following issues:

- MAC commands were not acknowledged.

- When the package is a broadcast package the package must not be
  acknowledged.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 7571be3261 net: l2: ieee802154: deprecate NET_L2_IEEE802154_ACK_REPLY
Acknowledgment is mandatory if legitimately requested by the package's
"ACK requested" flag. The L2 layer will have to ensure that compliant
ACK packages will always be sent out automatically as required by the
standard.

For IEEE 802.15.4 compliance, the NET_L2_IEEE802154_ACK_REPLY option is
therefore being deprecated.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel f96b620d12 net: l2: ieee802154: properly handle TX HW capabilities
The existing calls to ieee802154_radio_send() and soft MAC ACK handling
were inconsistent and/or not properly integrated with more recent
radio driver capabilities as CSMA/CA and ACK in hardware.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 1ee4d3ed77 net: l2: ieee802154: document L1/L2 sep. of concerns
The method ieee802154_radio_handle_ack() does not belong to the
PHY/radio layer but to the L2 layer. It is a callback called from the
radio layer into the L2 layer and to be implemented by all L2 stacks.
This is the same pattern as is used for ieee802154_init(). The
'_radio_' infix in this function is therefore confusing and
conceptually wrong.

This change fixes the naming inconsistency and extensively documents
its rationale.

It is assumed that the change can be made without prior deprecation of the
existing method as in the rare cases where users have implemented custom
radio drivers these will break in obvious ways and can easily be fixed.

Nevertheless such a rename would not be justified on its own if it were
not for an important conceptual reason:

The renamed function represents a generic "inversion-of-control" pattern
which will become important in the TSCH context: It allows for clean
separation of concerns between the PHY/radio driver layer and the
MAC/L2 layer even in situations where the radio driver needs to be
involved for performance or deterministic timing reasons. This
"inversion-of-control" pattern can be applied to negotiate timing
sensitive reception and transmission windows, it let's the L2 layer
deterministically timestamp information elements just-in-time with
internal radio timer counter values, etc.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel ffcae5f029 net: l2: ieee802154: separate CCA and retransmission
The IEEE 802.15.4 standard clearly separates clear channel assessment
from retransmission. This separation of concern was not represented in
the current channel access vs. retransmission implementation which
resulted in considerable duplication of code and logic.

This change removes the duplication of logic and encapsulates the
resulting functions in a private API that may only be used from within
Zephyr's native L2 layer.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Bjarki Arge Andreasen 22152915ab drivers/gsm_ppp: Update existing modules to use PPP L2
This commit replaces the workarounds spread around the
drivers and subsystems with the updated PPP L2
interface.

Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
2023-06-17 07:46:21 -04:00
Florian Grandel b224a099fd net: l2: ieee802154: standardize RSSI value
The RSSI value in net_pkt (net_pkt_cb_ieee802154.rssi) was used
inconsistently across drivers. Some drivers did cast a signed dBm value
directly to net_pkt's unsigned byte value. Others were assigning the
negative value of the signed dBm value and again others were offsetting
and stretching the signed dBm value linearly onto the full unsigned byte
range.

This change standardizes net_pkt's rssi attribute to represent RSSI on
the RX path as an unsigned integer ranging from 0 (–174 dBm) to 254 (80
dBm) and lets 255 represent an "unknown RSSI" (IEEE 802.15.4-2020,
section 6.16.2.8). On the TX path the rssi attribute will always be
zero. Out-of-range values will be truncated to max/min values.

The change also introduces conversion functions to and from signed dBm
values and introduces these consistently to all existing call sites. The
"unknown RSSI" value is represented as INT16_MIN in this case.

In some cases drivers had to be changed to calculate dBm values from
internal hardware specific representations.

The conversion functions are fully covered by unit tests.

Fixes: #58494

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 07:16:32 -04:00
Andrei Emeltchenko 2b607733e6 tests: coap_client: Type case to uint8_t after shift
Type casting to uint8_t before shift by 8 does not make sense.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-05-30 13:04:13 -04:00
Robert Lubos cf15f0e48e tests: net: socket: tls: Verify accept is interrupted correctly on close
Add similar test as for TCP, that verifies that accept() call is
interrupted correctly when the socket is closed from another thread.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-29 14:34:03 -04:00
Robert Lubos af8c980e51 tests: net: socket: tcp: Verify accept is interrupted correctly on close
Add test that verifies that accept() call is interrupted correctly when
the socket is closed from another thread.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-29 14:34:03 -04:00
Jarno Lämsä 2d06f8061b tests: Add ztest tests for coap client
Add tests for coap client and stubs for isolating the tests.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-05-26 09:44:50 -04:00
Robert Lubos 1d5b3af3c1 tests: net: socket: tcp: Verify recv is interrupted correctly on close
Add test that verifies that recv() call is interrupted correctly when
the socket is closed from another thread.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-26 09:05:12 -04:00
Anas Nashif 75c11c0564 tests: net: socket: fix test identifier
Remove definition of testcases in yaml file, those are now detected from
binary.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-05-25 04:44:11 -04:00
Florian Grandel ea6a55afad net: l2: ieee802154: zero-copy encryption
Currently the insertion of an authentication tag requires a memcpy() call
and breaks encapsulation.

This change removes the need for memcpy() and improves the encapsulation
by calculating and reserving the required headspace early on while
keeping insertion where it belongs in the outgoing security procedure.

This is also a preparation for improved standard compliance of the
outgoing security procedure which is scheduled for a later commit.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel 315394eb53 net: l2: ieee802154: consistently name authtag length
The naming of variables and arguments containing the authentication
tag length was inconsistent:

* Naming inconsistency between header "length" vs. authtag "size"
  in the same API calls
* "Tag" rather than "Auth[orization ]Tag" in external API calls
  which is too generic from a compliance and readability viewpoint.

This is in preparation to zero-copy authentication support.

Almost all call sites will be subject to required structural changes
later on so no relevant git blame noise/history loss will be introduced
by this naming change in the long run.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Florian Grandel fc879ffa16 net: l2: ieee802154: payload length coverage
This change introduces test coverage for payload length calculation
to stabilize the change introduced earlier and ensure that future
changes will not cause regressions in that area.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Florian Grandel ca6d552bbb net: l2: ieee802154: fix payload handling
The current implicit MAC payload length algorithm (based on
an otherwise irrelevant footer pointer) produces invalid
(non-standard) values for beacon and command frames.

This change produces standard-conforming MAC payload length
values and simplifies access to payload length.

It would have been possible to fix the current footer pointer
based approach but there are arguments in favor of the new
approach:
- The footer pointer is used nowhere in the current code
  base and makes length calculations rather non-obvious.
- The new approach does not use more memory and is easier
  to understand and use.
- This change is a first step to support of IEEE 802.15.4
  information element (IE) support. At a later stage the
  distinction between MAC payload length and frame payload
  length will be introduced and become relevant to
  distinguish between header and payload IEs. At that point
  the current implicit length calculation algorithm will
  break down anyways.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Florian Grandel 988ffe9c48 tests: net: l2: ieee802154: active scan shell/mgmnt coverage
This change introduces integration test coverage for the
stack's scan shell command including the underlying net
management and command handling methods.

Later changes will build on this test to ensure that
changes to command handling will not break backwards
compatibility

This is also the reason why a separate test suite and
test file are being introduced already as further tests
will be added later on. We avoid having to move code
and thereby loose history.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 16:33:28 +02:00
Matthias Breithaupt 82c39a7805 test: DHCPv4: Add test for option callbacks
Add tests for the option callback API. The test uses a previously unused
option already contained in the sample offer.

Signed-off-by: Matthias Breithaupt <m.breithaupt@vogl-electronic.com>
2023-05-22 15:25:40 +02:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Florian Grandel 51108a9ce4 net: l2: ieee802154: test: /w and /wo sockets
This change splits the IEEE 802.15.4 test into two separate
test profiles, one with and one without sockets enabled to ensure
that both configurations work correctly.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 425d252d67 net: l2: ieee802154: test: sequence number coverage
IEEE 802.15.4-2020 introduces a sequence number suppression feature.

This change covers sequence number handling to ensure that future
changes will not break sequence number handling when introducing
the sequence number suppression feature.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 60c3107ef3 net: l2: ieee802154: test: fix resource mgmt
This change fixes some minor resource leaks in the test suite.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel f9492c399e net: l2: ieee802154: test: improved pkt doc
Introduces inline documentation of binary test frames to ease
future maintenance.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 6d6630528c net: l2: ieee802154: test: simlify sockaddr config
This refactoring dries up duplicate code required to configure
the socket address structure used in tests.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 259d6678d7 net: l2: ieee802154: test: cover ACK procedure
This change introduces test coverage for the IEEE 802.15.4
acknowledgement procedure.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel c0facfbf24 net: l2: ieee802154: test: extract data pkt with ar
Additional test cases introduced in later commits will re-use
an existing test frame that requests acknowledgement. It is
therefore extracted into a function.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 254d92666a net: l2: ieee802154: test: cover raw reception
Additional test case that covers AF_SOCKET/SOCK_RAW package
reception.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 834ad1e521 net: l2: ieee802154: test: cover dgram reception
Additional test case that covers reception of AF_SOCKET/SOCK_DGRAM
packages via socket API.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 66bd007f30 net: l2: ieee802154: security: properly clean up previous session
When changing IEEE 802.15.4 security settings or setting security
to 'none' then the previous session must be cleaned up to avoid
resource leaks.

This change introduces proper clean-up of the security session.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel d9cf3b024b net: l2: ieee802154: test: extract security set up/tear down
Security set-up and clean-up is extracted into functions
to enable re-use by test cases introduced in later commits.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 773108293b net: l2: ieee802154: test: raw packet readability
Improves inline documentation of binary IEEE 802.15.4 frames
to ease future maintenance. In this case the frame required
for testing raw sockets.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Florian Grandel 0f583303f7 net: l2: ieee802154: test: prepare expectation struct enlargement
This is a purely syntactical change that makes test case
expectations configuration more readable.

This is required as later commits will introduce further
expectations.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-22 08:06:14 +00:00
Sjors Hettinga a28a656aa0 net: tcp: Avoid double acknowlegding retransmitted data
In the FIN_WAIT_1 any incoming data is dropped, but anknowledged. Add a
check to see if the data is already acknowleged to prevent double
acknowledging of the data and bringing the acknowlegde counter out of
sync. When the acknowledge counter gets out of sync, the connection will
never properly terminate any more.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-05-15 15:25:51 +02:00
Sjors Hettinga fd9e7b4e52 net: tcp: test: Implement correct sequence number feeding around FIN
Due to more strict checking of the sequence numbering in the FIN_WAIT_1
state in the tcp stack, the test broke. Fix the sequence numbering
for sending the FIN and FIN ACK messages.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-05-15 15:25:51 +02:00
Lukas Woodtli 92ad3c1d6d tests: net: lwm2m: Add tests for block transfer
The tests check that a message is correctly split into
multiple blocks.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Georges Oates_Larsen 3bce8c09fc net: conn_mgr: Add test suite
Create test suite covering all major features of conn_mgr

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 62168b659e net: conn_mgr: connect/disconnect adjustments
Rather than raise error on connect if iface is down, just take the iface
up.

Rather than raise error on disconnect if iface is down, just ignore the
disconnection request.

Adjust tests and documentation accordingly.

This should make the API easier to use for applications and is more in
line with the original L2 agnostic connectivity RFC.

Also replace some instances of net_if_flag_is_set with
net_if_is_admin_up, which is cleaner and identical in function.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Georges Oates_Larsen 41d6a9bcec net: conn_mgr: relocate if_get_binding
Relocate conn_mgr_if_get_binding to conn_mgr_private.h so that it
can be used by test suites.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Robert Lubos ff0fd2d7a7 net: iface: Improve thread safety of net_if_ipv*_maddr_* functions
Provide an extra struct net_if * iface parameter to
net_if_ipv*_maddr_join/leave functions, so that the corresponding
interface context, the mcast address belong to, can be locked for the
operation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-05-10 11:06:15 +02:00
Gerard Marull-Paretas 93b63df762 samples, tests: convert string-based twister lists to YAML lists
Twister now supports using YAML lists for all fields that were written
as space-separated lists. Used twister_to_list.py script. Some artifacts
on string length are due to how ruamel dumps content.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-10 09:52:37 +02:00
Robert Lubos d0746a9a4f tests: net: mld: Add test case for NET_IF_IPV6_NO_MLD flag
Verify that no MLD messages are sent when NET_IF_IPV6_NO_MLD is set on
an interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-29 12:24:49 +02:00
Robert Lubos 61e5ce9cf4 tests: net: ipv6: Add test case for NET_IF_IPV6_NO_ND flag
Verify that no ND messages are sent when NET_IF_IPV6_NO_ND is set on
an interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-29 12:24:49 +02:00
Joshua Lilly f12ffaea1a tests: net: Disable test for mps2_an385
This test seems to run out of memory for this platform.
Temp. disabling it.

Signed-off-by: Joshua Lilly <jgl@meta.com>
2023-04-28 02:26:26 -04:00
Kumar Gala 0090ad718a net: Fix build issues with arm-clang
The arm-clang compiler/linker does not optimize away unused function
symbols and thus will error if symbols that are referenced are not
defined.  To fix this add needed ifdef'ry.

Build various network samples that utilize ethernet but don't have
CONFIG_NET_PROMISCUOUS_MODE will get a link error for:

	Error: L6218E: Undefined symbol
	net_mgmt_NET_REQUEST_ETHERNET_SET_PROMISC_MODE
	(referred from ethernet.o).

Fix by adding ifdef protection around promisc code.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-25 19:59:06 +02:00
Kumar Gala 64c0ac2acb tests: http_server: Add missing zephyr_iterable_section
As the test uses iterable sections, we need to utilize
zephyr_iterable_section for targets that need linker script
generation like arm-clang.

So add zephyr_iterable_section() for the ROM sections that the
testcases utilizes.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-25 12:18:42 +02:00
Georges Oates_Larsen fdaeabfdb6 net: conn_mgr: Fix event definitions
conn_mgr events cannot be used due to mistake in event definitions.

Fix these definitions so that events can be used.

Also patch hole in test coverage that allowed this in the first
place.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-04-24 16:29:01 +02:00
Pieter De Gendt 292bb97f0d net: lib: dns: mdns_responder: Simplify setup_dns_addr
The setup_dns_addr function packet argument can be reduced to
a socket address family.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-19 11:55:40 -04:00
Gerard Marull-Paretas 1eb683a514 device: remove redundant init functions
Remove all init functions that do nothing, and provide a `NULL` to
*DEVICE*DEFINE* macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-19 10:00:25 +02:00
Georges Oates_Larsen 129291f1e4 tests: net: Add tests for conn_mgr_conn
Adds integration tests for conn_mgr connectivity API

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-04-18 09:31:53 +02:00
Daniel Nejezchleb 42854bdf7b tests: net: socket: asynchronous connect
Added tests to check async socket connect

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2023-04-17 11:35:20 +02:00
Kenny Johansson 76e2b346e5 tests: net: Set explicit loopback MTU for TCP tests
Set explicit loopback MTU for TCP tests for clarity,
 and to avoid breaking tests if changed elsewhere.

Signed-off-by: Kenny Johansson <wirehell@gmail.com>
2023-04-17 10:17:09 +02:00
Kenny Johansson 10386f02f3 tests: net: Add tests for large IPv6 TCP messages
Add tests for lage IPv6 messages, reusing similar IPv4 test structure.

Signed-off-by: Kenny Johansson <wirehell@gmail.com>
2023-04-17 10:17:09 +02:00
Seppo Takalo 49857cdae4 tests: lwm2m: Add more tests to RD client
Add more test to RD client state machine.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-12 17:44:37 +02:00
Seppo Takalo 62bbdd59de tests: net: lwm2m: Add more tests for lwm2m_engine
Add more tests for LwM2M engine

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-12 17:44:37 +02:00
Seppo Takalo 1dd9d514f1 net: lwm2m: Move utility functions from engine
Some utility functions belong to lwm2m_util.c.
Block contexts belong to lwm2m_message_handling.c

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-12 17:44:37 +02:00
Gerard Marull-Paretas 4863c5f05b sys/util: extend usage of DIV_ROUND_UP
Many areas of Zephyr divide and round up without using the DIV_ROUND_UP
macro. Make use of it, so that we make use of a tested system macro and
at the same time we make code more readable.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 16:42:29 +02:00
Seppo Takalo 1c6a853528 net: lwm2m: Default lifetime is also a minimum accepted lifetime
If server or bootstrap writes a lifetime value less than
configured default lifetime, client will automatically overwrite
the value with default one.

This gives better control for the application where client
behaviour is fine tuned on the Kconfig, but default values
from bootstrap server cannot be fine-tuned.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-06 14:15:04 -05:00
Anas Nashif fcefc27823 tests: remove intel adsp cavs platforms from filters
Remove all filters related to dropped platforms.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-06 18:51:56 +02:00
Seppo Takalo 3a241592b5 net: lwm2m: Remove lwm2m_path_to_string
This function had only one use in SenML CBOR formatter and it
contained some specific tweaks, so move the function to be a
static member of that module.

Fixes #53674

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-04-06 15:37:21 +02:00
Robert Lubos 5b4a83f9b9 Revert "tests: net: websocket: exclude 64 bit platforms"
This reverts commit a1e07ddbbe.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-05 15:01:50 +02:00
Robert Lubos 162c0f64c2 tests: net: websocket: Fix test execution on 64-bit platforms
Instead of passing the test parameters to the websocket function, by
casting the pointer to integer (which may not work on 64-bit platform
due to int/pointer size mismatch), let the test allocate a file
descriptor, and initialize it with test context. The tested functions
expect a file descriptor as an argument anyway, so it's a more intuitive
approach.

The conditional test code within WS implementation can retrieve the test
context by using FD APIs to obtain the object represented by the FD.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-04-05 15:01:50 +02:00
Anas Nashif b876a25bd6 tests: net: util: do not use TC_START for debugging
TC_START is used to evaluate output of tests and is used internally by
ztest when a test starts, no need to call this manually here.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-05 10:27:28 +02:00
Anas Nashif 0f03b1283b tests: net: socketpair: prefix tests with test_
tests need to be prefixed with test_ or else we will not be able to
parse output correctly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-05 10:27:28 +02:00
Anas Nashif e7e06d112e tests: mqtt: do not use TC_START for debugging
TC_START is used to evaluate output of tests and is used internally by
ztest when a test starts, no need to call this manually here.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-05 10:27:28 +02:00
Anas Nashif a223d667fa tests: net: 6lo: do not use TC_START for debugging
TC_START is used to evaluate output of tests and is used internally by
ztest when a test starts, no need to call this manually here.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-05 10:27:28 +02:00
Fabio Baltieri a1e07ddbbe tests: net: websocket: exclude 64 bit platforms
The websocket library uses int for pointers for testing and does not
work reliably on 64 bit architectures.

Exclude the test so it does not block other unrelated PRs.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-04-05 08:20:24 +00:00
Robert Lubos 159559b807 tests: net: sockets: tcp: Add SO_SNDTIMEO test cases
Add test cases which verify that the TX timeouts configured with
SO_SNDTIMEO work correctly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-03-20 16:54:41 +01:00
Robert Lubos 3da59df974 tests: net: sockets: tcp: Extend SO_RCVBUF/SO_SNDBUF tests
Add new test cases for SO_RCVBUF/SO_SNDBUF which verify that setting
those options actually affects the RX/TX window sizes at the TCP level.
Existing tests only verified whether the options can be set/read
correctly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-03-20 16:54:41 +01:00
Georges Oates_Larsen cac932d849 tests: net: Add tests for offloaded_netdev
Adds integration tests for offloaded_netdev iface API extension

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-03-20 09:53:25 +01:00
Georges Oates_Larsen 3c6b7dc35a net: dummy L2 for offloaded ifaces
Adds dummy link layer for offloaded ifaces, allowing
ifaces to directly receive l2_enable calls

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-03-20 09:53:25 +01:00
Christopher Friedt 1c985a8029 Revert "tests: net: socketpair: skip nonblocking tests on posix arch"
This reverts commit 2eb53f4bd7.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-03-15 07:17:25 -04:00
Christopher Friedt 71f12d7161 tests: net: socketpair: explicit fcntl path on native_posix
Previously, `socketpair()` tests had pulled in the native
`fcntl()` implementation instead of using the Zephyr version
when being run under `native_posix_64`.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-03-15 07:17:25 -04:00
Mariusz Skamra 063c039480 test: net: buf_simple: Add unit tests for simple buffers
This adds set of unit tests for simple network buffers.
The suite is based of the test cases that are already defined for
network buffers.
Those test_net_buf_byte_order test case have been split to
smaller tests testing one functionality at a time.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-15 10:50:16 +01:00
Mariusz Skamra 3f09fd9e82 tests: net: buf: Fix invalid check in test
This fixes using invalid byte array for verification of 64 bit
value.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-15 10:50:16 +01:00
Anas Nashif 60430e5481 tests: lwm2m: fix test identifier
Fix identifier and remove extra lib string.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-03-10 14:01:59 +02:00
Chris Friedt 7b364c7f9a tests: net: http_service: verify service and resource macros
Add tests to verify the newly-added HTTP service and resource
macros.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-03-08 13:57:13 +00:00
Dave Lacerte 96c8d16986 net: lwm2m: Add IPSO voltage sensor object
Add support fot the IPSO voltage sensor object

Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
2023-03-06 12:34:22 +01:00
Jamie McCrae 0bad35de45 samples and tests: Use non-environmental zephyr base variable
This drops using the environmental part when referencing ZEPHYR_BASE
as the environment value does not have to be set and, in most cases,
is no longer set at all.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-03 10:49:10 +01:00
Anas Nashif f3a9d4348a tests: net: utils: move to new ztest API
Use new ZTEST API.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-24 09:16:27 +01:00
Anas Nashif 7f231a185a tests: net: tx_timestamp: move to new ztest API
Move to new ztest API.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-24 09:16:11 +01:00
Anas Nashif 6662771185 tests: net: mqtt_sn_packet: move to new ztest API
Move to new ztest API.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-24 09:15:38 +01:00
Anas Nashif 6307fe207a tests: net: mqtt_sn_client: move to new ztest API
Use new ztest API.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-24 09:15:38 +01:00
Juha Ylinen 6b9d3c0a64 tests: net: lwm2m: Add tests for lwm2m_engine.c
Add tests for lwm2m_engine.c using FFF framework.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-02-22 14:26:52 +01:00
Stig Bjørlykke b77c234691 net: icmpv6: Initialize dns sockaddr in RA RDNSS
Initialize struct sockaddr_in6 in RDNSS handling to avoid
uninitialized sin6_port or sin6_scope_id.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2023-02-22 14:26:39 +01:00
Anas Nashif fb48914600 tests: net: socket: remove platform exclude on native_posix_64
This test runs fine on native_posix_64. The exclude was added long time
ago and seems to not apply anymore.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-22 12:18:04 +01:00
Anas Nashif eaeaede7b6 tests: net: socket: do not enable shell
Shell support not needed for this test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-22 12:18:04 +01:00
Hu Zhenyu 9c10e8958f tests: net: socket: websocket move to new ztest API
Move net/socket/websocket tests to use new ztest API
TEST=twister -T tests/net/socket/websocket

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-22 12:18:04 +01:00
Hu Zhenyu 6559c62ef3 tests: net: trickle move to new ztest API
Move trickle tests to use new ztest API
TEST=twister -T tests/net/trickle

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2023-02-21 08:24:35 -05:00
Stig Bjørlykke cb50d49f33 net: icmpv6: Implement IPv6 RA Recursive DNS Server option
Handle RA RDNSS and use the first DNS server fetched. This is needed
when building IPv6 only without static DNS server IP addresses.

This implementation does not handle the lifetime, because the current
resolve logic does not have support for a DNS server lifetime.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2023-02-21 10:59:18 +01:00
Jeroen van Dooren d20cceb48e net: ip: net_mgmt: Increase default queue size
There is no reason why the default size should be 2,
because an event is only a combination of

{uint32_t + void*} + info

Using 2 as default causes a high risk of loosing events,
setting the default to a more sensible value of 5 still
restricts memory usage but keeps it more safe.

Signed-off-by: Jeroen van Dooren <jeroen.van.dooren@nobleo.nl>
2023-02-21 10:58:10 +01:00
Andreas Chmielewski 3ef08df10e tests: net: lwm2m: cover dtls releated code path
As long the code path differs in case DTLS is used, we need tests for
this.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2023-02-20 11:12:29 +01:00
Chris Friedt 2eb53f4bd7 tests: net: socketpair: skip nonblocking tests on posix arch
The `fcntl()` call (`zsock_fcntl()`) does not seem to work
properly (specifically with `CONFIG_ARCH_POSIX`). This will
be resolved in subsequent work harmonizing the networking
subsystem and POSIX library.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-20 11:04:07 +01:00
Chris Friedt 494faf3e2c tests: net: socketpair: coverage for all C libraries
Previously, the test was only run for configurations that used
the Newlib C library. However, socketpair runs equally well
under the minimal libc, and picolibc, as well as the native
libc.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-20 11:04:07 +01:00
Chris Friedt b9fe11c7f2 tests: net: socketpair: use do not alias read and write
* do not define `read`, `write`, as different symbols
* use `recv`, and `send` as defined by
  `CONFIG_NET_SOCKETS_POSIX_NAMES`
* do not specify `(2)` as manual-page sections are
  somewhat irrelevant

Note: we use `CONFIG_NET_SOCKETS_POSIX_NAMES` here, and
`CONFIG_POSIX_API` in `samples/` to show that the socketpair
API is available in both configurations.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-20 11:04:07 +01:00
Chris Friedt c73b8ed4f3 tests: net: socketpair: put common includes in one header
This serves to increase SNR in the test sources (i.e. to
make test sources easier to read).

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-20 11:04:07 +01:00
Chris Friedt 750299534e tests: net: socketpair: rename files to be less redundant
Wow, this testsuite was really celebrating some redundancy
before.

While that is sometimes a good thing, it's also sometimes
better to be more concise.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-20 11:04:07 +01:00
Chris Friedt ee2656d83f tests: net: socketpair: remove test_socketpair_ prefix
The `test_socketpair_` prefix was leftover from the old ztest
framework.

It is also redundant, so remove it.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-20 11:04:07 +01:00
Chris Friedt bb465bd78c tests: net: socketpair: remove unused extern declarations
The declarations of extern test functions were leftover from
the old ztest framework.

They are unnecessary now.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-02-20 11:04:07 +01:00
Juha Ylinen 3c48b71eee tests: lwm2m_rd_client: Update tests
Update unit tests for lwm2m_rd_client.c after adding new event
LWM2M_RD_CLIENT_EVENT_REG_UPDATE.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-02-19 20:44:02 -05:00
Robert Lubos dc641ceffd net: ieee802154: 6lo: Add test case for IPHC fragmentation corner case
Add a test case, which reproduces a scenario, where packet before IPHC
exceeds 802154 MTU, but after header compression, in fits.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-19 20:33:36 -05:00
Hu Zhenyu a8bda2ef8f tests: net: socket: tls_ext move to new ztest API
Move net/socket/tls_ext tests to use new ztest API
TEST=west build -p -b native_posix tests/net/socket/tls_ext

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2023-02-19 10:32:03 -05:00
Kumar Gala ab764aada9 tests: lwm2m_registry: Add newlib filter to testcase.yaml
Not all toolchains support newlib so tests that require newlib need
to have a filter to we don't try and build those tests on those
testcases.  Add the following to testcase.yaml to handle the issue:

        filter: TOOLCHAIN_HAS_NEWLIB == 1

Fixes #54440

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-02-06 18:22:41 +09:00
Marc Desvaux 1bde7184bd tests: net: igmp and igmp.preempt fix issue
we have 1 IPv4 net_if addresses but 2 network interfaces
we must increase CONFIG_NET_IF_MAX_IPV4_COUNT value.

Signed-off-by: Marc Desvaux <marc.desvaux-ext@st.com>
2023-02-06 10:07:30 +01:00
Krishna T 8069d47c5e net: pkt: Allow zero payload for non-IPv4/v6 frames
For socket families that are niether INET/INET6 e.g., PACKET, we cannot
estimate header length, so, if the payload is zero as well, networking
stack drop the packet.

Instead, allow for zero header + payload packets and let L2 take care of
handling them, for some L2's this is still a valid frame.

E..g, In case of Wi-Fi this is sent as 802.11 Header + LLC Header
(no payload).

Add unittests for both AF_INET + Zero payload and AF_PACKET + Zero
payload.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-06 10:04:03 +01:00
Lukas Woodtli 6403c02112 tests: net: coap: Add test for options
The test checks if options are added to a CoAP buffer correctly.
It should eventually check if opstions can be added out of order
e.g. not in increasing order of option codes.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-02-06 10:02:19 +01:00
David Leach 871611eeee tests: net: igmp: Set allowed platforms filter
The IGMP test cases are designed to use DUMMY L2 and not on real
hardware. Add an "platform_allow" filter to only run on qemu
platforms.

Fixes #54087

Signed-off-by: David Leach <david.leach@nxp.com>
2023-02-03 02:25:54 +09:00
Robert Lubos d686af9fa2 tests: net: tcp: Make sure the underlying TCP connection is closed
In this test suite, the actual peer interacting with the TCP stack is
the test suite itself, therefore all test cases should take care to
finalize the underlying TCP connection before ending, not to interfere
with other test cases.

This was not the case for test_server_out_of_order_data(), which
although released the underlying context on their side, did not finalize
the connection at the TCP level, i. e. did not reply for the FIN packet
etc.

As it seems to be unnecessary overhead to implement the full connection
teardown for the test case, simply send a RST packet to abort the
connection at the TCP level before releasing the context.

This was causing occasional failures in this test suite, as the FIN
packets retransmitted by the TCP stack could interfere with other test
cases logic.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-01 06:50:20 -08:00
Robert Lubos ab43bfe7b1 tests: net: tcp: Fix packet leak in recv callback
The net_context recv callback used by the test suite did not release the
net_pkt provided, causing packet leak. Since the test suite allocated
plenty of packets, it wasn't visible, however could become a problem if
more tests are added.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-02-01 06:50:20 -08:00
Jarno Lämsä 2f6d13bb81 tests: lwm2m_registry: Fix license to Apache-2.0
Apache-2.0

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-02-01 03:49:39 +09:00
Jarno Lämsä 66a4fab571 tests: lwm2m_registry: Add ZTest tests for lwm2m_registry
These tests test the basic functionality of creating
object and resource instances, setting buffers, writing
and reading to and from resources, and setting and triggering
callbacks.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-30 15:04:50 +00:00
Seppo Takalo b63a3abeb8 net: lwm2m: Move LwM2M tests to tests/net/lib/lwm2m
This directory has existing LwM2M tests and tests/net/lib
has other protocols as well, so keep all in one place.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-01-27 22:50:24 +09:00
Robert Lubos c79a25b8f9 tests: net: tcp: Fix a few issues with TCP tests
The net_context-based TCP tests required some adjustments/fixes:

* seq number was not incremented for the final ACK after FIN
* accepted net_context was not dereferenced (with net_context_put())
* net_context_put() should be used instead of net_tcp_put(), as it's the
  net_context that is allocated in the test (with net_context_get())
* out of order tests depend on each other, therefore it must be assured
  they're executed in the correct order

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-01-26 12:34:04 +00:00
Robert Lubos 690140baa6 tests: net: socket: tcp: Disable IPv6 ND
There is a test case which verifies that no new packets show up on the
interface, assuming that the only source of the packets is TCP stack.
ND protocol could interfere with that assumption, sending
advertisements.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-01-26 12:34:04 +00:00
Jamie McCrae ec7044437e treewide: Disable automatic argparse argument shortening
Disables allowing the python argparse library from automatically
shortening command line arguments, this prevents issues whereby
a new command is added and code that wrongly uses the shortened
command of an existing argument which is the same as the new
command being added will silently change script behaviour.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-26 20:12:36 +09:00
Kumar Gala 8f04408725 tests: Add newlib filter for some testcases that dont have it
Not all toolchains support newlib so tests that require newlib need
to have a filter to we don't try and build those tests on those
testcases.  Some newer tests are missing:

	filter: TOOLCHAIN_HAS_NEWLIB == 1

so add that to testcases that needed.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-01-24 11:10:27 +00:00
Jarno Lämsä abafd7e810 net: lib: lwm2m: Replace deprecated function calls
Replace calls to deprecated functions with new ones.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-01-19 10:16:22 +01:00
Stephanos Ioannidis 4a64bfe351 treewide: Use CONFIG_CPP instead of CONFIG_CPLUSPLUS
This commit updates all in-tree code to use `CONFIG_CPP` instead of
`CONFIG_CPLUSPLUS`, which is now deprecated.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Florian Grandel 79adc524cd net: l2: ieee802154: ensure L2/L3 recv package handover
Issue #53630 proved that we didn't have sufficient test coverage for
L2/L3 package handover on the RX side. This commit creates additional
test coverage to reproduce the problem found in #53630 and avoid future
regressions.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2023-01-13 13:38:03 +00:00
Pascal Brogle 7a117b620d net: lwm2m: fix observation path list ordering test
adjust test to compile with latest main code and changes by
PR #53677

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-13 14:16:52 +01:00
Pascal Brogle 6ac281887c net: lwm2m: fix observation path list ordering
under certain conditions the current implementation did not maintain
the desired sort order.

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-13 13:47:27 +01:00
Nicolas Pitre bb3795505d tests/net/socket: fix compiler warnings
warning: format '%d' expects argument of type 'int', but argument 3
has type 'size_' {aka 'long unsigned int'} [-Wformat=]

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-01-10 09:58:01 +01:00
Sjors Hettinga 1be1b472cd net: tcp: Extend TCP receive queue timeout
After several fixes of the re-ordering logic in TCP, the receive queue
works as intended and cleans itself up properly. Previously the default
timeout was 100 ms, which pretty much disables it for real applications.

Increase the timeout to 2 seconds to actually enable it for in practice.
This should help pass much more of the Maxwell Pro tests.

This is the first step before removing the timeout completely.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2023-01-10 09:26:28 +01:00
Chris Friedt 8659e2f69e libc: minimal: include: move fcntl.h to posix
The `fcntl.h` header has never been a part of ISO C so move it to
`include/zephyr/posix`.

To ensure a smooth migration, a header was left in
`lib/libc/minimal/include` that prints a deprecation warning.

Users should either include `<zephyr/posix/fcntl.h>` or switch to
`CONFIG_POSIX_API=y`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Henrik Brix Andersen 11aa8454f0 Revert "random: Change testing random generator"
This reverts commit d6881de3b3.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-09 19:29:50 +09:00
Declan Snyder d6881de3b3 random: Change testing random generator
The old random timer test was not random-looking
enough on some platforms.

Replace with new test which is psuedo-xoshiro.

The generator is still deterministic
and does not depend on entropy at all,
but should look more random for testing.

Change name of generator tree-wide also.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-01-09 10:16:55 +01:00
Pascal Brogle 60bf310aae net: lwm2m: fix senml cbor object link encoding
use text format instead of tlv format

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2023-01-05 12:43:24 +01:00
Fabio Baltieri f5b4acac57 yamllint: indentation: fix files in tests/
Fix the YAML files indentation for files in tests/.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-01-04 14:23:53 +01:00
Fabio Baltieri 7dd902d035 yamllint: fix all yamllint comments-indentation errors
Fix all comments-indentation errors detected by yamllint:

yamllint -f parsable -c .yamllint $( find -regex '.*\.y[a]*ml' ) | \
  grep '(comments-indentation)'

This checks that the comment is aligned with the content.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-01-04 01:16:45 +09:00
Juha Ylinen c7a5f7fda7 net: lwm2m: Deprecate Kconfig for LwM2M RD Client
RD-Client is essential part of LwM2M specification and it can't
be disabled from LwM2M engine. This commit deprecates Kconfig
variable CONFIG_LWM2M_RD_CLIENT_SUPPORT and removes
all usages if it.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-01-03 13:23:46 +01:00
Erwan Gouriou 66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Grixa Yrev 2a992c65c0 net: websocket: new receiving algorithm
websocket_recv_msg() is reworked with using fsm. Now the function
return 0 when payload is empty, -ENOTCONN if socket close. Receiving
empty ping and sending empty pong were added in tests.
Fixes #52327

Signed-off-by: Grixa Yrev <grixayrev@yandex.ru>
2022-12-20 17:05:12 +00:00
Marco Argiolas f8f3629efd net: lib: lwm2m: add uCIFI LPWAN object
Add support for Low Power Wide Area Network (LPWAN) Object (ID 3412)

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2022-12-14 09:51:38 +01:00
Anas Nashif ba7d730e9b tests/samples: use integration_plaforms in more tests/samples
integration_platforms help us control what get built/executed in CI and
for each PR submitted. They do not filter out platforms, instead they
just minimize the amount of builds/testing for a particular
tests/sample.
Tests still run on all supported platforms when not in integration mode.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-29 16:03:23 +01:00
Krzysztof Chruscinski 8112da31c2 tests: net: shell: Align to LOG_PRINTK as default
Alignging test to a change which enabled LOG_PRINTK as default.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-11-29 10:46:26 +01:00
Anas Nashif cffe98d9de crc: Make the build of crc function dependent on a Kconfig
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.

Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.

Partial fix for #50654

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-23 13:30:00 +01:00
Robert Lubos 0c4e669cd7 tests: net: Enable CONFIG_NET_BUF_VARIABLE_DATA_SIZE in some tests
CONFIG_NET_BUF_VARIABLE_DATA_SIZE option had not test coverage at all,
making in vulnerable for regressions. There is no dedicated test suite
to verify this option, but at least we can enable it in a few test
suites to make sure the configuration is functional.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-19 07:39:32 -05:00
Robert Lubos 387a66131e net: pkt: Introduce minimum length requirement to net_pkt_get_frag()
net_pkt_get_frag() and a few other functions did not specify the
allocated fragment length, incorrectly assuming that fixed-sized
buffers are always used.

In order to make the function work properly also with variable-sized
buffers, extend the function argument list with minimum expected
fragment length parameter. This allows to use net_buf_alloc_len()
allocator in variable buffer length configuration, as well as verify if
the fixed-sized buffer is large enough to satisfy the requirements
otherwise.

Update the existing codebase to provide the expected fragment length,
based on the context.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-19 07:39:32 -05:00
Robert Lubos 250116cd44 tests: net: ipv6_fragment: Improve test_recv_ipv6_fragment test case
Fix some problems with test_recv_ipv6_fragment test case:
* net_pkt_ipv6_hdr_prev was not set, in result reassembly logic
  overwritten wrong part of the IPv6 header
* Wrong checksum was set in the first fragment

Add more verification to the test_recv_ipv6_fragment test case:
* Actually register ICMPv6 Echo Reply handler so that the reassembled
  packet can be analyzed
* Verify that IPv6, ICMPv6 headers and data are correct

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-14 16:26:20 +01:00
Robert Lubos f0619254ca tests: net: ipv6_fragment: Add test to verify fragmentation loopback
Add test case which verifies that IPv6 fragmentation and reassembly
works correctly in loopback scenario. The test case verfies that:

* IPv6 packet is fragmented correctly in the send handler
* IPv6 packet is reassembled correctly in UDP receive handler.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-14 16:26:20 +01:00
Robert Lubos f7eff96c88 tests: net: ipv6_fragment: Fix wait_data semaphore usage
The test cases which make use of wait_data semaphore incorrectly fed the
semaphore after processing the first fragment, instead of waiting for
all of the expected fragments to be processed. Adittionally, the test
cases did not really fail if the semaphore timeout occured (hence if for
example last fragment was lost, it wouldn't be detected by the test).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-14 16:26:20 +01:00
Robert Lubos c8fa200329 tests: net: ipv6_fragment: Remove unused interface
The second interface was not really used by the testsuite and only
obfuscated the testsuite content, hence remove it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-14 16:26:20 +01:00
René Beckmann fdea8e5556 tests: net: mqtt-sn: Add test for MQTT-SN client
Validate that basic lifecycling and usage of the MQTT-SN client
work correctly by providing a mocked MQTT-SN transport. Connection
setup and state changes are tested.

Signed-off-by: René Beckmann <rene.beckmann@grandcentrix.net>
2022-11-09 10:43:00 +01:00
René Beckmann 1c0c603de3 tests: net: mqtt-sn: Add encoding/decoding test
Validate that the encoding and decoding part of the MQTT-SN library
work correctly using prepared byte arrays of messages.

Signed-off-by: René Beckmann <rene.beckmann@grandcentrix.net>
2022-11-09 10:43:00 +01:00
Jamie McCrae e1babe0c0a tests: net: Add ipv4_fragment test
This adds a test for the new ipv4_fragment feature. This test suite
checks TCP and UDP messages are correctly fragmented and reassembled,
checks that an ICMP error is sent if not all fragments were received
and checks that packets with the do not fragment bit are not
fragmented.

Signed-off-by: Jamie McCrae <spam@helper3000.net>
2022-11-05 19:58:26 +01:00
Juha Heiskanen 05a92f9258 net: lwm2m: Timeseries data cache read update
Added support for handle case when all data is not possible to
add in 1 message for Send and Observed Notification.

Notification continuous pending timeseries data is triggred
by iMIN attribute.

Send Operation generate continuous message in multiple lwm2m
message.

Normal Read by server only report back latest stored data.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-11-04 09:59:51 +01:00
Maciej Perkowski 458afb9064 tests: net: Add min flash requirment for overflowing tests
These tests turn on mbedtls and require ajusting min flash
requirements to prevent twister from trying to build them on
platforms without required amount of flash.
Fixes: #51421

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
2022-10-27 11:01:24 +02:00
Robert Lubos 3ccb62a8d9 tests: net: dns_sd: Don't use NET_CONFIG_SETTINGS
DNS SD test suite does not really make use of IP connectivity, so
there's no need to configure IP addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos 48c3b5bb2a tests: net: socket: udp: Don't use NET_CONFIG_SETTINGS
As the UDP test suite is mostly intended to run over loopback, use
loopback addresses and skip configuration of other addresses.

For the test cases that use fake Ethernet iterface the configuration
is done manually anyway, so just rename the symbols to avoid
collission.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos ba308cbc44 tests: net: socket: tls: Don't use NET_CONFIG_SETTINGS
As the TLS test suite is intended to run over loopback interface, use
loopback addresses and skip configuration of other addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos d3eb3f8a5e tests: net: socket: tcp: Don't use NET_CONFIG_SETTINGS
As the TCP test suite is intended to run over loopback interface, use
loopback addresses and skip configuration of other addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos 1b00a853cd tests: net: socket: socketpair: Don't use NET_CONFIG_SETTINGS
The socketpair test suite does not really make use of IP connectivity.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos fab28b8978 tests: net: socket: select: Don't use NET_CONFIG_SETTINGS
As the test suite is intended to run over loopback interfce, use
loopback address and skip configuration of other addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos 0293efe28b tests: net: socket: poll: Don't use NET_CONFIG_SETTINGS
As the test suite is intended to run over loopback interfce, use
loopback address and skip configuration of other addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos a72f6a70f2 tests: net: socket: net_mgmt: Don't use NET_CONFIG_SETTINGS
The test suite did not make use of autoconfigured IP addresses at all.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos d8ae904d95 tests: net: socket: misc: Don't use NET_CONFIG_SETTINGS
The test suite already configured the dummy interfaces manually, so it's
only needed to provide respective address strings, no need to involve
NET_CONFIG_SETTINGS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos 3dfbef9f46 tests: net: socket: getnameinfo: Don't use NET_CONFIG_SETTINGS
No really need to set additional addresses on the interface, as they're
not used by the test.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos 8ca7b8de1e tests: net: socket: getaddrinfo: Don't use NET_CONFIG_SETTINGS
The loopback addresses are configured automatically on the loopback
interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Robert Lubos 21134f52cd tests: net: socket: af_packet: Don't use NET_CONFIG_SETTINGS
Configure the test interfaces manually instead to increase test
reliability on real hardware.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-26 12:00:22 +02:00
Henrik Brix Andersen f8a88cdb27 drivers: can: use flags fields for can_frame and can_filter structs
The can_frame and can_filter structs support a number of different flags
(standard/extended CAN ID type, Remote Transmission Request, CAN-FD format,
Bit Rate Switch, ...). Each of these flags is represented as a discrete bit
in the given structure.

This design pattern requires every user of these structs to initialize all
of these flags to either 0 or 1, which does not scale well for future flag
additions.

Some of these flags have associated enumerations to be used for assignment,
some do not. CAN drivers and protocols tend to rely on the logical value of
the flag instead of using the enumeration, leading to a very fragile
API. The enumerations are used inconsistently between the can_frame and
can_filter structures, which further complicates the API.

Instead, convert these flags to bitfields with separate flag definitions
for the can_frame and can_filter structures. This API allows for future
extensions without having to revisit existing users of the two
structures. Furthermore, this allows driver to easily check for unsupported
flags in the respective API calls.

As this change leads to the "id_mask" field of the can_filter to be the
only mask present in that structure, rename it to "mask" for simplicity.

Fixes: #50776

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-25 16:32:10 +02:00
Sjors Hettinga 8a4734d45c net: ip: Add unit test for the IP/UDP/TCP checksum
Validate the faster IP checksum algorithm against the straightforward
implemation using a variety of packet length and contents.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-10-25 12:46:11 +02:00
Juha Heiskanen 4bcc880670 net: lwm2m: LwM2M engine time API update
Updated lwm2m_enigen_set/get_time API for support time_t.

Updated LwM2M engine set/get resource time to time resource support
time_t and uint32_t input.

LwM2M engine put and get time API update to use time_t.

Time series data cache entry have own type for time resource.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-24 10:39:03 +02:00
Juha Heiskanen e1e2228e9c net: lwm2m: LwM2M object time resource update
Updated Timestamp resource default buffer type to time_t.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-10-24 10:39:03 +02:00
Hu Zhenyu 470e333ab1 tests: net: icmpv4 move to new ztest API
Move net icmpv4 tests to use new ztest API
1. Add teardown, remove addr
2. Fix a packet release bug in test_send_echo_req_bad_opt
3. Combine send_echo_req/rep, as they should be run in sequence

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-10-21 13:15:11 +02:00
Robert Lubos af8d09f40b tests: net: ieee802154: l2: Fix stack overflow on certain platforms
The default ztest stack size was not large enough for the test suite to
execute on certain platforms (noticed on x86, cortex-m4). Therefore
increase the CONFIG_ZTEST_STACK_SIZE for the suite to prevent stack
overflow.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 16:13:35 -05:00
Robert Lubos e9cb600514 tests: net: ieee802154: l2: Fix build warning with minimal libc
CONFIG_MBEDTLS_TEST enables mbed TLS self-test routines, which require
rand() function. As this function is not available by default with
minimal libc, it caused build warning on certain platforms.

As this feature is not really needed for 802.15.4 tests, simply remove
it from the project file to fix the issue.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 16:13:35 -05:00
Robert Lubos 4d7b177a3f tests: net: dhcpv4: Increase buffer count for the test
Given that DHCP input packet is now released after
dhcpv4_handle_reply() function is called (and potentially new message
allocated/sent) the test needs more net buffers to work.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:01:13 +02:00
Robert Lubos 42c78e2af1 tests: net: iface: Add test to verify operational state transitions
Add test which verifies that interface operational state changes
correctly when carrier and dormant status is updated.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:00:31 +02:00
Robert Lubos 1df9c4e1e3 tests: net: virtual: Add test to verify behavior when real iface goes down
Add test that verifies if a virtual interface state is updated properly
when an underlying real interface is brought down/up.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:00:31 +02:00
Robert Lubos 6e9e35c18d tests: net: socket: tls: Fix test_v4_dtls_sendmsg test case
test_v4_dtls_sendmsg test case wrongly used IPv6 socket instead of IPv4.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:00:18 +02:00
Stephanos Ioannidis 6fae7a1c4c tests: net: getaddrinfo: Use newlib nano variant when available
This commit updates the `getaddrinfo` test to use the newlib nano
variant when available because it can run out of RAM with the newlib
full variant on the platforms with a small RAM.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2022-10-19 16:02:51 +02:00
Hu Zhenyu d2ffa8a3eb tests: net: lib: lwm2m: content_senml_cbor: move to new ztest API
Move net content_senml_cbor tests to use new ztest API

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-10-18 14:14:25 +02:00
Florian Grandel b674ed6b8b net: pkt: decouple from ieee802154 internals
This change implements part two of the program laid out in the TSCH RFC,
see #50336#issuecomment-1250250154 :

> Consolidate IEEE 802.15.4 options in net_pkt

This change improves decoupling of generic net core code from
IEEE 802.15.4 internals. It also simplifies IEEE 802.15.4
attribute cloning and thereby makes it easier to maintain and less
error prone (and probably even faster as individual bits are no longer
copied over separately).

This enables us to extend and design IEEE 802.15.4 L2 attributes inside
the package in isolation from the net core code which will no longer
have to be changed when introducing changes or additions to the flags.

This flexibility will be built upon in later change sets to model the
IEEE 802.15.4 attributes closer to the spec.

The solution is inspired by Linux's sk_buff->cb attribute which addresses
the same concern as the attribute introduced in this change set:
https://elixir.bootlin.com/linux/v6.0.1/source/include/linux/skbuff.h#L871

As the inline comment says: The cb attribute can be made a union or even a
uint8[something] in the future, if further L2s need a control block, too.
Right now such full indirection would make the code overly abstract, so
I chose to compromise with maintainability in mind.

Care has been taken to ensure that this changes does not introduce
additional padding into the net package. To maintain zero-padding, future
changes to the net packet struct will have to ensure that the
IEEE 802.15.4 struct is 4-byte aligned (iff the IEEE 802.15.4 struct
continues with max uint32_t scalar members) which is no deviation from
the previous implementation.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-17 16:54:37 +02:00
Florian Grandel 389bd57753 net: ip: fix and consolidate cloning of ll addr
The net packet structure contains pointers to link-layer source and
destination addresses. Usually, these structures do not point to
separately allocated memory but directly into the packet's data buffer.

In case of a deep package clone (which includes copying the buffer) the
copy of the ll addresses continued to point into the old package
(contrary to a rather misleading inline comment). This was proven by an
additional failing unit test assertion.

As the original package may be unreferenced while the cloned package is
still being accessed, the ll address pointers of the cloned package may
become invalid.

The fix consists of two parts:
 * First it is determined whether a given ll address actually points into
   the buffer and if so at which logical cursor offset it is located.
 * If the address points into the package buffer then the cursor API is
   used to determine the corresponding physical memory location in the
   cloned package. The ll address of the cloned package is then patched
   to point to the cloned buffer.

Additional assertions were introduced to the existing unit test to ensure
that the newly generated address points to the correct content of the
cloned package.

The solution is implemented in a generic way so that the previously
redundant implementations were consolidated into a single one. The code
includes a check that ensures that the ll address check and manipulation
will be skipped in case of shallow package copies.

The change also addresses problems related to the "overwrite" flag of the
package:
 * Package cloning assumes the overwrite flag to be set. Otherwise it
   will not work correctly. This was not ensured inside the clone method.
 * Package cloning manipulates the overwrite flag of the cloned package
   but does not reset it to represent the same state as the original
   package.

The change introduces a fix and unit test assertions for both problems.

Fixes: #51265

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-17 16:54:37 +02:00
Andy Ross 633c41d52c tests/net/lib/dns_addremove: Initialize resolver objects
These were never being initialized by the test, leaving an embedded
k_mutex as bare memory.  That used to work (I guess?), it doesn't with
k_zync.

Signed-off-by: Andy Ross <andyross@google.com>
2022-10-17 10:13:56 +02:00
Florian Grandel 14c608e9c4 net: l2: ieee802154: improved context thread safety
Several attributes in the ieee802154_context struct may potentially be
accessed from different threads and/or ISR context. Only some of these
attributes were properly guarded against race conditions.

This may not have been to problematic in the past but as other changes
in this PR introduce additional attributes and mutate several attributes
in a single atomic transaction, leaving such changes unprotected seems
dangerous.

This change therefore introduces systematic locking of the
ieee802154_context structure.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-12 18:40:59 +02:00
Florian Grandel 6a6b89516d net: l2: ieee802154: improve short address support
IEEE 802.15.4 short address support is incomplete in several places.
This change improves short address support without claiming to fix
it everywhere. Future iterations will have to continue where this change
leaves off.

The purpose of this change was to:
 * use the short address returned by association responses,
 * automatically bind IEEE 802.15.4 datagram sockets to the short
   address if available,
 * use the short address in outgoing packages where applicable,
 * improve validation of association/disassociation frames,
 * model association more closely to the spec by tying it to the
   existence of a short address in the MAC PIB thereby removing
   redundancy in the PIB (which makes race conditions less probable),
 * keep both, the short and extended addresses, of the coordinator.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-12 18:40:59 +02:00
Florian Grandel bff6a5cce5 net: l2: ieee802154: fix short/ext address endianness
This changes fixes several bugs and inconsistencies in the IEEE 802.15.4
L2 implementation. These bugs were revealed while documenting intended
endianness of driver, IP, socket and L2 attributes (see previous
changes).

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-12 18:40:59 +02:00
Christopher Friedt dbe2c0d59e include: net: http: rename http_x.h http/x.h
Some minor housekeeping prior to adding an http server
implementation. There are already a number of http headers
and that number will likely increase with subsequent work.
Moving them into a common directory cleans up the
`include/net` directory a bit.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2022-10-12 09:02:21 -04:00
Ryan Erickson a68ab8ded9 tests: net: bridge: exclude mg100 and pinnacle_100_dvk
mg100 and pinnacle_100_dvk require IPv4 and/or
IPv6 networking.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-09-15 11:58:23 +01:00
Sagar Shah 91ffbaa0fc tests: net: lib: coap: test coap_handle_request() for invalid request code.
Adding tests to test the case where an invalid request code is
received. coap_handle_request() should return with -ENOTSUP.

Signed-off-by: Sagar Shah <sagar.shah@legrand.us>
2022-09-12 10:53:34 +00:00
Michał Barnaś dae8efa692 ztest: remove the obsolete NULL appended to zassert macros
This commit removes the usage of NULL parameter as message in
zassert_* macros after making it optional

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-09-09 07:05:38 -04:00
Hu Zhenyu 6514c63b17 tests: net: lib: mqtt_publisher: move to new ztest API
Move net mqtt_publisher tests to use new ztest API

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-09-08 15:27:27 +00:00
Hu Zhenyu ffb78f51ca tests: net: tcp: move to new ztest API
Move net tcp tests to use new ztest API

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-09-08 10:13:34 +02:00
Hu Zhenyu 011b1ea8da tests: net: socket: offload_dispatcher move to new ztest API
Move offload_dispatcher tests to use new ztest API
TEST=twister -T tests/net/socket/offload_dispatcher

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-09-07 10:29:56 +02:00
Martin Jäger c05e71ed4b net: socketcan: make socketcan_frame CAN FD capable
Align the struct socketcan_frame to most recent Linux kernel.

Compatibility with legacy can frames is maintained because the DLC is
equal to payload length for up to 8 bytes. Only the data buffer is
extended, resulting in larger size when CAN FD is enabled.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-09-05 14:48:22 +00:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Hu Zhenyu 8c6ca7701b tests: net: lib: mqtt_subscriber: move to new ztest API
Move net mqtt_subscriber tests to use new ztest API

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-09-02 11:04:32 +00:00
Hu Zhenyu 4b46748c94 tests: net: lib: mqtt_pubsub: move to new ztest API
Move net mqtt_pubsub tests to use new ztest API

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-09-02 11:04:01 +00:00
Sagar Shah 99d1a593d3 tests: net: lib: coap: testing new return values of coap_packet_parse()
Adding tests for new return values of coap_packet_parse.

Signed-off-by: Sagar Shah <sagar.shah@legrand.us>
2022-09-02 11:02:38 +00:00
Hu Zhenyu 6505200b8e tests: net: socket: socketpair: move to new ztest API
Move socketpair tests to use new ztest API
TEST=twister -T tests/net/socket/socketpair

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-09-02 10:54:49 +00:00
Xiao Song 83246ec025 tests: net: lib: move tls_credentials to new ztest API
Move tests/net/lib/tls_credentials/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-09-02 10:54:29 +00:00
Sjors Hettinga 39328e8836 net: tcp: Discard duplicate data in reodering correctly
When all the data of the new packet is already present in the
queue_recv_data, make sure the packet is discarded.
This commit adds a test line that reproduces the issue and implements a
fix.

Also in appending the packet, call the official net_buf_frag_add function
instead of updating the last net_buf pointer, since the net_pkt_remove_tail
called in between, might have removed the last net_buf.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Sjors Hettinga 069e003380 net: tcp: Also run the packet loss test with NO_DELAY option
When the NO_DELAY option is enabled, the retransmitted packets
will likely be differently broken down from the packets transmitted
initially. This provides a nice stress test for the out or order
reception logic.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Sjors Hettinga 89860fd74e net: tcp: Correctly deal with fully duplicated buffered out of order data
TCP is a streaming protocol, this means it can set the packet boundary
at an arbitrary location. Therefor a re-transmitted packet may have the
packet boundary at a different location from the original missing segment.

The reordering logic should be able to deal with this situation and
throw away the overlapping data. This fix clears the out of order queue
when the queued data is not relevant.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Sjors Hettinga 515fc73b79 net: tcp: Correctly handle partial duplicate buffered out of order data
TCP is a streaming protocol, this means it can set the packet boundary
at an arbitrary location. Therefor a re-transmitted packet may have the
packet boundary at a different location from the original missing segment.

The reordering logic should be able to deal with this situation and
throw away the overlapping data. Now also for data that needs to be added
to the existing queue

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Sjors Hettinga e255f1a9c7 net: tcp: Correctly handle partial duplicate out of order data
TCP is a streaming protocol, this means it can set the packet boundary
at an arbitrary location. Therefor a re-transmitted packet may have the
packet boundary at a different location from the original missing segment.

The reordering logic should be able to deal with this situation and
throw away the overlapping data.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Sjors Hettinga 67770b7af8 net: tcp: Restructure out of order testcase
To provide more fine grained testing on out of order acknowledgements
restructure the testcase to use a list with expected in and outputs.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Sjors Hettinga 02bb842403 net: tcp: Update testcase for acknowledging out of order packets
The stack acknowledges out of order packets right now, update the
test_server_recv_out_of_order_data test to properly validate this
behavior.

Out of order packets should be acknowledged using sequence number of
the last correctly received byte.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Sjors Hettinga f2d94a7f5c net: tcp: Implement a fast retransmit algorithm
Instead of waiting for the retransmit timeout, retransmit as soon as
missing data is deduced based on a triple-duplicate ACK.

Increase the number of buffers in the testcase, to allow for at least 4
packets in flight to trigger the triple-duplicate ACK.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-09-01 10:38:28 +00:00
Florian Grandel 7fb2e1ec4d net: l2: ieee802154: add unittests
This change introduces test coverage for IEEE 802.15.4 AF_PACKET support
and IEEE 802.15.4 security operation.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-31 21:52:37 +00:00
Florian Grandel 705a8b6ea1 net: ieee802154: introduce consistent MTU definition
Zephyr IEEE 802.15.4 drivers and L2 stack use the same constant names
for different MTU definitions. The intent of this change is to introduce
a consistent MTU definition which can be used everywhere in zephyr to
avoid confusion, bugs and name conflict.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-31 21:52:37 +00:00
Hu Zhenyu 6e2b6fed26 tests: net: igmp: move to new ztest API
Move net igmp tests to use new ztest API
1. Add teardown, delete callback and remove addr
2. Combine join/leave

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-30 14:18:41 +00:00
Hu Zhenyu 5e4b99772c tests: net: ipv6: move to new ztest API
Move net ipv6 tests to use new ztest API
1. Add rm_neighbor/rm_max_neighbors
2. Add a setup function including:
   add ifaddr_record to record ifaddr for teardown use
   add neighbor operations
3. Add a teardown fuction including:
   remove neighbor operations
   remove maddr
   set ifaddr_record to not used
4. add k_yield after rs message, so that ra_message can start receive
5. add leave_group, to restore to the original state after join_group
6. restore the mac address to original in test_change_ll_addr()
7. remove the addr/maddr to restore original in necessary test cases

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-30 14:18:28 +00:00
Hu Zhenyu 724bbcbc05 tests: net: iface: move to new ztest API
Move net iface tests to use new ztest API
1. Add teardown, remove addr and interface down
2. Add pkt unref
3. Combine interface up/down, promisc off/on, addr add/rm

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-30 14:18:11 +00:00
Hu Zhenyu 739b3d16fc tests: net: ethernet_mgmt: move to new ztest API
Move net/ethernet_mgmt tests to use new ztest API
1. Combine the tests of the same kind
2. To make the test be able to run multiple times
   set back "auto neg" to original state(true) when test is done.
   set back linkspeed to original 10Mbps when the test is done.
   set back duplex to original state(true) when test is done.

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-30 14:18:00 +00:00
Hu Zhenyu 13742807ff tests: net: traffic_class move to new ztest API
Move traffic_class tests to use new ztest API
TEST=twister -T tests/net/traffic_class

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-30 10:27:07 +02:00
Hu Zhenyu dcda3eab8d tests: net: socket: tcp: move to new ztest API
Move net/socket/tcp tests to use new ztest API
TEST=twister -T tests/net/socket/tcp

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 11:58:17 -04:00
Hu Zhenyu f3de8c2c3b tests: net: context: move to new ztest API
Move net context tests to use new ztest API

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 14:37:26 +00:00
Hu Zhenyu ff2c64a329 tests: net: lib: lwm2m: content_json: move to new ztest API
Move net content_json tests to use new ztest API
Split all the test cases into 3 test suites, each test suite has
its own before function.

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 14:34:37 +00:00
Hu Zhenyu 70bd5a98a0 tests: net: lib: lwm2m: content_link_format: move to new ztest API
Move net content_link_format tests to use new ztest API
Split all the test cases into 2 test suites, each test suite has
its own before function.

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 14:34:12 +00:00
Hu Zhenyu a07402d692 tests: net: lib: lwm2m: content_oma_tlv: move to new ztest API
Move net content_oma_tlv tests to use new ztest API
Split all the test cases into 3 test suites, each test suite has
its own before function.

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 14:33:52 +00:00
Hu Zhenyu f73371c8b4 tests: net: lib: lwm2m: content_plain_text: move to new ztest API
Move net content_plain_text tests to use new ztest API
Split all the test cases into 3 test suites, each test suite has
its own before function.

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 14:33:32 +00:00
Hu Zhenyu 4e7ec5eb87 tests: net: lib: lwm2m: content_raw_cbor: move to new ztest API
Move net content_raw_cbor tests to use new ztest API
Split all the test cases into 3 test suites, each test suite has
its own before function.

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 14:33:23 +00:00
Hu Zhenyu d548ebc318 tests: net: socket: udp move to new ztest API
Move net/socket/udp tests to use new ztest API
TEST=twister -T tests/net/socket/udp

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-29 10:30:14 -04:00
Gerard Marull-Paretas a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Hu Zhenyu b962074a68 tests: net: socket: tls move to new ztest API
Move net/socket/tls tests to use new ztest API
TEST=twister -T tests/net/socket/tls

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-18 12:36:20 +02:00
Neil Armstrong 95c863e0f6 tests: net: lib: tls_credentials: Add tfm_trusted test
This enables the Trusted TLS Credentials Protected Storage
backend for this test.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-08-18 12:33:07 +02:00
Neil Armstrong 0690693d8f tests: tls_credentials: fix test
Fix test to not assume anymore that:
- credential iteration buffer has the same pointer as the buffer
  used in credential_add, now compare the length & content.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2022-08-18 12:33:07 +02:00