selftests/net: Provide test_snprintf() helper
authorDmitry Safonov <0x7f454c46@gmail.com>
Fri, 23 Aug 2024 22:04:52 +0000 (23:04 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 27 Aug 2024 21:11:27 +0000 (14:11 -0700)
commit7053e788ded5f8ec589e4507d764d6a894780d6c
tree27615d6409f1f1b681d7d725b6e2cd142df0f759
parent79504a47339cd9a1574d974869aecaba838e1213
selftests/net: Provide test_snprintf() helper

Instead of pre-allocating a fixed-sized buffer of TEST_MSG_BUFFER_SIZE
and printing into it, call vsnprintf() with str = NULL, which will
return the needed size of the buffer. This hack is documented in
man 3 vsnprintf.

Essentially, in C++ terms, it re-invents std::stringstream, which is
going to be used to print different tracing paths and formatted strings.
Use it straight away in __test_print() - which is thread-safe version of
printing in selftests.

Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-2-05623636fe8c@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/tcp_ao/lib/aolib.h