void handleAttach() { #if defined(os_bg_test) return; #elif !defined(os_windows_test) char ch = 'T'; struct timeval start_time; if (!useAttach) return; if (write(pfd, &ch, sizeof(char)) != sizeof(char)) { output->log(STDERR, "*ERROR*: Writing to pipe\n"); exit(-1); } close(pfd); logstatus("mutatee %d: Waiting for mutator to attach...\n", getpid()); gettimeofday(&start_time, NULL); #else char ch = 'T'; LPCTSTR pipeName = "\\\\.\\pipe\\mutatee_signal_pipe"; DWORD bytes_written = 0; BOOL wrote_ok = FALSE; HANDLE signalPipe; if (!useAttach) return; signalPipe = CreateFile(pipeName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(signalPipe == INVALID_HANDLE) { if(GetLastError() != ERROR_PIPE_BUSY) { output->log(STDERR, "*ERROR*: Couldn't open pipe\n"); exit(-1); } if(!WaitNamedPipe(pipeName, 2000)) { output->log(STDERR, "*ERROR*: Couldn't open pipe\n"); exit(-1); } } wrote_ok = WriteFile(signalPipe, &ch, 1, &bytes_written, NULL); if(!wrote_ok ||(bytes_written != 1)) { output->log(STDERR, "*ERROR*: Couldn't write to pipe\n"); exit(-1); } CloseHandle(signalPipe); logstatus("mutatee: Waiting for mutator to attach...\n"); #endif setUseAttach(TRUE); flushOutputLog(); while (!checkIfAttached()) { #if !defined(os_windows_test) && !defined(os_bg_test) struct timeval present_time; gettimeofday(&present_time, NULL); if (present_time.tv_sec > (start_time.tv_sec + 30)) { if (checkIfAttached()) break; logstatus("mutatee: mutator attach problem, failing...\n"); exit(-1); } #endif /* Do nothing */ } fflush(stderr); logstatus("Mutator attached. Mutatee continuing.\n"); }
int main(int argc, char *argv[]) { unsigned i; void *ret_val; char c = 'T'; pthread_attr_t attr; if(argc == 1) { printf("Mutatee %s [%s]:\"%s\"\n", argv[0], mutateeCplusplus ? "C++" : "C", Builder_id); return 0; } pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); thr_exits = 0; parse_args(argc, argv); /* create the workers */ for (i=1; i<NTHRD; i++) { pthread_create(&(thrds[i]), &attr, init_func, &(thr_ids[i])); } thrds[0] = pthread_self(); if (attached_fd) { if (write(attached_fd, &c, sizeof(char)) != sizeof(char)) { fprintf(stderr, "*ERROR*: Writing to pipe\n"); exit(-1); } close(attached_fd); printf("Waiting for mutator to attach...\n"); while(! checkIfAttached()) ; printf("Mutator attached. Mutatee continuing.\n"); } /* give time for workers to run thr_loop */ while(thr_exits == 0) sched_yield(); /* wait for worker exits */ for (i=1; i<NTHRD; i++) { pthread_join(thrds[i], &ret_val); } if(sync_failure) fprintf(stderr, "%s[%d]: ERROR: oneTimeCode failed for %d threads\n", __FILE__, __LINE__, sync_failure); if(async_failure) fprintf(stderr, "%s[%d]: ERROR: oneTimeCodeAsync failed for %d threads\n", __FILE__, __LINE__, async_failure); /* let mutator do final work after noticing all workers exit */ sleep(5); return 0; }
int main(int iargc, char *argv[]) { /* despite different conventions */ unsigned argc=(unsigned)iargc; /* make argc consistently unsigned */ unsigned int i, j; #if !defined(i386_unknown_nt4_0) int pfd; #endif int useAttach = FALSE; int doAttachCheck = TRUE; for (j=0; j <= MAX_TEST; j++) runTest[j] = FALSE; for (i=1; i < argc; i++) { if (!strcmp(argv[i], "-verbose")) { debugPrint = 1; } else if (!strcmp(argv[i], "-attach")) { useAttach = TRUE; #ifndef i386_unknown_nt4_0 if (++i >= argc) { printf("attach usage\n"); fprintf(stderr, "%s\n", USAGE); exit(-1); } pfd = atoi(argv[i]); #endif } else if (!strcmp(argv[i], "-attachrun")) { doAttachCheck = FALSE; } else if (!strcmp(argv[i], "-run")) { for (j=i+1; j < argc; j++) { unsigned int testId; if (argv[j] && isdigit(*argv[j]) && (testId = atoi(argv[j]))) { if ((testId > 0) && (testId <= MAX_TEST)) { dprintf("selecting test %d\n", testId); runTest[testId] = TRUE; } else { printf("%s[%d]: invalid test %d requested\n", __FILE__, __LINE__, testId); exit(-1); } } else { /* end of test list */ break; } } i = j-1; } else if (!strcmp(argv[i], "-runall")) { for (j=0; j <= MAX_TEST; j++) runTest[j] = TRUE; } else { printf("unexpected parameter '%s'\n", argv[i]); fprintf(stderr, "%s\n", USAGE); exit(-1); } } if ((argc==1) || debugPrint) printf("Mutatee %s [%s]:\"%s\"\n", argv[0], mutateeCplusplus ? "C++" : "C", Builder_id); if (argc==1) exit(0); /* set xlc flag if appropriate */ mutateeXLC = 0; if (strstr(argv[0], "xlc") || strstr(argv[0], "xlC")) mutateeXLC = 1; /* see if we should wait for the attach */ if (useAttach) { #ifndef i386_unknown_nt4_0 char ch = 'T'; if (write(pfd, &ch, sizeof(char)) != sizeof(char)) { fprintf(stderr, "*ERROR*: Writing to pipe\n"); exit(-1); } close(pfd); #endif if (doAttachCheck) { printf("Waiting for mutator to attach...\n"); fflush(stdout); while (!checkIfAttached()) ; printf("Mutator attached. Mutatee continuing.\n"); } } /* test1 operates on a different "mode", ie the mutatee is started specially for test1, which executes it apart from the other tests. */ if (runTest[2] || runTest[3] || runTest[4] || runTest[5] || runTest[6] || runTest[7] || runTest[8]) runTest[1] = FALSE; if (runTest[1]) func1_1(); if (runTest[2]) func2_1(); if (runTest[3]) func3_1(); if (runTest[4]) func4_1(); if (runTest[5]) func5_1(); if (runTest[6]) func6_1(); if (runTest[7]) func7_1(); if (runTest[8]) func8_1(); #if 0 while(1); #endif return(0); }