aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/net/tcp_ao/lib/utils.c
diff options
context:
space:
mode:
authorDmitry Safonov <[email protected]>2024-08-23 22:04:58 +0000
committerJakub Kicinski <[email protected]>2024-08-27 21:11:27 +0000
commit586d87021f224b0434372f5b4418216e29b0a544 (patch)
tree4455fded839323f5a798e878cbd97118ab970191 /tools/testing/selftests/net/tcp_ao/lib/utils.c
parentselftests/net: Synchronize client/server before counters checks (diff)
downloadkernel-586d87021f224b0434372f5b4418216e29b0a544.tar.gz
kernel-586d87021f224b0434372f5b4418216e29b0a544.zip
selftests/net: Add trace events matching to tcp_ao
Setup trace points, add a new ftrace instance in order to not interfere with the rest of the system, filtering by net namespace cookies. Raise a new background thread that parses trace_pipe, matches them with the list of expected events. Wiring up trace events to selftests provides another insight if there is anything unexpected happining in the tcp-ao code (i.e. key rotation when it's not expected). Note: in real programs libtraceevent should be used instead of this manual labor of setting ftrace up and parsing. I'm not using it here as I don't want to have an .so library dependency that one would have to bring into VM or DUT (Device Under Test). Please, don't copy it over into any real world programs, that aren't tests. Signed-off-by: Dmitry Safonov <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
Diffstat (limited to 'tools/testing/selftests/net/tcp_ao/lib/utils.c')
-rw-r--r--tools/testing/selftests/net/tcp_ao/lib/utils.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/tcp_ao/lib/utils.c b/tools/testing/selftests/net/tcp_ao/lib/utils.c
index 372daca525f5..bdf5522c9213 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/utils.c
+++ b/tools/testing/selftests/net/tcp_ao/lib/utils.c
@@ -21,6 +21,32 @@ void randomize_buffer(void *buf, size_t buflen)
}
}
+__printf(3, 4) int test_echo(const char *fname, bool append,
+ const char *fmt, ...)
+{
+ size_t len, written;
+ va_list vargs;
+ char *msg;
+ FILE *f;
+
+ f = fopen(fname, append ? "a" : "w");
+ if (!f)
+ return -errno;
+
+ va_start(vargs, fmt);
+ msg = test_snprintf(fmt, vargs);
+ va_end(vargs);
+ if (!msg) {
+ fclose(f);
+ return -1;
+ }
+ len = strlen(msg);
+ written = fwrite(msg, 1, len, f);
+ fclose(f);
+ free(msg);
+ return written == len ? 0 : -1;
+}
+
const struct sockaddr_in6 addr_any6 = {
.sin6_family = AF_INET6,
};