Firmware
mavlink_ftp_test.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2014 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
36 
37 #pragma once
38 
39 #include <unit_test.h>
40 #include "../mavlink_bridge_header.h"
41 #include "../mavlink_ftp.h"
42 
43 class MavlinkFtpTest : public UnitTest
44 {
45 public:
47  virtual ~MavlinkFtpTest() = default;
48 
49  virtual bool run_tests(void);
50 
51  static void receive_message_handler_generic(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data);
52 
54  struct BurstInfo {
55  MavlinkFtpTest *ftp_test_class;
56  int burst_state;
57  bool single_packet_file;
58  uint32_t file_size;
59  uint8_t *file_bytes;
60  };
61 
62  static void receive_message_handler_burst(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data);
63 
64  static const uint8_t serverSystemId = 50;
65  static const uint8_t serverComponentId = 1;
66  static const uint8_t serverChannel = 0;
67 
68  static const uint8_t clientSystemId = 1;
69  static const uint8_t clientComponentId = 0;
70 
71  // We don't want any of these
73  MavlinkFtpTest &operator=(const MavlinkFtpTest &);
74 
75 private:
76  virtual void _init(void);
77  virtual void _cleanup(void);
78 
79  bool _ack_test(void);
80  bool _bad_opcode_test(void);
81  bool _bad_datasize_test(void);
82  bool _list_test(void);
83  bool _list_eof_test(void);
84  bool _open_badfile_test(void);
85  bool _open_terminate_test(void);
86  bool _terminate_badsession_test(void);
87  bool _read_test(void);
88  bool _read_badsession_test(void);
89  bool _burst_test(void);
90  bool _removedirectory_test(void);
91  bool _createdirectory_test(void);
92  bool _removefile_test(void);
93 
94  void _receive_message_handler_generic(const mavlink_file_transfer_protocol_t *ftp_req);
95  void _setup_ftp_msg(const MavlinkFTP::PayloadHeader *payload_header, uint8_t size, const uint8_t *data,
96  mavlink_message_t *msg);
97  bool _decode_message(const mavlink_file_transfer_protocol_t *ftp_msg, const MavlinkFTP::PayloadHeader **payload);
98  bool _send_receive_msg(MavlinkFTP::PayloadHeader *payload_header,
99  uint8_t size,
100  const uint8_t *data,
101  const MavlinkFTP::PayloadHeader **payload_reply);
102  void _cleanup_microsd(void);
103 
105  struct DownloadTestCase {
106  const char *file;
107  const uint16_t length;
108  bool singlePacketRead;
109  bool exactlyFillPacket;
110  };
111 
113  static const DownloadTestCase _rgDownloadTestCases[];
114 
116  enum {
117  burst_state_first_ack,
118  burst_state_last_ack,
119  burst_state_nak_eof,
120  burst_state_complete
121  };
122 
123  bool _receive_message_handler_burst(const mavlink_file_transfer_protocol_t *ftp_req, BurstInfo *burst_info);
124 
125  MavlinkFTP *_ftp_server;
126  uint16_t _expected_seq_number;
127 
128  mavlink_file_transfer_protocol_t _reply_msg;
129 
130  static const char _unittest_microsd_dir[];
131  static const char _unittest_microsd_file[];
132 };
133 
134 bool mavlink_ftp_test(void);
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.
Definition: mavlink_ftp_test.cpp:816
Definition: mavlink_ftp_test.h:43
static const uint8_t serverSystemId
System ID for server.
Definition: mavlink_ftp_test.h:64
static const uint8_t clientSystemId
System ID for client.
Definition: mavlink_ftp_test.h:68
static const uint8_t serverComponentId
Component ID for server.
Definition: mavlink_ftp_test.h:65
static const uint8_t clientComponentId
Component ID for client.
Definition: mavlink_ftp_test.h:69
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.
Definition: mavlink_ftp_test.cpp:803
Base class to be used for unit tests.
Definition: unit_test.h:54
MAVLink remote file server. Support FTP like commands using MAVLINK_MSG_ID_FILE_TRANSFER_PROTOCOL mes...
Definition: mavlink_ftp.h:52
virtual bool run_tests(void)
Runs all the unit tests.
Definition: mavlink_ftp_test.cpp:948
Worker data for stream handler.
Definition: mavlink_ftp_test.h:54
static const uint8_t serverChannel
Channel to send to.
Definition: mavlink_ftp_test.h:66