add test run config
Rust/spacepackets/pipeline/pr-main This commit looks good Details
Rust/spacepackets/pipeline/head This commit looks good Details

This commit is contained in:
Robin Müller 2023-05-30 11:09:41 +02:00
parent 44223c1c0f
commit 5c3c9a9bde
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 89 additions and 15 deletions

View File

@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
<option name="command" value="test" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="emulateTerminal" value="false" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="true" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>

View File

@ -15,6 +15,8 @@ pub enum RecordContinuationState {
StartAndEnd = 0b11,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SegmentMetadata<'seg_meta> {
record_continuation_state: RecordContinuationState,
seg_metadata_len: u8,
@ -41,8 +43,11 @@ impl SegmentMetadata<'_> {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct FileDataPdu<'seg_meta, 'file_data> {
pdu_header: PduHeader,
#[cfg_attr(feature = "serde", serde(borrow))]
segment_metadata: Option<SegmentMetadata<'seg_meta>>,
offset: u64,
file_data: &'file_data [u8],
@ -101,6 +106,18 @@ impl<'seg_meta, 'file_data> FileDataPdu<'seg_meta, 'file_data> {
len
}
pub fn offset(&self) -> u64 {
self.offset
}
pub fn file_data(&self) -> &'file_data [u8] {
self.file_data
}
pub fn seg_metadata(&self) -> Option<&SegmentMetadata> {
self.segment_metadata.as_ref()
}
pub fn write_to_bytes(&self, buf: &mut [u8]) -> Result<usize, PduError> {
if buf.len() < self.written_len() {
return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch {
@ -130,8 +147,21 @@ impl<'seg_meta, 'file_data> FileDataPdu<'seg_meta, 'file_data> {
#[cfg(test)]
mod tests {
use crate::cfdp::pdu::file_data::FileDataPdu;
use crate::cfdp::pdu::{CommonPduConfig, PduHeader};
use crate::util::UbfU8;
#[test]
fn test_basic() {
let src_id = UbfU8::new(1);
let dest_id = UbfU8::new(2);
let transaction_seq_num = UbfU8::new(3);
let common_conf =
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num).unwrap();
let pdu_header = PduHeader::new_for_file_data_default(common_conf, 0);
let file_data: [u8; 4] = [1, 2, 3, 4];
let fd_pdu = FileDataPdu::new_no_seg_metadata(pdu_header, 10, &file_data);
assert_eq!(fd_pdu.file_data(), file_data);
assert_eq!(fd_pdu.offset(), 10);
}
}
}

View File

@ -47,7 +47,7 @@ pub fn build_metadata_opts_from_vec(
/// Helper structure to loop through all options of a metadata PDU. It should be noted that
/// iterators in Rust are not fallible, but the TLV creation can fail, for example if the raw TLV
/// data in invalid for some reason. In that case, the iterator will yield [None] because there
/// data is invalid for some reason. In that case, the iterator will yield [None] because there
/// is no way to recover from this.
///
/// The user can accumulate the length of all TLVs yielded by the iterator and compare it against

View File

@ -227,8 +227,43 @@ impl PduHeader {
seg_metadata_flag: SegmentMetadataFlag,
seg_ctrl: SegmentationControl,
) -> Self {
PduHeader {
pdu_type: PduType::FileData,
Self::new_generic(
PduType::FileData,
pdu_conf,
pdu_datafield_len,
seg_metadata_flag,
seg_ctrl,
)
}
pub fn new_for_file_data_default(pdu_conf: CommonPduConfig, pdu_datafield_len: u16) -> Self {
Self::new_generic(
PduType::FileData,
pdu_conf,
pdu_datafield_len,
SegmentMetadataFlag::NotPresent,
SegmentationControl::NoRecordBoundaryPreservation,
)
}
pub fn new_no_file_data(pdu_conf: CommonPduConfig, pdu_datafield_len: u16) -> Self {
Self::new_generic(
PduType::FileDirective,
pdu_conf,
pdu_datafield_len,
SegmentMetadataFlag::NotPresent,
SegmentationControl::NoRecordBoundaryPreservation,
)
}
pub fn new_generic(
pdu_type: PduType,
pdu_conf: CommonPduConfig,
pdu_datafield_len: u16,
seg_metadata_flag: SegmentMetadataFlag,
seg_ctrl: SegmentationControl,
) -> Self {
Self {
pdu_type,
pdu_conf,
seg_metadata_flag,
seg_ctrl,
@ -236,16 +271,6 @@ impl PduHeader {
}
}
pub fn new_no_file_data(pdu_conf: CommonPduConfig, pdu_datafield_len: u16) -> Self {
PduHeader {
pdu_type: PduType::FileDirective,
pdu_conf,
seg_metadata_flag: SegmentMetadataFlag::NotPresent,
seg_ctrl: SegmentationControl::NoRecordBoundaryPreservation,
pdu_datafield_len,
}
}
/// Returns only the length of the PDU header when written to a raw buffer.
pub fn header_len(&self) -> usize {
FIXED_HEADER_LEN