X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_fork.c;fp=tests%2Ftest_urcu_fork.c;h=0000000000000000000000000000000000000000;hb=f5ab766ee2c8300cb00ca5878b1cb464f960a66d;hp=6e454b59e50454502ae7025c1c8f0f275212bf07;hpb=a5bae03d59c22e57263b8610b9fed99738303cf0;p=urcu.git diff --git a/tests/test_urcu_fork.c b/tests/test_urcu_fork.c deleted file mode 100644 index 6e454b5..0000000 --- a/tests/test_urcu_fork.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * test_urcu_fork.c - * - * Userspace RCU library - test program (fork) - * - * Copyright February 2012 - Mathieu Desnoyers - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#define _GNU_SOURCE -#include "../config.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifndef DYNAMIC_LINK_TEST -#define _LGPL_SOURCE -#else -#define rcu_debug_yield_read() -#endif -#include - -struct test_node { - int somedata; - struct rcu_head head; -}; - -static void cb(struct rcu_head *head) -{ - struct test_node *node; - - fprintf(stderr, "rcu callback invoked in pid: %d\n", - (int) getpid()); - node = caa_container_of(head, struct test_node, head); - free(node); -} - -static void test_rcu(void) -{ - struct test_node *node; - - rcu_register_thread(); - - synchronize_rcu(); - - rcu_read_lock(); - rcu_read_unlock(); - - node = malloc(sizeof(*node)); - assert(node); - - call_rcu(&node->head, cb); - - synchronize_rcu(); - - rcu_unregister_thread(); -} - -int main(int argc, char **argv) -{ - pid_t pid; - int ret; - -#if 0 - /* pthread_atfork does not work with malloc/free in callbacks */ - ret = pthread_atfork(call_rcu_before_fork, - call_rcu_after_fork_parent, - call_rcu_after_fork_child); - if (ret) { - errno = ret; - perror("pthread_atfork"); - exit(EXIT_FAILURE); - } -#endif - - test_rcu(); - - synchronize_rcu(); - - fprintf(stderr, "%s parent pid: %d, before fork\n", - argv[0], (int) getpid()); - - call_rcu_before_fork(); - pid = fork(); - - if (pid == 0) { - /* child */ - call_rcu_after_fork_child(); - fprintf(stderr, "%s child pid: %d, after fork\n", - argv[0], (int) getpid()); - test_rcu(); - fprintf(stderr, "%s child pid: %d, after rcu test\n", - argv[0], (int) getpid()); - } else if (pid > 0) { - int status; - - /* parent */ - call_rcu_after_fork_parent(); - fprintf(stderr, "%s parent pid: %d, after fork\n", - argv[0], (int) getpid()); - test_rcu(); - fprintf(stderr, "%s parent pid: %d, after rcu test\n", - argv[0], (int) getpid()); - for (;;) { - pid = wait(&status); - if (WIFEXITED(status)) { - fprintf(stderr, "child %u exited normally with status %u\n", - pid, WEXITSTATUS(status)); - break; - } else if (WIFSIGNALED(status)) { - fprintf(stderr, "child %u was terminated by signal %u\n", - pid, WTERMSIG(status)); - break; - } else { - continue; - } - } - } else { - perror("fork"); - exit(EXIT_FAILURE); - } - exit(EXIT_SUCCESS); -}