PX4 Firmware
PX4 Autopilot Software http://px4.io
|
#include <mavlink_ftp_test.h>
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 &) | |
MavlinkFtpTest & | operator= (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... | |
Definition at line 43 of file mavlink_ftp_test.h.
|
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.
MavlinkFtpTest::MavlinkFtpTest | ( | ) |
Definition at line 61 of file mavlink_ftp_test.cpp.
|
virtualdefault |
MavlinkFtpTest::MavlinkFtpTest | ( | const MavlinkFtpTest & | ) |
|
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().
|
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().
|
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().
|
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().
|
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.
|
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().
|
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.
|
private |
Decode and validate the incoming message.
ftp_msg | Incoming FTP message |
payload | Payload 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().
|
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().
|
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.
|
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.
|
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().
|
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().
|
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().
|
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().
|
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().
|
private |
Definition at line 808 of file mavlink_ftp_test.cpp.
References _reply_msg.
|
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().
|
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().
|
private |
Sends the specified FTP message to the server and returns response.
payload_header | FTP payload header |
size | size in bytes of data |
data | Data to start into FTP message payload |
payload_reply | Payload 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().
|
private |
Initializes an FTP message into a mavlink message.
payload_header | FTP payload header |
size | size in bytes of data |
data | Data to start into FTP message payload |
msg | Returned 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().
|
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().
MavlinkFtpTest& MavlinkFtpTest::operator= | ( | const MavlinkFtpTest & | ) |
|
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().
|
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().
|
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.
|
private |
Definition at line 126 of file mavlink_ftp_test.h.
Referenced by _decode_message(), _init(), and _setup_ftp_msg().
|
private |
Definition at line 125 of file mavlink_ftp_test.h.
Referenced by _bad_datasize_test(), _burst_test(), _cleanup(), _init(), _receive_message_handler_burst(), and _send_receive_msg().
|
private |
Definition at line 128 of file mavlink_ftp_test.h.
Referenced by _bad_datasize_test(), _receive_message_handler_generic(), and _send_receive_msg().
|
staticprivate |
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().
|
staticprivate |
Definition at line 130 of file mavlink_ftp_test.h.
Referenced by _cleanup_microsd(), _createdirectory_test(), _removedirectory_test(), and _removefile_test().
|
staticprivate |
Definition at line 131 of file mavlink_ftp_test.h.
Referenced by _cleanup_microsd(), _removedirectory_test(), and _removefile_test().
|
static |
Component ID for client.
Definition at line 69 of file mavlink_ftp_test.h.
Referenced by _decode_message(), and _setup_ftp_msg().
|
static |
System ID for client.
Definition at line 68 of file mavlink_ftp_test.h.
Referenced by _decode_message(), and _setup_ftp_msg().
|
static |
Channel to send to.
Definition at line 66 of file mavlink_ftp_test.h.
Referenced by MavlinkFTP::_getServerChannel().
|
static |
Component ID for server.
Definition at line 65 of file mavlink_ftp_test.h.
Referenced by MavlinkFTP::_getServerComponentId(), and _setup_ftp_msg().
|
static |
System ID for server.
Definition at line 64 of file mavlink_ftp_test.h.
Referenced by MavlinkFTP::_getServerSystemId(), and _setup_ftp_msg().