From 3ff90433ab22c001215d9a26c65de1b7f448dc79 Mon Sep 17 00:00:00 2001 From: Elie De Brauwer Date: Fri, 1 Mar 2013 19:37:38 +0100 Subject: integck.c: rework file_check_data to immediately dump the buffer containing the errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See my problem description int the previous commit, the point is that integck in file_check_data reads a buffer, and then checks if the data is correct,  it will do a seek(0), and reread from the same fd. The point is that in the scenario I observed integck failed (due to a buffer mismatch) but the it saved (and what was in flash) was actually correct. So I modified this function to dump the buffers to stderr at the moment an error is found. Signed-off-by: Elie De Brauwer Signed-off-by: Artem Bityutskiy --- tests/fs-tests/integrity/integck.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c index 2c6ffea..5ea3642 100644 --- a/tests/fs-tests/integrity/integck.c +++ b/tests/fs-tests/integrity/integck.c @@ -1502,7 +1502,8 @@ static void file_check_data(struct file_info *file, int fd, { size_t remains, block, i; off_t r; - char buf[IO_BUFFER_SIZE]; + unsigned char read_buf[IO_BUFFER_SIZE]; + unsigned char check_buf[IO_BUFFER_SIZE]; unsigned int seed = w->random_seed; if (args.power_cut_mode && !file->clean) @@ -1517,17 +1518,28 @@ static void file_check_data(struct file_info *file, int fd, block = IO_BUFFER_SIZE; else block = remains; - CHECK(read(fd, buf, block) == block); - for (i = 0; i < block; ++i) { - char c = (char)rand_r(&seed); - if (buf[i] != c) { - errmsg("file_check_data failed at %zu checking " - "data at %llu size %zu", w->size - remains + i, - (unsigned long long)w->offset, w->size); - file_info_display(file); - save_file(fd, file); - } - CHECK(buf[i] == c); + CHECK(read(fd, read_buf, block) == block); + for (i = 0; i < block; ++i) + check_buf[i] = (char)rand_r(&seed); + + if (memcmp(check_buf, read_buf, block) != 0) { + errmsg("file_check_data failed, dumping " + "data at offset %llu size %zu", + (unsigned long long)w->offset, w->size); + + fprintf (stderr, "Read data:\n"); + for (r = 0; r < block; ++r) + fprintf(stderr, "%02x%c", + read_buf[r], ((r+1)%16)?' ':'\n'); + fprintf(stderr, "\nExpected data:\n"); + for (r = 0; r < block; ++r) + fprintf(stderr, "%02x%c", + check_buf[r], ((r+1)%16)?' ':'\n'); + fprintf(stderr, " \n"); + + file_info_display(file); + save_file(fd, file); + CHECK(0); } remains -= block; } -- cgit v1.2.3