2003-04-01 01:59:04 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
|
* Copyright by The HDF Group. *
|
2003-04-01 01:59:04 +08:00
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
2007-02-07 22:56:24 +08:00
|
|
|
|
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
|
* access to either file, you may request a copy from help@hdfgroup.org. *
|
2003-04-01 01:59:04 +08:00
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
/*
|
|
|
|
|
* Programmer: Robb Matzke <matzke@llnl.gov>
|
|
|
|
|
* Tuesday, June 16, 1998
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests functions in H5Tbit.c
|
|
|
|
|
*/
|
2001-04-04 02:09:16 +08:00
|
|
|
|
#include "h5test.h"
|
1998-11-21 11:36:51 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
#define H5T_PACKAGE
|
2001-04-04 02:09:16 +08:00
|
|
|
|
#include "H5Tpkg.h"
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
#define NTESTS 100000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_find
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test bit find operations. This is just the basic stuff; more
|
|
|
|
|
* rigorous testing will be performed by the other test
|
|
|
|
|
* functions.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Tuesday, June 16, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_find (void)
|
|
|
|
|
{
|
1998-11-19 02:40:09 +08:00
|
|
|
|
uint8_t v1[8];
|
2001-08-15 06:09:56 +08:00
|
|
|
|
int i;
|
1998-06-17 03:38:26 +08:00
|
|
|
|
ssize_t n;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
TESTING("bit search operations");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
/* The zero length buffer */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
HDmemset(v1, 0xaa, sizeof v1);
|
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, (size_t)0, H5T_BIT_LSB, TRUE);
|
|
|
|
|
if(-1 != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Zero length test failed (lsb)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-10-31 08:13:27 +08:00
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, (size_t)0, H5T_BIT_MSB, TRUE);
|
|
|
|
|
if(-1 != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Zero length test failed (msb)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
/* The zero buffer */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
HDmemset(v1, 0, sizeof v1);
|
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, 8 * sizeof(v1), H5T_BIT_LSB, TRUE);
|
|
|
|
|
if(-1 != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Zero buffer test failed (lsb)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-10-31 08:13:27 +08:00
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, 8 * sizeof(v1), H5T_BIT_MSB, TRUE);
|
|
|
|
|
if(-1 != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Zero buffer test failed (msb)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try all combinations of one byte */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
for(i = 0; i < 8 * (int)sizeof(v1); i++) {
|
|
|
|
|
HDmemset(v1, 0, sizeof v1);
|
|
|
|
|
v1[i / 8] = 1 << (i % 8);
|
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, 8 * sizeof(v1), H5T_BIT_LSB, TRUE);
|
|
|
|
|
if((ssize_t)i != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Test for set bit %d failed (lsb)!\n", i);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-10-31 08:13:27 +08:00
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, 8 * sizeof(v1), H5T_BIT_MSB, TRUE);
|
|
|
|
|
if((ssize_t)i != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Test for set bit %d failed (msb)!\n", i);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
/* The one buffer */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
HDmemset(v1, 0xff, sizeof v1);
|
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, 8 * sizeof(v1), H5T_BIT_LSB, FALSE);
|
|
|
|
|
if(-1 != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" One buffer test failed (lsb)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-10-31 08:13:27 +08:00
|
|
|
|
n = H5T_bit_find(v1, (size_t)0, 8 * sizeof(v1), H5T_BIT_MSB, FALSE);
|
|
|
|
|
if(-1 != n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" One buffer test failed (msb)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try all combinations of one byte */
|
|
|
|
|
for (i=0; i<8*(int)sizeof(v1); i++) {
|
|
|
|
|
memset (v1, 0xff, sizeof v1);
|
|
|
|
|
v1[i/8] &= ~(1<<(i%8));
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v1, (size_t)0, 8*sizeof(v1), H5T_BIT_LSB, FALSE);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if ((ssize_t)i!=n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Test for clear bit %d failed (lsb)!\n", i);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v1, (size_t)0, 8*sizeof(v1), H5T_BIT_MSB, FALSE);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if ((ssize_t)i!=n) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Test for clear bit %d failed (lsb)!\n", i);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
PASSED();
|
1998-06-17 03:38:26 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
failed:
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" v = 0x");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
for (i=0; i<(int)sizeof(v1); i++) printf ("%02x", v1[i]);
|
|
|
|
|
printf ("\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_copy
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test bit copy operations.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Tuesday, June 16, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_copy (void)
|
|
|
|
|
{
|
1998-11-19 02:40:09 +08:00
|
|
|
|
uint8_t v1[8], v2[8];
|
1998-06-17 03:38:26 +08:00
|
|
|
|
size_t s_offset, d_offset, size;
|
2001-08-15 06:09:56 +08:00
|
|
|
|
int i, j;
|
1998-06-17 03:38:26 +08:00
|
|
|
|
ssize_t n;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
TESTING("bit copy operations");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
for (i=0; i<NTESTS; i++) {
|
2005-05-08 03:37:48 +08:00
|
|
|
|
s_offset = HDrand() % (8*sizeof v1);
|
|
|
|
|
d_offset = HDrand() % (8*sizeof v2);
|
|
|
|
|
size = (unsigned)HDrand() % MIN (8*sizeof(v1), 8*sizeof(v2));
|
1998-06-17 03:38:26 +08:00
|
|
|
|
size = MIN3 (size, 8*sizeof(v1)-s_offset, 8*sizeof(v2)-d_offset);
|
|
|
|
|
memset (v1, 0xff, sizeof v1);
|
|
|
|
|
memset (v2, 0x00, sizeof v2);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
/* Copy some bits to v2 and make sure something was copied */
|
|
|
|
|
H5T_bit_copy (v2, d_offset, v1, s_offset, size);
|
2001-08-15 06:09:56 +08:00
|
|
|
|
for (j=0; j<(int)sizeof(v2); j++) if (v2[j]) break;
|
|
|
|
|
if (size>0 && j>=(int)sizeof(v2)) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Unabled to find copied region in destination");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2001-08-15 06:09:56 +08:00
|
|
|
|
if (0==size && j<(int)sizeof(v2)) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found copied bits when we shouldn't have");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
/* Look for the zeros and ones */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_LSB, 1);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (size>0 && n!=(ssize_t)d_offset) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find first copied bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==size && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found copied bits and shouldn't have!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
n = H5T_bit_find (v2, d_offset, 8*sizeof(v2)-d_offset, H5T_BIT_LSB, 0);
|
|
|
|
|
if (d_offset+size<8*sizeof(v2) && n!=(ssize_t)size) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find last copied bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (d_offset+size==8*sizeof(v2) && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" High-order zeros are present and shouldn't be!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Look for zeros and ones in reverse order. This is only to test
|
|
|
|
|
* that reverse searches work as expected.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_MSB, 1);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (size>0 && (size_t)(n+1)!=d_offset+size) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find last copied bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(reverse, n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==size && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found copied bits but shouldn't have (reverse)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, d_offset+size, H5T_BIT_MSB, 0);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (d_offset>0 && n+1!=(ssize_t)d_offset) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find beginning of copied data "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(reverse, n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==d_offset && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found leading original data but shouldn't have!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
PASSED();
|
1998-06-17 03:38:26 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
failed:
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" i=%d, s_offset=%lu, d_offset=%lu, size=%lu\n",
|
1998-06-17 03:38:26 +08:00
|
|
|
|
i, (unsigned long)s_offset, (unsigned long)d_offset,
|
|
|
|
|
(unsigned long)size);
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" s = 0x");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
for (j=sizeof(v1)-1; j>=0; --j) printf ("%02x", v1[j]);
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf ("\n d = 0x");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
for (j=sizeof(v2)-1; j>=0; --j) printf ("%02x", v2[j]);
|
|
|
|
|
printf ("\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-14 02:37:14 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* 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;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2004-04-14 02:37:14 +08:00
|
|
|
|
TESTING("bit shift operations");
|
|
|
|
|
|
|
|
|
|
for (i=0; i<NTESTS; i++) {
|
2005-05-08 03:37:48 +08:00
|
|
|
|
offset = HDrand() % (8*sizeof vector);
|
|
|
|
|
size = (unsigned)HDrand() % (8*sizeof(vector)-offset);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
/* Don't want size to be 0 */
|
|
|
|
|
if(size == 0) continue;
|
2005-05-08 03:37:48 +08:00
|
|
|
|
shift_dist = HDrand() % size;
|
2004-04-14 02:37:14 +08:00
|
|
|
|
|
|
|
|
|
/*-------- 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 */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
|
2004-07-02 04:02:47 +08:00
|
|
|
|
if ((size_t)n!=offset+shift_dist) {
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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 */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
|
2004-07-02 04:02:47 +08:00
|
|
|
|
if ((size_t)n!=offset) {
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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 */
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* Randomly decide shift direction */
|
2004-04-14 02:37:14 +08:00
|
|
|
|
if(size % 2 == 0)
|
|
|
|
|
shift_dist = size;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
else
|
2004-07-02 04:02:47 +08:00
|
|
|
|
shift_dist = -((ssize_t)size);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
|
|
|
|
|
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 */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
if (n >= 0) {
|
|
|
|
|
H5_FAILED();
|
|
|
|
|
printf (" Unable to verify all bits are zero in destination(LSB) "
|
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
|
/* Look from the other direction */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* 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;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2004-04-14 02:37:14 +08:00
|
|
|
|
TESTING("bit increment operations");
|
|
|
|
|
|
|
|
|
|
for (i=0; i<NTESTS; i++) {
|
2005-05-08 03:37:48 +08:00
|
|
|
|
offset = HDrand() % (8*sizeof vector);
|
|
|
|
|
size = (unsigned)HDrand() % (8*sizeof(vector)-offset);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
/* 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 */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
|
2004-07-02 04:02:47 +08:00
|
|
|
|
if (size!=1 && (size_t)n!=offset+size-1) {
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* 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;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2004-04-14 02:37:14 +08:00
|
|
|
|
TESTING("bit decrement operations");
|
|
|
|
|
|
|
|
|
|
for (i=0; i<NTESTS; i++) {
|
2005-05-08 03:37:48 +08:00
|
|
|
|
offset = HDrand() % (8*sizeof vector);
|
|
|
|
|
size = (unsigned)HDrand() % (8*sizeof(vector)-offset);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
/* 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 */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
|
2004-07-02 04:02:47 +08:00
|
|
|
|
if ((size_t)n!=offset) {
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_negate
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test operation to negate bit vector.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Monday, April 12, 2004
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_negate (void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t vector[8];
|
|
|
|
|
size_t offset, size;
|
|
|
|
|
int i, j;
|
|
|
|
|
ssize_t n;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2004-04-14 02:37:14 +08:00
|
|
|
|
TESTING("bit negate operations");
|
|
|
|
|
|
|
|
|
|
for (i=0; i<NTESTS; i++) {
|
2005-05-08 03:37:48 +08:00
|
|
|
|
offset = HDrand() % (8*sizeof vector);
|
|
|
|
|
size = (unsigned)HDrand() % (8*sizeof(vector)-offset);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
/* Don't want size to be 0 */
|
|
|
|
|
if(size == 0) continue;
|
|
|
|
|
|
|
|
|
|
/* All-zero sequence will become 111111(size=6) after negating */
|
|
|
|
|
memset (vector, 0x00, sizeof vector);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2004-04-14 02:37:14 +08:00
|
|
|
|
/* negate the sequence */
|
|
|
|
|
H5T_bit_neg (vector, offset, size);
|
|
|
|
|
|
|
|
|
|
/* Look for the ones */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
|
2004-07-02 04:02:47 +08:00
|
|
|
|
if ((size_t)n!=offset) {
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* All-one sequence will become 000000(size=6) after negating */
|
|
|
|
|
memset (vector, 0x00, sizeof vector);
|
|
|
|
|
H5T_bit_set (vector, offset, size, 1);
|
|
|
|
|
|
|
|
|
|
/* negate the sequence */
|
|
|
|
|
H5T_bit_neg (vector, offset, size);
|
|
|
|
|
|
|
|
|
|
/* Look for the ones */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_LSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
if (n>=0) {
|
|
|
|
|
H5_FAILED();
|
|
|
|
|
printf (" Unable to verify all-zero bits in destination "
|
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Look for ones in reverse order. This is only to test
|
|
|
|
|
* that reverse searches work as expected.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (vector, (size_t)0, 8*sizeof(vector), H5T_BIT_MSB, 1);
|
2004-04-14 02:37:14 +08:00
|
|
|
|
if (n>=0) {
|
|
|
|
|
H5_FAILED();
|
|
|
|
|
printf (" Unable to verify all-zero bits 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;
|
|
|
|
|
}
|
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_set
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test bit set operations
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Tuesday, June 16, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_set (void)
|
|
|
|
|
{
|
1998-11-19 02:40:09 +08:00
|
|
|
|
uint8_t v2[8];
|
1998-06-17 03:38:26 +08:00
|
|
|
|
size_t d_offset, size;
|
2001-08-15 06:09:56 +08:00
|
|
|
|
int i, j;
|
1998-06-17 03:38:26 +08:00
|
|
|
|
ssize_t n;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
TESTING("bit set operations");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
for (i=0; i<NTESTS; i++) {
|
2005-05-08 03:37:48 +08:00
|
|
|
|
d_offset = HDrand() % (8*sizeof v2);
|
|
|
|
|
size = (unsigned)HDrand() % (8*sizeof(v2));
|
1998-06-17 03:38:26 +08:00
|
|
|
|
size = MIN (size, 8*sizeof(v2)-d_offset);
|
|
|
|
|
memset (v2, 0x00, sizeof v2);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
/* Set some bits in v2 */
|
|
|
|
|
H5T_bit_set (v2, d_offset, size, TRUE);
|
2001-08-15 06:09:56 +08:00
|
|
|
|
for (j=0; j<(int)sizeof(v2); j++) if (v2[j]) break;
|
|
|
|
|
if (size>0 && j>=(int)sizeof(v2)) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Unabled to find set region in buffer");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2001-08-15 06:09:56 +08:00
|
|
|
|
if (0==size && j<(int)sizeof(v2)) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found set bits when we shouldn't have");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
/* Look for the zeros and ones */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_LSB, 1);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (size>0 && n!=(ssize_t)d_offset) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find first set bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==size && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found set bits and shouldn't have!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
n = H5T_bit_find (v2, d_offset, 8*sizeof(v2)-d_offset, H5T_BIT_LSB, 0);
|
|
|
|
|
if (d_offset+size<8*sizeof(v2) && n!=(ssize_t)size) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find last set bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (d_offset+size==8*sizeof(v2) && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" High-order zeros are present and shouldn't be!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Look for zeros and ones in reverse order. This is only to test
|
|
|
|
|
* that reverse searches work as expected.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_MSB, 1);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (size>0 && (size_t)(n+1)!=d_offset+size) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find last set bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(reverse, n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==size && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found set bits but shouldn't have (reverse)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, d_offset+size, H5T_BIT_MSB, 0);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (d_offset>0 && n+1!=(ssize_t)d_offset) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find beginning of set bit region "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(reverse, n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==d_offset && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found leading zeros but shouldn't have!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
PASSED();
|
1998-06-17 03:38:26 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
failed:
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" i=%d, d_offset=%lu, size=%lu\n",
|
1998-06-17 03:38:26 +08:00
|
|
|
|
i, (unsigned long)d_offset, (unsigned long)size);
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" d = 0x");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
for (j=sizeof(v2)-1; j>=0; --j) printf ("%02x", v2[j]);
|
|
|
|
|
printf ("\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* 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)
|
|
|
|
|
{
|
1998-11-19 02:40:09 +08:00
|
|
|
|
uint8_t v2[8];
|
1998-06-17 03:38:26 +08:00
|
|
|
|
size_t d_offset, size;
|
2001-08-15 06:09:56 +08:00
|
|
|
|
int i, j;
|
1998-06-17 03:38:26 +08:00
|
|
|
|
ssize_t n;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
TESTING("bit clear operations");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
for (i=0; i<NTESTS; i++) {
|
2005-05-08 03:37:48 +08:00
|
|
|
|
d_offset = HDrand() % (8*sizeof v2);
|
|
|
|
|
size = (unsigned)HDrand() % (8*sizeof(v2));
|
1998-06-17 03:38:26 +08:00
|
|
|
|
size = MIN (size, 8*sizeof(v2)-d_offset);
|
|
|
|
|
memset (v2, 0xff, sizeof v2);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
/* Clear some bits in v2 */
|
|
|
|
|
H5T_bit_set (v2, d_offset, size, FALSE);
|
2001-08-15 06:09:56 +08:00
|
|
|
|
for (j=0; j<(int)sizeof(v2); j++) if (0xff!=v2[j]) break;
|
|
|
|
|
if (size>0 && j>=(int)sizeof(v2)) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Unabled to find cleared region in buffer");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2001-08-15 06:09:56 +08:00
|
|
|
|
if (0==size && j<(int)sizeof(v2)) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found cleared bits when we shouldn't have");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
|
|
|
|
/* Look for the zeros and ones */
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_LSB, 0);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (size>0 && n!=(ssize_t)d_offset) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find first cleared bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==size && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found cleared bits and shouldn't have!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
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) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find last cleared bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (d_offset+size==8*sizeof(v2) && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" High-order ones are present and shouldn't be!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Look for zeros and ones in reverse order. This is only to test
|
|
|
|
|
* that reverse searches work as expected.
|
|
|
|
|
*/
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, 8*sizeof(v2), H5T_BIT_MSB, 0);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (size>0 && (size_t)(n+1)!=d_offset+size) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find last cleared bit in destination "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(reverse, n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==size && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found cleared bits but shouldn't have (reverse)!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2006-11-08 04:19:41 +08:00
|
|
|
|
n = H5T_bit_find (v2, (size_t)0, d_offset+size, H5T_BIT_MSB, 1);
|
1998-06-17 03:38:26 +08:00
|
|
|
|
if (d_offset>0 && n+1!=(ssize_t)d_offset) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" Unable to find beginning of cleared bit region "
|
1998-06-17 03:38:26 +08:00
|
|
|
|
"(reverse, n=%d)\n", (int)n);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
if (0==d_offset && n>=0) {
|
2001-01-26 01:03:29 +08:00
|
|
|
|
H5_FAILED();
|
1998-11-21 11:36:51 +08:00
|
|
|
|
puts (" Found leading ones but shouldn't have!");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-21 11:36:51 +08:00
|
|
|
|
PASSED();
|
1998-06-17 03:38:26 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
failed:
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" i=%d, d_offset=%lu, size=%lu\n",
|
1998-06-17 03:38:26 +08:00
|
|
|
|
i, (unsigned long)d_offset, (unsigned long)size);
|
1998-11-21 11:36:51 +08:00
|
|
|
|
printf (" d = 0x");
|
1998-06-17 03:38:26 +08:00
|
|
|
|
for (j=sizeof(v2)-1; j>=0; --j) printf ("%02x", v2[j]);
|
|
|
|
|
printf ("\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: main
|
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Purpose:
|
1998-06-17 03:38:26 +08:00
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Return: Success:
|
1998-06-17 03:38:26 +08:00
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Failure:
|
1998-06-17 03:38:26 +08:00
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Tuesday, June 16, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
main (void)
|
|
|
|
|
{
|
2001-08-15 06:09:56 +08:00
|
|
|
|
int nerrors=0;
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
2003-02-08 05:14:19 +08:00
|
|
|
|
/*
|
|
|
|
|
* Open the library explicitly for thread-safe builds, so per-thread
|
|
|
|
|
* things are initialized correctly.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef H5_HAVE_THREADSAFE
|
|
|
|
|
H5open();
|
|
|
|
|
#endif /* H5_HAVE_THREADSAFE */
|
|
|
|
|
|
1998-06-17 03:38:26 +08:00
|
|
|
|
nerrors += test_find ()<0?1:0;
|
|
|
|
|
nerrors += test_set ()<0?1:0;
|
|
|
|
|
nerrors += test_clear()<0?1:0;
|
|
|
|
|
nerrors += test_copy ()<0?1:0;
|
2004-04-14 02:37:14 +08:00
|
|
|
|
nerrors += test_shift()<0?1:0;
|
|
|
|
|
nerrors += test_increment ()<0?1:0;
|
|
|
|
|
nerrors += test_decrement ()<0?1:0;
|
|
|
|
|
nerrors += test_negate ()<0?1:0;
|
1998-06-17 03:38:26 +08:00
|
|
|
|
|
1998-08-20 06:46:31 +08:00
|
|
|
|
if (nerrors) {
|
1998-08-28 00:48:50 +08:00
|
|
|
|
printf("***** %u FAILURE%s! *****\n",
|
1998-08-20 06:46:31 +08:00
|
|
|
|
nerrors, 1==nerrors?"":"S");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
printf("All bit tests passed.\n");
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
|
|
#ifdef H5_HAVE_THREADSAFE
|
|
|
|
|
H5close();
|
|
|
|
|
#endif /* H5_HAVE_THREADSAFE */
|
1998-08-20 06:46:31 +08:00
|
|
|
|
return 0;
|
1998-06-17 03:38:26 +08:00
|
|
|
|
}
|