2022-10-06 14:15:19 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-06 14:15:19 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-06 14:15:19 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "mocks.h"
|
2023-10-15 06:38:15 +00:00
|
|
|
#include <net/ethernet.h>
|
2022-10-06 14:15:19 +00:00
|
|
|
#include "devices/ctapdriver.h"
|
|
|
|
|
|
|
|
TEST(CTapDriverTest, Crc32)
|
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
array<uint8_t, ETH_FRAME_LEN> buf;
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
buf.fill(0x00);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(0xe3d887bb, CTapDriver::Crc32(span(buf.data(), ETH_FRAME_LEN)));
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
buf.fill(0xff);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(0x814765f4, CTapDriver::Crc32(span(buf.data(), ETH_FRAME_LEN)));
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
buf.fill(0x10);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(0xb7288Cd3, CTapDriver::Crc32(span(buf.data(), ETH_FRAME_LEN)));
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
buf.fill(0x7f);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(0x4b543477, CTapDriver::Crc32(span(buf.data(), ETH_FRAME_LEN)));
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
buf.fill(0x80);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(0x29cbd638, CTapDriver::Crc32(span(buf.data(), ETH_FRAME_LEN)));
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < buf.size(); i++) {
|
2022-11-02 06:36:25 +00:00
|
|
|
buf[i] = (uint8_t)i;
|
2022-10-06 14:15:19 +00:00
|
|
|
}
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(0xe7870705, CTapDriver::Crc32(span(buf.data(), ETH_FRAME_LEN)));
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
for (size_t i = buf.size() - 1; i > 0; i--) {
|
2022-11-02 06:36:25 +00:00
|
|
|
buf[i] = (uint8_t)i;
|
2022-10-06 14:15:19 +00:00
|
|
|
}
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(0xe7870705, CTapDriver::Crc32(span(buf.data(), ETH_FRAME_LEN)));
|
2022-10-06 14:15:19 +00:00
|
|
|
}
|