Commit 3794540f authored by Daniele Francesco Kruse's avatar Daniele Francesco Kruse
Browse files

1) Added the test for the wrapper functions of the ST driver. This test aims...

1) Added the test for the wrapper functions of the ST driver. This test aims at checking the correctness of the behaviour of the interface functions.
2) Changed the name of 2 interface functions to better describe their behaviour:

spaceFilesBackwards -> spaceFileMarksBackwards
spaceFilesForward -> spaceFileMarksForward
parent 6eca5cb5
......@@ -369,10 +369,10 @@ void Tape::Drive::rewind(void) throw (Tape::Exception) {
}
/**
* Space count files backwards.
* Space count file marks backwards.
* @param count
*/
void Tape::Drive::spaceFilesBackwards(size_t count) throw (Tape::Exception) {
void Tape::Drive::spaceFileMarksBackwards(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTBSF;
m_mtCmd.mt_count = (int)count;
......@@ -381,10 +381,10 @@ void Tape::Drive::spaceFilesBackwards(size_t count) throw (Tape::Exception) {
}
/**
* Space count files forward.
* Space count file marks forward.
* @param count
*/
void Tape::Drive::spaceFilesForward(size_t count) throw (Tape::Exception) {
void Tape::Drive::spaceFileMarksForward(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTFSF;
m_mtCmd.mt_count = (int)count;
......@@ -393,7 +393,10 @@ void Tape::Drive::spaceFilesForward(size_t count) throw (Tape::Exception) {
}
/**
* Space count blocks backwards.
* Space count logical blocks backwards.
* A logical block is the smallest user data unit accessible on tape and its
* length is defined at write time. This function will throw an exception if the
* next logical object is not a logical block (i.e. if it is a file mark instead).
* @param count
*/
void Tape::Drive::spaceBlocksBackwards(size_t count) throw (Tape::Exception) {
......@@ -405,7 +408,10 @@ void Tape::Drive::spaceBlocksBackwards(size_t count) throw (Tape::Exception) {
}
/**
* Space count blocks forward.
* Space count logical blocks forward.
* A logical block is the smallest user data unit accessible on tape and its
* length is defined at write time. This function will throw an exception if the
* next logical object is not a logical block (i.e. if it is a file mark instead).
* @param count
*/
void Tape::Drive::spaceBlocksForward(size_t count) throw (Tape::Exception) {
......
......@@ -247,16 +247,16 @@ namespace Tape {
virtual void spaceToEOM(void) throw (Exception);
/**
* Space count files backwards.
* Space count file marks backwards.
* @param count
*/
virtual void spaceFilesBackwards(size_t count) throw (Exception);
virtual void spaceFileMarksBackwards(size_t count) throw (Exception);
/**
* Space count files forward.
* Space count file marks forward.
* @param count
*/
virtual void spaceFilesForward(size_t count) throw (Exception);
virtual void spaceFileMarksForward(size_t count) throw (Exception);
/**
* Space count blocks backwards.
......
......@@ -29,6 +29,34 @@
#include "../SCSI/Device.hh"
#include "Drive.hh"
#include <iostream>
#include <assert.h>
/*
* Prints and compares the current position with the expected one. Returns on
* success (expected value is the same as the actual value), or else fails the
* assertion and exits.
* @param expected_position expected position
*/
void print_and_assert_position(Tape::Drive *drive, int expected_position)
{
int curPos = (int)drive->getPositionInfo().currentPosition;
std::cout << "CurrentPosition: " << curPos << " (Expected: " << expected_position << ")" << std::endl;
assert(expected_position == curPos);
return;
}
/*
* Prints and compares the current data read with the expected one. Returns on
* success (expected value is the same as the actual value), or else fails the
* assertion and exits.
* @param expected_data expected data
*/
void print_and_assert_data(const char * expected_data, const char * actual_data)
{
std::cout << "Data Read: " << actual_data << " (Expected: " << expected_data << ")" << std::endl;
assert(0 == strcmp(expected_data, actual_data));
return;
}
int main ()
{
......@@ -138,7 +166,203 @@ int main ()
Alerts.pop_back();
}
//drive->SCSI_inquiry(); we use INQUIRY for tapes in getDeviceInfo
/**
* Rewind/Read/Write/Skip Test (needs a tape mounted on /dev/nst0)
*/
if (0 == dev.nst_dev.compare("/dev/nst0")) {
try {
const size_t count = 10;
unsigned char data[count];
memset(data, 0, count);
std::cout << "************** BEGIN: Rewind/Read/Write/Skip Test *************" << std::endl;
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape after Victor's positioning
print_and_assert_position(drive, 0);
memset(data, 'a', count-1);
std::cout << "Writing 1st block (9 a's)..." << std::endl;
drive->writeBlock(data, count); // write 9 a's + string term
print_and_assert_position(drive, 1);
std::cout << "Writing 1st Synchronous filemark..." << std::endl;
drive->writeSyncFileMarks(1); // filemark and flush
print_and_assert_position(drive, 2);
memset(data, 'b', count-1);
std::cout << "Writing 2nd block (9 b's)..." << std::endl;
drive->writeBlock(data, count); // write 9 b's + string term
print_and_assert_position(drive, 3);
std::cout << "Writing 2nd Synchronous filemark..." << std::endl;
drive->writeSyncFileMarks(1); // filemark and flush
print_and_assert_position(drive, 4);
memset(data, 'c', count-1);
std::cout << "Writing 3rd block (9 c's)..." << std::endl;
drive->writeBlock(data, count); // write 9 c's + string term
print_and_assert_position(drive, 5);
std::cout << "Writing EOD (2 filemarks)..." << std::endl;
drive->writeSyncFileMarks(2); // EOD and flush
print_and_assert_position(drive, 7);
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
std::cout << "Reading back 1st block 9 a's)..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count); // read 9 a's + string term
print_and_assert_position(drive, 1);
print_and_assert_data("aaaaaaaaa", (const char *)data);
std::cout << "Skipping first file mark..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count);
print_and_assert_position(drive, 2);
std::cout << "Reading back 2nd block (9 b's)..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count); // read 9 b's + string term
print_and_assert_position(drive, 3);
print_and_assert_data("bbbbbbbbb", (const char *)data);
std::cout << "Skipping first file mark..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count);
print_and_assert_position(drive, 4);
std::cout << "Reading back 3rd block (9 c's)..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count); // read 9 c's + string term
print_and_assert_position(drive, 5);
print_and_assert_data("ccccccccc", (const char *)data);
std::cout << "Skipping the last two file marks..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count);
memset(data, 0, count);
drive->readBlock(data, count);
print_and_assert_position(drive, 7);
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
std::cout << "Spacing to the end of media..." << std::endl;
drive->spaceToEOM();
print_and_assert_position(drive, 7);
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
std::cout << "Fast spacing to the end of media..." << std::endl;
drive->fastSpaceToEOM();
print_and_assert_position(drive, 7);
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
std::cout << "Spacing 2 file marks forward..." << std::endl;
drive->spaceFileMarksForward(2);
print_and_assert_position(drive, 4);
std::cout << "Spacing 1 file mark backwards..." << std::endl;
drive->spaceFileMarksBackwards(1);
print_and_assert_position(drive, 3);
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
std::cout << "Spacing 3 file marks forward..." << std::endl;
drive->spaceFileMarksForward(3);
print_and_assert_position(drive, 6);
memset(data, 'd', count-1);
std::cout << "Writing 9 d's..." << std::endl;
drive->writeBlock(data, count); // write 9 d's + string term
print_and_assert_position(drive, 7);
std::cout << "Writing Asynchronous filemark..." << std::endl;
drive->writeImmediateFileMarks(1); // buffered filemark
print_and_assert_position(drive, 8);
memset(data, 'e', count-1);
std::cout << "Writing 9 e's..." << std::endl;
drive->writeBlock(data, count); // write 9 e's + string term
print_and_assert_position(drive, 9);
std::cout << "Writing Asynchronous EOD..." << std::endl;
drive->writeImmediateFileMarks(2); // buffered filemarks
print_and_assert_position(drive, 11);
std::cout << "Synch-ing..." << std::endl;
drive->sync(); // flush buffer with no-op
print_and_assert_position(drive, 11);
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
for(int i=0; i<9; i++) {
memset(data, '0'+i, count-1);
std::cout << "Writing 9 " << i << "'s..." << std::endl;
drive->writeBlock(data, count);
print_and_assert_position(drive, i+1);
}
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
std::cout << "Spacing 2 logical blocks forward..." << std::endl;
drive->spaceBlocksForward(2);
print_and_assert_position(drive, 2);
std::cout << "Reading..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count);
print_and_assert_position(drive, 3);
print_and_assert_data("222222222", (const char *)data);
std::cout << "Spacing 1 logical block backwards..." << std::endl;
drive->spaceBlocksBackwards(1);
print_and_assert_position(drive, 2);
std::cout << "Spacing 5 logical blocks forward..." << std::endl;
drive->spaceBlocksForward(5);
print_and_assert_position(drive, 7);
std::cout << "Spacing 3 logical blocks backwards..." << std::endl;
drive->spaceBlocksBackwards(3);
print_and_assert_position(drive, 4);
std::cout << "Reading..." << std::endl;
memset(data, 0, count);
drive->readBlock(data, count);
print_and_assert_position(drive, 5);
print_and_assert_data("444444444", (const char *)data);
std::cout << "Rewinding..." << std::endl;
drive->rewind(); // go back to the beginning of tape
print_and_assert_position(drive, 0);
std::cout << "TEST PASSED!" << std::endl;
std::cout << "************** END: Rewind/Read/Write/Skip Test *************" << std::endl;
} catch (std::exception & e) {
std::cout << "-- EXCEPTION ---------------------------------" << std::endl
<< e.what() << std::endl
<< "----------------------------------------------" << std::endl;
}
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment