PERFORCE change 174238 for review

Robert Watson rwatson at FreeBSD.org
Wed Feb 3 14:11:32 UTC 2010


http://p4web.freebsd.org/chv.cgi?CH=174238

Change 174238 by rwatson at rwatson_vimage_client on 2010/02/03 14:10:57

	Add a 'pingpong' test, which is socketpair + fork + send + recv +
	send + recv + exit + waitpid.  A bit like sandbox but no exec or
	sandboxy magic.

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#12 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#12 (text+ko) ====

@@ -565,6 +565,94 @@
 	benchmark_stop();
 }
 
+/*
+ * A bit like sandbox, in that a process is forked, IPC ping-pong is done,
+ * but with none of the sandboxing goo.
+ */
+void
+test_pingpong(int num)
+{
+	char ch;
+	int so[2];
+	pid_t pid;
+	ssize_t len;
+	int i;
+
+	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, so) < 0)
+		err(-1, "test_pingpong: socketpair");
+	pid = fork();
+	if (pid < 0)
+		err(-1, "test_pingpong: fork");
+	if (pid == 0) {
+		close(so[0]);
+		len = recv(so[1], &ch, sizeof(ch), 0);
+		if (len < 0)
+			err(-1, "test_pingpong: child: recv");
+		if (len != 1)
+			errx(-1, "test_pingpong: child: recv %d", (int)len);
+		len = send(so[1], &ch, sizeof(ch), 0);
+		if (len < 0)
+			err(-1, "test_pingpong: child: send");
+		if (len != 1)
+			errx(-1, "test_pingpong: child: send %d", (int)len);
+		_exit(0);
+	}
+	close(so[1]);
+	len = send(so[0], &ch, sizeof(ch), 0);
+	if (len < 0)
+		err(-1, "test_pingpong: parent: send");
+	if (len != 1)
+		errx(-1, "test_pingpong: parent: send %d", (int)len);
+	len = recv(so[0], &ch, sizeof(ch), 0);
+	if (len < 0)
+		err(-1, "test_pingpong: parent: recv");
+	if (len != 1)
+		errx(-1, "test_pingpong: parent: recv %d", (int)len);
+	close(so[0]);
+	if (waitpid(pid, NULL, 0) < 0)
+		err(-1, "test_pingpong: waitpid");
+
+	benchmark_start();
+	for (i = 0; i < num; i++) {
+		if (socketpair(PF_LOCAL, SOCK_STREAM, 0, so) < 0)
+			err(-1, "test_pingpong: socketpair");
+		pid = fork();
+		if (pid < 0)
+			err(-1, "test_pingpong: fork");
+		if (pid == 0) {
+			close(so[0]);
+			len = recv(so[1], &ch, sizeof(ch), 0);
+			if (len < 0)
+				err(-1, "test_pingpong: child: recv");
+			if (len != 1)
+				errx(-1, "test_pingpong: child: recv %d",
+				    (int)len);
+			len = send(so[1], &ch, sizeof(ch), 0);
+			if (len < 0)
+				err(-1, "test_pingpong: child: send");
+			if (len != 1)
+				errx(-1, "test_pingpong: child: send %d",
+				    (int)len);
+			_exit(0);
+		}
+		close(so[1]);
+		len = send(so[0], &ch, sizeof(ch), 0);
+		if (len < 0)
+			err(-1, "test_pingpong: parent: send");
+		if (len != 1)
+			errx(-1, "test_pingpong: parent: send %d", (int)len);
+		len = recv(so[0], &ch, sizeof(ch), 0);
+		if (len < 0)
+			err(-1, "test_pingpong: parent: recv");
+		if (len != 1)
+			errx(-1, "test_pingpong: parent: recv %d", (int)len);
+		close(so[0]);
+		if (waitpid(pid, NULL, 0) < 0)
+			err(-1, "test_pingpong: waitpid");
+	}
+	benchmark_stop();
+}
+
 #define	MYNAME	"./syscall_timing"		/* Binary to run in sandbox. */
 
 /*
@@ -685,6 +773,7 @@
 	{ "fork_exec", test_fork_exec },
 	{ "vfork_exec", test_vfork_exec },
 	{ "pdfork_exec", test_pdfork_exec },
+	{ "pingpong", test_pingpong },
 	{ "sandbox", test_sandbox },
 };
 static const int tests_count = sizeof(tests) / sizeof(tests[0]);


More information about the p4-projects mailing list