mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-03-23 10:03:41 +08:00
refactor(mavlink): remove dead FTP unit test code
Remove the old MAVLINK_FTP_UNIT_TEST infrastructure that has been dead code for years (not enabled in any board config). This includes: - src/modules/mavlink/mavlink_tests/ directory (test suite, CMakeLists) - All #ifdef MAVLINK_FTP_UNIT_TEST blocks in mavlink_ftp.cpp - set_unittest_worker() callback mechanism in mavlink_ftp.h - Conditional uAvionix include in mavlink_bridge_header.h The test suite will be ported to GTest as a follow-up. Ref: https://github.com/PX4/PX4-Autopilot/issues/26738 Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
@@ -93,9 +93,7 @@ extern mavlink_status_t *mavlink_get_channel_status(uint8_t chan);
|
||||
extern mavlink_message_t *mavlink_get_channel_buffer(uint8_t chan);
|
||||
|
||||
#include <mavlink.h>
|
||||
#if !MAVLINK_FTP_UNIT_TEST
|
||||
#include <uAvionix.h>
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
@@ -75,49 +75,22 @@ MavlinkFTP::get_size()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
void
|
||||
MavlinkFTP::set_unittest_worker(ReceiveMessageFunc_t rcvMsgFunc, void *worker_data)
|
||||
{
|
||||
_utRcvMsgFunc = rcvMsgFunc;
|
||||
_worker_data = worker_data;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t
|
||||
MavlinkFTP::_getServerSystemId()
|
||||
{
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
// We use fake ids when unit testing
|
||||
return MavlinkFtpTest::serverSystemId;
|
||||
#else
|
||||
// Not unit testing, use the real thing
|
||||
return _mavlink.get_system_id();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t
|
||||
MavlinkFTP::_getServerComponentId()
|
||||
{
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
// We use fake ids when unit testing
|
||||
return MavlinkFtpTest::serverComponentId;
|
||||
#else
|
||||
// Not unit testing, use the real thing
|
||||
return _mavlink.get_component_id();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t
|
||||
MavlinkFTP::_getServerChannel()
|
||||
{
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
// We use fake ids when unit testing
|
||||
return MavlinkFtpTest::serverChannel;
|
||||
#else
|
||||
// Not unit testing, use the real thing
|
||||
return _mavlink.get_channel();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -173,11 +146,7 @@ MavlinkFTP::_process_request(
|
||||
if (payload->seq_number + 1 == last_payload->seq_number) {
|
||||
// this is the same request as the one we replied to last. It means the (n)ack got lost, and the GCS
|
||||
// resent the request
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
_utRcvMsgFunc(last_reply, _worker_data);
|
||||
#else
|
||||
mavlink_msg_file_transfer_protocol_send_struct(_mavlink.get_channel(), last_reply);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -332,12 +301,7 @@ MavlinkFTP::_reply(mavlink_file_transfer_protocol_t *ftp_req)
|
||||
|
||||
PX4_DEBUG("FTP: %s seq_number: %" PRIu16, payload->opcode == kRspAck ? "Ack" : "Nak", payload->seq_number);
|
||||
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
// Unit test hook is set, call that instead
|
||||
_utRcvMsgFunc(ftp_req, _worker_data);
|
||||
#else
|
||||
mavlink_msg_file_transfer_protocol_send_struct(_mavlink.get_channel(), ftp_req);
|
||||
#endif
|
||||
|
||||
}
|
||||
void MavlinkFTP::_constructPath(char *dst, int dst_len, const char *path) const
|
||||
@@ -1055,7 +1019,6 @@ void MavlinkFTP::send()
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef MAVLINK_FTP_UNIT_TEST
|
||||
// Skip send if not enough room
|
||||
unsigned max_bytes_to_send = _mavlink.get_free_tx_buf();
|
||||
PX4_DEBUG("MavlinkFTP::send max_bytes_to_send(%u) get_free_tx_buf(%u)", max_bytes_to_send, _mavlink.get_free_tx_buf());
|
||||
@@ -1064,8 +1027,6 @@ void MavlinkFTP::send()
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Send stream packets until buffer is full
|
||||
|
||||
bool more_data;
|
||||
@@ -1129,8 +1090,6 @@ void MavlinkFTP::send()
|
||||
_session_info.stream_download = false;
|
||||
|
||||
} else {
|
||||
#ifndef MAVLINK_FTP_UNIT_TEST
|
||||
|
||||
if (max_bytes_to_send < (get_size() * 2)) {
|
||||
more_data = false;
|
||||
|
||||
@@ -1142,14 +1101,10 @@ void MavlinkFTP::send()
|
||||
}
|
||||
|
||||
} else {
|
||||
#endif
|
||||
more_data = true;
|
||||
payload->burst_complete = false;
|
||||
#ifndef MAVLINK_FTP_UNIT_TEST
|
||||
max_bytes_to_send -= get_size();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
ftp_msg.target_system = _session_info.stream_target_system_id;
|
||||
|
||||
@@ -64,13 +64,6 @@ public:
|
||||
/// Handle possible FTP message
|
||||
void handle_message(const mavlink_message_t *msg);
|
||||
|
||||
typedef void (*ReceiveMessageFunc_t)(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data);
|
||||
|
||||
/// @brief Sets up the server to run in unit test mode.
|
||||
/// @param rcvmsgFunc Function which will be called to handle outgoing mavlink messages.
|
||||
/// @param worker_data Data to pass to worker
|
||||
void set_unittest_worker(ReceiveMessageFunc_t rcvMsgFunc, void *worker_data);
|
||||
|
||||
/// @brief This is the payload which is in mavlink_file_transfer_protocol_t.payload.
|
||||
/// This needs to be packed, because it's typecasted from mavlink_file_transfer_protocol_t.payload, which starts
|
||||
/// at a 3 byte offset, causing an unaligned access to seq_number and offset
|
||||
@@ -184,9 +177,6 @@ private:
|
||||
};
|
||||
struct SessionInfo _session_info {}; ///< Session info, fd=-1 for no active session
|
||||
|
||||
ReceiveMessageFunc_t _utRcvMsgFunc{}; ///< Unit test override for mavlink message sending
|
||||
void *_worker_data{nullptr}; ///< Additional parameter to _utRcvMsgFunc;
|
||||
|
||||
Mavlink &_mavlink;
|
||||
|
||||
/* do not allow copying this class */
|
||||
@@ -202,11 +192,7 @@ private:
|
||||
|
||||
// prepend a root directory to each file/dir access to avoid enumerating the full FS tree (e.g. on Linux).
|
||||
// Path traversal via ".." is rejected by _validatePath().
|
||||
#ifdef MAVLINK_FTP_UNIT_TEST
|
||||
static constexpr const char _root_dir[] = "";
|
||||
#else
|
||||
static constexpr const char _root_dir[] = PX4_ROOTFSDIR;
|
||||
#endif
|
||||
static constexpr const int _root_dir_len = sizeof(_root_dir) - 1;
|
||||
|
||||
bool _last_reply_valid = false;
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2015 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_module(
|
||||
MODULE modules__mavlink__mavlink_tests
|
||||
MAIN mavlink_tests
|
||||
STACK_MAIN 8192
|
||||
INCLUDES
|
||||
${MAVLINK_LIBRARY_DIR}
|
||||
${MAVLINK_LIBRARY_DIR}/${CONFIG_MAVLINK_DIALECT}
|
||||
COMPILE_FLAGS
|
||||
-DMAVLINK_FTP_UNIT_TEST
|
||||
#-DMAVLINK_FTP_DEBUG
|
||||
-DMavlinkStream=MavlinkStreamTest
|
||||
-DMavlinkFTP=MavlinkFTPTest
|
||||
-Wno-cast-align # TODO: fix and enable
|
||||
-Wno-address-of-packed-member # TODO: fix in c_library_v2
|
||||
-Wno-double-promotion # The fix has been proposed as PR upstream (2020-03-08)
|
||||
SRCS
|
||||
mavlink_tests.cpp
|
||||
mavlink_ftp_test.cpp
|
||||
../mavlink_stream.cpp
|
||||
../mavlink_ftp.cpp
|
||||
DEPENDS
|
||||
mavlink_c_generate
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,139 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/// @file mavlink_ftp_test.h
|
||||
/// @author Don Gagne <don@thegagnes.com>
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unit_test.h>
|
||||
#include "../mavlink_bridge_header.h"
|
||||
#include "../mavlink_ftp.h"
|
||||
#include "../mavlink_main.h"
|
||||
|
||||
class MavlinkFtpTest : public UnitTest
|
||||
{
|
||||
public:
|
||||
MavlinkFtpTest();
|
||||
virtual ~MavlinkFtpTest() = default;
|
||||
|
||||
virtual bool run_tests(void);
|
||||
|
||||
static void receive_message_handler_generic(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data);
|
||||
|
||||
/// Worker data for stream handler
|
||||
struct BurstInfo {
|
||||
MavlinkFtpTest *ftp_test_class;
|
||||
int burst_state;
|
||||
bool single_packet_file;
|
||||
uint32_t file_size;
|
||||
uint8_t *file_bytes;
|
||||
};
|
||||
|
||||
static void receive_message_handler_burst(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data);
|
||||
|
||||
static const uint8_t serverSystemId = 50; ///< System ID for server
|
||||
static const uint8_t serverComponentId = 1; ///< Component ID for server
|
||||
static const uint8_t serverChannel = 0; ///< Channel to send to
|
||||
|
||||
static const uint8_t clientSystemId = 1; ///< System ID for client
|
||||
static const uint8_t clientComponentId = 0; ///< Component ID for client
|
||||
|
||||
// We don't want any of these
|
||||
MavlinkFtpTest(const MavlinkFtpTest &);
|
||||
MavlinkFtpTest &operator=(const MavlinkFtpTest &);
|
||||
|
||||
private:
|
||||
virtual void _init(void);
|
||||
virtual void _cleanup(void);
|
||||
|
||||
bool _create_test_files(void);
|
||||
bool _remove_test_files(void);
|
||||
bool _ack_test(void);
|
||||
bool _bad_opcode_test(void);
|
||||
bool _bad_datasize_test(void);
|
||||
bool _list_test(void);
|
||||
bool _list_eof_test(void);
|
||||
bool _open_badfile_test(void);
|
||||
bool _open_terminate_test(void);
|
||||
bool _terminate_badsession_test(void);
|
||||
bool _read_test(void);
|
||||
bool _read_badsession_test(void);
|
||||
bool _burst_test(void);
|
||||
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);
|
||||
bool _setup_ftp_msg(const MavlinkFTP::PayloadHeader *payload_header,
|
||||
const uint8_t *data, const uint8_t data_len,
|
||||
mavlink_message_t *msg);
|
||||
bool _decode_message(const mavlink_file_transfer_protocol_t *ftp_msg, const MavlinkFTP::PayloadHeader **payload);
|
||||
bool _send_receive_msg(MavlinkFTP::PayloadHeader *payload_header,
|
||||
const uint8_t *data,
|
||||
const size_t data_len,
|
||||
const MavlinkFTP::PayloadHeader **payload_reply);
|
||||
void _cleanup_microsd(void);
|
||||
|
||||
/// A single download test case
|
||||
struct DownloadTestCase {
|
||||
const char *file;
|
||||
const uint16_t length;
|
||||
bool singlePacketRead;
|
||||
bool exactlyFillPacket;
|
||||
};
|
||||
|
||||
/// The set of test cases for download testing
|
||||
static const DownloadTestCase _rgDownloadTestCases[];
|
||||
|
||||
/// States for stream download handler
|
||||
enum {
|
||||
burst_state_first_ack,
|
||||
burst_state_last_ack,
|
||||
burst_state_nak_eof,
|
||||
burst_state_complete
|
||||
};
|
||||
|
||||
bool _receive_message_handler_burst(const mavlink_file_transfer_protocol_t *ftp_req, BurstInfo *burst_info);
|
||||
|
||||
MavlinkFTP *_ftp_server;
|
||||
Mavlink _mavlink;
|
||||
uint16_t _expected_seq_number;
|
||||
|
||||
mavlink_file_transfer_protocol_t _reply_msg;
|
||||
|
||||
static const char _unittest_microsd_dir[];
|
||||
static const char _unittest_microsd_file[];
|
||||
};
|
||||
|
||||
bool mavlink_ftp_test(void);
|
||||
@@ -1,47 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file mavlink_tests.cpp
|
||||
*/
|
||||
|
||||
#include <systemlib/err.h>
|
||||
|
||||
#include "mavlink_ftp_test.h"
|
||||
|
||||
extern "C" __EXPORT int mavlink_tests_main(int argc, char *argv[]);
|
||||
|
||||
int mavlink_tests_main(int argc, char *argv[])
|
||||
{
|
||||
return mavlink_ftp_test() ? 0 : -1;
|
||||
}
|
||||
Reference in New Issue
Block a user