Since the TCP context (and thus net_context) is not dereferenced
directly from the test thread anymore, add a small delay so that TCP
work queue have a chance to run, before checking net_context count or
reusing the port on new allocation.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Set separate option getters for bool, uint8_t and uint16_t
values. Use those generic getters when fetching the desired
option value.
Noticed mixed usage (bool vs int) for txtime option. Changed
the code to use int type like in other options.
The uint16_t option getter gets the value from uint16_t variable
but returns int value to the caller, and also expects that user
supplies int value.
For uint8_t value, it is expected that uint8_t value is supplied
instead of int.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure recvmsg() is able to return IPv4 IP_PKTINFO and
IPv6 IPV6_RECVPKTINFO ancillary data to the caller.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The optlen parameter passed to getsockopt() should be of (socklen_t *)
type. Using int produced build errors on 64 bit platforms.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Recently added tests require more stack on certain platforms
(nrf52840dk_nrf52840 in this case), hence increase the ZTEST stack size.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Instead of forcing use of NEWLIB_LIBC, select any available complete C
library implementation. Add CONFIG_REQUIRES_FLOAT_PRINTF where needed.
Signed-off-by: Keith Packard <keithp@keithp.com>
This checks that if connect() timeouts, we check TCP pointer
properly in select() and poll() in order to catch the situation.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The sent pkt must be removed after we have cloned it
in the simulated driver otherwise there is a memory leak.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The IPV6_V6ONLY option is only checked if
CONFIG_NET_IPV4_MAPPED_TO_IPV6 option is set.
By default the IPV6_V6ONLY option is set.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Split the conversion of the RTR frame flags from the data contents test as
RTR frames do not carry any data.
Replace a couple of direct DLC assignments with proper use of
can_bytes_to_dlc().
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.
Rename it to random.h and get consistently with other
subsystems.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
A little refactoring that simplifies dealing with nanosecond timestamp
values in packets and further decouples calling code from PTP:
Benefits:
- simplifies calling code by removing redundant conversions.
- prepares for removing PTP dependencies from net_pkt.
Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
net_context_foreach() is not a systemcall, therefore should not be used
from userspace threads. Usage of this API made SO_REUSADDR/SO_REUSEPORT
userspace tests unfunctional (crashing).
Fix this by using CONFIG_NET_TCP_TIME_WAIT_DELAY instead for tests that
involve TCP connections. Other tests don't really need to wait as
there's no teardown delay on UDP or unconnected TCP contexts.
Additionally, remove the platform exclude for qemu_x86 platform, as this
was the sole reason the tests were crashing on that platform.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit adds unit tests for the SO_REUSEPORT sockets option. It also
fixes some bugs in other tests triggered by the new features.
Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
This commit adds unit tests for the SO_REUSEADDR socket option to test
the different possible scenarios for the option to work correctly.
There is also a fix for the TCP testsuite to make a now failing test
pass again due to a TIME_WAIT socket.
Signed-off-by: Tobias Frauenschläger <t.frauenschlaeger@me.com>
In low memory conditions, its possible for socketpair memory allocation
to fail and then the socketpair is freed but after that the remote
semaphore is released causing a crash.
Fix this by freeing the socketpair after releasing the semaphore. Add a
test case to induce low memory conditions (low HEAP and high socketpair
buffer size), with the fix issue is not seen.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Make sure we use the network interface name (if configured)
instead of device name when binding to certain network
interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add tests which verify that getsockname() function works as expected.
Additionally, add a teardown delay in tests involving TCP, to make sure
all resources are released before the test ends, not to interfere with
other tests.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add test cases which verify that when UDP socket is connected, it only
accepts datagrams from a remote peer it was connected to, and not
others.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
For some reason, tests/net/socket/tcp/net.socket.tcp.preempt
was failing to link for vmu_rt1170 with these changes, and
for some reason reducing CONFIG_POSIX_MAX_FDS from 20 to 10
resolves that issue.
ld.bfd: scripts/build/gen_kobject_placeholders.py \
did not reserve enough space for kobject rodata.
Memory region Used Size Region Size %age Used
FLASH: 287860 B 64 MB 0.43%
RAM: 86460 B 512 KB 16.49%
OCRAM: 0 GB 256 KB 0.00%
OCRAM1: 0 GB 512 KB 0.00%
OCRAM2: 0 GB 512 KB 0.00%
ITCM: 0 GB 256 KB 0.00%
DTCM: 13908 B 256 KB 5.31%
IDT_LIST: 0 GB 2 KB 0.00%
collect2: error: ld returned 1 exit status
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The FIONREAD ioctl (or rather ZFD_IOCTL_FIONREAD) returns the
number of bytes available on the socket that can be read
immediately.
Test that the ioctl behaves according to the expectation.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add an `after()` function that is executed after each test in
the testsuite.
Previously, even if one one test failed, it would calls almost
all subsequent tests to fail. This way, other tests can still
succeed.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add an `after()` function that is executed after each test in
the testsuite.
Previously, even if one one test failed, it would calls almost
all subsequent tests to fail. This way, other tests can still
succeed.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The FIONREAD ioctl (or rather ZFD_IOCTL_FIONREAD) returns the
number of bytes available on the socket that can be read
immediately.
Test that the ioctl behaves according to the expectation.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
A fair bit of setup / teardown code was being duplicated in many
test cases in the socketpair testsuite.
Take advantage of the `setup()`, `before()`, and `after()`
functions in the new ZTest API.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Accidentally statements to enable logging in the TCP socket test
where pushed. This broke some tests running on real devices due
to the additional code size.
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
This has failed in repeated CI runs. Filed an issue
for having it checked. Excluding it until it's
fixed.
Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
To avoid a TCP connection from collapsing a link, implement a collision
avoidance algorithm. Initially TCP new Reno is implemented for its
simplicity.
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
The IEEE 802.15.4 API and networking subsystem were using several
inconsistent timestamp resolutions and types. This change defines all
timestamps with nanosecond resolution and reduces the number of
available types to represent timestamps to two:
* `struct net_ptp_time` for PTP timestamps
* `net_time_t` for all other high resolution timestamps
All timestamps (including PTP timestamps) are now referred to a
"virtual" local network subsystem clock source based on the well-defined
types above. It is the responsibility of network subsystem L2/driver
implementations (notably Ethernet and IEEE 802.15.4 L2 stacks) to ensure
consistency of all timestamps and radio timer values exposed by the
driver API to such a network subsystem uptime reference clock
independent of internal implementation details.
The "virtual" network clock source may be implemented based on arbitrary
hardware peripherals (e.g. a coarse low power RTC counter during sleep
time plus a high resolution/high precision radio timer while receiving
or sending). Such implementation details must be hidden from API
clients, as if the driver used a single high resolution clock source
instead.
For IEEE 802.15.4, whenever timestamps refer to packet send or receive
times, they are measured when the end of the IEEE 802.15.4 SFD (message
timestamp point) is present at the local antenna (reference plane).
Due to its limited range of ~290 years, net_time_t timestamps (and
therefore net_pkt timestamps and times) must not be used to represent
absolute points in time referred to an external epoch independent of
system uptime (e.g. UTC, TAI, PTP, NTP, ...).
Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
Add similar test as for TCP, that verifies that accept() call is
interrupted correctly when the socket is closed from another thread.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add test that verifies that accept() call is interrupted correctly when
the socket is closed from another thread.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add test that verifies that recv() call is interrupted correctly when
the socket is closed from another thread.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In the FIN_WAIT_1 any incoming data is dropped, but anknowledged. Add a
check to see if the data is already acknowleged to prevent double
acknowledging of the data and bringing the acknowlegde counter out of
sync. When the acknowledge counter gets out of sync, the connection will
never properly terminate any more.
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
Twister now supports using YAML lists for all fields that were written
as space-separated lists. Used twister_to_list.py script. Some artifacts
on string length are due to how ruamel dumps content.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Remove all init functions that do nothing, and provide a `NULL` to
*DEVICE*DEFINE* macros.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Set explicit loopback MTU for TCP tests for clarity,
and to avoid breaking tests if changed elsewhere.
Signed-off-by: Kenny Johansson <wirehell@gmail.com>
Instead of passing the test parameters to the websocket function, by
casting the pointer to integer (which may not work on 64-bit platform
due to int/pointer size mismatch), let the test allocate a file
descriptor, and initialize it with test context. The tested functions
expect a file descriptor as an argument anyway, so it's a more intuitive
approach.
The conditional test code within WS implementation can retrieve the test
context by using FD APIs to obtain the object represented by the FD.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
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>
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>
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>
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>
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>
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>
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>
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>
* 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>