コード例 #1
0
  /*
   * Main entry point for test harness
   */
int
run_testrunner(int argc, const char **argv, testentry_t tests[], int test_count)
{
    const char *test_name, *target;
    int i;
    stats_t stats;
    int target_matched, max_errors_before_quit, redirect_stdouterr;
    memset(&stats, 0, sizeof(stats));

    max_errors_before_quit = 1;
    redirect_stdouterr = 0;

    assert(tests != NULL);
    assert(test_count > 0);
    assert(argc > 0 && argv && *argv);
    while (true) {
	target = argc > 1 ? argv[1] : "";
	assert(target);
	if (*target != '-')
	    break;
	argc--;
	argv++;
	if (target[1] == 'f' && target[2])
	    max_errors_before_quit = atoi(target + 1);
	else if (target[1] == 'r')
	    redirect_stdouterr = 1;
    }

    target_matched = false;

    for (i = 0;
	 i < test_count && (max_errors_before_quit < 1
			    || stats.failed != max_errors_before_quit);
	 i++) {
	test_name = tests[i].name;

	assert(test_name);
	assert(tests[i].suite);
	assert(tests[i].test_function);
	if (eql(target, test_name) || eql(target, "all")
	    || eql(target, tests[i].suite)) {
	    if (!target_matched)
		printf("Running tests...\n");
	    target_matched = true;
	    run_one_test(&stats, &tests[i], redirect_stdouterr, argc - 1,
			 argv + 1);
	}
    }
    if (!target_matched) {
	fprintf(stderr, "Test '%s' not found",
		(strlen(target) > 0 ? target : "(empty)"));
	print_targets(tests, test_count);
    } else {
	printf("\nTest Results:%d tests,%d passed,%d failed.\n", stats.ran,
	       stats.passed, stats.failed);
    }

    return stats.passed == stats.ran && target_matched ? 0 : 1;

}
コード例 #2
0
void usage(char *p) {
	printf("Usage: %s <opts>\n",p);
	printf("-h\tthis lame message\n");
	printf("-t\ttarget\n");
	printf("-b\tbrute force\n");
	printf("\n");
	print_targets();
	exit(0);
}
コード例 #3
0
ファイル: dime.c プロジェクト: sturmE/uofm-projects
int main(int argc, char* argv[]) {
	// Declarations for getopt
	extern int optind;
	extern char* optarg;
	int ch;
	char* format = "hanf:l:";
	FILE* fd;
	char* filename = "Dimefile";
	char* output_file = "dime.log";
	bool execute = true;
	bool execute_all = false;
	bool output = false;

	// Part 2.2.1: Use getopt code to take input appropriately.
	while((ch = getopt(argc, argv, format)) != -1) {
		switch(ch) {
			case 'f':
				filename = strdup(optarg);
				break;
			case 'a': //execute all targets
				execute_all = true;
				break;
			case 'l': //change output
				output_file = strdup(optarg);
				output = true;
				
			case 'n':
				execute = false;
				break;
			case 'h':
				dime_usage(argv[0]);
				break;
			case '?':
				exit(0);
		}
	}
	argc -= optind;
	argv += optind;

	//Setup the logfile
	fd = file_open(output_file, "w+");//Always appends. Switch to w+ to overwrite
	int dup_result;
	if((dup_result = dup2(fileno(fd), fileno(DEBUG))) != fileno(DEBUG))
	{
		fprintf(DEBUG, "\nError in redirecting output [%d] \n", dup_result);
		fclose(fd);
		exit(0);
	}


	parse_file(filename);
	fprintf(DEBUG, "\n\n----------------DONE PARSING-------------\n\n");
	print_targets();

	//Execute depending on the flags	
	int i;
	if(execute_all)
	{
		TARGET* curr_tar = root;
		while(curr_tar != NULL)
		{
			fprintf(stdout, "\nExecuting Target[%s]\n", curr_tar->name);
			execute_target(curr_tar->name, execute);
			fprintf(stdout, "Execution Done..Maybe[%s]\n", curr_tar->name);
			curr_tar = curr_tar->next;
		}
	}
	else //Just execute a single target
	{
		//execute commands/print out commands for a given target	
		for(i = 0; i < argc; i++)
		{
			char* target = argv[i];
			if(find(target) == NULL) { fprintf(stdout, "Bad Target\n"); exit(0); }
			fprintf(stdout, "\nExecuting Target[%s]\n", target);
			execute_target(target, execute);
			fprintf(stdout, "\nExecution Done..Maybe[%s]\n", target);
			
		}
	}
	fprintf(DEBUG, "-------------------Exiting Main program---------------------\n");
	fclose(fd);
	return 0;
}
コード例 #4
0
ファイル: ebl_answer.hpp プロジェクト: 1292765944/MobileDemo
class_answer<T, Tds1, Tds2>::
class_answer(uint nclasses, double target_factor, bool binary_target_,
             t_confidence conf, bool apply_tanh_, const char *name_,
             int force, int single, idxdim *kerd, double sigma_scale)
    : answer_module<T, Tds1, Tds2>(binary_target_ ? 1 : nclasses, name_),
    conf_type(conf), binary_target(binary_target_), resize_output(true),
    apply_tanh(apply_tanh_), tmp(1, 1, 1), force_class(force),
    single_output(single)
{
    // create 1-of-n targets with target 1.0 for shown class, -1.0 for the rest
    targets = create_target_matrix<T>(nclasses, (T)1.0);
    // binary target
    if (binary_target)
    {
        if (nclasses != 2)
            eblerror("expecting 2 classes only when binary_target is on");
        targets = idx<T>(2, 1, 1);
        // int neg_id = ds.get_class_id("bg"); // negative class
        // if (neg_id == 0) {
        //      targets.set(-1.0, 0, 0); // negative: -1.0
        //      targets.set( 1.0, 1, 0); // positive:  1.0
        // } else {
        targets.sset((T)1.0, 0); // positive:  1.0
        targets.sset((T)-1.0, 1); // negative: -1.0
        // }
    }
    // target factor
    idx_dotc(targets, target_factor, targets);
    print_targets(targets);
    // set min/max of target
    target_min = idx_min(targets);
    target_max = idx_max(targets);
    target_range = target_max - target_min;
    // set confidence parameters
    T max_dist;
    switch (conf_type)
    {
    case confidence_sqrdist:
        max_dist = target_max - target_min;
        conf_ratio = targets.dim(0) * max_dist * max_dist;
        // shift value to be subtracted before dividing by conf_ratio
        conf_shift = target_min;
        eblprint("Using sqrdist confidence formula with normalization ratio "
                 << conf_ratio << " and shift value " << conf_shift << std::endl);
        break;
    case confidence_single:
        conf_ratio = target_max - target_min;
        // shift value to be subtracted before dividing by conf_ratio
        conf_shift = target_min;
        eblprint("Using single output confidence with normalization ratio "
                 << conf_ratio << " and shift value " << conf_shift << std::endl);
        break;
    case confidence_max:
        if (force >= 0)
        {
            conf_ratio = target_max - target_min;
            conf_shift = -conf_ratio;
            conf_ratio *= 2;
        }
        else
        {
            conf_ratio = target_max - target_min;
            conf_shift = 0; // no shift needed, the difference min is 0.
        }
        eblprint("Using max confidence formula with normalization ratio "
                 << conf_ratio << std::endl);
        break;
    default:
        eblerror("confidence type " << conf_type << " undefined");
    }

    if (kerd && kerd->order() == 2)
        smoothing_kernel =
            create_mexican_hat2<T>(kerd->dim(0), kerd->dim(1), 1,
                                   sigma_scale);
    else
        smoothing_kernel =
            create_mexican_hat2<T>(9, 9, 1, sigma_scale);
    eblprint("smoothing kernel:" << std::endl);
    smoothing_kernel.print();
}
コード例 #5
0
ファイル: util.c プロジェクト: sturmE/uofm-projects
/**
 * Parses the file dependencies. For each dependency, places a pointer to the correct dependency in the target
 */
TARGET* parse_dependencies(char* filename)
{
	char* line = malloc(160*sizeof(char));
	FILE* fp = file_open(filename);
	
	char* token;
	bool getCmds   		= false;
	bool getDep    		= false;
	DEP* dependency	 	= NULL;	
	TARGET* tar		= NULL;
		

	//TODO: Uneccessarily goes through whole file
	while((line = file_getline(line, fp)) != NULL)
	{
		
		if(strncmp(line, "#", 1) != 0) //line isnt a commnet
		{
			fprintf(stdout, "Line: %s\n", line);
			if(getCmds)
			{
				if(strncmp(line, "}", 1) == 0)
				{
					//put node into tree
					getCmds = false;
					
				}
				else
				{								
					
				}
			}
			else
			{
				token = strtok(line, " :\n");

				dependency = (DEP*)malloc(sizeof(DEP));
		
				if(token != NULL) {fprintf(stdout, "Getting Tokens: \n");}

				while(token != NULL)
				{
					fprintf(stdout, "Token:[%s]\n", token);
					if(strpbrk(token, "{") != NULL)
					{
							//done taking in dependencies
							getCmds = true;
							getDep = false;
							fprintf(stdout, "--Done getting Tokens\n");
					}
					else if(getDep)//looking at deps
					{
						//Get a pointer to the target that the dep is referring too
						dependency->dep = find(token);

						if(dependency->dep == NULL) //dep doesnt exist
						{
							fprintf(stdout, "Dependency(%s) does not exist\n", token);
						}
						else //add dep to the target
						{
							dependency->dep_name = (char*)malloc(strlen(token));
							strcpy(dependency->dep_name, 
								 token);							
							fprintf(stdout, "Adding Dependency(%s) to %s-->",dependency->dep->name, 
															tar->name);
							tar->dependencies = add_Dnode(dependency, tar->dependencies);	
							if(strcmp(tar->dependencies->dep->name, token) == 0)
							{
								fprintf(stdout, "Success\n\n"); 
								dependency = (DEP*)malloc(sizeof(DEP));
							}
							else
							{
								fprintf(stdout, "Failire\n\n");
							}
						}						
					}	
					else //looking at target
					{				
						getDep = true;
						tar = find(token); //get a pointer to the target that was previously made
						
						if(tar == NULL)
						{
							fprintf(stderr,"(%s) is not in the target list\n", token);
						}

					}
					token = strtok(NULL, " \n");
				}
				
			}	
		}
	}
	print_targets();
	fclose(fp);
	free(line);
	return root;
}