[PATCH] Add clone-f test

Fei Jie feij.fnst at cn.fujitsu.com
Wed Jan 13 08:43:58 UTC 2016


tests: add clone-f.test.

Check how strace -f follows clone syscall.

* tests/clone-f.c: New file.
* tests/clone-f.test: New test.
* tests/Makefile.am: (check_PROGRAMS): Add clone-f.
(TESTS): Add clone-f.test.
* tests/.gitignore: Add clone-f.
---
 tests/.gitignore   |  1 +
 tests/Makefile.am  |  2 ++
 tests/clone-f.c    | 44 ++++++++++++++++++++++++++++++++++++++++++++
 tests/clone-f.test | 11 +++++++++++
 4 files changed, 58 insertions(+)
 create mode 100644 tests/clone-f.c
 create mode 100755 tests/clone-f.test

diff --git a/tests/.gitignore b/tests/.gitignore
index cfe1e9f..7aa2449 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -12,6 +12,7 @@ bpf
 caps
 clock_nanosleep
 clock_xettime
+clone-f
 epoll_create1
 eventfd
 execve
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 33f76cb..80292c4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -58,6 +58,7 @@ check_PROGRAMS = \
 	caps \
 	clock_nanosleep \
 	clock_xettime \
+	clone-f \
 	epoll_create1 \
 	eventfd \
 	execve \
@@ -194,6 +195,7 @@ TESTS = \
 	caps.test \
 	clock_nanosleep.test \
 	clock_xettime.test \
+	clone-f.test \
 	dumpio.test \
 	epoll_create1.test \
 	eventfd.test \
diff --git a/tests/clone-f.c b/tests/clone-f.c
new file mode 100644
index 0000000..df97b54
--- /dev/null
+++ b/tests/clone-f.c
@@ -0,0 +1,44 @@
+#include "tests.h"
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sched.h>
+#include <signal.h>
+
+#define CHILD_STACK_SIZE 16384
+
+static int
+logit(const char *const str)
+{
+	return pwrite(-1, str, strlen(str), 0) >= 0;
+}
+
+void
+child(void)
+{
+	logit("child");
+}
+
+int main()
+{
+	logit("parent");
+
+	void *child_stack;
+	if ((child_stack = (void *) malloc(CHILD_STACK_SIZE)) == NULL) {
+		printf("cannot allocate stack for child!\n");
+	}
+
+	pid_t child_pid = clone(&child, child_stack + CHILD_STACK_SIZE, CLONE_VM, NULL);
+	if (child_pid < 0) {
+		perror_msg_and_fail("clone");
+	}
+
+	free(child_stack);
+
+	pid_t pid = getpid();
+	printf("%-5d pwrite64(-1, \"parent\", 6, 0) = -1 EBADF (%m)\n"
+	       "%-5d pwrite64(-1, \"child\", 5, 0) = -1 EBADF (%m)\n",
+	       pid, child_pid);
+	return 0;
+}
diff --git a/tests/clone-f.test b/tests/clone-f.test
new file mode 100755
index 0000000..439426d
--- /dev/null
+++ b/tests/clone-f.test
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+OUT="$LOG.out"
+run_prog > /dev/null
+run_strace -a32 -epwrite64 -esignal=none -f -qq $args >"$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
+
+exit 0
-- 
1.8.3.1







More information about the Strace-devel mailing list