Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 9, 2024
1 parent 0dfcc8a commit 77034da
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions cpp/test/tape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ static void WriteGoodData(ostream &file, int length = 512)
WriteSimhObject(file, data, length, data);
}

static void Rewind(shared_ptr<Tape> tape)
{
Dispatch(tape, scsi_command::rewind);
}

static void ValidateModePages(map<int, vector<byte>> &pages)
{
EXPECT_EQ(6U, pages.size()) << "Unexpected number of mode pages";
Expand Down Expand Up @@ -196,7 +201,7 @@ TEST(TapeTest, Read6)
WriteSimhObject(file, bad_data_not_recovered);
WriteSimhObject(file, end_of_data);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Non-fixed, 12 bytes
controller->SetCdbByte(1, 0x00);
Expand Down Expand Up @@ -238,7 +243,7 @@ TEST(TapeTest, Read6)
file.seekp(0);
WriteSimhObject(file, block_size_mismatch, 256, block_size_mismatch);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Fixed, 1 block, block size mismatch
controller->SetCdbByte(1, 0x01);
Expand All @@ -249,29 +254,29 @@ TEST(TapeTest, Read6)
EXPECT_EQ(0x80, controller->GetBuffer()[0] & 0x80) << "VALID must be set";
EXPECT_EQ(0x20, controller->GetBuffer()[2] & 0x20) << "ILI must be set";

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Non-fixed, 1 byte
controller->SetCdbByte(4, 1);
EXPECT_NO_THROW(Dispatch(tape, scsi_command::read_6));

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Non-fixed, 1 byte
controller->SetCdbByte(4, 1);
// SILI
controller->SetCdbByte(1, 0x02);
EXPECT_NO_THROW(Dispatch(tape, scsi_command::read_6));

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Non-fixed, 1024 bytes (more than block size)
controller->SetCdbByte(3, 0x04);
controller->SetCdbByte(4, 0x00);
controller->SetCdbByte(1, 0x00);
EXPECT_NO_THROW(Dispatch(tape, scsi_command::read_6));

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Non-fixed, 1024 bytes (more than block size)
controller->SetCdbByte(3, 0x04);
Expand All @@ -289,7 +294,7 @@ TEST(TapeTest, Read6)
file.seekp(0);
WriteSimhObject(file, good_data_non_fixed, good_data_non_fixed[0], bad_trailing);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Non-fixed, 12 bytes
controller->SetCdbByte(4, 12);
Expand All @@ -298,7 +303,7 @@ TEST(TapeTest, Read6)
file.seekp(0);
WriteFilemark(file);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Non-fixed, 90 byte
controller->SetCdbByte(4, 90);
Expand All @@ -307,7 +312,7 @@ TEST(TapeTest, Read6)
EXPECT_EQ(0x80, controller->GetBuffer()[0] & 0x80) << "VALID must be set";
EXPECT_EQ(90U, GetInt32(controller->GetBuffer(), 3));

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Fixed, 1 block
controller->SetCdbByte(1, 0x01);
Expand Down Expand Up @@ -342,7 +347,7 @@ TEST(TapeTest, Write6)
CheckMetaData(file, { simh_class::tape_mark_good_data_record, 2 });
CheckPositions(tape, 10, 1);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);
file.seekg(0);

// Non-fixed, 1 byte
Expand All @@ -354,7 +359,7 @@ TEST(TapeTest, Write6)
CheckMetaData(file, { simh_class::tape_mark_good_data_record, 1 });
CheckPositions(tape, 10, 1);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);
file.seekg(0);

// Non-fixed, 512 bytes
Expand All @@ -367,7 +372,7 @@ TEST(TapeTest, Write6)
CheckMetaData(file, { simh_class::tape_mark_good_data_record, 512 });
CheckPositions(tape, 520, 1);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);
file.seekg(0);

// Fixed, 1 block
Expand All @@ -394,7 +399,8 @@ TEST(TapeTest, Erase6_simh)
CheckPositions(tape, 0, 0);
EXPECT_EQ(0b10000000, controller->GetBuffer()[0]) << "EOP must be set";

EXPECT_NO_THROW(Dispatch(tape, scsi_command::rewind));
Rewind(tape);

// Set filemark in order to advance the tape position
controller->SetCdbByte(4, 0x01);
Dispatch(tape, scsi_command::write_filemarks_6);
Expand Down Expand Up @@ -431,7 +437,7 @@ TEST(TapeTest, Rewind)
auto [controller, tape] = CreateTape();

CreateImageFile(*tape, 600);
EXPECT_NO_THROW(Dispatch(tape, scsi_command::rewind));
Rewind(tape);
CheckPositions(tape, 0, 0);
EXPECT_EQ(0b10000000, controller->GetBuffer()[0]) << "BOP must be set";

Expand All @@ -440,7 +446,7 @@ TEST(TapeTest, Rewind)
Dispatch(tape, scsi_command::write_filemarks_6);
CheckPositions(tape, 4, 0);
controller->SetCdbByte(1, 0x00);
EXPECT_NO_THROW(Dispatch(tape, scsi_command::rewind));
Rewind(tape);
CheckPositions(tape, 0, 0);
EXPECT_EQ(0b10000000, controller->GetBuffer()[0]) << "BOP must be set";
}
Expand Down Expand Up @@ -492,7 +498,7 @@ TEST(TapeTest, Space6_simh)
WriteFilemark(file);
WriteSimhObject(file, end_of_data);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Space over 1 filemark
controller->SetCdbByte(1, 0b001);
Expand Down Expand Up @@ -530,14 +536,14 @@ TEST(TapeTest, Space6_simh)
EXPECT_EQ(0x80, controller->GetBuffer()[0] & 0x80) << "VALID must be set";
EXPECT_EQ(5U, GetInt32(controller->GetBuffer(), 3));

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Search for end-of-data
controller->SetCdbByte(1, 0b011);
EXPECT_NO_THROW(Dispatch(tape, scsi_command::space_6));
CheckPositions(tape, 24, 6);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Space over 1 filemark, then reverse-space over more filemarks than available
controller->SetCdbByte(1, 0b001);
Expand Down Expand Up @@ -578,7 +584,7 @@ TEST(TapeTest, Space6_simh)
WriteGoodData(file);
WriteFilemark(file);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Space over 1 block
controller->SetCdbByte(1, 0b000);
Expand Down Expand Up @@ -631,7 +637,7 @@ TEST(TapeTest, Space6_simh)
WriteGoodData(file);
WriteSimhObject(file, end_of_data);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Space over 2 blocks, which hits the filemark
controller->SetCdbByte(4, 2);
Expand All @@ -654,7 +660,7 @@ TEST(TapeTest, Space6_simh)
EXPECT_EQ(1U, GetInt32(controller->GetBuffer(), 3));
CheckPositions(tape, 1044, 3);

Dispatch(tape, scsi_command::rewind);
Rewind(tape);

// Space for end-of-data
controller->SetCdbByte(1, 0b011);
Expand Down

0 comments on commit 77034da

Please sign in to comment.