* This testing program makes sure the badblocks implementation works.
*
* Copyright (C) 1996 by Theodore Ts'o.
- *
+ *
* %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
* %End-Header%
*/
+#include "config.h"
#include <stdio.h>
#include <string.h>
#if HAVE_UNISTD_H
#define DEL_BLK 0x0002
blk_t test1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
-blk_t test2[] = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1 };
+blk_t test2[] = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1, 0 };
blk_t test3[] = { 3, 1, 4, 5, 9, 2, 7, 10, 5, 6, 10, 8, 0 };
blk_t test4[] = { 20, 50, 12, 17, 13, 2, 66, 23, 56, 0 };
blk_t test4a[] = {
- 20, 1,
+ 20, 1,
50, 1,
3, 0,
17, 1,
11, 0,
12, 1,
13, 1,
- 14, 0,
+ 14, 0,
80, 0,
45, 0,
66, 1,
1, DEL_BLK,
0
};
-
+
static int test_fail = 0;
static int test_expected_fail = 0;
errcode_t retval;
badblocks_list bb;
int i;
-
+
retval = ext2fs_badblocks_list_create(&bb, 5);
if (retval) {
com_err("create_test_list", retval, "while creating list");
badblocks_iterate iter;
blk_t blk;
int i, ok;
-
+
retval = ext2fs_badblocks_list_iterate_begin(bb, &iter);
if (retval) {
com_err("print_list", retval, "while setting up iterator");
}
ok = i = 1;
while (ext2fs_badblocks_list_iterate(iter, &blk)) {
- printf("%d ", blk);
+ printf("%u ", blk);
if (i++ != blk)
ok = 0;
}
ok = 0;
test_fail++;
}
- printf("\tblock %d is %s --- %s\n", vec[i],
+ printf("\tblock %u is %s --- %s\n", vec[i],
match ? "present" : "absent",
ok ? "OK" : "NOT OK");
}
case ADD_BLK:
ext2fs_badblocks_list_add(bb, vec[i]);
match = ext2fs_badblocks_list_test(bb, vec[i]);
- printf("Adding block %d --- now %s\n", vec[i],
+ printf("Adding block %u --- now %s\n", vec[i],
match ? "present" : "absent");
if (!match) {
printf("FAILURE!\n");
case DEL_BLK:
ext2fs_badblocks_list_del(bb, vec[i]);
match = ext2fs_badblocks_list_test(bb, vec[i]);
- printf("Removing block %d --- now %s\n", vec[i],
- ext2fs_badblocks_list_test(bb, vec[i]) ?
+ printf("Removing block %u --- now %s\n", vec[i],
+ ext2fs_badblocks_list_test(bb, vec[i]) ?
"present" : "absent");
if (match) {
printf("FAILURE!\n");
printf("Block bitmap NOT matched.\n");
test_fail++;
}
+ ext2fs_badblocks_list_free(new_bb);
return 0;
}
printf("Expected invalid block\n");
test_expected_fail++;
} else {
- printf("Invalid block #: %d\n", blk);
+ printf("Invalid block #: %u\n", blk);
test_fail++;
}
}
-int file_test_invalid(badblocks_list bb)
+void file_test_invalid(badblocks_list bb)
{
badblocks_list new_bb = 0;
errcode_t retval;
fs->super = malloc(SUPERBLOCK_SIZE);
memset(fs->super, 0, SUPERBLOCK_SIZE);
fs->super->s_first_data_block = 1;
- fs->super->s_blocks_count = 100;
+ ext2fs_blocks_count_set(fs->super, 100);
f = tmpfile();
if (!f) {
fprintf(stderr, "Error opening temp file: %s\n",
error_message(errno));
- return 1;
+ test_fail++;
+ goto out;
}
retval = ext2fs_write_bb_FILE(bb, 0, f);
if (retval) {
com_err("file_test", retval, "while writing bad blocks");
- return 1;
+ test_fail++;
+ goto out;
}
fprintf(f, "34500\n");
retval = ext2fs_read_bb_FILE(fs, f, &new_bb, invalid_proc);
if (retval) {
com_err("file_test", retval, "while reading bad blocks");
- return 1;
+ test_fail++;
+ goto out;
}
fclose(f);
if (!test_expected_fail) {
printf("Expected test failure didn't happen!\n");
test_fail++;
}
-
+
if (ext2fs_badblocks_equal(bb, new_bb)) {
printf("Block bitmap matched after reading and writing.\n");
printf("Block bitmap NOT matched.\n");
test_fail++;
}
- return 0;
+ ext2fs_badblocks_list_free(new_bb);
+out:
+ free(fs->super);
+ free(fs);
}
int main(int argc, char **argv)
int equal;
errcode_t retval;
+ add_error_table(&et_ext2_error_table);
+
bb1 = bb2 = bb3 = bb4 = bb5 = 0;
printf("test1: ");
if (retval == 0)
print_list(bb1, 1);
printf("\n");
-
+
printf("test2: ");
retval = create_test_list(test2, &bb2);
if (retval == 0)
if (retval == 0)
print_list(bb3, 1);
printf("\n");
-
+
printf("test4: ");
retval = create_test_list(test4, &bb4);
if (retval == 0) {
if (bb1 && bb2 && bb3 && bb4 && bb5) {
printf("Comparison tests:\n");
equal = ext2fs_badblocks_equal(bb1, bb2);
- printf("bb1 and bb2 are %sequal.\n", equal ? "" : "NOT ");
+ printf("bb1 and bb2 are %sequal.\n", equal ? "" : "NOT ");
if (equal)
test_fail++;
equal = ext2fs_badblocks_equal(bb1, bb3);
- printf("bb1 and bb3 are %sequal.\n", equal ? "" : "NOT ");
+ printf("bb1 and bb3 are %sequal.\n", equal ? "" : "NOT ");
if (!equal)
test_fail++;
-
+
equal = ext2fs_badblocks_equal(bb1, bb4);
- printf("bb1 and bb4 are %sequal.\n", equal ? "" : "NOT ");
+ printf("bb1 and bb4 are %sequal.\n", equal ? "" : "NOT ");
if (equal)
test_fail++;
equal = ext2fs_badblocks_equal(bb4, bb5);
- printf("bb4 and bb5 are %sequal.\n", equal ? "" : "NOT ");
+ printf("bb4 and bb5 are %sequal.\n", equal ? "" : "NOT ");
if (!equal)
test_fail++;
printf("\n");
}
-
+
file_test(bb4);
file_test_invalid(bb4);
-
+
if (test_fail == 0)
printf("ext2fs library badblocks tests checks out OK!\n");
ext2fs_badblocks_list_free(bb3);
if (bb4)
ext2fs_badblocks_list_free(bb4);
+ if (bb5)
+ ext2fs_badblocks_list_free(bb5);
return test_fail;