Ejemplo n.º 1
0
static pixman_bool_t
do_check (int i)
{
    pixman_image_t *source, *dest, *mask;
    pixman_op_t op;
    int x, y, width, height;
    pixman_image_t *dest_copy;
    pixman_bool_t result = TRUE;
    pixman_bool_t component_alpha;

    prng_srand (i);
    op = RANDOM_ELT (operators);
    x = prng_rand_n (MAX_WIDTH);
    y = prng_rand_n (MAX_HEIGHT);
    width = prng_rand_n (MAX_WIDTH) + 4;
    height = prng_rand_n (MAX_HEIGHT) + 4;

    source = create_image (NULL);
    mask = create_image (NULL);
    dest = create_image (&dest_copy);

    if (x >= dest->bits.width)
        x = dest->bits.width / 2;
    if (y >= dest->bits.height)
        y = dest->bits.height / 2;
    if (x + width > dest->bits.width)
        width = dest->bits.width - x;
    if (y + height > dest->bits.height)
        height = dest->bits.height - y;

    component_alpha = prng_rand_n (2);

    pixman_image_set_component_alpha (mask, component_alpha);
    
    pixman_image_composite32 (op, source, mask, dest,
                              0, 0, 0, 0,
                              x, y, width, height);

    if (!verify (i, op, source, mask, dest, dest_copy,
		 x, y, width, height, component_alpha))
    {
	result = FALSE;
    }
    
    pixman_image_unref (source);
    pixman_image_unref (mask);
    pixman_image_unref (dest);
    pixman_image_unref (dest_copy);

    return result;
}
Ejemplo n.º 2
0
int
main (int argc, const char *argv[])
{
    int i;

    prng_srand (0);

    for (i = 1; i <= 8; i++)
    {
	initialize_palette (&(rgb_palette[i]), i, TRUE);
	initialize_palette (&(y_palette[i]), i, FALSE);
    }

    return fuzzer_test_main("blitters", 2000000,
			    0xE0A07495,
			    test_composite, argc, argv);
}
Ejemplo n.º 3
0
int
main ()
{
    pixman_implementation_t *impl;
    argb_t *src_bytes = malloc (WIDTH * sizeof (argb_t));
    argb_t *mask_bytes = malloc (WIDTH * sizeof (argb_t));
    argb_t *dest_bytes = malloc (WIDTH * sizeof (argb_t));
    int i;

    enable_divbyzero_exceptions();
    
    impl = _pixman_internal_only_get_implementation();
    
    prng_srand (0);

    for (i = 0; i < ARRAY_LENGTH (op_list); ++i)
    {
	pixman_op_t op = op_list[i];
	pixman_combine_float_func_t combiner;
	int ca;

	for (ca = 0; ca < 2; ++ca)
	{
	    combiner = lookup_combiner (impl, op, ca);

	    random_floats (src_bytes, WIDTH);
	    random_floats (mask_bytes, WIDTH);
	    random_floats (dest_bytes, WIDTH);

	    combiner (impl, op,
		      (float *)dest_bytes,
		      (float *)mask_bytes,
		      (float *)src_bytes,
		      WIDTH);
	}
    }	

    return 0;
}
Ejemplo n.º 4
0
int
main (int argc, const char *argv[])
{
    int i;
    int result = 0;

    if (argc == 2)
    {
	if (strcmp (argv[1], "--forever") == 0)
	{
	    uint32_t n;

	    prng_srand (time (0));

	    n = prng_rand();

	    for (;;)
		do_check (n++);
	}
        else
	{
	    do_check (strtol (argv[1], NULL, 0));
	}
    }
    else
    {
#ifdef USE_OPENMP
#       pragma omp parallel for default(none) reduction(|:result)
#endif
        for (i = 0; i < N_TESTS; ++i)
	{
	    if (!do_check (i))
		result |= 1;
	}
    }
    
    return result;
}
Ejemplo n.º 5
0
static uint32_t
test_transform (int testnum, int verbose)
{
    pixman_image_t *src, *dest;
    uint32_t crc;

    prng_srand (testnum);
    
    src = make_image ();
    dest = make_image ();

    pixman_image_composite (RANDOM_OP(),
			    src, NULL, dest,
			    0, 0, 0, 0, WIDTH / 2, HEIGHT / 2,
			    WIDTH, HEIGHT);

    crc = compute_crc32_for_image (0, dest);

    pixman_image_unref (src);
    pixman_image_unref (dest);

    return crc;
}
/*
 * Composite operation with pseudorandom images
 */
uint32_t
test_composite (int      testnum,
		int      verbose)
{
    int                i;
    pixman_image_t *   src_img;
    pixman_image_t *   dst_img;
    pixman_region16_t  clip;
    int                dst_width, dst_height;
    int                dst_stride;
    int                dst_x, dst_y;
    int                dst_bpp;
    pixman_op_t        op;
    uint32_t *         dst_bits;
    uint32_t           crc32;
    pixman_format_code_t mask_format, dst_format;
    pixman_trapezoid_t *traps;
    int src_x, src_y;
    int n_traps;

    static pixman_color_t colors[] =
    {
	{ 0xffff, 0xffff, 0xffff, 0xffff },
	{ 0x0000, 0x0000, 0x0000, 0x0000 },
	{ 0xabcd, 0xabcd, 0x0000, 0xabcd },
	{ 0x0000, 0x0000, 0x0000, 0xffff },
	{ 0x0101, 0x0101, 0x0101, 0x0101 },
	{ 0x7777, 0x6666, 0x5555, 0x9999 },
    };
    
    FLOAT_REGS_CORRUPTION_DETECTOR_START ();

    prng_srand (testnum);

    op = RANDOM_ELT (operators);
    mask_format = RANDOM_ELT (mask_formats);

    /* Create source image */
    
    if (prng_rand_n (4) == 0)
    {
	src_img = pixman_image_create_solid_fill (
	    &(colors[prng_rand_n (ARRAY_LENGTH (colors))]));

	src_x = 10;
	src_y = 234;
    }
    else
    {
	pixman_format_code_t src_format = RANDOM_ELT(formats);
	int src_bpp = (PIXMAN_FORMAT_BPP (src_format) + 7) / 8;
	int src_width = prng_rand_n (MAX_SRC_WIDTH) + 1;
	int src_height = prng_rand_n (MAX_SRC_HEIGHT) + 1;
	int src_stride = src_width * src_bpp + prng_rand_n (MAX_STRIDE) * src_bpp;
	uint32_t *bits, *orig;

	src_x = -(src_width / 4) + prng_rand_n (src_width * 3 / 2);
	src_y = -(src_height / 4) + prng_rand_n (src_height * 3 / 2);

	src_stride = (src_stride + 3) & ~3;
	
	orig = bits = (uint32_t *)make_random_bytes (src_stride * src_height);

	if (prng_rand_n (2) == 0)
	{
	    bits += (src_stride / 4) * (src_height - 1);
	    src_stride = - src_stride;
	}
	
	src_img = pixman_image_create_bits (
	    src_format, src_width, src_height, bits, src_stride);

	pixman_image_set_destroy_function (src_img, destroy_bits, orig);

	if (prng_rand_n (8) == 0)
	{
	    pixman_box16_t clip_boxes[2];
	    int            n = prng_rand_n (2) + 1;
	    
	    for (i = 0; i < n; i++)
	    {
		clip_boxes[i].x1 = prng_rand_n (src_width);
		clip_boxes[i].y1 = prng_rand_n (src_height);
		clip_boxes[i].x2 =
		    clip_boxes[i].x1 + prng_rand_n (src_width - clip_boxes[i].x1);
		clip_boxes[i].y2 =
		    clip_boxes[i].y1 + prng_rand_n (src_height - clip_boxes[i].y1);
		
		if (verbose)
		{
		    printf ("source clip box: [%d,%d-%d,%d]\n",
			    clip_boxes[i].x1, clip_boxes[i].y1,
			    clip_boxes[i].x2, clip_boxes[i].y2);
		}
	    }
	    
	    pixman_region_init_rects (&clip, clip_boxes, n);
	    pixman_image_set_clip_region (src_img, &clip);
	    pixman_image_set_source_clipping (src_img, 1);
	    pixman_region_fini (&clip);
	}

	image_endian_swap (src_img);
    }

    /* Create destination image */
    {
	dst_format = RANDOM_ELT(formats);
	dst_bpp = (PIXMAN_FORMAT_BPP (dst_format) + 7) / 8;
	dst_width = prng_rand_n (MAX_DST_WIDTH) + 1;
	dst_height = prng_rand_n (MAX_DST_HEIGHT) + 1;
	dst_stride = dst_width * dst_bpp + prng_rand_n (MAX_STRIDE) * dst_bpp;
	dst_stride = (dst_stride + 3) & ~3;
	
	dst_bits = (uint32_t *)make_random_bytes (dst_stride * dst_height);

	if (prng_rand_n (2) == 0)
	{
	    dst_bits += (dst_stride / 4) * (dst_height - 1);
	    dst_stride = - dst_stride;
	}
	
	dst_x = -(dst_width / 4) + prng_rand_n (dst_width * 3 / 2);
	dst_y = -(dst_height / 4) + prng_rand_n (dst_height * 3 / 2);
	
	dst_img = pixman_image_create_bits (
	    dst_format, dst_width, dst_height, dst_bits, dst_stride);

	image_endian_swap (dst_img);
    }

    /* Create traps */
    {
	int i;

	n_traps = prng_rand_n (25);
	traps = fence_malloc (n_traps * sizeof (pixman_trapezoid_t));

	for (i = 0; i < n_traps; ++i)
	{
	    pixman_trapezoid_t *t = &(traps[i]);
	    
	    t->top = random_fixed (MAX_DST_HEIGHT) - MAX_DST_HEIGHT / 2;
	    t->bottom = t->top + random_fixed (MAX_DST_HEIGHT);
	    t->left.p1.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
	    t->left.p1.y = t->top - random_fixed (50);
	    t->left.p2.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
	    t->left.p2.y = t->bottom + random_fixed (50);
	    t->right.p1.x = t->left.p1.x + random_fixed (MAX_DST_WIDTH);
	    t->right.p1.y = t->top - random_fixed (50);
	    t->right.p2.x = t->left.p2.x + random_fixed (MAX_DST_WIDTH);
	    t->right.p2.y = t->bottom - random_fixed (50);
	}
    }
    
    if (prng_rand_n (8) == 0)
    {
	pixman_box16_t clip_boxes[2];
	int            n = prng_rand_n (2) + 1;
	for (i = 0; i < n; i++)
	{
	    clip_boxes[i].x1 = prng_rand_n (dst_width);
	    clip_boxes[i].y1 = prng_rand_n (dst_height);
	    clip_boxes[i].x2 =
		clip_boxes[i].x1 + prng_rand_n (dst_width - clip_boxes[i].x1);
	    clip_boxes[i].y2 =
		clip_boxes[i].y1 + prng_rand_n (dst_height - clip_boxes[i].y1);

	    if (verbose)
	    {
		printf ("destination clip box: [%d,%d-%d,%d]\n",
		        clip_boxes[i].x1, clip_boxes[i].y1,
		        clip_boxes[i].x2, clip_boxes[i].y2);
	    }
	}
	pixman_region_init_rects (&clip, clip_boxes, n);
	pixman_image_set_clip_region (dst_img, &clip);
	pixman_region_fini (&clip);
    }

    pixman_composite_trapezoids (op, src_img, dst_img, mask_format,
				 src_x, src_y, dst_x, dst_y, n_traps, traps);

    crc32 = compute_crc32_for_image (0, dst_img);

    if (verbose)
	print_image (dst_img);

    if (dst_stride < 0)
	dst_bits += (dst_stride / 4) * (dst_height - 1);
    
    fence_free (dst_bits);
    
    pixman_image_unref (src_img);
    pixman_image_unref (dst_img);
    fence_free (traps);

    FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
    return crc32;
}
Ejemplo n.º 7
0
/*
 * Composite operation with pseudorandom images
 */
uint32_t
test_composite (int testnum, int verbose)
{
    pixman_image_t *src_img = NULL;
    pixman_image_t *dst_img = NULL;
    pixman_image_t *mask_img = NULL;
    int src_width, src_height;
    int dst_width, dst_height;
    int src_stride, dst_stride;
    int src_x, src_y;
    int dst_x, dst_y;
    int mask_x, mask_y;
    int w, h;
    pixman_op_t op;
    pixman_format_code_t src_fmt, dst_fmt, mask_fmt;
    uint32_t *srcbuf, *maskbuf;
    uint32_t crc32;
    int max_width, max_height, max_extra_stride;
    FLOAT_REGS_CORRUPTION_DETECTOR_START ();

    max_width = max_height = 24 + testnum / 10000;
    max_extra_stride = 4 + testnum / 1000000;

    if (max_width > 256)
	max_width = 256;

    if (max_height > 16)
	max_height = 16;

    if (max_extra_stride > 8)
	max_extra_stride = 8;

    prng_srand (testnum);

    op = op_list[prng_rand_n (ARRAY_LENGTH (op_list))];

    if (prng_rand_n (8))
    {
	/* normal image */
	src_img = create_random_image (img_fmt_list, max_width, max_height,
				       max_extra_stride, &src_fmt);
    }
    else
    {
	/* solid case */
	src_img = create_random_image (img_fmt_list, 1, 1,
				       max_extra_stride, &src_fmt);

	pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
    }

    dst_img = create_random_image (img_fmt_list, max_width, max_height,
				   max_extra_stride, &dst_fmt);

    src_width = pixman_image_get_width (src_img);
    src_height = pixman_image_get_height (src_img);
    src_stride = pixman_image_get_stride (src_img);

    dst_width = pixman_image_get_width (dst_img);
    dst_height = pixman_image_get_height (dst_img);
    dst_stride = pixman_image_get_stride (dst_img);

    srcbuf = pixman_image_get_data (src_img);

    src_x = prng_rand_n (src_width);
    src_y = prng_rand_n (src_height);
    dst_x = prng_rand_n (dst_width);
    dst_y = prng_rand_n (dst_height);

    mask_img = NULL;
    mask_fmt = PIXMAN_null;
    mask_x = 0;
    mask_y = 0;
    maskbuf = NULL;

    if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) &&
	(prng_rand_n (4) == 0))
    {
	/* PIXBUF */
	mask_fmt = prng_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8;
	mask_img = pixman_image_create_bits (mask_fmt,
	                                     src_width,
	                                     src_height,
	                                     srcbuf,
	                                     src_stride);
	mask_x = src_x;
	mask_y = src_y;
	maskbuf = srcbuf;
    }
    else if (prng_rand_n (2))
    {
	if (prng_rand_n (2))
	{
	    mask_img = create_random_image (mask_fmt_list, max_width, max_height,
					   max_extra_stride, &mask_fmt);
	}
	else
	{
	    /* solid case */
	    mask_img = create_random_image (mask_fmt_list, 1, 1,
					   max_extra_stride, &mask_fmt);
	    pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL);
	}

	if (prng_rand_n (2))
	    pixman_image_set_component_alpha (mask_img, 1);

	mask_x = prng_rand_n (pixman_image_get_width (mask_img));
	mask_y = prng_rand_n (pixman_image_get_height (mask_img));
    }


    w = prng_rand_n (dst_width - dst_x + 1);
    h = prng_rand_n (dst_height - dst_y + 1);

    if (verbose)
    {
        printf ("op=%s\n", operator_name (op));
	printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n",
	    format_name (src_fmt), format_name (dst_fmt),
	    format_name (mask_fmt));
	printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
	    src_width, src_height, dst_width, dst_height);
	printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
	    src_x, src_y, dst_x, dst_y);
	printf ("src_stride=%d, dst_stride=%d\n",
	    src_stride, dst_stride);
	printf ("w=%d, h=%d\n", w, h);
    }

    pixman_image_composite (op, src_img, mask_img, dst_img,
			    src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);

    if (verbose)
	print_image (dst_img);

    free_random_image (0, src_img, PIXMAN_null);
    crc32 = free_random_image (0, dst_img, dst_fmt);

    if (mask_img)
    {
	if (srcbuf == maskbuf)
	    pixman_image_unref(mask_img);
	else
	    free_random_image (0, mask_img, PIXMAN_null);
    }

    FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
    return crc32;
}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
  char *outfile;
  struct bench_args_t *data;
  int fd;
  node_index_t *adjmat;
  node_index_t *permute;
  node_index_t r,rp,c,cp,s,temp;
  edge_index_t e;
  int scale;
  long int rint;
  struct prng_rand_t state;
  int useless=0;

  if( argc>1 )
    outfile = argv[1];
  else
    outfile = "input.data";

  // Allocate data structure and temporary adjacency matrix
  data = (struct bench_args_t *)malloc(sizeof(struct bench_args_t));
  adjmat = (node_index_t *)calloc(N_NODES*N_NODES, sizeof(node_index_t));

  // Generate dense matrix
  prng_srand(1, &state);

  // The naive way is to create a normal SKG matrix and then shuffle it to
  // eliminate degree locality. But that takes a while (and lots of memops).
  // An alternate way is to generate a permute schedule a priori, then map
  // the generated edges directly to the shuffled matrix.
  // (For this shuffle, see Knuth v2-3.4.2 alg P.
  //  Ours is sufficiently identical.)
  permute = (node_index_t *)malloc(N_NODES*sizeof(node_index_t));
  for( s=0; s<N_NODES; s++ ) {
    permute[s] = s; // Default is no-swap
  }
  for( s=0; s<N_NODES; s++ ) {
    rint = prng_rand(&state)%N_NODES;
    // Swap row s with row rint
    temp = permute[s];
    permute[s] = permute[rint];
    permute[rint] = temp;
  }

  printf("Generating edges (SKG parameters: %0.2f,%0.2f,%0.2f,%0.2f)...\n",
    ((double)(A))/PRNG_RAND_MAX,
    ((double)(B))/PRNG_RAND_MAX,
    ((double)(C))/PRNG_RAND_MAX,
    ((double)(D))/PRNG_RAND_MAX );
  e = 0;
  // generate N_EDGES/2 undirected edges (N_EDGES directed), but give up after
  // a set number of tries without gainfully producing one. This prevents bad
  // parameter settings (e.g.- n_edges>n_nodes^2) from spinning forever.
  while( e<N_EDGES/2 && useless<USELESS_THRESHOLD ) {
    r = 0;
    c = 0;
    // Pick a random edge according to SKG parameters
    for( scale=SCALE; scale>0; scale-- ) { // each level of the quadtree
      rint = prng_rand(&state); // implicit modulo PRNG_RAND_MAX
      if( rint>=(A+B) ) // C or D (bottom half)
        r += 1<<(scale-1);
      if( (rint>=A && rint<A+B) || (rint>=A+B+C) ) // B or D (right half)
        c += 1<<(scale-1);
    }       
    if( r!=c ) { // ignore self-edges, they're irrelevant
      rp = permute[r];
      cp = permute[c];
      if( adjmat[rp*N_NODES+cp]==0 ) {
        // We make undirected edges
        adjmat[rp*N_NODES+cp]=1;
        adjmat[cp*N_NODES+rp]=1;
        ++e;
        useless = 0;
      }     
    }     
    useless++;
  }
  if( useless>=USELESS_THRESHOLD ) {
    printf("WARNING: stopped generating edges due to fruitless search for unconnected nodes.\n");
    return -1;
  }

  // printf("Creating CSR form...\n");
  // Scan rows for edge list lengths, and fill edges while we're at it
  e = 0;
  for( r=0; r<N_NODES; r++ ) { // count first
    data->nodes[r].edge_begin = 0;
    data->nodes[r].edge_end = 0;
    for( c=0; c<N_NODES; c++ ) {
      if( adjmat[r*N_NODES+c] ) {
        ++data->nodes[r].edge_end;
        data->edges[e].dst = c;
        //data->edges[e].weight = random()%(MAX_WEIGHT-MIN_WEIGHT)+MIN_WEIGHT;
        ++e;
      }
    }
    //if( data->nodes[r].edge_begin==data->nodes[r].edge_end ) {
    //  printf("Isolated node %lu\n", r);
    //}
  }

  for( r=1; r<N_NODES; r++ ) { // now scan
    data->nodes[r].edge_begin = data->nodes[r-1].edge_end;
    data->nodes[r].edge_end += data->nodes[r-1].edge_end;
  }

  // Pick starting node
  do {
    rint = random()%N_NODES;
  } while( (data->nodes[rint].edge_end-data->nodes[rint].edge_begin)<2 );
  data->starting_node = rint;

  // Fill data structure
  memset(data->queue, 0, N_NODES*sizeof(node_index_t));
  memset(data->level, MAX_LEVEL, N_NODES*sizeof(level_t));
  memset(data->level_counts, 0, MAX_LEVEL*sizeof(edge_index_t));

  // Open and write
  fd = open(outfile, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
  assert( fd>0 && "Couldn't open input data file" );
  data_to_input(fd, data);

  return 0;
}