Example #1
0
void errwin(const char *s)
{
    static XmString str;
    log_results((char *)s);
    if ((!inwin) || (!ismaster))
    {
        fprintf(stderr, "%s\n", s);
        return;
    }
    if (error_popup)
    {
        XmStringFree(str);
        str = XmStringCreateLtoR((char *)s, charset);
        XtVaSetValues(error_popup,
                      XmNmessageString, str,
                      NULL);
        XtManageChild(error_popup);
        return;
    }
    str = XmStringCreateLtoR((char *)s, charset);
    error_popup = XmCreateErrorDialog(app_shell, (char *)"errordlg", NULL, 0);
    XtVaSetValues(error_popup,
                  XmNmessageString, str,
                  XmNdialogTitle, XmStringCreateLtoR((char *)"Error", charset),
                  XmNdialogStyle, XmDIALOG_APPLICATION_MODAL,
                  NULL);
    XtAddCallback(error_popup, XmNhelpCallback, (XtCallbackProc)error_helpCB,
                  (XtPointer)NULL);
    XtUnmanageChild(XmMessageBoxGetChild(error_popup, XmDIALOG_CANCEL_BUTTON));
    XtManageChild(error_popup);
}
Example #2
0
void loopback_run(struct loopback_test *t)
{
	int i;
	int ret;

	for (i = 0; dict[i].name != NULL; i++) {
		if (strstr(dict[i].name, t->test_name))
			t->test_id = dict[i].type;
	}
	if (!t->test_id) {
		fprintf(stderr, "invalid test %s\n", t->test_name);
		usage();
		return;
	}

	prepare_devices(t);

	ret = open_poll_files(t);
	if (ret)
		goto err;

	start(t);

	ret = wait_for_complete(t);
	close_poll_files(t);
	if (ret)
		goto err;


	get_results(t);

	log_results(t);

	return;

err:
	printf("Error running test\n");
	return;
}
Example #3
0
void loopback_run(struct loopback_test *t)
{
	int i;
	int ret;

	for (i = 0; dict[i].name != NULL; i++) {
		if (strstr(dict[i].name, t->test_name))
			t->test_id = dict[i].type;
	}
	if (!t->test_id) {
		fprintf(stderr, "invalid test %s\n", t->test_name);
		usage();
		return;
	}

	prepare_devices(t);

	ret = register_for_notification(t);
	if (ret)
		goto err;

	start(t);

	sleep(1);

	wait_for_complete(t);

	unregister_for_notification(t);

	get_results(t);

	log_results(t);

	return;

err:
	printf("Error running test\n");
	return;
}
Example #4
0
bool
verify_orth_pos(const GLubyte* img, GLsizei img_row_size_in_bytes,
                const char* title)
{

    /*
     * All of the tests in this group are constructed so that the
     * "correct" image covers a square of exactly drawing_size by
     * drawing_size pixels, embedded in a window that's two pixels
     * larger in both dimensions.  The border consists of pixels
     * with all components set to zero.  Within the image, all
     * pixels should be either red (only the red component is
     * nonzero) or green (only the green component is nonzero).  If
     * any pixels with all zero components are found, that indicates
     * the presence of gaps.  If any pixels with both red and green
     * nonzero components are found, that indicates the presence of
     * overlaps.
     */

    /* For logging results */
    struct orthpos_result res;

    /* For examining edges */
    GLubyte* row0 = (GLubyte*) img;
    GLubyte* row1 = row0 + img_row_size_in_bytes;
    GLubyte* row_last = row0 + (window_size - 1) * img_row_size_in_bytes;
    GLubyte* row_next_last = row_last - img_row_size_in_bytes;

    /* For examining the drawing area */
    int i, j, idx;
    GLubyte red, green, blue;

    /* Initialize results */
    res.has_gaps = false;
    res.has_overlaps = false;
    res.has_bad_edges = false;

    /* Check the bottom horizontal edge; it must be all zero. */
    if (logical_sum(row0, 3, window_size)) {
        printf("\t%s:  bottom border (at Y==0) was touched\n", title);
        res.has_bad_edges = true;
    }
    /* Repeat the process for the top horizontal edge. */
    if (logical_sum(row_last, 3, window_size)) {
        printf("\t%s:  top border (at Y==%i) was touched\n",
               title, window_size - 1);
        res.has_bad_edges = true;
    }
    /*
     * Check the second row; there must be at least one nonzero
     * pixel in the "drawn" region (excluding the first and last
     * column).
     */
    if (!logical_sum(row1 + 3/*skip 1st pixel's RGB*/, 3, drawing_size)) {
        printf("\t%s:  first row (at Y==1) was not drawn\n", title);
        res.has_bad_edges = true;
    }
    /* Repeat the process for the last row. */
    if (!logical_sum(row_next_last + 3, 3, drawing_size)) {
        printf("\t%s:  last row (at Y==%i) was not drawn\n",
               title, window_size - 2);
        res.has_bad_edges = true;
    }

    /* Check the left-hand vertical edge; it must be all zero. */
    if (logical_sum(row0, img_row_size_in_bytes, window_size)) {
        printf("\t%s:  left border (at X==0) was touched\n", title);
        res.has_bad_edges = true;
    }
    /* Repeat for the right-hand vertical edge. */
    if (logical_sum(row0 + 3 * (window_size - 1), img_row_size_in_bytes,
                    window_size)) {
        printf("\t%s:  right border (at X==%i) was touched\n",
               title, window_size - 1);
        res.has_bad_edges = true;
    }
    /* Check the left-hand column; something must be nonzero. */
    if (!logical_sum(row1 + 3, img_row_size_in_bytes, drawing_size)) {
        printf("\t%s:  first column (at X==1) was not drawn\n",
               title);
        res.has_bad_edges = true;
    }
    /* And repeat for the right-hand column: */
    if (!logical_sum(row1 + 3 * (drawing_size - 1), img_row_size_in_bytes,
                     drawing_size)) {
        printf("\t%s:  last column (at X==%i) was not drawn\n",
               title, window_size - 2);
        res.has_bad_edges = true;
    }

    /*
     * Scan the drawing area.  Anytime we find a pixel with all zero
     * components, that's a gap.  Anytime we find a pixel with both
     * red and green components nonzero, that's an overlap.
     */
    /* Not sure what was wrong with the original, but this works. */
    for (i = 1; i < window_size - 1; ++i) {
        for (j = 1; j < window_size - 1; ++j) {
            idx = 3*(window_size*i + j);
            red = img[idx + 0];
            green = img[idx + 1];
            blue = img[idx + 2];

            if (!red && !green && !blue) {
                if (!res.has_gaps) {
                    printf("\t%s:  found first ", title);
                    printf("gap at X==%i, Y==%i\n",
                           j, i);
                    res.has_gaps = true;
                }
            }
            if (red && green) {
                if (!res.has_overlaps) {
                    printf("\t%s:  found first ", title);
                    printf("overlap at X==%i, Y==%i\n",
                           j + 1, i + 1);
                    res.has_overlaps = true;
                }
            }
        }
    }

    return log_results(title, &res);
} /* verify_orth_pos */
Example #5
0
int main(int argc, char **argv)
{
	if(argc < 4) {
		printf("Usage\n");
		printf("    test random <heap> <vertices> [seed] [edgechance] [maxweight] [source]\n");
		printf("    test dkmax <heap> <vertices>\n");
		printf("    test dkmax2 <heap> <vertices>\n");
		printf("        Heaptypes:  bin, fib, pq\n");
		exit(1);
	}
	
	char *heap_name = malloc(10*sizeof(char));
	unsigned int (*dijkstra)(unsigned int num_vertices, unsigned int source, unsigned int * w, unsigned int ** edges, unsigned int *bops);
	if(strcmp(argv[2], "bin") == 0) {
		heap_name = "Binary";
		dijkstra = dijkstra_bin;
	} else if(strcmp(argv[2], "fib") == 0) {
		heap_name = "Fibonacci";
		dijkstra = dijkstra_fib;
	} else if(strcmp(argv[2], "pq") == 0) {
		heap_name = "Primitive";
		dijkstra = dijkstra_pq;
	} else {
		printf("Unknown heap type '%s'\n", argv[2]);
		exit(2);
	}
	
	unsigned int vertices = (unsigned int)strtoul(argv[3], NULL, 10);
	unsigned int source = 0;
	unsigned int *weights;
	unsigned int **edges = malloc(vertices * sizeof(unsigned int *));
	if(strcmp(argv[1], "random") == 0) {
		unsigned int seed;
		if(argc > 4 && argv[4]) {
			seed = (unsigned int)strtoul(argv[4], NULL, 10);
			srandom(seed);
		} else {
			srandom(time(NULL));
			seed = random()%99999999;
		}
		
		unsigned int edge_chance = 15;
		if(argc > 5)
			edge_chance = (unsigned int)strtoul(argv[5], NULL, 10);
		
		unsigned int max_weight = 20;
		if(argc > 6)
			max_weight = (unsigned int)strtoul(argv[6], NULL, 10);
		
		source = random()%vertices;
		if(argc > 7)
			source = (unsigned int)strtoul(argv[7], NULL, 10);
		
		weights = generate_graph(vertices, edge_chance, max_weight, seed);
		
		printf("Reticulating splines.\n");
		unsigned int *t_edges = malloc(vertices * sizeof(unsigned int));
		int i, j;
		for (i = 0; i < vertices; i++) {
			unsigned int count = 0;
			for (j = 0; j < vertices; j++)
				if (weights[(i * vertices) + j])
					t_edges[++count] = j;
			
			edges[i] = malloc((count+1) * sizeof(unsigned int));
			edges[i][0] = count;
			for (j = 1; j <= count; j++)
				edges[i][j] = t_edges[j];
		}
		free(t_edges);
	} else if(strcmp(argv[1], "dkmax") == 0) {
		weights = generate_decrease_key_max(vertices);
		
		printf("Reticulating splines.\n");
		unsigned int *t_edges = malloc(vertices * sizeof(unsigned int));
		int i, j;
		for (i = 0; i < vertices; i++) {
			unsigned int count = 0;
			for (j = 0; j < vertices; j++)
				if (weights[(i * vertices) + j])
					t_edges[++count] = j;

			edges[i] = malloc((count+1) * sizeof(unsigned int));
			edges[i][0] = count;
			for (j = 1; j <= count; j++)
				edges[i][j] = t_edges[j];
		}
		//free(t_edges);
	} else if (strcmp(argv[1], "dkmax2") == 0){
		weights = generate_decrease_key_max2(vertices);

		printf("Reticulating splines.\n");
		unsigned int *t_edges = malloc(vertices * sizeof(unsigned int));
		edges = malloc(vertices * sizeof(unsigned int *));
		int i, j;
		for (i = 0; i < vertices; i++) {
			unsigned int count = 0;
			for (j = 0; j < vertices; j++){
				if (weights[(i * vertices) + j])
					t_edges[++count] = j;
			}

			edges[i] = malloc((count+1) * sizeof(unsigned int));
			edges[i][0] = count;
			for (j = 1; j <= count; j++)
				edges[i][j] = t_edges[j];
		}
		//free(t_edges);
	}
	else {
		printf("Unknown graph algorithm '%s'\n", argv[1]);
		exit(3);
	}
	
	clock_t start;
	clock_t end;
	unsigned int decrease_key_calls;
	printf("Calculating distances.\n");
	printf("    Heap: %10s   Source:         %8d\n", heap_name, source);
	start = clock();
	decrease_key_calls = dijkstra(vertices, source, weights, edges, NULL);
	end = clock();
	double running_time = (double) (end-start) / (double) CLOCKS_PER_SEC;
	printf("    Time: %10gs  dec. key calls: %8d\n", running_time, decrease_key_calls);
	log_results(heap_name, argv[1], vertices, decrease_key_calls, running_time);
}