Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel Enhance pipe(2)-based IPC barrier in attach5 of...



details:   https://anonhg.NetBSD.org/src/rev/7988e420f4d1
branches:  trunk
changeset: 348889:7988e420f4d1
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Nov 14 00:18:33 2016 +0000

description:
Enhance pipe(2)-based IPC barrier in attach5 of t_ptrace_wait

The write(2) call does not block and there is need to perform handshake, in
order to wait on the read(2) call.

The pipe(2) interface for IPC purposes is quite difficult to design and get
right. It might be refactored and with added new helper functions, although
it would be better to switch to some other mechanism rather. But as it
works now quite well in the current set of tests, do not touch it.

Sponsored by <The NetBSD Foundation>.

diffstat:

 tests/kernel/t_ptrace_wait.c |  14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diffs (42 lines):

diff -r 291d3b7b15fb -r 7988e420f4d1 tests/kernel/t_ptrace_wait.c
--- a/tests/kernel/t_ptrace_wait.c      Sun Nov 13 22:59:31 2016 +0000
+++ b/tests/kernel/t_ptrace_wait.c      Mon Nov 14 00:18:33 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.11 2016/11/12 20:56:49 christos Exp $      */
+/*     $NetBSD: t_ptrace_wait.c,v 1.12 2016/11/14 00:18:33 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.11 2016/11/12 20:56:49 christos Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.12 2016/11/14 00:18:33 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -1041,6 +1041,10 @@
                /* Emit message to the parent */
                rv = write(fds_fromtracee[1], &msg, sizeof(msg));
                FORKEE_ASSERT(rv == sizeof(msg));
+               rv = read(fds_totracee[0], &msg, sizeof(msg));
+               FORKEE_ASSERT(rv == sizeof(msg));
+               rv = write(fds_fromtracee[1], &msg, sizeof(msg));
+               FORKEE_ASSERT(rv == sizeof(msg));
 
                /* Wait for message from the parent */
                rv = read(fds_totracee[0], &msg, sizeof(msg));
@@ -1053,7 +1057,11 @@
        ATF_REQUIRE(close(fds_totracee[0]) == 0);
        ATF_REQUIRE(close(fds_fromtracee[1]) == 0);
 
-       printf("Wait for child to record its parent identifier (pid\n");
+       printf("Wait for child to record its parent identifier (pid)\n");
+       rv = read(fds_fromtracee[0], &msg, sizeof(msg));
+       FORKEE_ASSERT(rv == sizeof(msg));
+       rv = write(fds_totracee[1], &msg, sizeof(msg));
+       FORKEE_ASSERT(rv == sizeof(msg));
        rv = read(fds_fromtracee[0], &msg, sizeof(msg));
        FORKEE_ASSERT(rv == sizeof(msg));
 



Home | Main Index | Thread Index | Old Index