void mutatorMAIN(char *pathname) { // Create an instance of the BPatch library bpatch = new BPatch; // Force functions to be relocated if (forceRelocation) { bpatch->setForcedRelocation_NP(true); } // Register a callback function that prints any error messages bpatch->registerErrorCallback(errorFunc); //bpatch->registerPreForkCallback(preForkFunc); bpatch->registerPostForkCallback(postForkFunc); bpatch->registerExitCallback(exitFunc); for(unsigned i=1; i<=MAX_TEST; i++) passedTest[i] = true; int n = 0; const char *child_argv[MAX_TEST+5]; dprintf("in mutatorTest1\n"); inTest = 1; child_argv[n++] = pathname; if (debugPrint) child_argv[n++] = const_cast<char*>("-verbose"); child_argv[n] = NULL; // Start the mutatee printf("Starting \"%s\"\n", pathname); setupMessaging(); parentThread = bpatch->createProcess(pathname, child_argv, NULL); if(parentThread == NULL) { fprintf(stderr, "Unable to run test program.\n"); exit(1); } initialPreparation(parentThread); /* ok, do the fork */; parentThread->continueExecution(); /* the rest of the execution occurs in postForkFunc() */ /* Secondary test: we should not have to manually continue either parent or child at any point */ while (!parentThread->isTerminated() || !childThread->isTerminated()) { bpatch->waitForStatusChange(); } delete parentThread; delete childThread; showFinalResults(); exit(0); }
static int mutatorTest(BPatch *bpatch, BPatch_thread *appThread) { if ( !setupMessaging(&msgid) ) { passedTest = false; return passedTest; } parentThread = appThread; initialPreparation(parentThread); /* ok, do the fork */; parentThread->getProcess()->continueExecution(); /* the rest of the execution occurs in postForkFunc() */ /* Secondary test: we should not have to manually continue either parent or child at any point */ while ( !parentThread->getProcess()->isTerminated() ) { bpatch->waitForStatusChange(); } // At this point if childThread == NULL the postfork handler failed // to run. Fail gracefully instead of segfaulting on // childThread->isTerminated() if (doError(&passedTest, childThread == NULL, "childThread == NULL: postForkFunc must not have run\n") ) { return passedTest; } while ( !childThread->getProcess()->isTerminated() ) { bpatch->waitForStatusChange(); } return passedTest; }