Commit graph

85 commits

Author SHA1 Message Date
David Vašek
aacd827f71 tests/atomic: lower the iteration counts with spinlock-emulated atomics 2024-12-12 20:21:50 +01:00
Jan Hák
e53c99d3cb tests: fix usage of new atomic in code -- test_atomic.c 2024-12-11 17:36:20 +01:00
David Vašek
80e28bccda tests/atomic: silence false positive Coverity warning (missing lock) 2024-05-06 14:34:51 +02:00
David Vašek
3f2f89ade1 tests/atomic: workaround for a GCC optimization bug on i386
With -O1 and higher, the test of atomic_exchange_explicit() doesn't work right for 64-bit variables
on i386 (and possibly other 32-bit architectures). It seems that atomic_exchange_explicit() doesn't
exchange 64-bit values properly when it's used in a loop and GCC compiler optimization is turned
on. As a workaround, we are testing ATOMIC_XCHG on a pointer size of the given architecture.

It isn't sure yet, if atomic_exchange_explicit() is safe for 64-bit variables with GCC on i386 when
not used in a loop. Therefore, ATOMIC_XCHG should not be used on general 64-bit variables until
this GCC bug is solved.

Clang and gcc -O0 don't seem to be affected by this issue.
2024-05-06 14:34:51 +02:00
David Vašek
b323b0c5d9 tests/atomic: finish the thread early once an invalid value occurs 2024-05-06 14:34:51 +02:00
David Vašek
c994bbe175 contrib/atomic: add an atomic exchange macro 2024-04-30 14:18:43 +02:00
David Vašek
3f37ed2940 contrib: universal atomic operations 2023-11-14 16:27:57 +01:00
Daniel Salzman
5628694324 tests: add test for knot_inet_ntop() 2023-03-07 13:16:00 +01:00
Daniel Salzman
51761407cb tests/sockaddr: add some tests for UNIX socket path match 2023-01-16 21:49:53 +01:00
Daniel Salzman
e987372a0a server: set 0222 mode to STREAM UNIX listen socket files 2023-01-04 08:47:45 +01:00
Daniel Salzman
ae0df89e9c tests/net: add small sleep to ensure the server socket is really closed
fixes #806
2022-09-13 07:22:32 +02:00
Daniel Salzman
fd8a8e49c7 tests: add missing include to test_toeplitz 2022-07-24 19:34:26 +02:00
Daniel Salzman
0a12374327 contrib: add Toeplitz-based hashing 2022-07-23 17:28:24 +02:00
Libor Peltan
ee45d9f9b6 tests: move dynarray test to libknot...
...as dynarray itself had been moved from contrib
2022-05-25 19:02:21 +02:00
Libor Peltan
929e238097 dynarray: implemented binary search in sorted dynarray 2022-05-25 19:02:21 +02:00
Josh Soref
43db89b880 spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2021-11-24 12:55:47 +01:00
David Vašek
25e7399eca tests: dynarray -- test removal of duplicate items 2021-11-10 14:50:26 +01:00
Daniel Salzman
a2dad1c287 Replace UNUSED with _unused_ 2021-07-17 19:53:31 +02:00
Daniel Salzman
5227ef050a dynarray: move from contrib to libknot 2021-07-08 16:04:00 +02:00
David Vašek
9956372717 tests: add a test for contrib/spinlock.h 2021-06-15 10:14:24 +02:00
Libor Peltan
3d38ec901c tests: better debuggability of problematic contrib/net 2021-06-02 16:27:57 +02:00
Daniel Salzman
f052ed1232 tests: use _unused_ in test_fdset and test_strtonum 2021-05-24 12:28:21 +02:00
Robert Edmonds
d783699778 tests/contrib/test_net: Use IPv4 loopback socket instead of IPv6
In some build environments it may not be possible to bind to ::1. Bind
to INADDR_LOOPBACK instead, which prevents this test suite from failing
or crashing.
2021-05-01 11:36:49 +02:00
Robert Edmonds
bd5453d7f4 tests/contrib/test_net: Don't assert on net_stream_recv() failure
This commit removes the assert() in _sync() and propagates the error to
the caller.

It was possible for the test_dns_tcp() test to set up an invalid socket
descriptor and not notice that the socket was not usable, which would
cause socket reads to fail, which would trigger the assert. This can
occur in some CI environments where IPv6 networking is not available.
These tests should probably just fail instead of crashing the build.

Here is what the strace output looked like when this test asserted:

    write(1, "# DNS messages over TCP\n", 24) = 24
    socket(PF_INET6, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
    setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
    setsockopt(3, SOL_IPV6, IPV6_V6ONLY, [1], 4) = 0
    bind(3, {sa_family=AF_INET6, sin6_port=htons(0), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EADDRNOTAVAIL (Cannot assign requested address)
    close(3)                                = 0
    write(1, "not ok 1 - single DNS, server, create socket\n", 45) = 45
    listen(-99, 5)                          = -1 EBADF (Bad file descriptor)
    write(1, "not ok 2 - single DNS, server, start listening\n", 47) = 47
    mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f340dc41000
    mprotect(0x7f340dc41000, 4096, PROT_NONE) = 0
    clone(child_stack=0x7f340e440ff0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f340e4419d0, tls=0x7f340e441700, child_tidptr=0x7f340e4419d0) = 80049
    write(1, "ok 3 - single DNS, server, start handler\n", 41) = 41
    getsockname(-99, 0x7fffc7378760, 0x7fffc737867c) = -1 EBADF (Bad file descriptor)
    write(1, "not ok 4 - check getsockname return\n", 36) = 36
    socket(PF_UNSPEC, SOCK_STREAM|SOCK_NONBLOCK, 0) = -1 EAFNOSUPPORT (Address family not supported by protocol)
    write(1, "not ok 5 - single DNS, client, create connected socket\n", 55) = 55
    write(2, "test_net: contrib/test_net.c:410: _sync: Assertion `r == sizeof(buf)' failed.\n", 78) = 78
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f340ec4d000
    rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
    tgkill(80048, 80048, SIGABRT)           = 0
    --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=80048, si_uid=0} ---
    +++ killed by SIGABRT (core dumped) +++

(I commented out all of the test_*() calls in main() except the call to
test_dns_tcp(), so the test numbering on stdout is off.)

This keeps the test_net program from assert()'ing on IPv4-only and
IPv4/IPv6 machines, but perhaps a better solution would be to have
the loop in test_dns_tcp() skip to the next test case if required
socket operations fail.
2021-05-01 11:36:49 +02:00
Daniel Salzman
ecf9156e15 net/requestor: add support for TFO 2021-03-15 13:21:50 +01:00
Simon South
4144d1e9b7 test_net_shortwrite: ensure connection can succeed
closes #693
2020-10-01 10:31:25 +02:00
Jan Hak
53642ae50c contrib: add base64url encoder and decoder 2020-07-01 20:33:00 +02:00
Daniel Salzman
0c869e9a21 contrib: allow sockaddr_cmp() to ignore port if needed 2020-04-03 12:47:16 +02:00
Daniel Salzman
b89cfd695e base32hex: use knot namespace for base32hex functions 2020-02-10 09:38:03 +01:00
Daniel Salzman
f29d7eaf48 base64: fix parameter alignment, update copyright 2020-02-10 09:31:11 +01:00
Emmanuel Bretelle
dec9caa2c0 base64: use knot namespace for base64 functions
both knot and gnutls (at least until [3.4](https://gitlab.com/gnutls/gnutls/-/blob/gnutls_3_4_x/gl/base64.c)) define they own base64_{en,de}code{_alloc}.

When linking with ODR violation detection, it fails with:
```
ld.lld: error: duplicate symbol: base64_encode
stderr: ld.lld: error: duplicate symbol: base64_encode
```

This diff put the base64* functions under `knot_` namespace to avoid the
conflict.
2020-02-10 09:31:03 +01:00
Daniel Salzman
880648f445 tests: mute some Coverity warnings 2019-10-06 11:11:01 +02:00
Daniel Salzman
f9a87c22c3 contrib: replace 'struct sockaddr' with 'struct sockaddr_storage' where reasonable 2019-10-05 21:59:13 +02:00
Vladimír Čunát
36ef0a0ec7 trie_get_try_wildcard(): more efficient version
It's not at all necessary to repeatedly search from the root,
though this optimization makes the code a bit more complex.

Even here, technically the last memcmp() wouldn't need to start at the
beginning, but I didn't want to overcomplicate this.
2019-09-08 17:10:04 +02:00
David Vašek
e3d311d8ed coding style improvements - copyright notice 2019-07-04 15:16:43 +02:00
Daniel Salzman
e2fa93faa7 tests/qp-cow: mute 'unused variable' if NDEBUG 2019-02-27 13:49:52 +01:00
Daniel Salzman
f83685b822 tests/net: remove commented, broken, and unreliable test 2019-02-08 16:36:59 +01:00
Daniel Salzman
949f7c198d Adapt to trie API change 2019-02-06 21:36:05 +01:00
Daniel Salzman
eed80ad6ff net: rename net_send/recv net_base_send/recv to fix name conflicts 2019-02-01 16:47:10 +01:00
Daniel Salzman
eecdcb55d8 time: add UTC time zone to ISO 8601 2018-12-18 12:00:54 +01:00
Daniel Kahn Gillmor
846bb431d2 use https://www.gnu.org instead of http://www.gnu.org
www.gnu.org has offered https for years now.
2018-08-29 09:45:57 -04:00
Tony Finch
1bc0971122 trie: support for copy-on-write transactions
A COW transaction allows a trie to be used for reading concurrently
while a modified version of the trie is being prepared. The change
can be committed by swapping the new trie root in place of the old one.

Internally, this feature uses one bit reference counts to identify which
parts of the trie are shared between the old and new versions, which
parts are new-only (so can be mutated) and which parts are old-only
(and will be free()d after commit).
2018-08-20 14:48:35 +02:00
Tony Finch
e7b7e187a3 trie: refactor to prepare for copy-on-write support
No functional change.

The point of this commit is to make it possible to stash a few
flags in leaf nodes as well as branch nodes, though we don't
yet exercise this possibility in any meaningful way.

This fixes a foolish mistake in the original qp trie data structure
declarations: the combination of unions and bitfields is a complete
disaster for portability, and it gets into dangerous territory wrt
compiler optimization. Instead, we just use a big enough word (uint64_t)
which is broken up into fields using accessor macros and inline functions,
and cast it to a pointer when necessary. We don't actually care about
the detailed layout in memory, just the numeric value, so a union was
the wrong tool.
2018-08-20 14:48:35 +02:00
Daniel Salzman
b9791462cd strtonum: add size_t variant, refactoring 2018-03-21 09:52:57 +01:00
Daniel Salzman
edf16dee50 Update license in previously changed files 2018-03-12 14:56:15 +01:00
Daniel Salzman
2faf8f9991 dnssec: move to libdnssec 2018-03-12 13:31:30 +01:00
Daniel Kahn Gillmor
47d4d6416a Fix minor spelling nit-picks
These were found by the "codespell" tool.
2018-02-26 16:57:36 +01:00
Mark Karpilovskij
a151d62f6e tests/contrib: fixed time printing unit test 2018-02-08 17:28:45 +01:00
Mark Karpilovskij
243db75e78 libknot: move wire.h from contrib to libknot 2018-01-20 20:49:05 +01:00
Mark Karpilovskij
8c72abd6ad libknot: moved endian.h from contrib to libknot 2018-01-20 20:49:05 +01:00