Skip to contentSkip to conversation

selftests: connector: make proc_filter terminate on its own

PATCH New Eva Kurchatova 1 participant 1 message Sep 17 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: connector: make proc_filter terminate on its own

proc_filter listens for process events until a signal interrupts it, so a caller that waits for it to finish waits forever. Generate one event, stop after five seconds, and fail if nothing was received.

---
 tools/testing/selftests/connector/proc_filter.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/connector/proc_filter.c +12 -1
index 36c11467a8f1..2412f66c38e1 100644
@@ -14,6 +14,7 @@
 #include <strings.h>
 #include <errno.h>
 #include <signal.h>
+#include <sys/wait.h>
 #include <string.h>
 
 #include "kselftest.h"
@@ -279,6 +280,16 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	/*
+	 * Generate one event to observe and stop listening shortly after,
+	 * so that the test terminates on its own.
+	 */
+	signal(SIGALRM, sigint);
+	alarm(5);
+	if (fork() == 0)
+		_exit(0);
+	wait(NULL);
+
 	while (!interrupted) {
 		err = handle_events(epoll_fd, &proc_ev);
 		if (err < 0) {
@@ -306,5 +317,5 @@ int main(int argc, char *argv[])
 	close(nl_sock);
 
 	printf("Done total count: %d\n", tcount);
-	exit(0);
+	exit(tcount > 0 ? KSFT_PASS : KSFT_FAIL);
 }
Signature · 1 line
2.55.0