31
31
0x80, 0xF0, 0x40, 0x40, 0x0, 0x0, 0x0, 0x0, 0x10, 0x20, 0x00, 0x00
35
7, 12, 13, 14,15, 22, 30, 68, 77, -1,
38
#define BIG_TEST_BIT (((unsigned) 1 << 31) + 42)
34
41
main(int argc, char **argv)
44
unsigned char testarray[12];
45
unsigned char *bigarray;
38
47
size = sizeof(bitarray)*8;
39
49
i = ext2fs_find_first_bit_set(bitarray, size);
41
51
printf("Bit set: %d\n", i);
42
52
i = ext2fs_find_next_bit_set(bitarray, size, i+1);
57
for (i=0,j=0; i < size; i++) {
58
if (ext2fs_test_bit(i, bitarray)) {
59
if (bits_list[j] == i) {
62
printf("Bit %d set, not expected\n", i);
66
if (bits_list[j] == i) {
67
printf("Expected bit %d to be clear.\n", i);
72
printf("ext2fs_test_bit appears to be correct\n");
74
/* Test ext2fs_set_bit */
75
memset(testarray, 0, sizeof(testarray));
76
for (i=0; bits_list[i] > 0; i++) {
77
ext2fs_set_bit(bits_list[i], testarray);
79
if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) {
80
printf("ext2fs_set_bit test succeeded.\n");
82
printf("ext2fs_set_bit test failed.\n");
83
for (i=0; i < sizeof(testarray); i++) {
84
printf("%02x ", testarray[i]);
89
for (i=0; bits_list[i] > 0; i++) {
90
ext2fs_clear_bit(bits_list[i], testarray);
92
for (i=0; i < sizeof(testarray); i++) {
94
printf("ext2fs_clear_bit failed, "
95
"testarray[%d] is %d\n", i, testarray[i]);
99
printf("ext2fs_clear_bit test succeed.\n");
102
/* Do bigarray test */
103
bigarray = malloc(1 << 29);
105
fprintf(stderr, "Failed to allocate scratch memory!\n");
109
bigarray[BIG_TEST_BIT >> 3] = 0;
111
ext2fs_set_bit(BIG_TEST_BIT, bigarray);
112
printf("big bit number (%u) test: %d, expected %d\n", BIG_TEST_BIT,
113
bigarray[BIG_TEST_BIT >> 3], (1 << (BIG_TEST_BIT & 7)));
114
if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7)))
117
ext2fs_clear_bit(BIG_TEST_BIT, bigarray);
119
printf("big bit number (%u) test: %d, expected 0\n", BIG_TEST_BIT,
120
bigarray[BIG_TEST_BIT >> 3], 0);
121
if (bigarray[BIG_TEST_BIT >> 3] != 0)
124
printf("ext2fs_set_bit big_test successful\n");
127
/* Now test ext2fs_fast_set_bit */
128
memset(testarray, 0, sizeof(testarray));
129
for (i=0; bits_list[i] > 0; i++) {
130
ext2fs_fast_set_bit(bits_list[i], testarray);
132
if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) {
133
printf("ext2fs_fast_set_bit test succeeded.\n");
135
printf("ext2fs_fast_set_bit test failed.\n");
136
for (i=0; i < sizeof(testarray); i++) {
137
printf("%02x ", testarray[i]);
142
for (i=0; bits_list[i] > 0; i++) {
143
ext2fs_clear_bit(bits_list[i], testarray);
145
for (i=0; i < sizeof(testarray); i++) {
147
printf("ext2fs_clear_bit failed, "
148
"testarray[%d] is %d\n", i, testarray[i]);
152
printf("ext2fs_clear_bit test succeed.\n");
155
bigarray[BIG_TEST_BIT >> 3] = 0;
157
ext2fs_fast_set_bit(BIG_TEST_BIT, bigarray);
158
printf("big bit number (%u) test: %d, expected %d\n", BIG_TEST_BIT,
159
bigarray[BIG_TEST_BIT >> 3], (1 << (BIG_TEST_BIT & 7)));
160
if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7)))
163
ext2fs_fast_clear_bit(BIG_TEST_BIT, bigarray);
165
printf("big bit number (%u) test: %d, expected 0\n", BIG_TEST_BIT,
166
bigarray[BIG_TEST_BIT >> 3], 0);
167
if (bigarray[BIG_TEST_BIT >> 3] != 0)
170
printf("ext2fs_fast_set_bit big_test successful\n");