PX4 Firmware
PX4 Autopilot Software http://px4.io
MavlinkFtpTest Class Reference

#include <mavlink_ftp_test.h>

Inheritance diagram for MavlinkFtpTest:
Collaboration diagram for MavlinkFtpTest:

Classes

struct  BurstInfo
 Worker data for stream handler. More...
 
struct  DownloadTestCase
 A single download test case. More...
 

Public Member Functions

 MavlinkFtpTest ()
 
virtual ~MavlinkFtpTest ()=default
 
virtual bool run_tests (void)
 Runs all the unit tests. More...
 
 MavlinkFtpTest (const MavlinkFtpTest &)
 
MavlinkFtpTestoperator= (const MavlinkFtpTest &)
 
- Public Member Functions inherited from UnitTest
 UnitTest ()=default
 
virtual ~UnitTest ()=default
 
void print_results ()
 Prints results from running of unit tests. More...
 

Static Public Member Functions

static void receive_message_handler_generic (const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data)
 Static method used as callback from MavlinkFTP for generic use. More...
 
static void receive_message_handler_burst (const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data)
 Static method used as callback from MavlinkFTP for stream download testing. More...
 

Static Public Attributes

static const uint8_t serverSystemId = 50
 System ID for server. More...
 
static const uint8_t serverComponentId = 1
 Component ID for server. More...
 
static const uint8_t serverChannel = 0
 Channel to send to. More...
 
static const uint8_t clientSystemId = 1
 System ID for client. More...
 
static const uint8_t clientComponentId = 0
 Component ID for client. More...
 

Private Types

enum  { burst_state_first_ack, burst_state_last_ack, burst_state_nak_eof, burst_state_complete }
 States for stream download handler. More...
 

Private Member Functions

virtual void _init (void)
 Called before every test to initialize the FTP Server. More...
 
virtual void _cleanup (void)
 Called after every test to take down the FTP Server. More...
 
bool _ack_test (void)
 Tests for correct behavior of an Ack response. More...
 
bool _bad_opcode_test (void)
 Tests for correct response to an invalid opcpde. More...
 
bool _bad_datasize_test (void)
 Tests for correct reponse to a payload which an invalid data size field. More...
 
bool _list_test (void)
 
bool _list_eof_test (void)
 Tests for correct response to a List command on a valid directory, but with an offset that is beyond the last directory entry. More...
 
bool _open_badfile_test (void)
 Tests for correct response to an Open command on a file which does not exist. More...
 
bool _open_terminate_test (void)
 Tests for correct reponse to an Open command on a file, followed by Terminate. More...
 
bool _terminate_badsession_test (void)
 Tests for correct reponse to a Terminate command on an invalid session. More...
 
bool _read_test (void)
 Tests for correct reponse to a Read command on an open session. More...
 
bool _read_badsession_test (void)
 Tests for correct reponse to a Read command on an invalid session. More...
 
bool _burst_test (void)
 Tests for correct reponse to a Read command on an open session. More...
 
bool _removedirectory_test (void)
 
bool _createdirectory_test (void)
 
bool _removefile_test (void)
 
void _receive_message_handler_generic (const mavlink_file_transfer_protocol_t *ftp_req)
 
void _setup_ftp_msg (const MavlinkFTP::PayloadHeader *payload_header, uint8_t size, const uint8_t *data, mavlink_message_t *msg)
 Initializes an FTP message into a mavlink message. More...
 
bool _decode_message (const mavlink_file_transfer_protocol_t *ftp_msg, const MavlinkFTP::PayloadHeader **payload)
 Decode and validate the incoming message. More...
 
bool _send_receive_msg (MavlinkFTP::PayloadHeader *payload_header, uint8_t size, const uint8_t *data, const MavlinkFTP::PayloadHeader **payload_reply)
 Sends the specified FTP message to the server and returns response. More...
 
void _cleanup_microsd (void)
 Cleans up an files created on microsd during testing. More...
 
bool _receive_message_handler_burst (const mavlink_file_transfer_protocol_t *ftp_req, BurstInfo *burst_info)
 

Private Attributes

MavlinkFTP_ftp_server
 
uint16_t _expected_seq_number
 
mavlink_file_transfer_protocol_t _reply_msg
 

Static Private Attributes

static const DownloadTestCase _rgDownloadTestCases []
 The set of test cases for download testing. More...
 
static const char _unittest_microsd_dir [] = PX4_STORAGEDIR "/ftp_unit_test_dir"
 
static const char _unittest_microsd_file [] = PX4_STORAGEDIR "/ftp_unit_test_dir/file"
 

Additional Inherited Members

- Protected Member Functions inherited from UnitTest
void _print_assert (const char *msg, const char *test, const char *file, int line)
 
void _print_compare (const char *msg, const char *v1_text, int v1, const char *v2_text, int v2, const char *file, int line)
 
- Protected Attributes inherited from UnitTest
int _tests_run {0}
 The number of individual unit tests run. More...
 
int _tests_failed {0}
 The number of unit tests which failed. More...
 
int _tests_passed {0}
 The number of unit tests which passed. More...
 
int _assertions {0}
 Total number of assertions tested by all unit tests. More...
 

Detailed Description

Definition at line 43 of file mavlink_ftp_test.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

States for stream download handler.

Enumerator
burst_state_first_ack 
burst_state_last_ack 
burst_state_nak_eof 
burst_state_complete 

Definition at line 116 of file mavlink_ftp_test.h.

Constructor & Destructor Documentation

◆ MavlinkFtpTest() [1/2]

MavlinkFtpTest::MavlinkFtpTest ( )

Definition at line 61 of file mavlink_ftp_test.cpp.

◆ ~MavlinkFtpTest()

virtual MavlinkFtpTest::~MavlinkFtpTest ( )
virtualdefault

◆ MavlinkFtpTest() [2/2]

MavlinkFtpTest::MavlinkFtpTest ( const MavlinkFtpTest )

Member Function Documentation

◆ _ack_test()

bool MavlinkFtpTest::_ack_test ( void  )
private

Tests for correct behavior of an Ack response.

Definition at line 87 of file mavlink_ftp_test.cpp.

References _send_receive_msg(), MavlinkFTP::kCmdNone, MavlinkFTP::kRspAck, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _bad_datasize_test()

bool MavlinkFtpTest::_bad_datasize_test ( void  )
private

Tests for correct reponse to a payload which an invalid data size field.

Definition at line 134 of file mavlink_ftp_test.cpp.

References _decode_message(), _ftp_server, _reply_msg, _setup_ftp_msg(), MavlinkFTP::handle_message(), MavlinkFTP::kCmdListDirectory, MavlinkFTP::kErrInvalidDataSize, MavlinkFTP::kRspNak, msg, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _bad_opcode_test()

bool MavlinkFtpTest::_bad_opcode_test ( void  )
private

Tests for correct response to an invalid opcpde.

Definition at line 110 of file mavlink_ftp_test.cpp.

References _send_receive_msg(), MavlinkFTP::kErrUnknownCommand, MavlinkFTP::kRspNak, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _burst_test()

bool MavlinkFtpTest::_burst_test ( void  )
private

Tests for correct reponse to a Read command on an open session.

Definition at line 508 of file mavlink_ftp_test.cpp.

References _ftp_server, _rgDownloadTestCases, _send_receive_msg(), _setup_ftp_msg(), MavlinkFtpTest::BurstInfo::burst_state, burst_state_complete, burst_state_first_ack, fd, MavlinkFtpTest::BurstInfo::file_bytes, MavlinkFtpTest::BurstInfo::file_size, MavlinkFtpTest::BurstInfo::ftp_test_class, MavlinkFTP::handle_message(), hrt_abstime, MavlinkFTP::kCmdBurstReadFile, MavlinkFTP::kCmdOpenFileRO, MavlinkFTP::kCmdTerminateSession, MavlinkFTP::kRspAck, msg, read(), receive_message_handler_burst(), receive_message_handler_generic(), MavlinkFTP::send(), MavlinkFTP::set_unittest_worker(), MavlinkFtpTest::BurstInfo::single_packet_file, lps25h::test(), ut_assert, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _cleanup()

void MavlinkFtpTest::_cleanup ( void  )
privatevirtual

Called after every test to take down the FTP Server.

Reimplemented from UnitTest.

Definition at line 79 of file mavlink_ftp_test.cpp.

References _cleanup_microsd(), and _ftp_server.

Here is the call graph for this function:

◆ _cleanup_microsd()

void MavlinkFtpTest::_cleanup_microsd ( void  )
private

Cleans up an files created on microsd during testing.

Definition at line 941 of file mavlink_ftp_test.cpp.

References _unittest_microsd_dir, and _unittest_microsd_file.

Referenced by _cleanup(), and _init().

Here is the caller graph for this function:

◆ _createdirectory_test()

bool MavlinkFtpTest::_createdirectory_test ( void  )
private

Definition at line 696 of file mavlink_ftp_test.cpp.

References _send_receive_msg(), _unittest_microsd_dir, MavlinkFTP::kCmdCreateDirectory, MavlinkFTP::kErrFailErrno, MavlinkFTP::kErrFailFileExists, MavlinkFTP::kRspAck, MavlinkFTP::kRspNak, lps25h::test(), and ut_compare.

Here is the call graph for this function:

◆ _decode_message()

bool MavlinkFtpTest::_decode_message ( const mavlink_file_transfer_protocol_t *  ftp_msg,
const MavlinkFTP::PayloadHeader **  payload 
)
private

Decode and validate the incoming message.

Parameters
ftp_msgIncoming FTP message
payloadPayload inside FTP message response

Definition at line 877 of file mavlink_ftp_test.cpp.

References _expected_seq_number, clientComponentId, clientSystemId, and ut_compare.

Referenced by _bad_datasize_test(), _receive_message_handler_burst(), and _send_receive_msg().

Here is the caller graph for this function:

◆ _init()

void MavlinkFtpTest::_init ( void  )
privatevirtual

Called before every test to initialize the FTP Server.

Reimplemented from UnitTest.

Definition at line 69 of file mavlink_ftp_test.cpp.

References _cleanup_microsd(), _expected_seq_number, _ftp_server, receive_message_handler_generic(), and MavlinkFTP::set_unittest_worker().

Here is the call graph for this function:

◆ _list_eof_test()

bool MavlinkFtpTest::_list_eof_test ( void  )
private

Tests for correct response to a List command on a valid directory, but with an offset that is beyond the last directory entry.

Definition at line 248 of file mavlink_ftp_test.cpp.

References _send_receive_msg(), MavlinkFTP::kCmdListDirectory, MavlinkFTP::kErrEOF, MavlinkFTP::kRspNak, and ut_compare.

Here is the call graph for this function:

◆ _list_test()

bool MavlinkFtpTest::_list_test ( void  )
private

< Directory to run List command on

< Expected response entries from List command

< Number of directories that should be returned

< true: List command should succeed, false: List command should fail

Definition at line 161 of file mavlink_ftp_test.cpp.

References _send_receive_msg(), MavlinkFTP::kCmdListDirectory, MavlinkFTP::kErrFailErrno, MavlinkFTP::kRspAck, MavlinkFTP::kRspNak, PX4_MAVLINK_TEST_DATA_DIR, lps25h::test(), ut_assert, and ut_compare.

Here is the call graph for this function:

◆ _open_badfile_test()

bool MavlinkFtpTest::_open_badfile_test ( void  )
private

Tests for correct response to an Open command on a file which does not exist.

Definition at line 274 of file mavlink_ftp_test.cpp.

References _send_receive_msg(), MavlinkFTP::kCmdOpenFileRO, MavlinkFTP::kErrFailErrno, MavlinkFTP::kRspNak, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _open_terminate_test()

bool MavlinkFtpTest::_open_terminate_test ( void  )
private

Tests for correct reponse to an Open command on a file, followed by Terminate.

Definition at line 300 of file mavlink_ftp_test.cpp.

References _rgDownloadTestCases, _send_receive_msg(), MavlinkFTP::kCmdOpenFileRO, MavlinkFTP::kCmdTerminateSession, MavlinkFTP::kRspAck, lps25h::test(), and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_badsession_test()

bool MavlinkFtpTest::_read_badsession_test ( void  )
private

Tests for correct reponse to a Read command on an invalid session.

Definition at line 600 of file mavlink_ftp_test.cpp.

References _rgDownloadTestCases, _send_receive_msg(), MavlinkFtpTest::DownloadTestCase::file, file, MavlinkFTP::kCmdOpenFileRO, MavlinkFTP::kCmdReadFile, MavlinkFTP::kErrInvalidSession, MavlinkFTP::kRspAck, MavlinkFTP::kRspNak, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_test()

bool MavlinkFtpTest::_read_test ( void  )
private

Tests for correct reponse to a Read command on an open session.

Definition at line 389 of file mavlink_ftp_test.cpp.

References _rgDownloadTestCases, _send_receive_msg(), fd, MavlinkFTP::kCmdOpenFileRO, MavlinkFTP::kCmdReadFile, MavlinkFTP::kCmdTerminateSession, MavlinkFTP::kRspAck, MavlinkFTP::kRspNak, read(), lps25h::test(), ut_assert, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _receive_message_handler_burst()

bool MavlinkFtpTest::_receive_message_handler_burst ( const mavlink_file_transfer_protocol_t *  ftp_req,
BurstInfo burst_info 
)
private

Definition at line 822 of file mavlink_ftp_test.cpp.

References _decode_message(), _ftp_server, MavlinkFtpTest::BurstInfo::burst_state, burst_state_complete, burst_state_first_ack, burst_state_last_ack, burst_state_nak_eof, MavlinkFtpTest::BurstInfo::file_bytes, MavlinkFtpTest::BurstInfo::file_size, MavlinkFTP::get_size(), hrt_abstime, MavlinkFTP::kRspAck, MavlinkFTP::send(), MavlinkFtpTest::BurstInfo::single_packet_file, ut_assert, and ut_compare.

Referenced by receive_message_handler_burst().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _receive_message_handler_generic()

void MavlinkFtpTest::_receive_message_handler_generic ( const mavlink_file_transfer_protocol_t *  ftp_req)
private

Definition at line 808 of file mavlink_ftp_test.cpp.

References _reply_msg.

◆ _removedirectory_test()

bool MavlinkFtpTest::_removedirectory_test ( void  )
private

Definition at line 640 of file mavlink_ftp_test.cpp.

References _send_receive_msg(), _unittest_microsd_dir, _unittest_microsd_file, fd, MavlinkFTP::kCmdRemoveDirectory, MavlinkFTP::kErrFailErrno, MavlinkFTP::kRspAck, MavlinkFTP::kRspNak, PX4_MAVLINK_TEST_DATA_DIR, lps25h::test(), ut_assert, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _removefile_test()

bool MavlinkFtpTest::_removefile_test ( void  )
private

Definition at line 747 of file mavlink_ftp_test.cpp.

References _rgDownloadTestCases, _send_receive_msg(), _unittest_microsd_dir, _unittest_microsd_file, fd, MavlinkFtpTest::DownloadTestCase::file, file, MavlinkFTP::kCmdRemoveFile, MavlinkFTP::kErrFailErrno, MavlinkFTP::kRspAck, MavlinkFTP::kRspNak, lps25h::test(), ut_assert, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _send_receive_msg()

bool MavlinkFtpTest::_send_receive_msg ( MavlinkFTP::PayloadHeader *  payload_header,
uint8_t  size,
const uint8_t *  data,
const MavlinkFTP::PayloadHeader **  payload_reply 
)
private

Sends the specified FTP message to the server and returns response.

Parameters
payload_headerFTP payload header
sizesize in bytes of data
dataData to start into FTP message payload
payload_replyPayload inside FTP message response

Definition at line 928 of file mavlink_ftp_test.cpp.

References _decode_message(), _ftp_server, _reply_msg, _setup_ftp_msg(), MavlinkFTP::handle_message(), and msg.

Referenced by _ack_test(), _bad_opcode_test(), _burst_test(), _createdirectory_test(), _list_eof_test(), _list_test(), _open_badfile_test(), _open_terminate_test(), _read_badsession_test(), _read_test(), _removedirectory_test(), _removefile_test(), and _terminate_badsession_test().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setup_ftp_msg()

void MavlinkFtpTest::_setup_ftp_msg ( const MavlinkFTP::PayloadHeader *  payload_header,
uint8_t  size,
const uint8_t *  data,
mavlink_message_t *  msg 
)
private

Initializes an FTP message into a mavlink message.

Parameters
payload_headerFTP payload header
sizesize in bytes of data
dataData to start into FTP message payload
msgReturned mavlink message

Definition at line 897 of file mavlink_ftp_test.cpp.

References _expected_seq_number, clientComponentId, clientSystemId, serverComponentId, and serverSystemId.

Referenced by _bad_datasize_test(), _burst_test(), and _send_receive_msg().

Here is the caller graph for this function:

◆ _terminate_badsession_test()

bool MavlinkFtpTest::_terminate_badsession_test ( void  )
private

Tests for correct reponse to a Terminate command on an invalid session.

Definition at line 348 of file mavlink_ftp_test.cpp.

References _rgDownloadTestCases, _send_receive_msg(), MavlinkFtpTest::DownloadTestCase::file, file, MavlinkFTP::kCmdOpenFileRO, MavlinkFTP::kCmdTerminateSession, MavlinkFTP::kErrInvalidSession, MavlinkFTP::kRspAck, MavlinkFTP::kRspNak, and ut_compare.

Referenced by run_tests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

MavlinkFtpTest& MavlinkFtpTest::operator= ( const MavlinkFtpTest )

◆ receive_message_handler_burst()

void MavlinkFtpTest::receive_message_handler_burst ( const mavlink_file_transfer_protocol_t *  ftp_req,
void *  worker_data 
)
static

Static method used as callback from MavlinkFTP for stream download testing.

This method will be called by MavlinkFTP when it needs to send a message out on Mavlink.

Definition at line 816 of file mavlink_ftp_test.cpp.

References _receive_message_handler_burst(), and MavlinkFtpTest::BurstInfo::ftp_test_class.

Referenced by _burst_test().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ receive_message_handler_generic()

void MavlinkFtpTest::receive_message_handler_generic ( const mavlink_file_transfer_protocol_t *  ftp_req,
void *  worker_data 
)
static

Static method used as callback from MavlinkFTP for generic use.

This method will be called by MavlinkFTP when it needs to send a message out on Mavlink.

Definition at line 803 of file mavlink_ftp_test.cpp.

Referenced by _burst_test(), and _init().

Here is the caller graph for this function:

◆ run_tests()

bool MavlinkFtpTest::run_tests ( void  )
virtual

Runs all the unit tests.

Implements UnitTest.

Definition at line 948 of file mavlink_ftp_test.cpp.

References _ack_test(), _bad_datasize_test(), _bad_opcode_test(), _burst_test(), _open_badfile_test(), _open_terminate_test(), _read_badsession_test(), _read_test(), _removedirectory_test(), _removefile_test(), _terminate_badsession_test(), UnitTest::_tests_failed, mavlink_ftp_test(), ut_declare_test, and ut_run_test.

Here is the call graph for this function:

Member Data Documentation

◆ _expected_seq_number

uint16_t MavlinkFtpTest::_expected_seq_number
private

Definition at line 126 of file mavlink_ftp_test.h.

Referenced by _decode_message(), _init(), and _setup_ftp_msg().

◆ _ftp_server

MavlinkFTP* MavlinkFtpTest::_ftp_server
private

◆ _reply_msg

mavlink_file_transfer_protocol_t MavlinkFtpTest::_reply_msg
private

◆ _rgDownloadTestCases

const MavlinkFtpTest::DownloadTestCase MavlinkFtpTest::_rgDownloadTestCases
staticprivate
Initial value:
= {
{ PX4_MAVLINK_TEST_DATA_DIR "/unit_test_data/mavlink_tests/test_238.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) - 1, true, false },
{ PX4_MAVLINK_TEST_DATA_DIR "/unit_test_data/mavlink_tests/test_239.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader), true, true },
{ PX4_MAVLINK_TEST_DATA_DIR "/unit_test_data/mavlink_tests/test_240.data", MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) + 1, false, false },
}

The set of test cases for download testing.

Test case file name for Read command. File are generated using mavlink_ftp_test_data.py.

Definition at line 113 of file mavlink_ftp_test.h.

Referenced by _burst_test(), _open_terminate_test(), _read_badsession_test(), _read_test(), _removefile_test(), and _terminate_badsession_test().

◆ _unittest_microsd_dir

const char MavlinkFtpTest::_unittest_microsd_dir = PX4_STORAGEDIR "/ftp_unit_test_dir"
staticprivate

◆ _unittest_microsd_file

const char MavlinkFtpTest::_unittest_microsd_file = PX4_STORAGEDIR "/ftp_unit_test_dir/file"
staticprivate

Definition at line 131 of file mavlink_ftp_test.h.

Referenced by _cleanup_microsd(), _removedirectory_test(), and _removefile_test().

◆ clientComponentId

const uint8_t MavlinkFtpTest::clientComponentId = 0
static

Component ID for client.

Definition at line 69 of file mavlink_ftp_test.h.

Referenced by _decode_message(), and _setup_ftp_msg().

◆ clientSystemId

const uint8_t MavlinkFtpTest::clientSystemId = 1
static

System ID for client.

Definition at line 68 of file mavlink_ftp_test.h.

Referenced by _decode_message(), and _setup_ftp_msg().

◆ serverChannel

const uint8_t MavlinkFtpTest::serverChannel = 0
static

Channel to send to.

Definition at line 66 of file mavlink_ftp_test.h.

Referenced by MavlinkFTP::_getServerChannel().

◆ serverComponentId

const uint8_t MavlinkFtpTest::serverComponentId = 1
static

Component ID for server.

Definition at line 65 of file mavlink_ftp_test.h.

Referenced by MavlinkFTP::_getServerComponentId(), and _setup_ftp_msg().

◆ serverSystemId

const uint8_t MavlinkFtpTest::serverSystemId = 50
static

System ID for server.

Definition at line 64 of file mavlink_ftp_test.h.

Referenced by MavlinkFTP::_getServerSystemId(), and _setup_ftp_msg().


The documentation for this class was generated from the following files: