コード例 #1
0
ファイル: bittests.c プロジェクト: EgoIncarnate/appleseed
/*-------------------------------------------------------------------------
 * Function:	test_decrement
 *
 * Purpose:	Test operation to decrement bit vector by 1.
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Raymond Lu
 *              Monday, April 12, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_decrement (void)
{
    uint8_t	vector[8];
    size_t	offset, size;
    int	        i, j;
    ssize_t	n;

    TESTING("bit decrement operations");

    for (i=0; i<NTESTS; i++) {
	offset = HDrand() % (8*sizeof vector);
	size = (unsigned)HDrand() % (8*sizeof(vector)-offset);
        /* Don't want size to be 0 */
        if(size == 0) continue;

        /* All-zero sequence will become 111111(size=6) after decrement */
	memset (vector, 0x00, sizeof vector);

	/* decrement the sequence by one */
        H5T_bit_dec (vector, offset, size);

	/* Look for the ones */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
	if ((size_t)n!=offset) {
	    H5_FAILED();
	    printf ("    Unable to find first bit in destination "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}

	/*
	 * Look for zeros and ones in reverse order.  This is only to test
	 * that reverse searches work as expected.
	 */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
	if (n!=(ssize_t)(offset+size-1)) {
	    H5_FAILED();
	    printf ("    Unable to find last bit in destination "
		    "(reverse, n=%d)\n", (int)n);
	    goto failed;
	}
    }

    PASSED();
    return 0;

 failed:
    printf ("    i=%d, offset=%lu, size=%lu\n",
	    i, (unsigned long)offset, (unsigned long)size);
    for (j=sizeof(vector)-1; j>=0; --j) printf ("%02x", vector[j]);
    printf ("\n");
    return -1;
}
コード例 #2
0
ファイル: bittests.c プロジェクト: EgoIncarnate/appleseed
/*-------------------------------------------------------------------------
 * Function:	test_clear
 *
 * Purpose:	Test bit clear operations
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Robb Matzke
 *              Tuesday, June 16, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_clear (void)
{
    uint8_t	v2[8];
    size_t	d_offset, size;
    int	i, j;
    ssize_t	n;

    TESTING("bit clear operations");

    for (i=0; i<NTESTS; i++) {
	d_offset = HDrand() % (8*sizeof v2);
	size = (unsigned)HDrand() % (8*sizeof(v2));
	size = MIN (size, 8*sizeof(v2)-d_offset);
	memset (v2, 0xff, sizeof v2);

	/* Clear some bits in v2 */
	H5T_bit_set (v2, d_offset, size, FALSE);
	for (j=0; j<(int)sizeof(v2); j++) if (0xff!=v2[j]) break;
	if (size>0 && j>=(int)sizeof(v2)) {
	    H5_FAILED();
	    puts ("    Unabled to find cleared region in buffer");
	    goto failed;
	}
	if (0==size && j<(int)sizeof(v2)) {
	    H5_FAILED();
	    puts ("    Found cleared bits when we shouldn't have");
	    goto failed;
	}


	/* Look for the zeros and ones */
	n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_LSB, 0);
	if (size>0 && n!=(ssize_t)d_offset) {
	    H5_FAILED();
	    printf ("    Unable to find first cleared bit in destination "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}
	if (0==size && n>=0) {
	    H5_FAILED();
	    puts ("    Found cleared bits and shouldn't have!");
	    goto failed;
	}
	n = H5T_bit_find (v2, d_offset, 8*sizeof(v2)-d_offset, H5T_BIT_LSB, 1);
	if (d_offset+size<8*sizeof(v2) && n!=(ssize_t)size) {
	    H5_FAILED();
	    printf ("    Unable to find last cleared bit in destination "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}
	if (d_offset+size==8*sizeof(v2) && n>=0) {
	    H5_FAILED();
	    puts ("    High-order ones are present and shouldn't be!");
	    goto failed;
	}

	/*
	 * Look for zeros and ones in reverse order.  This is only to test
	 * that reverse searches work as expected.
	 */
	n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_MSB, 0);
	if (size>0 && (size_t)(n+1)!=d_offset+size) {
	    H5_FAILED();
	    printf ("    Unable to find last cleared bit in destination "
		    "(reverse, n=%d)\n", (int)n);
	    goto failed;
	}
	if (0==size && n>=0) {
	    H5_FAILED();
	    puts ("    Found cleared bits but shouldn't have (reverse)!");
	    goto failed;
	}
	n = H5T_bit_find (v2, (size_t)0, d_offset+size, H5T_BIT_MSB, 1);
	if (d_offset>0 && n+1!=(ssize_t)d_offset) {
	    H5_FAILED();
	    printf ("    Unable to find beginning of cleared bit region "
		    "(reverse, n=%d)\n", (int)n);
	    goto failed;
	}
	if (0==d_offset && n>=0) {
	    H5_FAILED();
	    puts ("    Found leading ones but shouldn't have!");
	    goto failed;
	}

    }

    PASSED();
    return 0;

 failed:
    printf ("    i=%d, d_offset=%lu, size=%lu\n",
	    i, (unsigned long)d_offset, (unsigned long)size);
    printf ("    d = 0x");
    for (j=sizeof(v2)-1; j>=0; --j) printf ("%02x", v2[j]);
    printf ("\n");
    return -1;
}
コード例 #3
0
ファイル: bittests.c プロジェクト: EgoIncarnate/appleseed
/*-------------------------------------------------------------------------
 * Function:	test_shift
 *
 * Purpose:	Test bit shifting operations.
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Raymond Lu
 *              Monday, April 12, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_shift (void)
{
    uint8_t	vector[8];
    size_t	offset, size;
    int	        i, j;
    ssize_t	shift_dist, n;

    TESTING("bit shift operations");

    for (i=0; i<NTESTS; i++) {
	offset = HDrand() % (8*sizeof vector);
	size = (unsigned)HDrand() % (8*sizeof(vector)-offset);
        /* Don't want size to be 0 */
        if(size == 0) continue;
        shift_dist = HDrand() % size;

	/*-------- LEFT-shift some bits and make sure something was shifted --------*/
	memset (vector, 0x00, sizeof vector);
        H5T_bit_set (vector, offset, size, 1);

        H5T_bit_shift (vector, shift_dist, offset, size);

	/* Look for the ones */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
	if ((size_t)n!=offset+shift_dist) {
	    H5_FAILED();
	    printf ("    Unable to find first bit in destination "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}

	/*
	 * Look for zeros and ones in reverse order.  This is only to test
	 * that reverse searches work as expected.
	 */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
	if (n!=(ssize_t)(offset+size-1)) {
	    H5_FAILED();
	    printf ("    Unable to find last bit in destination "
		    "(reverse, n=%d)\n", (int)n);
	    goto failed;
	}

	/*-------- RIGHT-shift some bits and make sure something was shifted --------*/
	memset (vector, 0x00, sizeof vector);
        H5T_bit_set (vector, offset, size, 1);

        H5T_bit_shift (vector, -shift_dist, offset, size);

	/* Look for the ones */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
	if ((size_t)n!=offset) {
	    H5_FAILED();
	    printf ("    Unable to find first bit in destination "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}

	/*
	 * Look for zeros and ones in reverse order.  This is only to test
	 * that reverse searches work as expected.
	 */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
	if (n!=(ssize_t)(offset+size-shift_dist-1)) {
	    H5_FAILED();
	    printf ("    Unable to find last bit in destination "
		    "(reverse, n=%d)\n", (int)n);
	    goto failed;
	}

        /*-------- Shift the bits out of sight --------*/
        /* A sequence 111111 will be 000000 if shift_dist=6 */

        /* Randomly decide shift direction */
        if(size % 2 == 0)
            shift_dist = size;
        else
            shift_dist = -((ssize_t)size);

	memset (vector, 0x00, sizeof vector);
        H5T_bit_set (vector, offset, size, 1);

        H5T_bit_shift (vector, shift_dist, offset, size);

	/* Supposed to fail to find any ones */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
	if (n >= 0) {
	    H5_FAILED();
	    printf ("    Unable to verify all bits are zero in destination(LSB) "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}

        /* Look from the other direction */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
	if (n >= 0) {
	    H5_FAILED();
	    printf ("    Unable to verify all bits are zero in destination(MSB) "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}
    }

    PASSED();
    return 0;

 failed:
    printf ("    i=%d, offset=%lu, size=%lu, shift_dist=%lu\n",
	    i, (unsigned long)offset, (unsigned long)size,
	    (unsigned long)shift_dist);
    for (j=sizeof(vector)-1; j>=0; --j) printf ("%02x", vector[j]);
    printf ("\n");
    return -1;
}
コード例 #4
0
ファイル: bittests.c プロジェクト: EgoIncarnate/appleseed
/*-------------------------------------------------------------------------
 * Function:	test_increment
 *
 * Purpose:	Test operation to increment bit vector by 1.
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Raymond Lu
 *              Monday, April 12, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_increment (void)
{
    uint8_t	vector[8];
    size_t	offset, size;
    int	        i, j;
    ssize_t	n;

    TESTING("bit increment operations");

    for (i=0; i<NTESTS; i++) {
	offset = HDrand() % (8*sizeof vector);
	size = (unsigned)HDrand() % (8*sizeof(vector)-offset);
        /* Don't want size to be 0 */
        if(size == 0) continue;

	memset (vector, 0x00, sizeof vector);
        if(size>1)  /* if size=6, make a sequence like 011111 */
            H5T_bit_set (vector, offset, size-1, 1);
        else  /* if size=1, just set this one bit to 1 */
            H5T_bit_set (vector, offset, size, 1);

	/* Increment the sequence by one */
        H5T_bit_inc (vector, offset, size);

	/* Look for the one */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
	if (size!=1 && (size_t)n!=offset+size-1) {
	    H5_FAILED();
	    printf ("    Unable to find first bit in destination "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}
        if(size==1 && n>=0) {
	    H5_FAILED();
	    printf ("    Unable to verify all-zero bit in destination "
		    "(n=%d)\n", (int)n);
	    goto failed;
	}

	/*
	 * Look for one in reverse order.  This is only to test
	 * that reverse searches work as expected.
	 */
	n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
	if (size!=1 && n!=(ssize_t)(offset+size-1)) {
	    H5_FAILED();
	    printf ("    Unable to find last bit in destination "
		    "(reverse, n=%d)\n", (int)n);
	    goto failed;
	}
        if(size==1 && n>=0) {
	    H5_FAILED();
	    printf ("    Unable to verify all-zero bit in destination "
		    "(reverse, n=%d)\n", (int)n);
	    goto failed;
	}
    }

    PASSED();
    return 0;

 failed:
    printf ("    i=%d, offset=%lu, size=%lu\n",
	    i, (unsigned long)offset, (unsigned long)size);
    for (j=sizeof(vector)-1; j>=0; --j) printf ("%02x", vector[j]);
    printf ("\n");
    return -1;
}
コード例 #5
0
ファイル: overhead.c プロジェクト: MichaelToal/hdf5
/*-------------------------------------------------------------------------
 * Function:  test
 *
 * Purpose:  The guts of the test
 *
 * Return:  Success:  0
 *
 *    Failure:  number of errors
 *
 * Programmer:  Robb Matzke
 *              Wednesday, September 30, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test(fill_t fill_style, const double splits[],
     hbool_t verbose, hbool_t use_rdcc)
{
    hid_t  file = (-1), fapl = (-1), dcpl = (-1), xfer = (-1), mspace = (-1), fspace = (-1), dset = (-1);
    hsize_t  ch_size[1] = {1};    /*chunk size    */
    hsize_t  cur_size[1] = {1000};    /*current dataset size  */
    hsize_t  max_size[1] = {H5S_UNLIMITED};  /*maximum dataset size  */
    hsize_t  hs_start[1];      /*hyperslab start offset*/
    hsize_t  hs_count[1] = {1};    /*hyperslab nelmts  */
    int    fd = (-1);      /*h5 file direct  */
    int  *had = NULL;      /*for random filling  */
    const char  *sname=NULL;      /*fill style nam  */
    int    mdc_nelmts;      /*num meta objs to cache*/
    hsize_t  i;
    int    j;
    h5_stat_t  sb;

    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) goto error;
    if(!use_rdcc) {
        if(H5Pget_cache(fapl, &mdc_nelmts, NULL, NULL, NULL) < 0) goto error;
        if(H5Pset_cache(fapl, mdc_nelmts, 0, 0, 0.0F) < 0) goto error;
    }
    if((file = H5Fcreate(FILE_NAME_1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) goto error;
    if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error;
    if(H5Pset_chunk(dcpl, 1, ch_size) < 0) goto error;
    if((xfer = H5Pcreate(H5P_DATASET_XFER)) < 0) goto error;
    if(H5Pset_btree_ratios(xfer, splits[0], splits[1], splits[2]) < 0) goto error;
    if((fspace = H5Screate_simple(1, cur_size, max_size)) < 0) goto error;
    if((mspace = H5Screate_simple(1, ch_size, ch_size)) < 0) goto error;
    if((dset = H5Dcreate2(file, "chunked", H5T_NATIVE_INT,
        fspace, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
    if ((fd=HDopen(FILE_NAME_1, O_RDONLY, 0666)) < 0) goto error;

    if(FILL_RANDOM==fill_style) 
        had = calloc((size_t)cur_size[0], sizeof(int));
    
    for (i=1; i<=cur_size[0]; i++) {

        /* Decide which chunk to write to */
        switch (fill_style) {
        case FILL_FORWARD:
            hs_start[0] = i-1;
            break;
        case FILL_REVERSE:
            hs_start[0] = cur_size[0]-i;
            break;
        case FILL_INWARD:
            hs_start[0] = i%2 ? i/2 : cur_size[0]-i/2;
            break;
        case FILL_OUTWARD:
            j = (int)(cur_size[0]-i)+1;
            hs_start[0] = j%2 ? j/2 : (hssize_t)cur_size[0]-j/2;
            break;
        case FILL_RANDOM:
            for (j=HDrand()%(int)cur_size[0]; had[j]; j=(j+1)%(int)cur_size[0])
                /*void*/;
            hs_start[0] = j;
            had[j] = 1;
            break;
        case FILL_ALL:
            abort();
        default:
            /* unknown request */
            HDfprintf(stderr, "Unknown fill style\n");
            goto error;
            break;
        }

        /* Write the chunk */
        if (H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_start, NULL,
                hs_count, NULL) < 0) goto error;
        if (H5Dwrite(dset, H5T_NATIVE_INT, mspace, fspace, xfer, &i) < 0) {
            goto error;
        }

        /* Determine overhead */
        if (verbose) {
            if (H5Fflush(file, H5F_SCOPE_LOCAL) < 0) goto error;
            if (HDfstat(fd, &sb) < 0) goto error;
            /*
             * The extra cast in the following statement is a bug workaround
             * for the Win32 version 5.0 compiler.
             * 1998-11-06 ptl
             */
            printf("%4lu %8.3f ***\n",
                    (unsigned long)i,
                    (double)(hssize_t)(sb.st_size-i*sizeof(int))/(hssize_t)i);
        }
    }

    if(had) {
        free(had);
        had = NULL;
    } /* end if */

    H5Dclose(dset);
    H5Sclose(mspace);
    H5Sclose(fspace);
    H5Pclose(dcpl);
    H5Pclose(xfer);
    H5Fclose(file);

    if (!verbose) {
        switch (fill_style) {
        case FILL_FORWARD:
            sname = "forward";
            break;
        case FILL_REVERSE:
            sname = "reverse";
            break;
        case FILL_INWARD:
            sname = "inward";
            break;
        case FILL_OUTWARD:
            sname = "outward";
            break;
        case FILL_RANDOM:
            sname = "random";
            break;
        case FILL_ALL:
            abort();
        default:
            /* unknown request */
            HDfprintf(stderr, "Unknown fill style\n");
            goto error;
            break;
        }

        if (HDfstat(fd, &sb) < 0) goto error;
        printf("%-7s %8.3f\n", sname,
                (double)(hssize_t)(sb.st_size-cur_size[0]*sizeof(int))/
                (hssize_t)cur_size[0]);
    }
    HDclose(fd);

    return 0;

 error:
    H5Dclose(dset);
    H5Sclose(mspace);
    H5Sclose(fspace);
    H5Pclose(dcpl);
    H5Pclose(xfer);
    H5Fclose(file);
    if(had)
        free(had);
    HDclose(fd);
    return 1;
}