X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fbtape.c;h=74e117e5898c5d54e8d31c443a5b4eaf300fbbde;hb=00351932040a9662315cb75002ddaa3544de997d;hp=61c14e5aafa4e87a0350308fde4ece91afc2938c;hpb=79b3e3b3491946a8607b75219880a00a03acbff9;p=bacula%2Fbacula diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 61c14e5aaf..74e117e589 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -796,35 +796,35 @@ bail_out: return stat; } +const int num_recs = 10000; -/* - * This test writes Bacula blocks to the tape in - * several files. It then rewinds the tape and attepts - * to read these blocks back checking the data. - */ -static int write_read_test() +static bool write_two_files() { DEV_BLOCK *block; DEV_RECORD *rec; - int stat = 0; int len, i, j; int *p; + bool rc = false; /* bad return code */ - Pmsg0(-1, _("\n=== Write, rewind, and re-read test ===\n\n" - "I'm going to write 1000 records and an EOF\n" - "then write 1000 records and an EOF, then rewind,\n" + Pmsg2(-1, _("\n=== Write, rewind, and re-read test ===\n\n" + "I'm going to write %d records and an EOF\n" + "then write %d records and an EOF, then rewind,\n" "and re-read the data to verify that it is correct.\n\n" - "This is an *essential* feature ...\n\n")); + "This is an *essential* feature ...\n\n"), num_recs, num_recs); + block = dcr->block; + empty_block(block); rec = new_record(); + rec->data = check_pool_memory_size(rec->data, block->buf_len); + rec->data_len = block->buf_len-100; + len = rec->data_len/sizeof(i); + if (!dev->rewind(dcr)) { Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror()); goto bail_out; } - rec->data = check_pool_memory_size(rec->data, block->buf_len); - rec->data_len = block->buf_len-100; - len = rec->data_len/sizeof(i); - for (i=1; i<=1000; i++) { + + for (i=1; i<=num_recs; i++) { p = (int *)rec->data; for (j=0; jdata_len); + Pmsg2(0, _("Wrote %d blocks of %d bytes.\n"), num_recs, rec->data_len); weofcmd(); - for (i=1001; i<=2000; i++) { + for (i=num_recs+1; i<=2*num_recs; i++) { p = (int *)rec->data; for (j=0; jdata_len); + Pmsg2(0, _("Wrote %d blocks of %d bytes.\n"), num_recs, rec->data_len); weofcmd(); if (dev->has_cap(CAP_TWOEOF)) { weofcmd(); } + rc = true; + +bail_out: + free_record(rec); + return rc; + +} + +/* + * This test writes Bacula blocks to the tape in + * several files. It then rewinds the tape and attepts + * to read these blocks back checking the data. + */ +static int write_read_test() +{ + DEV_BLOCK *block; + DEV_RECORD *rec; + int stat = 0; + int len, i, j; + int *p; + + rec = new_record(); + + if (!write_two_files()) { + goto bail_out; + } + + block = dcr->block; + empty_block(block); + if (!dev->rewind(dcr)) { Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror()); goto bail_out; } else { Pmsg0(0, _("Rewind OK.\n")); } - for (i=1; i<=2000; i++) { + + rec->data = check_pool_memory_size(rec->data, block->buf_len); + rec->data_len = block->buf_len-100; + len = rec->data_len/sizeof(i); + + /* Now read it back */ + for (i=1; i<=2*num_recs; i++) { read_again: if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) { berrno be; @@ -893,8 +929,8 @@ read_again: } p++; } - if (i == 1000 || i == 2000) { - Pmsg0(-1, _("1000 blocks re-read correctly.\n")); + if (i == num_recs || i == 2*num_recs) { + Pmsg1(-1, _("%d blocks re-read correctly.\n"), num_recs); } } Pmsg0(-1, _("=== Test Succeeded. End Write, rewind, and re-read test ===\n\n")); @@ -915,62 +951,20 @@ static int position_test() DEV_BLOCK *block = dcr->block; DEV_RECORD *rec; int stat = 0; - int len, i, j; + int len, j; bool ok = true; int recno = 0; int file = 0, blk = 0; int *p; bool got_eof = false; - Pmsg0(-1, _("\n=== Write, rewind, and position test ===\n\n" - "I'm going to write 1000 records and an EOF\n" - "then write 1000 records and an EOF, then rewind,\n" - "and position to a few blocks and verify that it is correct.\n\n" - "This is an *essential* feature ...\n\n")); + block = dcr->block; empty_block(block); rec = new_record(); - if (!dev->rewind(dcr)) { - Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror()); - goto bail_out; - } rec->data = check_pool_memory_size(rec->data, block->buf_len); rec->data_len = block->buf_len-100; - len = rec->data_len/sizeof(i); - for (i=1; i<=1000; i++) { - p = (int *)rec->data; - for (j=0; jdata_len); - weofcmd(); - for (i=1001; i<=2000; i++) { - p = (int *)rec->data; - for (j=0; jdata_len); - weofcmd(); - if (dev->has_cap(CAP_TWOEOF)) { - weofcmd(); - } + len = rec->data_len/sizeof(j); + if (!dev->rewind(dcr)) { Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror()); goto bail_out;