continue tests
This commit is contained in:
49
src/dest.rs
49
src/dest.rs
@@ -2223,29 +2223,14 @@ mod tests {
|
||||
);
|
||||
assert_eq!(finished_pdu.fs_responses_raw(), &[]);
|
||||
assert!(tb.handler.pdu_sender.queue_empty());
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
DeliveryCode::Complete,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Incomplete,
|
||||
ConditionCode::CheckLimitReached,
|
||||
transaction_id,
|
||||
);
|
||||
tb.expected_full_data = faulty_file_data.to_vec();
|
||||
}
|
||||
|
||||
fn verify_finished_indication(
|
||||
user: &mut TestCfdpUser,
|
||||
delivery_code: DeliveryCode,
|
||||
cond_code: ConditionCode,
|
||||
id: TransactionId,
|
||||
) {
|
||||
assert_eq!(user.finished_indic_queue.len(), 1);
|
||||
let finished_indication = user.finished_indic_queue.pop_front().unwrap();
|
||||
assert_eq!(finished_indication.id, id);
|
||||
assert_eq!(finished_indication.condition_code, cond_code);
|
||||
assert_eq!(finished_indication.delivery_code, delivery_code);
|
||||
assert_eq!(finished_indication.file_status, FileStatus::Retained);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_file_copy_to_directory() {
|
||||
let fault_handler = TestFaultHandler::default();
|
||||
@@ -2294,8 +2279,7 @@ mod tests {
|
||||
)
|
||||
.expect("state machine call with EOF insertion failed");
|
||||
assert_eq!(packets, 0);
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2354,8 +2338,7 @@ mod tests {
|
||||
if insert_packet {
|
||||
// Checksum success, so data is complete.
|
||||
assert_eq!(finished_pdu.delivery_code(), DeliveryCode::Complete);
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2370,8 +2353,7 @@ mod tests {
|
||||
assert_eq!(ignored.0, id);
|
||||
assert_eq!(ignored.1, ConditionCode::FileChecksumFailure);
|
||||
assert_eq!(ignored.2, 5);
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Incomplete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2385,8 +2367,7 @@ mod tests {
|
||||
EntityIdTlv::new(LOCAL_ID.into())
|
||||
);
|
||||
} else {
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2426,8 +2407,7 @@ mod tests {
|
||||
.handler
|
||||
.state_machine_no_packet(&mut user)
|
||||
.expect("state machine call with EOF insertion failed");
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2469,8 +2449,7 @@ mod tests {
|
||||
finished_pdu.fault_location(),
|
||||
Some(EntityIdTlv::new(REMOTE_ID.into()))
|
||||
);
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2519,8 +2498,7 @@ mod tests {
|
||||
);
|
||||
tb.expected_file_size = file_size;
|
||||
tb.expected_full_data = file_data[0..file_size as usize].to_vec();
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Incomplete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2550,8 +2528,7 @@ mod tests {
|
||||
.state_machine_no_packet(&mut user)
|
||||
.expect("state machine call with EOF insertion failed");
|
||||
assert_eq!(packets, 0);
|
||||
verify_finished_indication(
|
||||
&mut user,
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::CancelRequestReceived,
|
||||
id,
|
||||
@@ -2589,5 +2566,11 @@ mod tests {
|
||||
assert_eq!(packets, 0);
|
||||
// File was disposed.
|
||||
assert!(!Path::exists(tb.dest_path()));
|
||||
assert_eq!(user.finished_indic_queue.len(), 1);
|
||||
let finished_indication = user.finished_indic_queue.pop_front().unwrap();
|
||||
assert_eq!(finished_indication.id, transaction_id);
|
||||
assert_eq!(finished_indication.condition_code, ConditionCode::CancelRequestReceived);
|
||||
assert_eq!(finished_indication.delivery_code, DeliveryCode::Incomplete);
|
||||
assert_eq!(finished_indication.file_status, FileStatus::DiscardDeliberately);
|
||||
}
|
||||
}
|
||||
|
||||
47
src/lib.rs
47
src/lib.rs
@@ -102,7 +102,7 @@ pub mod user;
|
||||
|
||||
use crate::time::Countdown;
|
||||
use core::{cell::RefCell, fmt::Debug, hash::Hash};
|
||||
use crc::{CRC_32_ISCSI, CRC_32_ISO_HDLC, Crc};
|
||||
use crc::{Crc, CRC_32_ISCSI, CRC_32_ISO_HDLC};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub use alloc_mod::*;
|
||||
@@ -111,8 +111,8 @@ use core::time::Duration;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use spacepackets::{
|
||||
cfdp::{
|
||||
ChecksumType, ConditionCode, FaultHandlerCode, PduType, TransmissionMode,
|
||||
pdu::{FileDirectiveType, PduError, PduHeader},
|
||||
ChecksumType, ConditionCode, FaultHandlerCode, PduType, TransmissionMode,
|
||||
},
|
||||
util::{UnsignedByteField, UnsignedEnum},
|
||||
};
|
||||
@@ -1009,11 +1009,11 @@ impl PduProvider for PduRawWithInfo<'_> {
|
||||
#[cfg(feature = "alloc")]
|
||||
pub mod alloc_mod {
|
||||
use spacepackets::cfdp::{
|
||||
PduType,
|
||||
pdu::{FileDirectiveType, PduError},
|
||||
PduType,
|
||||
};
|
||||
|
||||
use crate::{PacketTarget, PduProvider, PduRawWithInfo, determine_packet_target};
|
||||
use crate::{determine_packet_target, PacketTarget, PduProvider, PduRawWithInfo};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct PduOwnedWithInfo {
|
||||
@@ -1086,16 +1086,17 @@ pub(crate) mod tests {
|
||||
use alloc::{collections::VecDeque, string::String, vec::Vec};
|
||||
use spacepackets::{
|
||||
cfdp::{
|
||||
ChecksumType, ConditionCode, PduType, TransmissionMode,
|
||||
lv::Lv,
|
||||
pdu::{
|
||||
CommonPduConfig, FileDirectiveType, PduHeader,
|
||||
eof::EofPdu,
|
||||
file_data::FileDataPdu,
|
||||
finished::{DeliveryCode, FileStatus},
|
||||
metadata::{MetadataGenericParams, MetadataPduCreator},
|
||||
CommonPduConfig, FileDirectiveType, PduHeader,
|
||||
},
|
||||
ChecksumType, ConditionCode, PduType, TransmissionMode,
|
||||
},
|
||||
util::{UnsignedByteField, UnsignedByteFieldU8, UnsignedByteFieldU16, UnsignedEnum},
|
||||
util::{UnsignedByteField, UnsignedByteFieldU16, UnsignedByteFieldU8, UnsignedEnum},
|
||||
};
|
||||
use user::{CfdpUser, OwnedMetadataRecvdParams, TransactionFinishedParams};
|
||||
|
||||
@@ -1266,6 +1267,30 @@ pub(crate) mod tests {
|
||||
&& self.metadata_recv_queue.is_empty()
|
||||
&& self.file_seg_recvd_queue.is_empty()
|
||||
}
|
||||
|
||||
pub fn verify_finished_indication_retained(
|
||||
&mut self,
|
||||
delivery_code: DeliveryCode,
|
||||
cond_code: ConditionCode,
|
||||
id: TransactionId,
|
||||
) {
|
||||
self.verify_finished_indication(delivery_code, cond_code, id, FileStatus::Retained);
|
||||
}
|
||||
|
||||
pub fn verify_finished_indication(
|
||||
&mut self,
|
||||
delivery_code: DeliveryCode,
|
||||
cond_code: ConditionCode,
|
||||
id: TransactionId,
|
||||
file_status: FileStatus,
|
||||
) {
|
||||
assert_eq!(self.finished_indic_queue.len(), 1);
|
||||
let finished_indication = self.finished_indic_queue.pop_front().unwrap();
|
||||
assert_eq!(finished_indication.id, id);
|
||||
assert_eq!(finished_indication.condition_code, cond_code);
|
||||
assert_eq!(finished_indication.delivery_code, delivery_code);
|
||||
assert_eq!(finished_indication.file_status, file_status);
|
||||
}
|
||||
}
|
||||
|
||||
impl CfdpUser for TestCfdpUser {
|
||||
@@ -1706,11 +1731,9 @@ pub(crate) mod tests {
|
||||
);
|
||||
let cfg_0 = remote_cfg_provider.get(REMOTE_ID.value()).unwrap();
|
||||
assert_eq!(cfg_0.entity_id, REMOTE_ID.into());
|
||||
assert!(
|
||||
remote_cfg_provider
|
||||
.add_config(&remote_entity_cfg_2)
|
||||
.unwrap()
|
||||
);
|
||||
assert!(remote_cfg_provider
|
||||
.add_config(&remote_entity_cfg_2)
|
||||
.unwrap());
|
||||
assert_eq!(remote_cfg_provider.0.len(), 2);
|
||||
let cfg_1 = remote_cfg_provider.get(LOCAL_ID.value()).unwrap();
|
||||
assert_eq!(cfg_1.entity_id, LOCAL_ID.into());
|
||||
|
||||
@@ -43,40 +43,40 @@ use core::{
|
||||
};
|
||||
|
||||
use spacepackets::{
|
||||
ByteConversionError,
|
||||
cfdp::{
|
||||
ConditionCode, Direction, LargeFileFlag, PduType, SegmentMetadataFlag, SegmentationControl,
|
||||
TransactionStatus, TransmissionMode,
|
||||
lv::Lv,
|
||||
pdu::{
|
||||
CfdpPdu, CommonPduConfig, FileDirectiveType, PduError, PduHeader, WritablePduPacket,
|
||||
ack::AckPdu,
|
||||
eof::EofPdu,
|
||||
file_data::{
|
||||
FileDataPduCreatorWithReservedDatafield,
|
||||
calculate_max_file_seg_len_for_max_packet_len_and_pdu_header,
|
||||
FileDataPduCreatorWithReservedDatafield,
|
||||
},
|
||||
finished::{DeliveryCode, FileStatus, FinishedPduReader},
|
||||
metadata::{MetadataGenericParams, MetadataPduCreator},
|
||||
nak::NakPduReader,
|
||||
CfdpPdu, CommonPduConfig, FileDirectiveType, PduError, PduHeader, WritablePduPacket,
|
||||
},
|
||||
ConditionCode, Direction, LargeFileFlag, PduType, SegmentMetadataFlag, SegmentationControl,
|
||||
TransactionStatus, TransmissionMode,
|
||||
},
|
||||
util::{UnsignedByteField, UnsignedEnum},
|
||||
ByteConversionError,
|
||||
};
|
||||
|
||||
use spacepackets::seq_count::SequenceCounter;
|
||||
|
||||
use crate::{
|
||||
DummyPduProvider, EntityType, GenericSendError, PduProvider, PositiveAckParams, TimerCreator,
|
||||
time::Countdown,
|
||||
time::Countdown, DummyPduProvider, EntityType, GenericSendError, PduProvider,
|
||||
PositiveAckParams, TimerCreator,
|
||||
};
|
||||
|
||||
use super::{
|
||||
LocalEntityConfig, PacketTarget, PduSendProvider, RemoteConfigStore, RemoteEntityConfig, State,
|
||||
TransactionId, UserFaultHook,
|
||||
filestore::{FilestoreError, VirtualFilestore},
|
||||
request::{ReadablePutRequest, StaticPutRequestCacher},
|
||||
user::{CfdpUser, TransactionFinishedParams},
|
||||
LocalEntityConfig, PacketTarget, PduSendProvider, RemoteConfigStore, RemoteEntityConfig, State,
|
||||
TransactionId, UserFaultHook,
|
||||
};
|
||||
|
||||
/// This enumeration models the different transaction steps of the source entity handler.
|
||||
@@ -93,7 +93,6 @@ pub enum TransactionStep {
|
||||
SendingEof = 6,
|
||||
WaitingForEofAck = 7,
|
||||
WaitingForFinished = 8,
|
||||
//SendingAckOfFinished = 9,
|
||||
NoticeOfCompletion = 10,
|
||||
}
|
||||
|
||||
@@ -272,14 +271,14 @@ pub struct SourceHandler<
|
||||
}
|
||||
|
||||
impl<
|
||||
PduSender: PduSendProvider,
|
||||
UserFaultHookInstance: UserFaultHook,
|
||||
Vfs: VirtualFilestore,
|
||||
RemoteConfigStoreInstance: RemoteConfigStore,
|
||||
TimerCreatorInstance: TimerCreator<Countdown = CountdownInstance>,
|
||||
CountdownInstance: Countdown,
|
||||
SequenceCounterInstance: SequenceCounter,
|
||||
>
|
||||
PduSender: PduSendProvider,
|
||||
UserFaultHookInstance: UserFaultHook,
|
||||
Vfs: VirtualFilestore,
|
||||
RemoteConfigStoreInstance: RemoteConfigStore,
|
||||
TimerCreatorInstance: TimerCreator<Countdown = CountdownInstance>,
|
||||
CountdownInstance: Countdown,
|
||||
SequenceCounterInstance: SequenceCounter,
|
||||
>
|
||||
SourceHandler<
|
||||
PduSender,
|
||||
UserFaultHookInstance,
|
||||
@@ -1184,11 +1183,11 @@ mod tests {
|
||||
use rand::Rng;
|
||||
use spacepackets::{
|
||||
cfdp::{
|
||||
ChecksumType, CrcFlag,
|
||||
pdu::{
|
||||
file_data::FileDataPdu, finished::FinishedPduCreator, metadata::MetadataPduReader,
|
||||
nak::NakPduCreator,
|
||||
},
|
||||
ChecksumType, CrcFlag,
|
||||
},
|
||||
util::UnsignedByteFieldU16,
|
||||
};
|
||||
@@ -1196,14 +1195,14 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
CRC_32, FaultHandler, IndicationConfig, PduRawWithInfo, RemoteConfigStoreStd,
|
||||
filestore::NativeFilestore,
|
||||
request::PutRequestOwned,
|
||||
source::TransactionStep,
|
||||
tests::{
|
||||
SentPdu, TestCfdpSender, TestCfdpUser, TestCheckTimer, TestCheckTimerCreator,
|
||||
TestFaultHandler, TimerExpiryControl, basic_remote_cfg_table,
|
||||
basic_remote_cfg_table, SentPdu, TestCfdpSender, TestCfdpUser, TestCheckTimer,
|
||||
TestCheckTimerCreator, TestFaultHandler, TimerExpiryControl,
|
||||
},
|
||||
FaultHandler, IndicationConfig, PduRawWithInfo, RemoteConfigStoreStd, CRC_32,
|
||||
};
|
||||
use spacepackets::seq_count::SequenceCounterSimple;
|
||||
|
||||
@@ -1687,14 +1686,20 @@ mod tests {
|
||||
)
|
||||
.expect("creating put request failed");
|
||||
let mut user = tb.create_user(0, file_size);
|
||||
let transaction_info =
|
||||
let transfer_info =
|
||||
tb.common_file_transfer_init_with_metadata_check(&mut user, put_request, file_size);
|
||||
tb.common_eof_pdu_check(
|
||||
&mut user,
|
||||
transaction_info.closure_requested,
|
||||
transfer_info.closure_requested,
|
||||
EofParams::new_success(file_size, CRC_32.digest().finalize()),
|
||||
1,
|
||||
);
|
||||
user.verify_finished_indication(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::NoError,
|
||||
transfer_info.id,
|
||||
FileStatus::Unreported
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1827,7 +1832,12 @@ mod tests {
|
||||
EofParams::new_success(file_size, CRC_32.digest().finalize()),
|
||||
1,
|
||||
);
|
||||
tb.finish_handling(&mut user, &transaction_info)
|
||||
tb.finish_handling(&mut user, &transaction_info);
|
||||
user.verify_finished_indication_retained(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::NoError,
|
||||
transaction_info.id,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2011,11 +2021,10 @@ mod tests {
|
||||
let fd_pdu = FileDataPdu::from_bytes(&next_packet.raw_pdu).unwrap();
|
||||
assert_eq!(fd_pdu.file_data(), &rand_data[0..first_chunk.len()]);
|
||||
let expected_id = tb.handler.transaction_id().unwrap();
|
||||
assert!(
|
||||
tb.handler
|
||||
.cancel_request(&mut user, &expected_id)
|
||||
.expect("cancellation failed")
|
||||
);
|
||||
assert!(tb
|
||||
.handler
|
||||
.cancel_request(&mut user, &expected_id)
|
||||
.expect("cancellation failed"));
|
||||
assert_eq!(tb.handler.state(), State::Idle);
|
||||
assert_eq!(tb.handler.step(), TransactionStep::Idle);
|
||||
let next_packet = tb.get_next_sent_pdu().unwrap();
|
||||
@@ -2071,6 +2080,11 @@ mod tests {
|
||||
tb.acknowledge_eof_pdu(&mut user, &transfer_info);
|
||||
tb.finish_handling(&mut user, &transfer_info);
|
||||
tb.common_finished_pdu_ack_check();
|
||||
user.verify_finished_indication_retained(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::NoError,
|
||||
transfer_info.id,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2115,6 +2129,11 @@ mod tests {
|
||||
tb.acknowledge_eof_pdu(&mut user, &transfer_info);
|
||||
tb.finish_handling(&mut user, &transfer_info);
|
||||
tb.common_finished_pdu_ack_check();
|
||||
user.verify_finished_indication_retained(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::NoError,
|
||||
transfer_info.id,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2279,5 +2298,10 @@ mod tests {
|
||||
tb.acknowledge_eof_pdu(&mut user, &transfer_info);
|
||||
tb.finish_handling(&mut user, &transfer_info);
|
||||
tb.common_finished_pdu_ack_check();
|
||||
user.verify_finished_indication_retained(
|
||||
DeliveryCode::Complete,
|
||||
ConditionCode::NoError,
|
||||
transfer_info.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user