projects
/
urcu.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Build and run regression and unit tests as C++ programs
[urcu.git]
/
tests
/
regression
/
test_urcu_fork.c
diff --git
a/tests/regression/test_urcu_fork.c
b/tests/regression/test_urcu_fork.c
index 06786b0cc3285b988e225b1bb74c0f0522c76d36..db4e81dcf67a36d8750684cc5f025a233a23ed33 100644
(file)
--- a/
tests/regression/test_urcu_fork.c
+++ b/
tests/regression/test_urcu_fork.c
@@
-20,8
+20,6
@@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#define _GNU_SOURCE
-#include "config.h"
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
@@
-30,10
+28,10
@@
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
-#include <assert.h>
#include <sched.h>
#include <errno.h>
#include <sched.h>
#include <errno.h>
+#include <urcu/assert.h>
#include <urcu/arch.h>
#include <urcu/tls-compat.h>
#include <urcu/arch.h>
#include <urcu/tls-compat.h>
@@
-44,13
+42,27
@@
#endif
#include <urcu.h>
#endif
#include <urcu.h>
+#include "tap.h"
+
/* We generate children 3 levels deep */
#define FORK_DEPTH 3
/* Each generation spawns 10 children */
#define NR_FORK 10
/* We generate children 3 levels deep */
#define FORK_DEPTH 3
/* Each generation spawns 10 children */
#define NR_FORK 10
+#define NR_TESTS NR_FORK
+
static int fork_generation;
static int fork_generation;
+/*
+ * Only print diagnostic for top level parent process, else the console
+ * has trouble formatting the tap output.
+ */
+#define diag_gen0(...) \
+ do { \
+ if (!fork_generation) \
+ diag(__VA_ARGS__); \
+ } while (0)
+
struct test_node {
int somedata;
struct rcu_head head;
struct test_node {
int somedata;
struct rcu_head head;
@@
-60,8
+72,7
@@
static void cb(struct rcu_head *head)
{
struct test_node *node;
{
struct test_node *node;
- fprintf(stderr, "rcu callback invoked in pid: %d\n",
- (int) getpid());
+ diag_gen0("rcu callback invoked in pid: %d", (int) getpid());
node = caa_container_of(head, struct test_node, head);
free(node);
}
node = caa_container_of(head, struct test_node, head);
free(node);
}
@@
-77,8
+88,8
@@
static void test_rcu(void)
rcu_read_lock();
rcu_read_unlock();
rcu_read_lock();
rcu_read_unlock();
- node = malloc(sizeof(*node));
- assert(node);
+ node =
(struct test_node *)
malloc(sizeof(*node));
+
urcu_posix_
assert(node);
call_rcu(&node->head, cb);
call_rcu(&node->head, cb);
@@
-94,7
+105,7
@@
static int do_fork(const char *execname)
{
pid_t pid;
{
pid_t pid;
-
fprintf(stderr, "%s parent pid: %d, before fork\n
",
+
diag_gen0("%s parent pid: %d, before fork
",
execname, (int) getpid());
call_rcu_before_fork();
execname, (int) getpid());
call_rcu_before_fork();
@@
-102,12
+113,13
@@
static int do_fork(const char *execname)
if (pid == 0) {
/* child */
fork_generation++;
if (pid == 0) {
/* child */
fork_generation++;
+ tap_disable();
call_rcu_after_fork_child();
call_rcu_after_fork_child();
-
fprintf(stderr, "%s child pid: %d, after fork\n
",
+
diag_gen0("%s child pid: %d, after fork
",
execname, (int) getpid());
test_rcu();
execname, (int) getpid());
test_rcu();
-
fprintf(stderr, "%s child pid: %d, after rcu test\n
",
+
diag_gen0("%s child pid: %d, after rcu test
",
execname, (int) getpid());
if (fork_generation >= FORK_DEPTH)
exit(EXIT_SUCCESS);
execname, (int) getpid());
if (fork_generation >= FORK_DEPTH)
exit(EXIT_SUCCESS);
@@
-117,25
+129,26
@@
static int do_fork(const char *execname)
/* parent */
call_rcu_after_fork_parent();
/* parent */
call_rcu_after_fork_parent();
-
fprintf(stderr, "%s parent pid: %d, after fork\n
",
+
diag_gen0("%s parent pid: %d, after fork
",
execname, (int) getpid());
test_rcu();
execname, (int) getpid());
test_rcu();
-
fprintf(stderr, "%s parent pid: %d, after rcu test\n
",
+
diag_gen0("%s parent pid: %d, after rcu test
",
execname, (int) getpid());
for (;;) {
pid = wait(&status);
if (pid < 0) {
execname, (int) getpid());
for (;;) {
pid = wait(&status);
if (pid < 0) {
- perror("wait");
+ if (!fork_generation)
+ perror("wait");
return -1;
}
if (WIFEXITED(status)) {
return -1;
}
if (WIFEXITED(status)) {
-
fprintf(stderr, "child %u exited normally with status %u\n
",
+
diag_gen0("child %u exited normally with status %u
",
pid, WEXITSTATUS(status));
if (WEXITSTATUS(status))
return -1;
break;
} else if (WIFSIGNALED(status)) {
pid, WEXITSTATUS(status));
if (WEXITSTATUS(status))
return -1;
break;
} else if (WIFSIGNALED(status)) {
-
fprintf(stderr, "child %u was terminated by signal %u\n
",
+
diag_gen0("child %u was terminated by signal %u
",
pid, WTERMSIG(status));
return -1;
} else {
pid, WTERMSIG(status));
return -1;
} else {
@@
-144,15
+157,18
@@
static int do_fork(const char *execname)
}
return 1;
} else {
}
return 1;
} else {
- perror("fork");
+ if (!fork_generation)
+ perror("fork");
return -1;
}
}
return -1;
}
}
-int main(int argc, char **argv)
+int main(int argc
__attribute__((unused))
, char **argv)
{
unsigned int i;
{
unsigned int i;
+ plan_tests(NR_TESTS);
+
#if 0
/* pthread_atfork does not work with malloc/free in callbacks */
ret = pthread_atfork(call_rcu_before_fork,
#if 0
/* pthread_atfork does not work with malloc/free in callbacks */
ret = pthread_atfork(call_rcu_before_fork,
@@
-172,14
+188,27
@@
restart:
test_rcu();
synchronize_rcu();
ret = do_fork(argv[0]);
test_rcu();
synchronize_rcu();
ret = do_fork(argv[0]);
- if (ret == 0) /* child */
+ if (!fork_generation) {
+ ok(ret >= 0, "child status %d", ret);
+ }
+ if (ret == 0) { /* child */
goto restart;
goto restart;
- else if (ret < 0)
+ } else if (ret < 0) {
goto error;
goto error;
- /* else parent, continue. */
+ } else {
+ /* else parent, continue. */
+ }
+ }
+ if (!fork_generation) {
+ return exit_status();
+ } else {
+ exit(EXIT_SUCCESS);
}
}
- exit(EXIT_SUCCESS);
error:
error:
- exit(EXIT_FAILURE);
+ if (!fork_generation) {
+ return exit_status();
+ } else {
+ exit(EXIT_FAILURE);
+ }
}
}
This page took
0.02589 seconds
and
4
git commands to generate.