2 * This testing program makes sure the badblocks implementation works.
4 * Copyright (C) 1996 by Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
20 #include <sys/types.h>
28 blk_t test1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
29 blk_t test2[] = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1 };
30 blk_t test3[] = { 3, 1, 4, 5, 9, 2, 7, 10, 5, 6, 10, 8, 0 };
31 blk_t test4[] = { 20, 50, 12, 17, 13, 2, 66, 23, 56, 0 };
48 static int test_fail = 0;
50 static errcode_t create_test_list(blk_t *vec, badblocks_list *ret)
56 retval = ext2fs_badblocks_list_create(&bb, 5);
58 com_err("create_test_list", retval, "while creating list");
61 for (i=0; vec[i]; i++) {
62 retval = ext2fs_badblocks_list_add(bb, vec[i]);
64 com_err("create_test_list", retval,
65 "while adding test vector %d", i);
66 ext2fs_badblocks_list_free(bb);
74 static void print_list(badblocks_list bb, int verify)
77 badblocks_iterate iter;
81 retval = ext2fs_badblocks_list_iterate_begin(bb, &iter);
83 com_err("print_list", retval, "while setting up iterator");
87 while (ext2fs_badblocks_list_iterate(iter, &blk)) {
92 ext2fs_badblocks_list_iterate_end(iter);
103 static void validate_test_seq(badblocks_list bb, blk_t *vec)
107 for (i = 0; vec[i]; i += 2) {
108 match = ext2fs_badblocks_list_test(bb, vec[i]);
109 if (match == vec[i+1])
115 printf("\tblock %d is %s --- %s\n", vec[i],
116 match ? "present" : "absent",
117 ok ? "OK" : "NOT OK");
121 int file_test(badblocks_list bb)
123 badblocks_list new_bb = 0;
129 fprintf(stderr, "Error opening temp file: %s\n",
130 error_message(errno));
133 retval = ext2fs_write_bb_FILE(bb, 0, f);
135 com_err("file_test", retval, "while writing bad blocks");
140 retval = ext2fs_read_bb_FILE2(0, f, &new_bb, 0, 0);
142 com_err("file_test", retval, "while reading bad blocks");
147 if (ext2fs_badblocks_equal(bb, new_bb)) {
148 printf("Block bitmap matched after reading and writing.\n");
150 printf("Block bitmap NOT matched.\n");
157 int main(int argc, char **argv)
159 badblocks_list bb1, bb2, bb3, bb4;
163 bb1 = bb2 = bb3 = bb4 = 0;
166 retval = create_test_list(test1, &bb1);
172 retval = create_test_list(test2, &bb2);
178 retval = create_test_list(test3, &bb3);
184 retval = create_test_list(test4, &bb4);
188 validate_test_seq(bb4, test4a);
192 if (bb1 && bb2 && bb3 && bb4) {
193 printf("Comparison tests:\n");
194 equal = ext2fs_badblocks_equal(bb1, bb2);
195 printf("bb1 and bb2 are %sequal.\n", equal ? "" : "NOT ");
199 equal = ext2fs_badblocks_equal(bb1, bb3);
200 printf("bb1 and bb3 are %sequal.\n", equal ? "" : "NOT ");
204 equal = ext2fs_badblocks_equal(bb1, bb4);
205 printf("bb1 and bb4 are %sequal.\n", equal ? "" : "NOT ");
212 printf("ext2fs library badblocks tests checks out OK!\n");
217 ext2fs_badblocks_list_free(bb1);
219 ext2fs_badblocks_list_free(bb2);
221 ext2fs_badblocks_list_free(bb3);
223 ext2fs_badblocks_list_free(bb4);