int main(int argc, char**argv) { Config *user_config; char * cwd = getcwd(NULL, 0); int args_index=1; //Set "gstats.xml" location GSTATS_PATH=malloc(snprintf(NULL, 0, "%s/gstats.xml", cwd) + 1); sprintf(GSTATS_PATH, "%s/gstats.xml", cwd); if(argc==2){ open_GStats(GSTATS_PATH); if(strcmp(argv[args_index],"--gstats-clear")==0){ if(clear_GStats(GSTATS_PATH)==0){ printf("gstat-status: File %s deleted.\n", GSTATS_PATH); exit(EXIT_SUCCESS); }else{ fprintf(stderr, "gstat-status: Error deleting the file %s.\n", GSTATS_PATH); exit(EXIT_FAILURE); } }else if(strcmp(argv[args_index],"--gstats-collect")==0){ //Show stats char*args_cat[]={"cat",GSTATS_PATH,NULL}; startprogram(args_cat,NULL,0); exit(EXIT_SUCCESS); } close_GStats(GSTATS_PATH); } if(strcmp(argv[args_index],"--gstreamer")==0){ args_index++; preset_project=1; } if(strcmp(argv[args_index],"-v")==0){ user_config = processConfigFile(argv[2]); verbose_mode=1; args_index++; } user_config = processConfigFile(argv[args_index]); if(user_config==NULL){ fprintf(stderr,"error: incorrect arguments\n"); exit(EXIT_FAILURE); } if (cwd== NULL){ perror("getcwd() error"); exit(EXIT_FAILURE); } if (user_config) { char**source=user_config->source; //Duplicate the project in order to revert back to after mutations char *chptr = strrchr(user_config->sourceRootDir, '/'); long dif = chptr - user_config->sourceRootDir; char *copy_put =strndup(chptr+1, strlen(user_config->sourceRootDir)-dif); //Remove the copy of the program under test if it exists due to an execution terminated by the user cleanUp(copy_put); cleanUp("mutation_out"); //Create mutation_out mkdir("mutation_out",S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); //Create gcov_out mkdir("mutation_out/PUT",S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); //copy PUT char *args_cp[5]; args_cp[0]="cp"; args_cp[1]="-r"; args_cp[2]=user_config->sourceRootDir; args_cp[3]=copy_put; args_cp[4]=NULL; startprogram(args_cp,NULL,0); //Generate initial stats for PUT setenv("IS_MUTATE","false",1); runMake(copy_put,NULL,user_config->makeTestTarget); // CFG data for the PUT extractCFGBranches(copy_put,"mutation_out/PUT",NULL); // Valgrind data for the PUT ValgrindResult* valgrindResultPUT = genValgrindResult(cwd,"PUT","PUT",copy_put,user_config); if(valgrindResultPUT!=NULL){ PUTValgrindErrors = valgrindResultPUT->valgrind_error_count; } setenv("IS_MUTATE","true",1); if(user_config->testingFramework==1){ //Replace the CuTest library in the project with our modified library char * cutest_source = malloc(snprintf(NULL, 0, "%s/%s", copy_put,user_config->CuTestLibSource) + 1); sprintf(cutest_source, "%s/%s",copy_put , user_config->CuTestLibSource); if(user_config->CuTestVersion==1){ copy_file("CuTest/CuTest.forked.c",cutest_source); } else{ copy_file("CuTest/CuTest.forked2.c",cutest_source); } free(cutest_source); }else if(user_config->testingFramework==2 && user_config->CheckTestLibSource!=NULL){ //Replace the Check library in the project with our modified library char * check_source = malloc(snprintf(NULL, 0, "%s/%s", copy_put,user_config->CheckTestLibSource) + 1); sprintf(check_source, "%s/%s",copy_put , user_config->CheckTestLibSource); //Check if a preset project is being run if(preset_project==1){ copy_file("libcheck-presets/check.c.gstreamer",check_source); }else{ copy_file("libcheck/src/check.c",check_source); } free(check_source); } //Initialize txl arguments in order to perform mutations on each source file char**args_txl = malloc((9+TXL_OPTS) * sizeof(char*));; args_txl[0]="txl"; args_txl[1]="mutator.Txl"; args_txl[2]="-size"; args_txl[3]="2048"; args_txl[2+TXL_OPTS]="-o"; args_txl[5+TXL_OPTS]="-"; args_txl[6+TXL_OPTS]="-mut_out"; args_txl[8+TXL_OPTS]=NULL; //mutator.txl path args_txl[1]=malloc(snprintf(NULL, 0, "%s/mutator.Txl",cwd) + 1); sprintf(args_txl[1],"%s/mutator.Txl",cwd); //Store mutation_results_path mutation_results_path = malloc(snprintf(NULL, 0, "%s/%s/%s",cwd, copy_put,"mutation_results.log") + 1); sprintf(mutation_results_path, "%s/%s/%s",cwd, copy_put, "mutation_results.log"); //Create a temporary log file in order to keep track of mutation results temp_results_path = malloc(snprintf(NULL, 0, "%s/%s/%s",cwd, copy_put,"temp_results.log") + 1); sprintf(temp_results_path, "%s/%s/%s",cwd, copy_put,"temp_results.log"); //Create temparary environment variables to store temp_results_path and mutation_results_path to be accessed by child processes setenv("MUTATION_RESULTS_PATH",mutation_results_path,1); setenv("TEMP_RESULTS_PATH",temp_results_path,1); //Because we run the test suite again from Valgrind, in order to prevent duplicate output, we uniquely identify this program setenv("IS_MUTATE","true",1); int sc; struct stat s; for(sc=0;sc < user_config->numberOfSource;sc++){ //get local path char *path = malloc(sizeof(char)*(snprintf(NULL, 0, "%s/%s/%s",cwd, copy_put, *source) + 1)); sprintf(path, "%s/%s/%s",cwd, copy_put, *source); //Check if the path is a directory or a file if( stat(path,&s) == 0 ) { if( s.st_mode & S_IFDIR ) { //it's a directory process_source_directory(path,cwd,copy_put,args_txl,source,user_config); } else if( s.st_mode & S_IFREG ) { //it's a file args_txl[4+TXL_OPTS]=path; process_source_file(path,cwd,copy_put,args_txl,source,user_config); } } source++; } //Remove the copy of the program under test we made earlier cleanUp(copy_put); printf("\n"); } return 0; }
int main(int argc, char **argv) { void *retval; int engine, evaltype, record, errorcode, usevaluefile = 1; Board *state; threadParameter *threadparameter; char *errorstring; char *tempcheck; FILE *logfile, *gamefile; pthread_t inputThread, outputThread; /* thread that takes care of input/output to user/front end */ prodcons *input, *output; /* communication buffers for iothread */ Cmdline *cmd; logfile = gamefile = NULL; #ifdef WIN32 /* copied from Dann Corbit to use under windows environment */ /* No buffering, please... */ setbuf(stdout, NULL); setbuf(stdin, NULL); /* and I *really* mean it, too! */ setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0); fflush(NULL); #endif srandom((unsigned int) time(NULL)); state = (Board *) xmalloc(sizeof(Board)); threadparameter = (threadParameter *) xmalloc(sizeof(threadParameter)); cmd = parseCmdline(argc, argv); if (cmd->show_helpP) usage(); if (cmd->show_versionP) { printf("%s %s\n", argv[0], VERSION); exit(0); } if (cmd->configfileP) { processConfigFile(cmd->configfile); } else { processConfigFile(NULL); } if ((cmd->verboseP) && (cmd->verbose > 0)){ configvalues.verbose = cmd->verbose; } if (configvalues.verbose > 0) { if (cmd->logfileP) { logfile = fopen(cmd->logfile, "w"); } else if (configvalues.logfilename) { logfile = fopen(configvalues.logfilename, "w"); } else { logfile = NULL; configvalues.verbose = 0; } if (logfile) { /* Make log file line buffered*/ setlinebuf(logfile); } state->logfile = logfile; } else { state->logfile = NULL; } state->verbosity = configvalues.verbose; record = 0; gamefile = NULL; if ((cmd->recordP) || (configvalues.record)) { if (!cmd->norecordP) { record = 1; if (cmd->gamefileP) { gamefile = fopen(cmd->gamefile, "a"); } else if (configvalues.gamefilename) { gamefile = fopen(configvalues.gamefilename, "a"); } else { gamefile = NULL; record = 0; } } } state->record = record; state->gamefile = gamefile; if (cmd->randomvarianceP) { state->random = cmd->randomvariance; } else { state->random = configvalues.random; } engine = configvalues.engine; if (cmd->randomP) { engine = RANDOM_ENGINE; } if (cmd->onestepP) { engine = ONESTEP_ENGINE; } if (cmd->completeP) { engine = COMPLETENEGAMAX_ENGINE; } if (cmd->multistepP) { engine = MULTISTEP_ENGINE; } if (cmd->negascoutP) { engine = NEGASCOUT_ENGINE; } evaltype = configvalues.evaltype; usevaluefile = configvalues.usevaluefile; if (cmd->fixedevalP) { usevaluefile = 0; } if (cmd->relativeevalP) { evaltype = RELATIVEPOSITIONPIECE_EVAL; } else if (cmd->positionevalP) { evaltype = POSITIONPIECE_EVAL; } switch (engine) { case RANDOM_ENGINE: state->engine = randomPlay; break; case ONESTEP_ENGINE: state->engine = oneStep; break; case COMPLETENEGAMAX_ENGINE: state->engine = multiNegamax; break; case MULTISTEP_ENGINE: state->engine = multiStep; break; case NEGASCOUT_ENGINE: state->engine = timedIterative; state->searcher = negaScoutDriver; break; default: state->engine = NULL; } if (cmd->resignP) { configvalues.resign = - ((int) (cmd->resign * 100)); } switch (evaltype) { case POSITIONPIECE_EVAL: if (cmd->noresignP) { state->resign = MINVALUE - 1; } else { state->resign = configvalues.resign; } state->evalboard = positionheuri; break; case RELATIVEPOSITIONPIECE_EVAL: state->evalboard = relativepositionheuri; state->resign = MINVALUE - 1; break; default: state->evalboard = NULL; } if (!cmd->nobookP) { if (cmd->bookfileP) { errorcode = initialiseOpeningBook(cmd->bookfile); if (errorcode) { errorstring = bookErrorToString(errorcode); fprintf(stderr,"%s\n",errorstring); free(errorstring); } } else if ((configvalues.usebook) && (configvalues.bookfilename)) { errorcode = initialiseOpeningBook(configvalues.bookfilename); if (errorcode) { errorstring = bookErrorToString(errorcode); fprintf(stderr,"%s\n",errorstring); free(errorstring); } } } if (usevaluefile) { if (cmd->valuefileP) { initialisePieceValues(cmd->valuefile); configvalues.valuefilename = cmd->valuefile; } else if (configvalues.valuefilename) { initialisePieceValues(configvalues.valuefilename); } else { initialisePieceValues(NULL); } } else { initialisePieceValues(NULL); } if (cmd->computernameP) { state->name = xstrdup(cmd->computername); } else if (configvalues.computername) { state->name = xstrdup(configvalues.computername); } else { if (configvalues.valuefilename) { state->name = (char *) xmalloc(strlen(PACKAGE_STRING) + strlen(configvalues.valuefilename) + 2); tempcheck = state->name; state->name = strcpy(state->name, PACKAGE_STRING); state->name = strcat(state->name, " "); state->name = strcat(state->name, configvalues.valuefilename); if (tempcheck != state->name) { printf("f****d\n"); } } else { state->name = (char *) xstrdup (PACKAGE_STRING); } } if (cmd->dP) { configvalues.maxdepth = cmd->d; } state->depth = configvalues.maxdepth; if (cmd->epdmindepthP) { configvalues.epdmindepth = cmd->epdmindepth; } state->epdmindepth = configvalues.epdmindepth; if (cmd->drawvalueP) { configvalues.drawvalue = cmd->drawvalue; } state->drawvalue = configvalues.drawvalue; state->timeaggression = configvalues.timeaggression; if (cmd->hashsizeP) { state->hashtable = initialiseHashTable(cmd->hashsize); } else if (cmd->hashkilobytesP) { state->hashtable = initialiseHashTableBySize(cmd->hashkilobytes); } else if (configvalues.hashentries) { state->hashtable = initialiseHashTable(configvalues.hashentries); } else if (configvalues.hashkilobytes) { state->hashtable = initialiseHashTableBySize(configvalues.hashkilobytes); } else { state->hashtable = initialiseHashTable(0); } initialiseMoveLists(); initialiseGenerateFunctions(); input = (prodcons *) xmalloc(sizeof(prodcons)); output = (prodcons *) xmalloc(sizeof(prodcons)); initComms(input); initComms(output); state->input = input; state->output = output; threadparameter->input = input; threadparameter->output = output; threadparameter->name = state->name; pthread_create(&inputThread, NULL, doInput, (void *) threadparameter); pthread_create(&outputThread, NULL, doOutput, (void *) threadparameter); play(state); pthread_cancel(inputThread); pthread_join(outputThread, &retval); finaliseComms(input); finaliseComms(output); closeOpeningBook(); free(state); free(input); free(output); if (configvalues.verbose) { fflush(logfile); fclose(logfile); } if (record) { fflush(gamefile); fclose(gamefile); } exit(0); }
void gtBaseOpts::parse (int ac, char **av) { bool haveRestrictConfigFile = !statFile (m_sys_restrict_cfg_file.c_str ()); bool haveDefaultConfigFile = !statFile (m_sys_cfg_file.c_str ()); bool haveUserConfigFile = false; try { add_options (); add_positionals (); bpo::command_line_parser parser (ac, av); parser.options (m_all_desc); parser.positional (m_pos); bpo::variables_map cli_vm; // CLI and non-restricted Config File options. bpo::variables_map res_vm; // Restricted Config File options. bpo::store (parser.run(), cli_vm); if (cli_vm.count (OPT_VERBOSE)) m_haveVerboseOnCli = true; if (cli_vm.count (OPT_CFG_FILE)) haveUserConfigFile = true; if (haveRestrictConfigFile) processConfigFile (m_sys_restrict_cfg_file, m_cfg_desc, res_vm); // Store config file variables on cli variables map if (haveRestrictConfigFile && res_vm.count (OPT_NO_USER_CFG_FILE)) { // Restricted config disallows user-supplied config file if (haveUserConfigFile) commandLineError ("Restricted configuration file disallows the " "use of the '" OPT_CFG_FILE "' option."); if (haveDefaultConfigFile) processConfigFile (m_sys_cfg_file, m_cfg_desc, cli_vm); } else { // Prefer user-supplied config file over default config file if (haveUserConfigFile) { std::string cfgPath = cli_vm[OPT_CFG_FILE].as<std::string>(); processConfigFile (cfgPath, m_cfg_desc, cli_vm); } else if (haveDefaultConfigFile) { processConfigFile (m_sys_cfg_file, m_cfg_desc, cli_vm); } } if (haveRestrictConfigFile) { processConfigFile (m_sys_restrict_cfg_file, m_cfg_desc, cli_vm); checkForIllegalOverrides(res_vm, cli_vm); } // This call signals that the variables_map is now "finalized" // and calls notifiers to set variables to option values // (which we don't currently use) bpo::notify (cli_vm); m_vm = cli_vm; } catch (bpo::error &e) { std::ostringstream msg ("Options Error: "); msg << e.what(); commandLineError (msg.str()); } if (m_vm.count (OPT_HELP)) displayHelp (); if (m_vm.count (OPT_VERSION)) displayVersion (); processOptions (); // log_options_used (); }