start small file transfer test
This commit is contained in:
parent
9a1437980f
commit
6c6b552059
@ -204,6 +204,11 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
|
||||
if (fileSize > UINT32_MAX) {
|
||||
transactionParams.pduConf.largeFile = true;
|
||||
}
|
||||
if (fileSize == 0) {
|
||||
transactionParams.checksumType = ChecksumType::NULL_CHECKSUM;
|
||||
} else {
|
||||
transactionParams.checksumType = ChecksumType::CRC_32;
|
||||
}
|
||||
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
|
||||
transactionParams.remoteCfg = cfg;
|
||||
return OK;
|
||||
@ -212,7 +217,9 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
|
||||
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
|
||||
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
|
||||
cfdp::StringLv destName(transactionParams.destName.data(), transactionParams.destNameSize);
|
||||
auto metadataInfo = MetadataGenericInfo(transactionParams.fileSize);
|
||||
auto metadataInfo =
|
||||
MetadataGenericInfo(transactionParams.closureRequested, transactionParams.checksumType,
|
||||
transactionParams.fileSize);
|
||||
auto metadataPdu =
|
||||
MetadataPduCreator(transactionParams.pduConf, metadataInfo, sourceName, destName, nullptr, 0);
|
||||
ReturnValue_t result = sendGenericPdu(metadataPdu);
|
||||
|
@ -73,6 +73,7 @@ class SourceHandler {
|
||||
cfdp::Fss fileSize;
|
||||
size_t progress = 0;
|
||||
bool closureRequested = false;
|
||||
ChecksumType checksumType = ChecksumType::NULL_CHECKSUM;
|
||||
RemoteEntityCfg remoteCfg;
|
||||
PduConfig pduConf;
|
||||
cfdp::TransactionId id{};
|
||||
|
@ -17,7 +17,7 @@ struct FilesystemParams {
|
||||
};
|
||||
|
||||
struct FileOpParams {
|
||||
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
|
||||
FileOpParams(const char* path, size_t opSize) : fsParams(path), size(opSize) {}
|
||||
|
||||
[[nodiscard]] const char* path() const { return fsParams.path; }
|
||||
|
||||
|
@ -43,14 +43,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
||||
fp.tcStore = &tcStore;
|
||||
fp.tmStore = &tmStore;
|
||||
auto sourceHandler = SourceHandler(dp, fp);
|
||||
CHECK(sourceHandler.initialize() == OK);
|
||||
|
||||
SECTION("Test Basic") {
|
||||
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
||||
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
||||
}
|
||||
|
||||
SECTION("Transfer empty file") {
|
||||
RemoteEntityCfg cfg;
|
||||
EntityId id(cfdp::WidthInBytes::TWO_BYTES, 5);
|
||||
cfg.remoteId = id;
|
||||
@ -62,13 +55,11 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
||||
FilesystemParams destFileNameFs(destFileName.c_str());
|
||||
cfdp::StringLv destNameLv(destFileNameFs.path, std::strlen(destFileNameFs.path));
|
||||
PutRequest putRequest(id, srcNameLv, destNameLv);
|
||||
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
|
||||
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
|
||||
CHECK(sourceHandler.initialize() == OK);
|
||||
|
||||
auto genericMetadataCheck = [&](SourceHandler::FsmResult& fsmResult, size_t expectedFileSize) {
|
||||
TmTcMessage tmtcMessage;
|
||||
const uint8_t* pduPtr;
|
||||
// Verify metadata PDU was sent.
|
||||
{
|
||||
CHECK(fsmResult.packetsSent == 1);
|
||||
CHECK(mqMock.numberOfSentMessages() == 1);
|
||||
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
||||
@ -83,15 +74,19 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
||||
CHECK(srcNameRead == srcFileName);
|
||||
std::string destNameRead = metadataReader.getDestFileName().getString();
|
||||
CHECK(destNameRead == destFileName);
|
||||
if (expectedFileSize == 0) {
|
||||
CHECK(metadataInfo.getChecksumType() == ChecksumType::NULL_CHECKSUM);
|
||||
CHECK(metadataInfo.getFileSize().value() == 0);
|
||||
CHECK(!metadataInfo.isClosureRequested());
|
||||
} else {
|
||||
CHECK(metadataInfo.getChecksumType() == ChecksumType::CRC_32);
|
||||
}
|
||||
|
||||
// Verify EOF PDU was sent. No file data PDU is sent for an empty file.
|
||||
{
|
||||
CHECK(metadataInfo.getFileSize().value() == expectedFileSize);
|
||||
CHECK(!metadataInfo.isClosureRequested());
|
||||
mqMock.clearMessages();
|
||||
fsmResult = sourceHandler.stateMachine();
|
||||
};
|
||||
auto genericEofCheck = [&](SourceHandler::FsmResult& fsmResult, size_t expectedFileSize,
|
||||
uint32_t expectedChecksum) {
|
||||
TmTcMessage tmtcMessage;
|
||||
const uint8_t* pduPtr;
|
||||
CHECK(fsmResult.packetsSent == 1);
|
||||
CHECK(mqMock.numberOfSentMessages() == 1);
|
||||
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
||||
@ -104,14 +99,46 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
||||
EofInfo eofInfo;
|
||||
EofPduReader eofReader(pduPtr, accessor.second.size(), eofInfo);
|
||||
REQUIRE(eofReader.parseData() == OK);
|
||||
CHECK(eofInfo.getChecksum() == 0);
|
||||
CHECK(eofInfo.getChecksum() == expectedChecksum);
|
||||
CHECK(eofInfo.getConditionCode() == ConditionCode::NO_ERROR);
|
||||
CHECK(eofInfo.getFileSize().value() == 0);
|
||||
CHECK(eofInfo.getFileSize().value() == expectedFileSize);
|
||||
};
|
||||
SECTION("Test Basic") {
|
||||
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
||||
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
||||
}
|
||||
|
||||
SECTION("Transfer empty file") {
|
||||
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
|
||||
|
||||
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
|
||||
// Verify metadata PDU was sent.
|
||||
genericMetadataCheck(fsmResult, 0);
|
||||
|
||||
fsmResult = sourceHandler.stateMachine();
|
||||
// Verify EOF PDU was sent. No file data PDU is sent for an empty file.
|
||||
genericEofCheck(fsmResult, 0, 0);
|
||||
|
||||
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
||||
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
||||
}
|
||||
|
||||
SECTION("Transfer small file") {}
|
||||
SECTION("Transfer small file") {
|
||||
fsMock.createFile(srcFileNameFs);
|
||||
std::string fileContent = "hello world\n";
|
||||
size_t expectedFileSize = fileContent.size();
|
||||
FileOpParams params(srcFileName.c_str(), expectedFileSize);
|
||||
fsMock.writeToFile(params, reinterpret_cast<const uint8_t*>(fileContent.data()));
|
||||
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
|
||||
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
|
||||
|
||||
// Verify metadata PDU was sent.
|
||||
genericMetadataCheck(fsmResult, expectedFileSize);
|
||||
fsmResult = sourceHandler.stateMachine();
|
||||
// TODO: Verify one file data PDU was sent.
|
||||
|
||||
// TODO: Verify one EOF PDU was sent.
|
||||
}
|
||||
|
||||
SECTION("Transfer two segment file") {}
|
||||
}
|
@ -80,7 +80,7 @@ ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool dele
|
||||
|
||||
ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath,
|
||||
FileSystemArgsIF *args) {
|
||||
renameQueue.push(RenameInfo(oldPath, newPath));
|
||||
renameQueue.emplace(oldPath, newPath);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data)
|
||||
if (iter == fileMap.end()) {
|
||||
FileSegmentQueue queue;
|
||||
if (params.size > 0) {
|
||||
queue.push(FileWriteInfo(filename, params.offset, data, params.size));
|
||||
queue.emplace(filename, params.offset, data, params.size);
|
||||
}
|
||||
FileInfo info;
|
||||
info.fileSegQueue = queue;
|
||||
@ -100,7 +100,7 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data)
|
||||
fileMap.emplace(filename, info);
|
||||
} else {
|
||||
FileInfo &info = iter->second;
|
||||
info.fileSegQueue.push(FileWriteInfo(filename, params.offset, data, params.size));
|
||||
info.fileSegQueue.emplace(filename, params.offset, data, params.size);
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -149,7 +149,7 @@ bool FilesystemMock::isDirectory(const char *path) { return false; }
|
||||
bool FilesystemMock::getFileSize(FilesystemParams params, size_t &fileSize) {
|
||||
std::string filename(params.path);
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
if (iter != fileMap.end()) {
|
||||
fileSize = iter->second.fileRaw.size();
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user