Commit graph

1725 commits

Author SHA1 Message Date
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
Henrik Brix Andersen 27eb12ed48 net: socketcan: decouple SocketCAN and CAN controller headers
Decouple the zephyr/net/socketcan.h and zephyr/drivers/can.h header files
by moving the SocketCAN utilities to their own header.

This is preparation for including the SocketCAN types defined in
socketcan.h in a native posix (Linux) SocketCAN driver context without name
clashes.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen ef1e492032 net: socketcan: SocketCAN supports classic CAN, not CAN-FD
SocketCAN does not support CAN-FD data lengths of up to 64 bytes
payload. Decouple the maximum supported SocketCAN data length from the
maximum supported CAN controller data length.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen d1d48e8304 net: socketcan: rename SocketCAN header from socket_can.h to socketcan.h
Rename the SocketCAN header from socket_can.h to socketcan.h to better
match the naming of the functionality.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen b40a8cb9fd net: socket: can: rename utility functions
Rename the SocketCAN utility functions to reflect the new naming of the CAN
controller API and SocketCAN API data types.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen 13c75417ba drivers: can: remove z prefix from public CAN API types
Remove the "z" prefix from the public CAN controller API types as this
makes them appear as internal APIs.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen d159947443 net: socket: can: prepend SocketCAN data types with socketcan
Rename the SocketCAN data types to "socketcan_*" in preparation of renaming
the low-level CAN controller API data types.

This breaks the naming compatibility with the similar SocketCAN data types
from the Linux kernel, but Zephyr and Linux SocketCAN are not 100%
compatible anyways (only the structure fields are compatible, extended
functionality such filtering, error reporting etc. are not).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen 6099e180b1 tests: move the SocketCAN tests to tests/net/socket/can
Move the SocketCAN tests from tests/drivers/can/utilities to
tests/net/socket/can to match the location of the code under test.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Hu Zhenyu f2077888a2 tests: net: virtual: move to new ztest API
Move net/virtual tests to use new ztest API
TEST=twister -T tests/net/virtual

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-08-15 08:13:15 +00:00
Kumar Gala 6124ccfccf drivers: ethernet: provide Kconfig means to disable ethernet drivers
There are several test cases that create fake ethernet devices and
expect the fake device to be the only ethernet device enabled.  Some
tests handle this be explicitly disabling actual ethernet drivers,
but this doesn't scale well.

Change drivers/ethernet/Kconfig to utilze a menuconfig option that
wraps all the drivers.  This allows us for those test cases that
don't want any actual ethernet drivers to disable them with a
simple CONFIG_ETH_DRIVER=n.

Note, the fake ethernet devices utilize CONFIG_ETH_INIT_PRIORITY so
we have it outside of the 'if ETH_DRIVER' block.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-08-12 11:33:43 +02:00
Xiao Song c35f1f977d tests: net: lib: move dns_addremove to new ztest API
Move tests/net/lib/dns_addremove/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-08-10 16:11:46 +02:00
Gerard Marull-Paretas b74a22924e net: lib: config: remove NET_CONFIG_IEEE802154_DEV_NAME
Remove NET_CONFIG_IEEE802154_DEV_NAME in favor of DT based choice using
zephyr,ieee802154.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-10 11:57:34 +02:00
Gerard Marull-Paretas f1e059a3e5 tests: net: ieee802154: use native_posix
All IEEE 802.15.4 tests use internal fake devices, so use native_posix
platform to run them as they are not meant to test IEEE 802.15.4 on
hardware.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-10 11:57:34 +02:00
Robert Lubos 3eaf55a364 tests: net: socket: Disable unstable tests for mps2_an385
Disable unstable tests cases for mps2_an385, which fail sporadically
due to timer stability issues on that platform (see #48608).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-08 22:18:23 +09:00
Martí Bolívar 4583ebe50d tests: net: socket: adjust fudge factors
Loosen some timing constraints in order to hack arond spurious
failures in upstream Zephyr's CI while working on an unrelated task.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-08-08 10:44:41 +02:00
Florian Grandel dcb2ead52c net: l2: ieee802154: rename *fragment to *6lo_fragment
6LoWPAN fragmentation is not related to IEEE 802.15.4 proper but is just
part of its IPv6-specific L3-adaptation layer. To make this more obvious
we rename all resources related to 6LoWPAN fragmentation.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-04 13:44:06 +02:00
Florian Grandel 2e5e761074 net: l2: ieee802154: decouple L2/L3 concerns
This change decouples the IEEE 802.15.4 (L2) layer from all IPv6 (L3)
concerns.

Applications may now choose to set CONFIG_NET_6LO=n and
CONFIG_NET_L2_IEEE802154=y at the same time.

Setting CONFIG_NET_6LO=n will build a vanilla IEEE 802.15.4-2006 specs
compliant L2 layer without any reference to 6LoWPAN or IPv6. This allows
application developers to design custom non-IP protocols on top of
IEEE 802.15.4-2006 and thereby makes the L2 layer much more re-usable.

Fixes #48585.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-04 13:44:06 +02:00
Gerard Marull-Paretas e6a345f967 drivers: ieee802154: uart_pipe: make driver DT-based
Use Devicetree to describe the UART UPIPE IEEE 802.15.4 driver. This
allows to remove usage of IEEE802154_UPIPE_DRV_NAME in preparation for
the removal of NET_CONFIG_IEEE802154_DEV_NAME.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 2df965f490 drivers: ieee802154: nrf5: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_NRF5_DRV_NAME in preparation for the
removal of NET_CONFIG_IEEE802154_DEV_NAME.

All SoC files have been updated with the addition of an ieee802154 node
(disabled and only on those SoCs that define ieee802154-supported. The
peripheral has been enabled in the nRF52840DK board (used for testing
ieee802154).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 7d5272db62 drivers: ieee802154: kw41z: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_KW41Z_DRV_NAME in preparation for the removal
of NET_CONFIG_IEEE802154_DEV_NAME.

KW41Z files have been updated with the addition of radio and an
ieee802154 nodes The peripheral has been enabled in the frdm_k41z board
(used for testing ieee802154).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas dc0728fb2a drivers: ieee802154: cc2520: drop IEEE802154_CC2520_CRYPTO_DRV_NAME
The crypto driver is used internally, so there's no real need to expose
its name as a Kconfig option. Just drop it in favor of a plain string
with the same previous value.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 1ff6577e30 drivers: ieee802154: cc1200: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_CC1200_DRV_NAME in preparation for the removal
of NET_CONFIG_IEEE802154_DEV_NAME.

In this case, the driver already had bindings, however, it was still
using NET_DEVICE_INIT.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Stephanos Ioannidis 815b974382 tests: net: socket: tcp: Disable preempt test for mps2_an385
This commit disables the `net.socket.tcp.preempt` test on the
`mps2_an385` platform because it fails very frequently due to the
system timer stability issues.

For more details, refer to the issue zephyrproject-rtos/zephyr#48608.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-03 08:56:28 -04:00
Fabio Baltieri def230187b test: fix more legacy #include paths
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-02 16:41:41 +01:00
Xiao Song dd1eac6602 tests: net: lib: move mqtt_packet to new ztest API
Move tests/net/lib/mqtt_packet/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-08-01 17:59:57 +02:00
Sjors Hettinga fafcbf59b9 net: tcp: Implement randomized retransmission timeouts
It can happen that two similar stacks enter a retransmission cycle
due to a packet collision. If the transmission timeout is the same
both stacks will retry at the same moment resulting in another
collision.

By introducing a randomized retry timeout, the chance of
a second collision is reduced and it reduces furter the more
retransmissions occur.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-08-01 10:33:24 +02:00
Sjors Hettinga ea4f10fc58 net: tcp: Basic exponential backoff implementation
Apply an exponentially increasing wait time between tcp retries. This
is a good balance between reacting fast to single lost packets and reduce
the network load when an outage takes a little longer. It also allows the
connection to survive a longer interruption with less retransmissions.

Update the test to accommodate for the increased socket closure timeout

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-08-01 10:33:24 +02:00
Sjors Hettinga a0ca04b893 net: tcp: Explicitly wait for context closure instead of simply waiting
Previously the test waited for the worst case time till all sockets
where closed, this causes the test to wait for a long unnecessary time.
Secondly it does not ensure the sockets are actually closed before
starting the next tests.

For tests that are not conducted in user mode, wait until all the contexts
are close for a maximum time. If the contexts are not closed in time raise
an explicit assertion.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-08-01 10:33:24 +02:00
Hu Zhenyu 4f6011c981 tests: net: vlan: move to new ztest API
Move vlan tests to use new ztest API
TEST=twister -T tests/net/vlan

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 11:05:10 -04:00
Hu Zhenyu 8090fa3b33 tests: net: socket: select move to new ztest API
Move net/socket/select tests to use new ztest API
TEST=twister -T tests/net/socket/select

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 10:51:16 -04:00
Hu Zhenyu 74fdc04234 tests: net: socket: register: move to new ztest API
Move net/socket/register tests to use new ztest API
TEST=twister -T tests/net/socket/register

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 10:51:02 -04:00
Hu Zhenyu 79c68eb783 tests: net: socket: poll move to new ztest API
Move net/socket/poll tests to use new ztest API
TEST=twister -T tests/net/socket/poll

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 10:50:50 -04:00
Hu Zhenyu f40e50f519 tests: net: socket: net_mgmt move to new ztest API
Move net_mgmt tests to use new ztest API
TEST=twister -T tests/net/socket/net_mgmt

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 10:50:18 -04:00
Hu Zhenyu 8b39587f23 tests: net: socket: getnameinfo: move to new ztest API
Move getnameinfo tests to use new ztest API
TEST=twister -T tests/net/socket/getnameinfo

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 10:49:59 -04:00
Hu Zhenyu 2ff8588cd3 tests: net: socket: getaddrinfo: move to new ztest API
Move getaddrinfo tests to use new ztest API
TEST=twister -T tests/net/socket/getaddrinfo

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 10:49:45 -04:00
Hu Zhenyu 7bc775c479 tests: net: socket: af_packet_ipproto_raw move to new ztest API
Move af_packet_ipproto_raw tests to use new ztest API
TEST=twister -T tests/net/socket/af_packet_ipproto_raw/

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-28 10:49:28 -04:00
Xiao Song befcf017ea tests: net: checksum_offload: move to new ztest API
Move tests/net/checksum_offload/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-28 10:32:42 -04:00
Xiao Song e6049662ee tests: net: lib: move http_header_fields to new ztest API
Move tests/net/lib/http_header_fields/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-28 10:32:07 -04:00
Xiao Song 741dffa786 tests: net: lib: move dns_sd to new ztest API
Move tests/net/lib/dns_sd/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-28 10:31:25 -04:00
Xiao Song f87d13ffe8 tests: net: lib: move dns_resolve to new ztest API
Move tests/net/lib/dns_resolve/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-28 10:30:58 -04:00
Xiao Song 162fc5cdf7 tests: net: lib: move dns_packet to new ztest API
Move tests/net/lib/dns_packet/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-28 10:30:09 -04:00
Xiao Song 197969b3df tests: net: ipv6_fragment: move to new ztest API
Move tests/net/ipv6_fragment/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-28 10:29:36 -04:00
Hu Zhenyu ada34a250e tests: net: socket: move to new ztest API
Move net tests to use new ztest API
TEST=twister -T tests/net/socket/af_packet

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-27 18:47:21 +02:00
Hu Zhenyu 4fd935b6ef test: Update the new ZTEST APIs tests/net/socket/misc
TEST=twister -T tests/net/socket/misc

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-25 11:08:26 -04:00
Hu Zhenyu de40c4e986 test: Update the new ZTEST APIs tests/net/shell
TEST=twister -T tests/net/shell

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-21 13:57:47 +00:00
Kumar Gala e99652b67d drivers: ieee802154: cc2520: Convert to DEVICE_DT_INST_DEFINE
Move driver to use {NET_}DEVICE_DT_INST_DEFINE.  This lets us
remove the IEEE802154_CC2520_DRV_NAME Kconfig symobl.

We also update the ieee802154 build_all test to actually enable
the CC2520 driver.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-19 10:32:21 +02:00
Xiao Song 2218cb1094 tests: net: lib: move coap to new ztest API
Move tests/net/lib/coap/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-19 10:30:06 +02:00
Tomislav Milkovic 0fe2c1fe90 everywhere: Fix legacy include paths
Any project with Kconfig option CONFIG_LEGACY_INCLUDE_PATH set to n
couldn't be built because some files were missing zephyr/ prefix in
includes
Re-run the migrate_includes.py script to fix all legacy include paths

Signed-off-by: Tomislav Milkovic <milkovic@byte-lab.com>
2022-07-18 16:16:47 +00:00
Xiao Song 1f414faf58 tests: net: ip-addr: move to new ztest API
Move tests/net/ip-addr to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-14 10:40:19 +02:00
romain pelletant 3908b9dc74 net: lwm2m: Add Event Log object
Event Log object (ID:20) from OMA LwM2M support added

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2022-07-13 10:19:26 +02:00
Xiao Song 0b73446c5d tests: net: ieee802154: move l2 to new ztest API
Move tests/net/ieee802154/l2/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-12 12:26:16 +02:00
Xiao Song ec3a208f87 tests: net: ieee802154: move fragment to new ztest API
Move tests/net/ieee802154/fragment/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-12 12:26:16 +02:00
Xiao Song e19544a7c0 tests: net: ieee802154: move custom_l2 to new ztest API
Move tests/net/ieee802154/custom_l2/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-12 12:26:16 +02:00
Xiao Song eda0bef213 tests: net: hostname: move to new ztest API
Move tests/net/hostname/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-11 11:06:42 +02:00
Xiao Song 4d500f8f49 tests: net: bridge: move to new ztest API
Move tests/net/bridge/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-08 11:59:02 +02:00
Hu Zhenyu 7bfbbf5221 test: Update the new ZTEST APIs tests/net/ptp
TEST=twister -T tests/net/ptp

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu a2b49ec10c test: Update the new ZTEST APIs tests/net/promiscuous
TEST=twister -T tests/net/promiscuous

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu 21092ae367 test: Update the new ZTEST APIs tests/net/ppp
TEST=twister -T tests/net/ppp

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu aa3cb29b9e test: Update the new ZTEST APIs tests/net/pm
TEST=twister -T tests/net/pm

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu 1f09e66060 test: Update the new ZTEST APIs tests/net/npf
TEST=twister -T tests/net/npf

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu 42901b58ba test: Update the new ZTEST APIs tests/net/net_pkt
TEST=twister -T tests/net/net_pkt

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu 0aabf5942e test: Update the new ZTEST APIs tests/net/neighbor
TEST=twister -T tests/net/neighbor

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu 29b419b8bc test: Update the new ZTEST APIs tests/net/mld
TEST=twister -T tests/net/mld

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu 3c7387050c test: Update the new ZTEST APIs tests/net/mgmt
TEST=twister -T tests/net/mgmt # Only build

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 10:58:24 +02:00
Hu Zhenyu 2aa1890dfb test: Update the new ZTEST APIs tests/net/route_mcast
TEST=twister -T tests/net/route_mcast

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 09:37:02 +02:00
Hu Zhenyu 512ffec795 test: Update the new ZTEST APIs tests/net/route
TEST=twister -T tests/net/route

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
2022-07-08 09:37:02 +02:00
Xiao Song 0c6210c2e0 tests: net: icmpv6: move to new ztest API
Move tests/net/icmpv6/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-07 15:13:08 +02:00
Anas Nashif 02f2896586 tests: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Xiao Song 1f4db6fc90 tests: net: arp: move to new ztest API
Move tests/net/arp/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-06 11:11:47 +02:00
Andreas Chmielewski 363e2f3014 net: coap: make coap vars configurable
COAP_DEFAULT_MAX_RETRANSMIT and COAP_DEFAULT_ACK_RANDOM_FACTOR
should be configurable to determine the max transmission
timeout of a CoAP packet.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-07-05 21:56:34 +00:00
Xiao Song f10f900f10 tests: net: dhcpv4: move to new ztest API
Move tests/net/dhcpv4/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-05 11:13:24 -04:00
Xiao Song 3e40c590f8 tests: net: all: move to new ztest API
Move tests/net/all/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-05 12:17:32 +00:00
Xiao Song 257717ce83 tests: net: 6lo: move to new ztest API
Move tests/net/6lo/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-05 12:17:19 +00:00
Xiao Song 2c8841ac02 tests: net: buf: move to new ztest API
Move tests/net/buf/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-05 10:08:09 +02:00
Xiao Song 64981940c2 tests: net: udp: move to new ztest API
Move tests/net/udp/ to use new ztest API.

Signed-off-by: Xiao Song <songx.xiao@intel.com>
2022-07-01 17:59:07 +00:00
Andrei Emeltchenko 30be920bd6 tests: net: socket: Add missing return code check
Add missing check.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-30 10:34:40 +02:00
Andrei Emeltchenko 6360f75d0c tests: net: socket: Fix checking wrong variable
Check return code instead of parameter.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-30 10:34:40 +02:00
Krzysztof Chruscinski 041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Marcin Niestroj 994f6c8630 tests: net: sockets: tls: increase ztest and sysworkq stack sizes
Increase threads stack sizes from 2k to 3k, so that it will pass without
stack overflow on qemu_x86 platform when SHA384 support will be reenabled.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-06-15 09:11:09 +02:00
Markus Rekdal 071a017b18 net: lwm2m: Add SenML CBOR content writer tests
This will add unit tests for the SenML CBOR content encoder/decoder

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-09 11:32:01 +02:00
Juha Heiskanen 2da8df8b7e net: lwm2m: Integrate JSON lib to LwM2M 1.0 JSON
Integrated updated JSON library to LwM2M 1.0 JSON.
Removed Old Json format default choice.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-06-06 12:06:43 +02:00
Andriy Gelman d67a130368 tests: net: Check leaks when appending frags to a cloned packet
This test checks that new frags appended to a cloned packet are properly
freed.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2022-06-05 14:29:19 +02:00
Andriy Gelman f119a368a2 tests: net: Add test to detect leak in pkt shallow clone
Checks that taking a shallow of a packet does not leak buffers after the
packet and its clone are unreffed.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2022-06-05 14:29:19 +02:00
Markus Rekdal 30dfcec45f net: lwm2m: Add raw CBOR content writer tests
Add unit tests for raw CBOR content encoder/decoder.

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-05 14:27:39 +02:00
Marcin Niestroj c4bd3f1e38 tests: net: socket: udp: verify that sent DGRAM was not fragmented
Datagrams should either be fully sent or not sent at all if networking
buffers or network interface MTU does not allow that.

Verify that by trying to send MTU+1 bytes in case of IPv4 (as IP level
fragmentation is not implemented) and IPv6 (should fail when IPv6
fragmentation support is not enabled and succeed otherwise). In case of
IPv6 try to send "total number of network buffers + 1", so that even with
IPv6 fragmentation enabled requested datagram will not be sent. In all
tested cases when datagram is too big, check that ENOMEM error code is set.

NOTE: Tested behavior is not 100% compliant with Linux, as on Linux
EMSGSIZE error code is set when trying to send datagram bigger than MTU,
when manually disabling IP fragmentation (by setting IP_MTU_DISCOVER to
IP_PMTUDISC_DO). However, it is not trivial to implement such
behavior (EMSGSIZE error due to MTU) now and there is always a risk of
running out of buffers (and getting ENOMEM), so for now implemented tests
just assume the latter case to always happen.

Add 3rd testcase, which enables IPv6 fragmentation support, so that UDP
socket behavior can be tested in that context.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-06-01 11:17:07 +02:00
Sjors Hettinga d55c921e2f tests: net: socket: tcp: Add test for a broken link
A reproducible case to the behavior when during a connection
the link gets broken and all data is lost, the TCP connection
should properly terminate.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-05-30 10:30:38 +02:00
Robert Lubos 3cd88c72b1 tests: net: sockets: Update packet socket tests
Fix the existing DGRAM packet socket test. The test will now specify
LL destination address and protocol type. Also, update the fake ethernet
device send handler, so that it sets the packet network interface
corretly, so that the packet is not rejected at Ethernet L2.

Additionally, add two additional test cases verifying datagram packet
sockets. Fist test will exchange packet between RAW and DGRAM socket,
making sure that net stack forwards/removes L2 header correctly. The
second test verifies that it's possible to recieve a packet on both RAW
and DGRAM socket, making sure the received data has correct format.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-05-27 15:40:29 -07:00
NingX Zhao 1bc003ad6a tests: net: Adjusting the memory buffer for ETH
The net cases failed to run on sam_e70b_xplained
platform because failed to reserve data net buffers,so
adjusting the memory buffer to fix this.

Fixes #42857

Signed-off-by: NingX Zhao <ningx.zhao@intel.com>
2022-05-26 13:39:11 -07:00
Marcin Niestroj 084aca1aa4 tests: socket: tls: check sendmsg() behavior for datagrams
Datagrams (for DTLS connection) need to be sent using single API call to
mbedTLS and should not result in sending each fragment in a separate
datagram. Check if that is the case, so allow only single fragment data to
be sent and expect an error when multiple fragments were passed to
sendmsg().

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-05-25 14:20:09 +02:00
Robert Lubos f49ed7a539 tests: net: socket: Add test to verify POLLOUT functionality
Add test which verifies that POLLOUT is reported correctly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-05-18 11:09:17 +02:00
Sjors Hettinga c3158804d4 tests: net: socket: tcp: Add test to validate obstructed close
When there is no response from the server, a client side close
is obstructed, it should terminate and clean the context. This
tests breaks the connection after the accept and validates
this behavior.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-05-16 16:55:51 +02:00
Robert Lubos d63cb79383 tests: net: socket: Increase ztest stack size for offload_dispatcher
The test suite is failing on qemu_cotext_a9 due to stack overflow.
Apparently this issue can also be observed on main after enabling
STACK_SENTINEL, however the test only started crashing after TCP
changes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-05-13 15:42:01 +02:00
Andrey Dodonov bc0cf10757 net: tcp: Remove unused config NET_TCP_BACKLOG_SIZE
Remove NET_TCP_BACKLOG_SIZE from KConfig and from test,
because it's not present anymore in current version of TCP stack.

Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
2022-05-13 13:04:59 +02:00
Gerard Marull-Paretas ade7ccb918 tests: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all tests to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:02:14 +02:00
Sjors Hettinga 11288cdbdd tests: net: socket: tcp: Make test_vX_msg_waitall more robust
The close function on a TCP socket can return before the complete
socket has been closed, as there might be packets still in flight.
Add a wait at the end of the test so we are sure all sockets have
been closed before the next test starts.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-05-05 14:45:02 -05:00
Sjors Hettinga cf3466ff74 tests: net: socket: tcp: Make test_open_close_immediately more robust
The close function on a TCP socket can return before the complete
socket has been closed, as there might be packets still in flight.
Modify the test to wait briefly (less then the retransmit time), before
counting the number of still open net_contexts. This makes the test
outcome not dependent on the scheduling order of the different tasks.

Secondly the test actually checks the number of open contexts to be zero
so there is no need to wait for any open contexts to still close.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-05-05 14:45:02 -05:00
Sjors Hettinga 40ee401dd2 tests: net: socket: tcp: Add test to validate connect timeout
When there is no response from the server, a client side connect
should return a ETIMEOUT. This tests breaks the connection and validates
this behavior.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-05-05 14:45:02 -05:00
Flavio Ceolin d490358e28 tests: ipv6: Fix DAD timeout test
DAD timeout was wrongly checking the reply order. The code will always
assign sequentially the reply to 0-2 with the current uptime. This means
that we will always have dad[0] < dad[1] < dad[2]. Check it is useless.
Instead, let just check if we got all replies.

The test checking the time between the first and last request is to
fragile. It is testing a constant independently of the tested platform
failing in several of them. Just remove it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-04-27 12:35:34 -04:00
Robert Lubos 6da10468ad tests: net: Add socket dispatcher unit tests
Add unit tests for socket dispatcher module. The tests verify that:
* a socket is automatically dispatched to a regular socket on any
  first socket call, if the socket was not bound already before
  (according to the default priority rules)
* a socket is correctly dispatched to an offloaded/native socket
  implementation after a SO_BINDTODEVICE call
* a socket is correctly dispatched to a native TLS socket, with an
  underlying native/offloaded socket, if TLS_NATIVE and SO_BINDOTODEVICE
  socket options are used

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-04-20 11:27:05 +02:00
Mohan Kumar Kumar 2558d277e2 tests: net: tcp: Add new tests for get/set SO_SNDBUF
Test SO_SNDBUF option using getsockopt and setsockopt.

Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
2022-04-11 10:23:31 +02:00
Sjors Hettinga 3b03344a8d tests: net: socket: tcp: Add test for big block data transfer
A reproducible case to see what happens when the TCP stack runs out
of buffers. It transfers a block, bigger then the number of buffers
available.
Also test by introducing packet loss in the loopback driver.

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-04-01 12:36:14 -05:00
Mohan Kumar Kumar 4e7a74c547 tests: net: tcp: Add new tests for get/set SO_RCVBUF
Test SO_RCVBUF option using getsockopt and setsockopt.

Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
2022-04-01 13:30:09 +02:00
Katarzyna Giadla 681e3a16c7 tests: Change duplicated names of the test cases
Some names of the test cases are duplicated within the project.
This commit contains the proposed names of the test scenarios.

Signed-off-by: Katarzyna Giadla <katarzyna.giadla@nordicsemi.no>
2022-03-30 17:42:01 -04:00
Robert Lubos c1f06c7442 tests: net: sokcets: tcp: Adjust net_pkt count
Since the loopback driver makes use of the RX packet pool now, adjust
the packet count for the test.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-30 11:08:22 +02:00
Emil Gydesen ae55dae454 sys: util: Change return type of ARRAY_SIZE to size_t
The ARRAY_SIZE macro uses sizeof and thus the return
type should be an unsigned value. size_t is typically
the type used for sizeof and fits well for the
ARRAY_SIZE macro as well.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-03-23 14:09:23 +01:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Robert Lubos cea2c8de3d tests: net: socket: Add getpeername() tests
Add tests for new getpeername() function.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-16 16:23:16 +01:00
Yong Cong Sin 4bcd33bb35 tests: net: all: Add shell MQTT backend
Test the compilation of shell MQTT backend.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-15 10:01:12 +01:00
Henrik Brix Andersen e9c9caa80d net: remove unmaintained 6LoCAN implementation
Remove the unmaintained, experimental 6LoCAN (IPv6 over CAN bus)
implementation.

Fixes: #42559

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-03-09 18:07:31 +01:00
Otavio Salvador e2edb3e405 scripts: Allow use of bash outside of /bin
Even though bash is commonly available as /bin/bash there are
exceptions (e.g NixOS). This commit allow the use of the scripts in my
environment and is generic.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2022-03-08 11:11:10 +01:00
Marcin Niestroj 4480831fc6 tests: socket: tcp: add shutdown(..., SHUT_RD) tests
Those tests cover behavior of shutdown(fd, SHUT_RD) and recv(fd, ...).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2022-03-02 10:05:09 -08:00
Robert Lubos 9ac83be650 net: lwm2m: Add proper resource-level discovery attribute handling
In case an individual resource is being discovered, the LwM2M client
should not only fill the attributes assinged at the resource level, but
also the ones inherited from the object and object instance levels.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:12:27 -08:00
Carles Cufi e83a13aabf kconfig: Rename the TEST_EXTRA stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
Carles Cufi 4b8f1c04ab kconfig: Rename the ZTEST stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
Gerard Marull-Paretas 5314690c3b drivers: ieee802154: mcr20a: define as DT device
The device already has a DT compatible (and uses DT properties).
Instantiate the device using the DT-based macros and remove hardcoded
name.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-21 22:16:10 -05:00
Xabier Marquiegui 52be66919e net: gptp: convert clock sync ratio from float to double
Using clock sync ratio as double instead of float improves
synchronization smoothness

Signed-off-by: Xabier Marquiegui <xmarquiegui@ainguraiiot.com>
2022-02-11 10:03:05 -06:00
Yong Cong Sin 731241f8d0 kernel: workq: Fix type errors in delayable work handlers
A common pattern here was to take the work item as the subfield of a
containing object. But the contained field is not a k_work, it's a
k_work_delayable.

Things were working only because the work field was first, so the
pointers had the same value. Do things right and fix things to
produce correct code if/when that field ever moves within delayable.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-02 18:43:12 -05:00
Robert Lubos 21e5cc7a31 tests: net: lwm2m: Add link-format content writer tests
Add unit tests for LwM2M link-format content encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 960512fa13 tests: net: lwm2m: Add JSON content writer tests
Add unit tests for LwM2M JSON conent encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 735fd86c0e tests: net: lwm2m: Add OMA TLV content writer tests
Add unit tests for LwM2M OMA TLV conent encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 48fd29a081 tests: net: lwm2m: Add plain text content writer tests
Add unit tests for LwM2M plain text conent encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Efrain Calderon 99e3e67661 test: net: coap: update tests
Update test to ensure that any file can be tranfered,
not only files that are aligned with the packet size.

Signed-off-by: Efrain Calderon <efrain.calderon@aquarobur.com>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:10:57 +01:00
Andrew Hedin 7f004f1b35 net: lwm2m: Add LwM2M gateway object
Add support for the gateway object [EXPERIMENTAL] used by the
MG100, BT510, and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2022-01-18 13:19:12 -05:00
Gerard Marull-Paretas ddc168fa78 pm: s/PM_DEVICE_(DT_(INST))_REF/PM_DEVICE_(DT_(INST))_GET
In order to align with macros used to obtain a device reference (e.g.
DEVICE_DT_GET), align the PM macros to use "GET" instead of "REF". This
change should have low impact since no official release has gone out yet
with the "REF" macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-18 12:14:06 -05:00
Nicolas Pitre a3a31257df net: npf: add the ability to do MAC address masked matching
Add the ability to do matching on partial MAC addresses.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-12-21 17:06:35 +01:00
Nicolas Pitre faa0b2a848 net: introduce a network packet filter framework
This provides the infrastructure to create network packet filter rules
and to apply them to the RX and TX packet paths. Rules are made of
simple condition tests that can be linked together, creating a facility
similarly to the Linux iptables functionality.

A couple of generic and Ethernet-specific condition tests are also
provided.

Additional tests can be easily created on top of this.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-12-21 17:06:35 +01:00
Robert Lubos 860e59e881 tests: net: ipv6: Verify Route Info data in Router Advertisment
Verify that Route Info data received in Router Advertisment creates a
route and correctly populates the net_route_entry structure.

Additionally, extend the MTU on the test interface, to accomodate the
extended Router Advertisement message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-12-20 17:44:28 +01:00
Robert Lubos 111992bb71 tests: net: route: Add new route tests
Add new route tests to cover lifetime and preference functionality.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-12-20 17:44:28 +01:00
Robert Lubos e9db822635 net: route: Add support for route preference
Implement a concept of Route Preference, as specified in RFC 4191. The
Zephyr host will prefer routes with higher preference, if they lead to
the same prefix through different neighbours.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-12-20 17:44:28 +01:00
Kim Bøndergaard ee6c552805 boards: frdm_k64f: Solve conflict between UART3 and enet
Arduino compatible boards should have a working UART on pin 0 & 1.
On frdm_k64f this is handled by uart3

Unfortunately pinmuxing of uart3 was destroyed when enabling NETWORKING,
because the uart3 RX/TX pins was reconfigured for 1588 timers.

1588 timers are enabled by the enet child node, ptp which by some reason
is enabled by default.
1588 timers aren't needed in most cases when ethernet is being used,
so this fix ensures ptp is by default disabled. Likewise pinmuxing of
the 1588 timer functionality is now dependant of ptp being active

Signed-off-by: Kim Bøndergaard <kim.boendergaard@escoglobal.com>
2021-11-30 11:08:15 -06:00
Robert Lubos 2eb67b2fe4 tests: net: Add custom 802154 L2 tests
Add some basic custom 802154 L2 tests, verifying that a custom L2 can be
integrated with Zephyr properly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-29 18:55:13 -05:00
Gerard Marull-Paretas 89a4f36fc8 device: remove inclusion of pm/device.h
The device PM subsystem _depends_ on device, not vice-versa. Devices
only hold a reference to struct pm_device now, and initialize this
reference with the value provided in Z_DEVICE_DEFINE. This requirement
can be solved with a forward struct declaration, meaning there is no
need to include device PM headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-29 11:08:38 +01:00
Robert Lubos 6dbd5c7876 net: icmpv6: Remove in6_addr from packed structs
Replace unpacked in6_addr structures with raw buffers in packed icmpv6
structs, to prevent compiler warnings about unaligned access.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-25 10:46:35 -05:00
Robert Lubos 666e9f80d6 net: ipv6: Remove in6_addr from packed net_ipv6_hdr struct
Replace unpacked in6_addr structures with raw buffers in net_ipv6_hdr
struct, to prevent compiler warnings about unaligned access.

Remove __packed parameter from `struct net_6lo_context` since the
structure isn't really serialized.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-25 10:46:35 -05:00
Robert Lubos 064200b420 net: ipv4: Remove in_addr from packed net_ipv4_hdr struct
Replace unpacked in_addr structures with raw buffers in net_ipv4_hdr
struct, to prevent compiler warnings about unaligned access.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-25 10:46:35 -05:00
Robert Lubos bbdeef4ac4 net: arp: Remove in_addr/in6_addr from packed net_arp_hdr struct
Replace unpacked in_addr/in6_addr structures with raw buffers in
net_arp_hdr struct, to prevent compiler warnings about unaligned
access.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-25 10:46:35 -05:00
Flavio Ceolin 6451626ce7 pm: Use pm_device_action_run instead of state_set
Since drivers implement a callback based on action and not the state,
we should be using the API based on the action instead of the one based
on the state.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-24 14:21:50 -05:00
Jordan Yates 8e99db5801 Kconfig: net: deprecate NET_BUF_USER_DATA_LEN
As user data sizes are now set on a per pool basis, this Kconfig option
has no purpose.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Jordan Yates 70649077a0 tests: net: buf: test per-pool data lengths
Validate that per-pool user data lengths are being set correctly.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Jordan Yates df327eeb58 net: buf: POOL_FIXED_DEFINE explicit user data
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Jordan Yates d17e0439c2 net: buf: POOL_HEAP_DEFINE explicit user data
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Jordan Yates 8236b600f7 net: buf: POOL_VAR_DEFINE explicit user data
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Jordan Yates 0b5e6f1f8f tests: net: buf: validate user_data_size fields
Validate the `user_data_size` field is populated correctly.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Gerard Marull-Paretas 39f21dc116 tests: pm: use new PM macros
Use PM_DEVICE_STATE_DEFINE to define PM state.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-19 10:11:32 +01:00
Christopher Friedt 3e86c627f7 kernel: atomics: update print specifiers for atomic_t
The print specifier for `atomic_t` should be updated
to `%ld`, `%lu`, or `%lx` to account for the type
change of `atomic_t` to `long`.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-15 09:59:01 -05:00
Tomasz Bursztyka 32db35a721 net/tcp: Rename TCP2 to TCP
TCP2 is no longer needed as it is the unique implementation since the
legacy one has been removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-11 07:26:41 -05:00
Tomasz Bursztyka 404f67ab5e tests/net: Raise TLS timeout option on waitall checks
Previous timeouts values were done when local TCP replies wourd occur
within sender's thread. This was a known behavior: no context switch,
shorter timings for sending packets (locally only) thus shorter
timeouts.

Such behavior changed when local replies had to go through TCP's work
queue. See commit 798588e709

Fixes #40129

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-09 12:51:44 +01:00
Andrew Hedin a6f831fea6 net: lwm2m: Add IPSO filling sensor object
Add support for the filling sensor object used by the MG100
and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-11-09 11:19:12 +01:00
Andrew Hedin e0715556e7 net: lwm2m: Add IPSO current sensor object
Add support for the current sensor object used by the MG100
and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-11-08 11:01:22 -05:00
Anas Nashif 6432289baf tests: add integration_platforms to socket/tls test
Run only on defined integration platforms in CI.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-11-05 09:23:41 -04:00
Tomasz Bursztyka 3718904a50 test/net: Make sure the tls server socket is accepting before connect
Client thread might run before the server gets to put itself on accept.
Leading to the server waiting forever.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-04 13:54:28 +01:00
Tomasz Bursztyka 174f489bec tests/net: Put the context down and not only the tcp part in tcp2 test
This will clean up the context properly and call net_tcp_put()
relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-04 13:54:28 +01:00
Tomasz Bursztyka f371f76e9a tests/net: Switch k_msleep to k_yield for tcp packet scheduling
TCP work queue is of higher priority so k_yield should do the trick, and
the test will not be affected by any timing.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-04 13:54:28 +01:00
Tomasz Bursztyka 1696f6de35 tests/net: TLS test requires more RX PKT and buffers
Due to the previous change on when to send TCP packet on local IP, pkt
may be held in a queue which is to run on a k_work. This changes the
scheduling, and due to that one of the test is failing to allocate a
RX net_pkt at the time it wants to. (previous TCP connection is not yet
fully closed and still own PKT that new connection cannot get then).

Of course all those waiting paquets require buffers so raising them.

It was verified that there is no leak, adding net_pkt_print() at
tcp_conn_unref() shows that when all tcp connection are finally unrefed:
all net_pkt get freed as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-11-04 13:54:28 +01:00
Gerard Marull-Paretas 18519ffe8d tests: use common PM action callback naming
The PM callback is no longer referenced as "pm_control" but
"pm_action_cb", so reflect this new naming on the callbacks.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 20:27:18 -04:00
Robert Lubos 20bdb6ee21 tests: net: all: Add LwM2M to build all test
LwM2M was not covered by networking build all test, leaving an opening
for possible regression in modules that are not enabled by default in
the sample.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-03 11:19:40 +01:00
Robert Lubos 477c0d9499 tests: net: net_pkt: Verify unchecked net_pkt functions results
Some net_pkt functions in `test_net_pkt_headroom_copy()` did not have
their return values verified, causing coverity complains.

CID: 240661

Fixes #39841

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-02 22:27:21 -04:00
Christopher Friedt 3ad85f41b5 tests: net: dns_sd, mdns: support service type enumeration
Tests for DNS-SD Service Type Enumeration.

Fixes #38673

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-10-01 20:11:50 -04:00
Robert Lubos 0dbdcc770d net: sockets: Add socket processing priority
When creating a socket, all of the registered socket implementation are
processed in a sequence, allowing to find appropriate socket
implementation for specified family/type/protocol. So far however,
the order of processing was not clearly defined, leaving ambiguity if
multiple implmentations supported the same set of parameters.

Fix this, by registering socket priority along with implementation. This
makes the processing order of particular socket implementations
explicit, giving more flexibility to the user, for example when it's
neeed to prioritze one implementation over another if they support the
same set of parameters.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-28 20:11:26 -04:00
Alex Sergeev e7778b8584 net: ptp: extract PTP interfaces outside gPTP subsys under NET_L2_PTP
As per #38352, we would like to start building out PTP (IEEE 1588)
support for superset of gPTP functionality in Zephyr. This is the first
step to abstract away some key interfaces from NET_GPTP umbrella to
NET_L2_PTP.

Signed-off-by: Alex Sergeev <asergeev@carbonrobotics.com>
2021-09-28 20:01:16 -04:00
Torsten Rasmussen 8e64038559 drivers: net: adding NET_DRIVERS menuconfig
Fixes: #38403

Adding NET_DRIVERS menuconfig so that network drivers are grouped
together in its own menu entry under drivers, similar to most other
drivers.

This further has the advantages that `CONFIG_NET_DRIVERS` can be used
for testing to determine if network drivers has been selected.

This changed revealed a dependency loop where both `select` (for SLIP)
and `depends` (for PPP) which both depends on NET_DRIVERS` where in use
in the dependency tree for Qemu networking, especially NET_SLIP_TAP.

This is handled by defaulting `NET_DRIVERS` to `y` when building for a
Qemu target.
`SLIP` had a dependency to `!QEMU_TARGET || NET_QEMU_SLIP`. This is
changed so that SLIP prompt depends on `!QEMU_TARGET` which provides
full user control in hardware but makes the symbol promptless on Qemu
targets.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-09-28 12:13:23 +02:00
Daniel DeGrasse b30ae46aa0 tests: ptp: Fixed PTP clock test failure on frdm_k64f
ptp_clock_test was failing when trying to access the ptp clock from user
mode. This was due to an arbitrary initialization priority between the
virtual PTP clock devices created by the ptp clocking test and the
physical PTP clock on the frdm_k64f board. Since the ptp test
initializes the virtual clock with the same device name as the physical
clock, if the physical clock was initialized first this test would
incorrectly reference the physical device during testing, instead of the
virtual one.

This fix simply defines the virtual ptp clock with a custom name, so
that the test will always locate the correct ptp clock.
Fixes #38731

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2021-09-23 04:17:40 -04:00
Jani Hirsimäki f7219e8a31 tests: net: socket: new tests for AF_PACKET&SOCK_RAW&IPPROTO_RAW
New test case for testing send/recv for
socket combo of: AF_PACKET&SOCK_RAW&IPPROTO_RAW.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2021-09-14 08:37:36 -04:00
Torsten Rasmussen 1cccc8a8fe cmake: increase minimal required version to 3.20.0
Move to CMake 3.20.0.

At the Toolchain WG it was decided to move to CMake 3.20.0.

The main reason for increasing CMake version is better toolchain
support.

Better toolchain support is added in the following CMake versions:
- armclang, CMake 3.15
- Intel oneAPI, CMake 3.20
- IAR, CMake 3.15 and 3.20

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-08-20 09:47:34 +02:00
Stancu Florin b4bf5cbf7a tests: ieee802154: fix test MAC addresses
Fake driver interface initialization and packet dst address were wrong.

Signed-off-by: Stancu Florin <niflostancu@gmail.com>
2021-08-17 09:19:39 -04:00
Gerard Marull-Paretas 7ccc1a41bc pm: use actions for device PM control
Instead of passing target states, use actions for device PM control.
Actions represent better the meaning of the callback argument.
Furthermore, they are more future proof as they can be suitable for
other PM actions that have no direct mapping to a state. If we compare
with Linux, we could have a multi-stage suspend/resume. Such scenario
would not have a good mapping when using target states.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 495672ab62 pm: cleanup pm control callback implementations
- Return -ENOTSUP if the requested state is not supported
- Remove redundant "noop style" functions.
- Use switch everywhere to handle requested state (not necessary in all
  drivers, but better take off with consistency in place after current
  changes).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas d41dadc569 pm: rename PM_DEVICE_STATE_SUSPEND to PM_DEVICE_STATE_SUSPENDED
The verb tense for the suspended state was not consistent with other
states. The likely reason: state was being used as a command/action.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 11eef4d8c8 pm: device: remove pointer usage for state
Since the state is no longer modified by the device PM callback, just
use the state value.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 9e7d545bb4 pm: device: remove ctrl_command callback argument
The ctrl_command is not used anymore, so remove it from the callback
signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas da0ff4ae46 pm: device: remove usage of ctrl_command
The callback is now invoked to set the device PM state in all cases, so
the usage of ctrl_command is redundant.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Fabio Baltieri 532a85ccd9 tests: net: dns-sd: add a test case for setup_dst_addr
Add a test case for mdns setup_dst_addr.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-07-26 10:46:50 -04:00
Nicolas Pitre 697f3544a7 net: bridge: test to exercise the bridge facility
This is accomplished with 3 fake ethernet interfaces hooked to a
common bridge, simulating incoming packets and controlling each
interface's transmission product.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-07-21 18:20:01 -04:00
Marcin Niestroj 1ce1d19bb5 net: pkt: introduce net_pkt_remove_tail()
Introduce a helper function for being able to remove any arbitrary
length from tail of packet. This is handy in cases when removing
unneeded data, like CRC once it was verified.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-07-15 06:54:33 -04:00
Robert Lubos 3fe94e088b tests: net: socket: select: Relax timing requirements
The test ocassionally fails on the mps2_an385 platform in the CI, due
to strict timing requirements of the test.

Relax the timeouts and acceptable fuzz time a bit, to prevent the
failures in the future.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-14 07:41:08 -04:00
Gerard Marull-Paretas 26ad8376bd pm: remove callback from control function
The callback is not used anymore, so just delete it from the pm_control
callback signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-13 09:36:45 -04:00
Gerard Marull-Paretas 217e610d8f pm: remove redundant callback usage
the device PM callback is not used anymore by the device PM subsystem,
so remove it from all drivers/tests using it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-13 09:36:45 -04:00
Robert Lubos bb0f061834 tests: net: coap: Convert unit tests to ztest API
Convert CoAP unit tests to ztest API.

Additionally, replace dynamic memory allocation with a static one, to
prevent memory leaks with ztest.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-10 12:21:48 -04:00
Jukka Rissanen fe3a11bafa tests: net: ethernet_mgmt: Fix tests when running in real hw
If the test is run in a board that has a network interface
enabled, then the tests might select and use wrong network interface
that is needed for the test. So this commit makes sure that
we always use the simulated network interface for the
Ethernet management tests.

Fixes #36419

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-07-07 21:01:27 -04:00
Gerard Marull-Paretas cc2f0e9c08 pm: use enum for device PM states
Move all PM_DEVICE_STATE_* definitions to an enum. The
PM_DEVICE_STATE_SET and PM_DEVICE_STATE_GET definitions have been kept
out of the enum since they do not represent any state. However, their
name has not been changed since they will be removed soon.

All drivers and tests have been adjusted accordingly.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-07 14:13:12 -04:00
Robert Lubos fe6e017649 tests: net: coap: Extend existing tests with additional checks
Make sure that internal CoAP packet fields are set correctly after
packet creation/parsing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Robert Lubos f6a2d3ac7a tests: net: socketpair: Verify that poll is signalled correctly
Add unit tests which verifies that poll() function is signalled
correctly if called after data was written/read to/from a socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-02 22:22:42 -04:00
David Leach 6688f70996 tests: net: socket: tls_ext: Add platform filter
Network test cases are designed for emulated
environments so add platform_allowed filter to
only allow qemu platforms.

Fixes: #36418

Signed-off-by: David Leach <david.leach@nxp.com>
2021-07-02 09:46:04 -04:00
Jukka Rissanen e9bad8f0a2 tests: net: eth: Add TXTIME tests
Simple tests that verify that TXTIME parameters can be passed from
application code into the driver and vice versa.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-14 07:00:10 -04:00
Jukka Rissanen d1629c4a61 tests: net: eth: Add Qbu tests
Simple tests that verify that Qbu parameters can be passed from
application code into the driver and vice versa.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-14 07:00:10 -04:00
Jukka Rissanen 8adc0a7863 tests: net: eth: Add Qbv tests
Simple tests that verify that Qbv parameters can be passed from
application code into the driver and vice versa.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-14 07:00:10 -04:00
Robert Lubos 2f409f401e tests: net: socket: tls: Fix timing issue on nRF devices
The timings were too tight for TLS tests executing on nRF52840 with
hardware entropy source enabled. Increase the timings to make tests
pass.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-06-09 16:11:11 +03:00
Ievgen Glinchuk 1ce8d6fae4 net: dns: Fix multiple IP DNS resolution
Fixed mutli-IP DNS resolution as previously the same IP address was
used to populate all AI entries and added DNS_RESOLVER_AI_MAX_ENTRIES
config entry to define max number of IP addresses per DNS name to be
handled.

Signed-off-by: Ievgen Glinchuk <john.iceblink@gmail.com>
2021-06-07 23:54:55 -04:00
Jukka Rissanen 0106e83c74 tests: net: socket: Add userspace tests to SO_BINDTODEVICE
Change the SO_BINDTODEVICE tests so that we test also userspace
mode.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-07 10:37:22 +03:00
Stephanos Ioannidis 79788137cf tests: net: getaddrinfo: Increase newlib heap size
This commit increases the newlib heap size to 2048, which is the
recommended minimum required to ensure proper operation of the newlib
nano used by test (see #35799).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2021-06-02 08:50:45 -05:00
Jukka Rissanen dab391f253 tests: net: getaddrinfo: Disable onboard Ethernet controller
If the tests/net/socket/getaddrinfo is run in a board that has
Ethernet controller, then it is possible that it will interfere
the test if the Ethernet cable is connected. As the test only
needs loopback support to run, disable the Ethernet as it is
not needed by the test.

Fixes #34923

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-05-13 22:07:00 -04:00
Flavio Ceolin 0c607adb63 pm: device: Align state names with system states
Change device pm states to the same pattern used by system power
management.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-05-07 18:35:12 -04:00
Flavio Ceolin 7eba310220 power: device: void *context -> uint32_t *state
The context parameter used across device power management is
actually the power state. Just use it and avoid a lot of
unnecessary casts.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-05-07 16:55:31 -04:00
Hake Huang ff4eb86903 net/virtual: test case need have random generator driver
add below to fitler out correct platforms
filter: CONFIG_ENTROPY_HAS_DRIVER

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2021-05-07 08:53:10 -05:00
Gerard Marull-Paretas 56f1a8ce98 pm: rename PM_DEVICE_GET/SET_POWER_STATE to PM_DEVICE_STATE_GET/SET
Adjust name to be consistent with device PM naming conventions.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 7988ab4a26 pm: rename device_set/get_power_state to pm_device_set/get
Make name consistent with other device PM APIs.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas dbf46b3815 pm: rename device_pm_cb to pm_device_cb
Prefix all device PM functions/data structures with pm.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 2c7b763e47 pm: replace DEVICE_PM_* states with PM_DEVICE_*
Prefix device PM states with PM.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Jukka Rissanen 6e1df0d603 tests: net: Refactor tests when running in real hw
The network tests were expecting that network interfaces
are in certain order. As we cannot guarantee that, refactor
the tests like this:

* if test is using DUMMY L2 driver, then disable Ethernet L2
  and fetch only DUMMY L2 instead of default interface
* if test is using Ethernet L2 driver, then make sure that the
  test is using the Ethernet interface specified in the test
  instead of the one provided by the DUT

Fixes #34505

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-30 11:59:10 +03:00
Jukka Rissanen d367fc73c5 tests: net: igmp: Remove device_pm_control_nop
The use of device_pm_control_nop is deprecated so remove it
from the test as it will give warning in CI.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-29 14:23:11 -04:00
Marcin Niestroj 9f478e0a80 tests: net: dns_addremove: cover dns_resolve_reconfigure()
Add tests for just introduced dns_resolve_reconfigure() API, which
allows to replace old DNS servers with new ones.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-29 08:00:09 -04:00
Marcin Niestroj 71c31c45c7 net: dns: add dns_resolve_reconfigure() API
So far there was no dedicated mechanism for replacing DNS servers with
new list. Add dns_resolve_reconfigure() API that allows to achieve that
in a thread-safe manner.

Introduce 3rd state in DNS context lifetime by converting from 'bool
is_used' to 'enum dns_resolve_context_state state'. This new
DEACTIVATING state allows to mark a DNS context as busy and safely close
context without holding lock. Closing DNS context with released lock
prevents deadlock in case net_context_close() has to synchronize with a
separate thread executing handler passed to net_context_recv() (which is
the case for example with ESP-AT WiFi driver).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-29 08:00:09 -04:00
Jukka Rissanen a4c119a23d tests: net: igmp: Add IPv4 IGMP tests
IGMP (Internet Group Management Protocol) support tests.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-29 14:49:55 +03:00
Gerard Marull-Paretas 5899b8a190 tests: net: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 12:53:09 -04:00
Jukka Rissanen 91ff30513f tests: net: poll: Increase ztest thread stack size
The socket poll test was running out of ztest stack so increase
it by 256 bytes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-27 12:02:19 +03:00
Jukka Rissanen a9b3057f15 tests: net: ptp: Compile only on relevant boards
The tests need gPTP support so set the options and boards
properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-27 12:02:19 +03:00
David Leach 70edc3c1d0 tests: net: tcp2: Perform tests on DUMMY interface
Tests are designed to run over the DUMMY interface but when run on
hardware, net_if_get_default() can return the actual hardware
interface.

Fixes: #31969

Signed-off-by: David Leach <david.leach@nxp.com>
2021-04-27 12:00:14 +03:00
Jukka Rissanen 9f2fa87e05 net: Remove support for CONFIG_NET_CONTEXT_TIMESTAMP option
This option was only able to collect statistics of transmitted
data. The same functionality is available if one sets the
CONFIG_NET_PKT_RXTIME_STATS and/or CONFIG_NET_PKT_TXTIME_STATS
options.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-26 10:46:43 +03:00
Lukasz Majewski b9f5ba2730 test: Rename interfaces defined in virtual networks test
This work is similar to one performed for ./net/ptp/clock/ test.

However, there is one notable extension - the check in iface_cb()
callback also checks for virtual interfaces defined in
subsys/net/l2/virtual/ipip/ipip.c. Those 'virtual' interfaces are
required for this test to be run.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2021-04-20 08:29:49 -04:00
Lukasz Majewski d1b6a80191 test: Lookup for struct net_if interface defined in ipv6 test
The tests/net/ipv6/src/main.c uses net_if_get_default() to get the
interface for testing. This is problematic when board introduces its own
linker script, which places board's network interface on the "default"
position - i.e. the first one.

To fix this issue - the lookup for network device defined for this test
is used instead.

Moreover, interfaces rename has been performed in a manner, which would
allow working with 'eth_native_posix' interface being added as linker
object when drivers/ethernet/eth_native_posix.c file is linked for
./zephyr/tests/net/ipv6 test on 'native_posix' board.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2021-04-20 08:29:49 -04:00
Lukasz Majewski f25dd77df2 test: Rename interfaces in ptp clock test
This change is required to allow correct tests operation after changing
the definition of linker script placement rule (to be more strict and
using the device name).

The struct net_if interfaces have been renamed to preserve correct
order.
Moreover, the iface_cb() function now immediately returns for
interfaces, which are not supposed to be used in this tests - for
example ones already defined on board on which the test is run.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2021-04-20 08:29:49 -04:00
Lukasz Majewski b8148922ee test: Rename interfaces defined in checksum offload test
The struct net_if object placement in linker 'net_if_area' section
now depends on the order of ETH_NET_DEVICE_INIT() macros in the source
code (for the same object file - like app/libapp.a(main.c.obj)).

Currently the 'eth_offloading_enabled_test' device is placed first,
followed by 'eth_offloading_disabled_test'.

This placement is important when one would like to access those
interfaces with net_if_get_default() function.

After the rename the order is explicit, when we append the device name
to the ._net_if.static.<dev name> object in linker's net_if_area.

The code now works as all struct net_if interfaces are placed as
'._net_if.static.net_if' objects.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2021-04-20 08:29:49 -04:00
Lukasz Majewski a18be0cdbb test: Lookup for struct net_if interface defined in arp test
The struct net_if object placement in linker 'net_if_area' section
now depends on the order of liked libraries (like
app/libapp.a(main.c.obj). As a result interfaces defined in testing
applications are placed first in the 'net_if_area' section.

Problem arises when board has other interfaces, which are placed on the
first (i.e. default) position. In this case the test just fails as wrong
network interface is used.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2021-04-20 08:29:49 -04:00
Peter Bigot 188cb2cb7c net: Conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-14 07:07:40 -04:00
Robert Lubos 71532eb8c2 tests: net: sockets: Implement SO_BINDTODEVICE option tests
Add tests for SO_BINDTODEVCIE socket option.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-02 07:23:17 -04:00
Robert Lubos 814fb71bf3 net: socket: Implement SO_BINDTODEVICE socket option
Implement SO_BINDTODEVICE socket option which allows to bind an open
socket to a particular network interface. Once bound, the socket will
only send and receive packets through that interface.

For the TX path, simply avoid overwriting the interface pointer by
net_context_bind() in case it's already bound to an interface with an
option. For the RX path, drop the packet in case the connection handler
detects that the net_context associated with that connection is bound to
a different interface that the packet origin interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-02 07:23:17 -04:00
Hake Huang 6d397801e7 tests: disable long time case from NXP FRDM_KW41Z
CMSIS_DSP and net_socket tests are either too
slow or too large for this platform, also drop
bluetooth for test

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2021-04-01 10:57:19 -05:00
Jukka Rissanen 8ea7eb9e51 tests: net: virtual: Add unit tests for checking tunneling
Add tests to verify that IP tunneling works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-29 07:40:24 -04:00
Kumar Gala 0bb4665df7 include: Move ptp_clock.h to drivers/ptp_clock.h
Move ptp_clock.h out of the top level include/ dir into
include/drivers/ptp_clock.h and deprecated the old location.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-25 10:09:33 +02:00
Christopher Friedt 5b1d71259b tests: sockets: add test for socket api tls extensions
This change adds a test for the socket API TLS extensions.

Fixes #30936

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-03-23 14:09:08 +02:00
Robert Lubos 8929b40b78 tests: net: sockets: tls: Add MSG_TRUNC flag tests
Add unit tests for MSG_TRUNC flag.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-23 13:16:30 +02:00
Robert Lubos d93003e267 tests: net: sockets: Add MSG_TRUNC flag tests
Add unit tests for MSG_TRUNC flag.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-23 13:16:30 +02:00
Jukka Rissanen 0af89fc4ec net: Remove legacy TCP stack
Remove legacy TCP stack as it is replaced by the new TCP2 stack.
The TCP2 stack has been the default stack since 2.4 release.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-22 13:06:54 -04:00
Guðni Már Gilbert 01252c2b6b tests: net: socket: getaddrinfo: fix resource leak
Fix resource leak detected by coverity by adding missing
zsock_freeaddrinfo(res) calls.

Coverity-CID: 219527
Fixes #32919

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2021-03-19 17:22:31 +02:00
Peter Bigot 1c7bf96019 net: dns: update to new k_work API
Switch to the new API for delayed work related to DNS queries.

In the previous solution it was assumed that the work item could be
immediately cancelled at the point the query slot was released.  This
is not true.  We need a secondary condition to record the fact that
the query was completed while the work item was still pending, and an
additional check to detect when the work item completed and the slot
reclaimed.

Also annotate functions to indicate when they require the lock on
query content to be held, add some helpers that abstract core
operations like invoking a callback or releasing a query slot, and fix
some more cases where query slot content was accessed outside of the
new lock infrastructure.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-15 17:19:54 +02:00
Guðni Már Gilbert 4d5566adf1 tests: net: socket: af_packet: fix resource leak
Fix resource leak by closing opened AF_PACKET sockets

Coverity-CID: 219491
Fixes #32949

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2021-03-15 17:19:39 +02:00
Anas Nashif 15b9565b37 Revert "tests: net: socket: af_packet: fix resource leak"
This reverts commit a1ae45fecd.

The test is failing now, reverting until properly fixed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-12 19:50:54 -05:00
Robert Lubos 5de148d8c0 tests: net: sockets: tls: Add unit test for TLS MSG_WAITALL flag
Add a unit test that covers MSG_WAITALL flag functionality for TLS
sockets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-12 13:57:11 -05:00
Robert Lubos 4582e57903 tests: net: sockets: tcp: Add unit test for MSG_WAITALL flag
Add a unit test that covers MSG_WAITALL flag functionality for TCP
sockets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-12 13:57:11 -05:00
Jukka Rissanen 8140fb8d2f tests: net: getaddrinfo: Verify that we receive all queries
The previous implementation of process_dns() handler did not
properly catch how many queries we sent.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-12 11:26:16 -05:00
Guðni Már Gilbert a1ae45fecd tests: net: socket: af_packet: fix resource leak
Fix resource leak by closing opened
sockets

Coverity-CID: 219491
Fixes #32949

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2021-03-12 09:22:26 -05:00
Andy Ross 3d81464194 tests: samples: Add targetted platform_excludes for intel_adsp_cavs15
This platform has a tiny handful of remaining tests that fail.  We
will track them as issues, but let's exclude them from integration
testing to allow full runs to complete.  Often a hung device in one
test will break an entire twister run.

Tests with known (and tracked) failures:

  samples/application_development/external_lib
  samples/posix/eventfd
  samples/userspace/hello_world_user
  tests/kernel/fatal/message_capture
  tests/net/socket/socketpair
  tests/portability/cmsis_rtos_v2

These tests never fail in isolated testing, but are reliable timeouts
when run in sequence in a big twister run.  It's possible that the bug
here may be in twister or the flash/serial scripts:

  tests/crypto/tinycrypt
  tests/subsys/logging/log_immediate
  tests/subsys/logging/log_output

See: #32836

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 19:25:25 -05:00
Andy Ross 589c781506 tests: No thread-shared/synchronized data on stack (coherence)
CONFIG_KERNEL_COHERENCE forbids synchronized data on the stack: no
spinlocks, IPC primitives, or things that contain them.  Application
code obviously doesn't have to follow these inconvenient rules, but
our test code needs to run on platforms with incoherent stack memory.

Make these things static.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 19:25:25 -05:00
Jukka Rissanen 865ed89b1d tests: net: checksum_offload: Use proper network interface
Instead of hardcoding the network interface value, use
net_if_ipv6_select_src_iface() so that proper network interface
gets used.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-04 16:05:52 +02:00
Jukka Rissanen 15e3355d85 tests: net: select: Increase the timeout to 20ms
The timeout might take more than 10ms in a heavily loaded system,
so increase the timeout to 20ms.

For example this is often seen for mps2_an385 platform.

  Assertion failed at \
  WEST_TOPDIR/zephyr/tests/net/socket/select/src/main.c:101: \
  test_select: (tstamp <= FUZZ is false)

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-02-24 08:01:43 -05:00
Hubert Miś ca87d134b5 tests: Socket send timeout option
This patch adds tests for SO_SNDTIMEO socket option.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-24 14:16:33 +02:00
Christian Taedcke c467149ad9 net: pkt: Add function net_pkt_get_contiguous_len()
This returns the available contingous space in the packet starting from
the current cursor position.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2021-02-24 09:43:52 +02:00
Reto Schneider 545fb92fc1 net: pkt: Fix headroom edge case
This commit fixes some edge cases when using net_bufs with reserved
bytes (headroom) as fragments of a net_pkt.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2021-02-22 19:33:16 +02:00
Reto Schneider d0144da95a net: pkt: Expose headroom edge case
When operating on a net_pkt using the cursor functionality, reserved
bytes (headroom) are currently not respected.

This commit adds test cases exposing this problem. Fix will be
introduced in a later commit.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2021-02-22 19:33:16 +02:00
Jukka Rissanen 7699563d81 net: mgmt: Use proper coop thread priority value
If user sets CONFIG_NUM_PREEMPT_PRIORITIES=0, then the priority
of the net_mgmt thread will be -1 which is the same as idle thread.
This will trigger assert in kernel as then the minimum coop priority
is -2 in this case. Remove the net_mgmt thread priority setting from
Kconfig file as it is low value and set the coop thread priority
the same way as other network threads are doing it.

Fixes #32375

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-02-17 16:42:15 +02:00
Hubert Miś 2f02ca0b39 tests: net: socket: SO_PROTOCOL socket option
This patch adds tests to verify getting SO_PROTOCOL socket option for
TCP, UDP, and TLS sockets.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-17 10:36:58 +02:00
Hubert Miś a6e83eb769 tests: net: socket: SO_TYPE socket option
This patch adds tests to verify getting SO_TYPE socket option for
TCP, UDP, and TLS sockets.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-17 10:36:58 +02:00
Hubert Miś 2e2915a596 tests: net: coap: Acknowledgement initialization
New test that verifies CoAP Acknowledgement initialization function
that create a response packet for given request. Both request and
expected response packets are given in the test as PDU.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-15 10:17:11 +02:00
Hubert Miś 77c68aa070 net: coap: clean up token usage in samples and tests
This patch replaces magic numbers with COAP_TOKEN_MAX_LEN value and
removes unnecessary castings of token buffer type.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-02 14:03:01 -05:00
Hubert Miś 22687c34e3 net: coap: define default CoAP version
RFC 7252 (CoAP) specifies value of the Version (Ver) field in the
protocol header to value 1. This patch defines value of the Version
field to make packet initialization easier. All samples and tests
are updated to use the new COAP_VERSION_1 field when initializing
a CoAP packet.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-02 14:03:01 -05:00
Flavio Ceolin 1335716b5f tests: socket: Fix compiler warnings
../src/main.c:662:13: warning: cast from pointer to integer of different
size [-Wpointer-to-int-cast]
  662 |  int sock = (int)p1;
      |             ^
../src/main.c: In function 'spawn_child':
../src/main.c:671:4: warning: cast to pointer from integer of different
size [-Wint-to-pointer-cast]
  671 |    (void *)sock, NULL, NULL, 0, K_USER,

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-27 08:05:48 -05:00
Hubert Miś 401ee4ae5b tests: Socket receive timeout option
This patch adds tests for SO_RCVTIMEO socket option for UDP and
TCP sockets.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-01-19 17:11:25 -05:00
Hubert Miś 13aa4b2f9e net: coap: define Content-Format option values
CoAP protocol defines registry of Content-Format option values.
This patch adds this enumeration to coap header file to make it
available to all applications using CoAP protocol. It modifies
code using CoAP service to use new enumeration.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-01-19 16:07:20 -05:00
Robert Lubos 538e19ee2e net: coap: Rework pending retransmission logic
Introduce retransmission counter to the coap_pending structure. This
allows to simplify the retransmission logic and allows to keep track of
the number of remaining retranmissions.

Additionally, extend the `coap_pending_init()` function with `retries`
parameter, which allows to set the retransmission count individually for
each confirmable transaction.

Fixes #28117

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-18 23:22:37 -05:00
Jukka Rissanen 5723f381e9 tests: net: ptp clock: Increase main stack size
The main stack size is too small by default in many boards.
Increase the size to 1024 bytes which works fine with
sam_e70_xplained board.

Fixes #31342

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-01-17 15:09:58 +02:00
Martin Åberg 4604c45541 tests: enable and run many tests on RISC-V
This commit enables lots of tests on riscv32 and riscv64 which were
previously disabled.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2021-01-15 13:06:33 -05:00
Jukka Rissanen ebd077b258 tests: net: af_packet: Increase main stack size
The main stack size is too small by default in many boards.
Increase the size to 1024 bytes which works fine with
sam_e70_xplained board.

Fixes #31343

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-01-15 12:14:53 -05:00
Lukasz Majewski 33028963c8 test: af_packet: Add test for passing UDP packet to open RAW socket
The af_packet test has been augmented to check if sent UDP packet from
one port to another (via net interface) is also passed to open SOCK_RAW
connection.
The test_packet_sockets() function has been reused to setup the SOCK_RAW
sockets for this test.
It is important to note that the packet is passed to receive part of net
stack after being sent.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2021-01-15 09:30:17 +02:00
Lukasz Majewski 4987c7ba47 test: af_packet: Do not change proto to network order when creating socket
The setup_socket() function calls socket() with proto changed to network
order. In this case functions with zsock_* prefix are called instead of
zpacket_*. The problem is with 'packet_is_supported()' method from
sockets_packet.c, which returns false when ETH_P_ALL proto is converted
with htons().

This patch fixes this issue by removing the htons() call.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Suggested-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-01-15 09:30:17 +02:00
Fabio Baltieri 4a4c63519d net: if: check for multicast address already registered
Add a check to stop a multicast address to be registered multiple times.
This can happen if the application is using net_if_ipv6_maddr_add()
directly.

Tested on the existing bluetooth/ipsp sample:

<wrn> net_if: Multicast address ff02::1 is is already registered.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-01-14 16:57:07 +02:00
Jukka Rissanen 408a6ceff3 tests: net: tcp2: Add tests for TCP recv data queueing
Make sure that received and out-of-order TCP segments are queued
until we receive proper segments.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-01-12 13:40:05 +02:00
Peter Bigot acd43cbaac net: timeout: refactor to fix multiple problems
The net_timeout structure is documented to exist because of behavior
that is no longer true, i.e. that `k_delayed_work_submit()` supports
only delays up to INT32_MAX milliseconds.  Nonetheless, use of 32-bit
timestamps within the work handlers mean the restriction is still
present.

This infrastructure is currently used for two timers with long
durations:
* address for IPv6 addresses
* prefix for IPv6 prefixes

The handling of rollover was subtly different between these: address
wraps reset the start time while prefix wraps did not.

The calculation of remaining time in ipv6_nbr was incorrect when the
original requested time in seconds was a multiple of
NET_TIMEOUT_MAX_VALUE: the remainder value would be zero while the
wrap counter was positive, causing the calculation to indicate no time
remained.

The maximum value was set to allow a 100 ms latency between elapse of
the deadline and assessment of a given timer, but detection of
rollover assumed that the captured time in the work handler was
precisely the expected deadline, which is unlikely to be true.  Use of
the shared system work queue also risks observed latency exceeding 100
ms.  These calculations could produce delays to next event that
exceeded the maximum delay, which introduced special cases.

Refactor so all operations that use this structure are encapsulated
into API that is documented and has a full-coverage unit test.  Switch
to the standard mechanism of detecting completed deadlines by
calculating the signed difference between the deadline and the current
time, which eliminates some special cases.

Uniformly rely on the scanning the set of timers to determine the next
deadline, rather than assuming that the most recent update is always
next.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-01-07 11:14:38 +02:00
Jordan Yates bd2c974c0c tests: net: buf: validate push & remove impl
Add test cases for checking the previously untested `net_buf_push_*`
functions in terms of the new `net_buf_remove_*` functions.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-01-05 14:31:13 +02:00
Hubert Miś 4ca7942411 tests: net: Test resolving literal IPv6 addresses
This patch adds a test for the network address resolver module
that verifies resolving literal IPv6 addresses.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2020-12-22 15:44:00 +02:00
Kumar Gala 1706bd2b41 tests: convert DEVICE_AND_API_INIT to DEVICE_DEFINE
Convert tests to DEVICE_{DT_}DEFINE instead of DEVICE_AND_API_INIT
so we can deprecate DEVICE_AND_API_INIT in the future.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-19 20:05:40 -05:00
Watson Zeng 7a3f9c4e39 tests: add filter for some tests using newlib
some tests configured with CONFIG_NEWLIB_LIBC=y,
it's better to add a filter filter: TOOLCHAIN_HAS_NEWLIB == 1
in those tests yaml file.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2020-12-16 08:57:40 -05:00
Seppo Takalo 3492e8e248 tests: socket: getaddrinfo: Add tests for getaddrinfo() with NULL host
Also improve test coverage on hints, when queried with numerical
host.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2020-12-15 19:22:50 +02:00
Anas Nashif dd931f93a2 power: standarize PM Kconfigs and cleanup
- Remove SYS_ prefix
- shorten POWER_MANAGEMENT to just PM
- DEVICE_POWER_MANAGEMENT -> PM_DEVICE

and use PM_ as the prefix for all PM related Kconfigs

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Andy Ross e95db3a366 tests/net/socket/udp: Increase kernel heap size
On userspace platforms, this test needs a little bit of kernel heap.
The old mem_pool number was specified without metadata overhead
(i.e. it reflected 128 bytes of actual data available and the metadata
was stored silently somewhere else), where the new heap specifies the
size of the contiguous buffer in memory that stores both data and
chunk headers, etc...

Increase to 256 bytes.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Jukka Rissanen 0ed6a3cd69 tests: net: tcp2: Add RST packet handling tests
Verify that TCP2 will drop invalid RST packets and accept
valid ones.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-11-24 13:08:39 +02:00
Peter Bigot 4ce7cafdf4 tests: net: socketpair: use system instead of user work queue
The socket pairs created for this test when run under user mode are
accessible only from the thread that created them.  Although it is
possible for that thread to grant access to another thread:

* there does not appear to be a way to do that when referencing a
  descriptor rather than a pointer to a kernel object;
* there is no public API that supports granting the object rights to a
  user thread that animates a work queue.

Until these gaps are addressed use the system work queue run
supervisor-mode threads to verify the asynchronous behavior of the
API.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-21 14:49:40 +02:00
Jukka Rissanen b88d5b6c67 tests: net: Adjust the thread priorities
Adjust the test thread priority so that the test / IP stack
has a chance to run and the test passes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-11-20 12:57:29 +02:00
Paul Sokolovsky 9fa33f27e1 tests: socket: tcp: Add test for ENOTCONN behavior
A socket which didn't undergo completed connect() or accept() calls
should react with ENOTCONN to recv() call. This test checks both
a freshly created socket ("client" one) and a socket in LISTEN
state ("server").

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2020-11-19 16:58:37 -05:00
Martin Åberg 137e8528ec net: run the net.pm test on LEON
Adds the test to at least one big-endian system.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-17 11:44:16 +02:00
Martin Åberg 5dcdf198da net: improved test for IPv6 pton() and ntop()
Represent IPv6 addresses as groups of 16-bit values in test vectors.

This commit corrects the following two test issues on big endian
systems:

  START - test_ipv6_pton_1
  Failed to verify ff08::
  against 0:ff08::

  START - test_ipv6_ntop_1
  Failed to verify 0:ff08::
  against ff08::

Makes the following tests pass on qemu_leon3:
- net.util

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-17 11:44:16 +02:00
Christopher Friedt 0ddce66d86 tests: net: dns: dns-sd: tests for dns service discovery
Tests for DNS-SD (RFC 6763)

Fixes #29099

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-11-09 16:15:02 -08:00
Jukka Rissanen accaab2112 net: shell: Add network mgmt events monitor support
Add "net events [on|off]" command that can be used to monitor
the generated network management events.

The monitor output looks like this when enabled:

EVENT: L2 [1] up
EVENT: L3 [1] IPv6 mcast address add ff02::1:ff00:1
EVENT: L3 [1] IPv6 mcast join ff02::1:ff00:1
EVENT: L3 [1] IPv6 address add 2001:db8::1
EVENT: L4 [1] connected
EVENT: L3 [1] IPv6 prefix add 2002:5b9b:41a0::
EVENT: L3 [1] IPv6 address add 2002:5b9b:41a0:0:fec2:3dff:fe11:c147
EVENT: L3 [1] IPv6 neighbor add fe80::9ec7:a6ff:fe5e:4735
EVENT: L3 [1] IPv6 router add fe80::9ec7:a6ff:fe5e:4735
EVENT: L3 [1] IPv6 DAD ok fe80::fec2:3dff:fe11:c147
EVENT: L3 [1] IPv6 DAD ok 2001:db8::1
EVENT: L3 [1] IPv6 DAD ok 2002:5b9b:41a0:0:fec2:3dff:fe11:c147
EVENT: L3 [1] IPv4 address add 192.168.1.69
EVENT: L3 [1] DHCPv4 bound 192.168.1.69

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-10-13 13:42:50 +03:00
Oliver Hitz 0c70877ceb net: IPv4 bcast address recognized as multicast
Modified net_ipv4_is_addr_mcast() to not wrongly classify an IPv4
broadcast address as a multicast address.

Signed-off-by: Oliver Hitz <oliver@net-track.ch>
2020-10-09 10:26:38 +03:00
Jukka Rissanen d4347b4015 net: dhcpv4: Generate start/bound/stop mgmt events
The L4 connected/disconnected events are usually used to detect
when the application is connected to the network. Unfortunately
if the device has also a static address, then the connected event
might be created (for the static address) even if DHCPv4 is not
ready yet and application would not be able to connect (yet) to the
network. In order to allow the application to fine tune the network
connection creation, generate start, bound and stop events for DHCPv4.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-10-03 17:15:15 +03:00
Jan Pohanka 9e5dc213cb net: mqtt: fix tests to use zsock_ functions
Use zsock_ variants of socket functions in mqtt tests.

Signed-off-by: Jan Pohanka <xhpohanka@gmail.com>
2020-10-01 17:35:45 +03:00
Jukka Rissanen 4a27246c06 tests: net: tcp2: Fix crash in frdm_k64f
Lowering the connection timeout in order to avoid spin lock assert
in frdm_k64f device. This error was seen with this device

ASSERTION FAIL [z_spin_lock_valid(l)] @ zephyr/include/spinlock.h:92
        Recursive spinlock 0x20003590

Fixes #28602

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-09-23 13:02:04 -05:00
Robert Lubos c18f15f694 net: mqtt: Remove unused defines from the sample and tests
APP_TX_RX_TIMEOUT and APP_NET_INIT_TIMEOUT were not used in any way
in the sample and test apps.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-09-09 15:46:24 +03:00
Jukka Rissanen 57a894a5ee tests: net: dns_packet: Disable Ethernet when test is run
The test was failing when run in sam_e70_xplained board.
Because the test does not use any network packet TX/RX functionality,
disable Ethernet support so that when run in a board with network
capabilities, the network interface is not created.

Fixes #28000

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-09-03 18:05:51 -04:00
Jukka Rissanen 747d2f4483 tests: net: af_packet: Fix the test when run in fast hw
If the recvfrom() in the test returns EAGAIN, try again in order
to make sure that we have really received the data.

Fixes #27963

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-09-03 10:59:11 +03:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Jukka Rissanen 6493af2714 tests: net: dns: Add tests for catching malformed packets
Add more tests to verify that we discard malformed packets.
In order to simplify the testing, separate message validation to
dns_validate_msg() function in resolve.c. Allow that function to
be called from unit test. This way we can construct invalid DNS
messages in unit test and verify that they are discarded when
needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-27 08:05:52 -04:00
Anas Nashif dca317c730 sanitycheck: inclusive language
change whitelist -> allow.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-08-27 07:04:07 -04:00
Jukka Rissanen 1a01aacd16 tests: net: af_packet: Initial tests for SOCK_DGRAM types
Add some tests for testing AF_PACKET and SOCK_DGRAM type
sockets. These are sockets where Ethernet header is automatically
added, caller just needs to provide upper stack header.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-27 10:56:06 +03:00
Philip Serbin b7b73d0160 net: ipv6: added interface multicast group filtering
Added additonal checks in net_ipv6_input to ensure that multicasts
are only passed to the upper layer if the originating interface
actually joined the destination multicast group.

Signed-off-by: Philip Serbin <philip.serbin@lemonbeat.com>
2020-08-24 13:53:15 +03:00
Jan Georgi 5931a29979 net: route: multicast routing feature
net: route: Add prefix-based ipv6 multicast forwarding

This adds/reenables the feature of multicast routing/forwarding.
The forwarding decision is based on the added multicast routes
and the new network interface flag:
NET_IF_FORWARD_MULTICASTS.

Signed-off-by: Jan Georgi <jan.georgi@lemonbeat.com>
2020-08-19 09:46:25 -04:00
David Leach c5f3da22ae tests: net: Fixes coverity issue CID 210552
Function scope of 'socket' was not closed before exiting
the function.

Fixes #25792

Signed-off-by: David Leach <david.leach@nxp.com>
2020-08-16 09:29:41 -04:00
David Leach c16711c7e6 tests: net: Fix coverity issue CID 211047
Assert check that the net_ipv6_nbr_lookup() did  not return NULL

fixes #26359

Signed-off-by: David Leach <david.leach@nxp.com>
2020-08-16 09:29:41 -04:00
Jukka Rissanen a5f4b44ab8 tests: net: socketpair: Fix debug logging
Only one LOG_MODULE_REGISTER() is allowed in the files that are
linked together. The other files must use LOG_MODULE_DECLARE()

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-14 09:47:51 -07:00
Tomasz Bursztyka 98d9b01322 device: Apply driver_api/data attributes rename everywhere
Via coccinelle:

@r_device_driver_api_and_data_1@
struct device *D;
@@
(
D->
-	driver_api
+	api
|
D->
-	driver_data
+	data
)

@r_device_driver_api_and_data_2@
expression E;
@@
(
net_if_get_device(E)->
-	driver_api
+	api
|
net_if_get_device(E)->
-	driver_data
+	data
)

And grep/sed rules for macros:

git grep -rlz 'dev)->driver_data' |
	xargs -0 sed -i 's/dev)->driver_data/dev)->data/g'

git grep -rlz 'dev->driver_data' |
	xargs -0 sed -i 's/dev->driver_data/dev->data/g'

git grep -rlz 'device->driver_data' |
	xargs -0 sed -i 's/device->driver_data/device->data/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Jukka Rissanen 18b145a5d5 tests: net: poll: Increase the TX/RX pkt counts and MAX_CONN
TCP2 uses slightly more network packets and connections in the
socket poll test, so increase the values for the test.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-07 10:35:48 +03:00
Jukka Rissanen 5007509c3f tests: net: tcp: These unit tests are only for legacy TCP
Run the TCP tests in tests/net/tcp only for legacy TCP stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-07 10:35:48 +03:00
Jukka Rissanen 7d90812f26 tests: net: af_packet: Fix running in real hw
The tests were failing when run on those boards that had
physical Ethernet support. In that case there were three Ethernet
interfaces, two simulated ones for testing, and the third one
was provided by the board. This extra Ethernet interface caused
the test to fail as the test was sending data to wrong interface.

Fixes #27238
Fixes #26568

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-07-30 12:25:49 +02:00
Jukka Rissanen 5eef2c5f24 tests: net: iface: Modify tests to verify userspace access
Modify the tests so that they verify that only allowed thread
is able to modify network interface data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-07-29 08:13:22 -04:00
Oleg Zhurakivskyy 8aed3aa669 tests: net: tcp2: Update test_sem_take()
Fail solely on semaphore timeout.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-20 13:55:22 +03:00
Oleg Zhurakivskyy 31aff65165 tests: net: tcp2: Check for failed connect on SYN resend
Since the peer isn't replying on SYN resend, update the
test to check for failed connect.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-20 13:55:22 +03:00
Oleg Zhurakivskyy f5a94e5877 tests: net: tcp2: Update timeout values
Since the connect is now blocking, update the timeout values
for the tests to pass.

In case of resend test, set the timeout to 1000ms to account
for the retransmission.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-20 13:55:22 +03:00
Flavio Ceolin c4f7faea10 random: Include header where it is used
Unit tests were failing to build because random header was included by
kernel_includes.h. The problem is that rand32.h includes a generated
file that is either not generated or not included when building unit
tests. Also, it is better to limit the scope of this file to where it is
used.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-07-08 21:05:36 -04:00
Stephanos Ioannidis 4b66aae3d3 tests: net: vlan: Fix typos
Fix typos in the test assert messages ("numer" to "number").

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-07-02 08:37:17 -04:00