diff --git a/ROMFS/px4fmu_test/CMakeLists.txt b/ROMFS/px4fmu_test/CMakeLists.txt index d199c602bf..be3e27cb99 100644 --- a/ROMFS/px4fmu_test/CMakeLists.txt +++ b/ROMFS/px4fmu_test/CMakeLists.txt @@ -33,4 +33,3 @@ add_subdirectory(init.d) add_subdirectory(mixers) -add_subdirectory(unit_test_data) diff --git a/ROMFS/px4fmu_test/unit_test_data/CMakeLists.txt b/ROMFS/px4fmu_test/unit_test_data/CMakeLists.txt deleted file mode 100644 index 64edf16408..0000000000 --- a/ROMFS/px4fmu_test/unit_test_data/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################ -# -# Copyright (c) 2018 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. -# -############################################################################ - -add_subdirectory(mavlink_tests) diff --git a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/CMakeLists.txt b/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/CMakeLists.txt deleted file mode 100644 index aa85bf9e57..0000000000 --- a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################ -# -# Copyright (c) 2018 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_romfs_files( - test_238.data - test_239.data - test_240.data - ) diff --git a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/empty_dir/.gitignore b/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/empty_dir/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_238.data b/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_238.data deleted file mode 100644 index 973de16e59..0000000000 Binary files a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_238.data and /dev/null differ diff --git a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_239.data b/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_239.data deleted file mode 100644 index 7e8764c031..0000000000 Binary files a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_239.data and /dev/null differ diff --git a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_240.data b/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_240.data deleted file mode 100644 index f3fe31687f..0000000000 Binary files a/ROMFS/px4fmu_test/unit_test_data/mavlink_tests/test_240.data and /dev/null differ diff --git a/src/modules/mavlink/mavlink_ftp.cpp b/src/modules/mavlink/mavlink_ftp.cpp index e109c7e68c..79b628ad26 100644 --- a/src/modules/mavlink/mavlink_ftp.cpp +++ b/src/modules/mavlink/mavlink_ftp.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2014-2016 PX4 Development Team. All rights reserved. + * Copyright (c) 2014-2020 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 @@ -43,9 +43,15 @@ #include #include "mavlink_ftp.h" -#include "mavlink_main.h" #include "mavlink_tests/mavlink_ftp_test.h" +#ifndef MAVLINK_FTP_UNIT_TEST +#include "mavlink_main.h" +#else +#include +#endif + + constexpr const char MavlinkFTP::_root_dir[]; MavlinkFTP::MavlinkFTP(Mavlink *mavlink) : @@ -171,7 +177,11 @@ 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; } } @@ -269,7 +279,8 @@ out: if (r_errno == EEXIST) { errorCode = kErrFailFileExists; - } else if (r_errno == ENOENT) { + + } else if (r_errno == ENOENT && errorCode == kErrFailErrno) { errorCode = kErrFileNotFound; } @@ -338,7 +349,7 @@ MavlinkFTP::_reply(mavlink_file_transfer_protocol_t *ftp_req) /// @brief Responds to a List command MavlinkFTP::ErrorCode -MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden) +MavlinkFTP::_workList(PayloadHeader *payload) { strncpy(_work_buffer1, _root_dir, _work_buffer1_len); strncpy(_work_buffer1 + _root_dir_len, _data_as_cstring(payload), _work_buffer1_len - _root_dir_len); @@ -428,8 +439,7 @@ MavlinkFTP::_workList(PayloadHeader *payload, bool list_hidden) #else case DT_DIR: #endif - if ((!list_hidden && (strncmp(result->d_name, ".", 1) == 0)) || - strcmp(result->d_name, ".") == 0 || strcmp(result->d_name, "..") == 0) { + if (strcmp(result->d_name, ".") == 0 || strcmp(result->d_name, "..") == 0) { // Don't bother sending these back direntType = kDirentSkip; diff --git a/src/modules/mavlink/mavlink_ftp.h b/src/modules/mavlink/mavlink_ftp.h index 96f6dc6d0e..f2d4b38c9c 100644 --- a/src/modules/mavlink/mavlink_ftp.h +++ b/src/modules/mavlink/mavlink_ftp.h @@ -43,7 +43,11 @@ #include #include +#ifndef MAVLINK_FTP_UNIT_TEST #include "mavlink_bridge_header.h" +#else +#include +#endif class MavlinkFtpTest; class Mavlink; @@ -133,7 +137,7 @@ private: void _reply(mavlink_file_transfer_protocol_t *ftp_req); int _copy_file(const char *src_path, const char *dst_path, size_t length); - ErrorCode _workList(PayloadHeader *payload, bool list_hidden = false); + ErrorCode _workList(PayloadHeader *payload); ErrorCode _workOpen(PayloadHeader *payload, int oflag); ErrorCode _workRead(PayloadHeader *payload); ErrorCode _workBurst(PayloadHeader *payload, uint8_t target_system_id, uint8_t target_component_id); diff --git a/src/modules/mavlink/mavlink_tests/CMakeLists.txt b/src/modules/mavlink/mavlink_tests/CMakeLists.txt index f8e0068a1c..398a818cfc 100644 --- a/src/modules/mavlink/mavlink_tests/CMakeLists.txt +++ b/src/modules/mavlink/mavlink_tests/CMakeLists.txt @@ -44,6 +44,7 @@ px4_add_module( -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 diff --git a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp b/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp index fb554473c4..28b2f8774f 100644 --- a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp +++ b/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2014 PX4 Development Team. All rights reserved. + * Copyright (C) 2014-2020 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 @@ -43,16 +43,21 @@ #include "../mavlink_ftp.h" #ifdef __PX4_NUTTX -#define PX4_MAVLINK_TEST_DATA_DIR "/etc" +#define PX4_MAVLINK_TEST_DATA_DIR "/fs/microsd/ftp_unit_test_data" #else -#define PX4_MAVLINK_TEST_DATA_DIR "etc" +#define PX4_MAVLINK_TEST_DATA_DIR "ftp_unit_test_data" #endif -/// @brief Test case file name for Read command. File are generated using mavlink_ftp_test_data.py +static const char *_test_files[] = { + PX4_MAVLINK_TEST_DATA_DIR "/" "test_238.data", + PX4_MAVLINK_TEST_DATA_DIR "/" "test_239.data", + PX4_MAVLINK_TEST_DATA_DIR "/" "test_240.data" +}; + const MavlinkFtpTest::DownloadTestCase MavlinkFtpTest::_rgDownloadTestCases[] = { - { 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 }, // Read takes less than single packet - { 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 }, // Read completely fills single packet - { 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 }, // Read take two packets + { _test_files[0], MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) - 1, true, false }, // Read takes less than single packet + { _test_files[1], MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader), true, true }, // Read completely fills single packet + { _test_files[2], MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader) + 1, false, false }, // Read take two packets }; const char MavlinkFtpTest::_unittest_microsd_dir[] = PX4_STORAGEDIR "/ftp_unit_test_dir"; @@ -72,17 +77,70 @@ void MavlinkFtpTest::_init() _ftp_server = new MavlinkFTP(nullptr); _ftp_server->set_unittest_worker(MavlinkFtpTest::receive_message_handler_generic, this); + _create_test_files(); + _cleanup_microsd(); } +bool MavlinkFtpTest::_create_test_files() +{ + int ret = ::mkdir(PX4_MAVLINK_TEST_DATA_DIR, S_IRWXU | S_IRWXG | S_IRWXO); + ut_assert("mkdir failed", ret == 0 || errno == EEXIST); + + ret = ::mkdir(PX4_MAVLINK_TEST_DATA_DIR "/empty_dir", S_IRWXU | S_IRWXG | S_IRWXO); + ut_assert("mkdir failed", ret == 0 || errno == EEXIST); + + bool failed = false; + + for (int i = 0; i < 3; ++i) { + int fd = ::open(_test_files[i], O_CREAT | O_EXCL | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); + + if (fd < 0) { + printf("fd: %d, error: %s\n", fd, strerror(errno)); + ut_assert("Open failed", fd != -1); + } + + // We create 3 files, with bytes counting from 0 to 238, 239, and 240. + uint8_t len = 238 + i; + + for (uint8_t c = 0; c < len; ++c) { + ret = ::write(fd, &c, 1); + + if (ret != 1) { + failed = true; + } + } + + close(fd); + } + + ut_assert("Could not write test file", !failed); + + return !failed; +} + /// @brief Called after every test to take down the FTP Server. void MavlinkFtpTest::_cleanup() { delete _ftp_server; _cleanup_microsd(); + _remove_test_files(); } +bool MavlinkFtpTest::_remove_test_files() +{ + for (int i = 0; i < 3; ++i) { + ::unlink(_test_files[i]); + } + + ::rmdir(PX4_MAVLINK_TEST_DATA_DIR "/empty_dir"); + ::rmdir(PX4_MAVLINK_TEST_DATA_DIR); + + return true; +} + + /// @brief Tests for correct behavior of an Ack response. bool MavlinkFtpTest::_ack_test() { @@ -106,7 +164,7 @@ bool MavlinkFtpTest::_ack_test() return true; } -/// @brief Tests for correct response to an invalid opcpde. +/// @brief Tests for correct response to an invalid opcode. bool MavlinkFtpTest::_bad_opcode_test() { MavlinkFTP::PayloadHeader payload; @@ -163,25 +221,19 @@ bool MavlinkFtpTest::_list_test() MavlinkFTP::PayloadHeader payload; const MavlinkFTP::PayloadHeader *reply; - char response1[] = "Dempty_dir|Ftest_238.data\t238|Ftest_239.data\t239|Ftest_240.data\t240"; -#ifdef __PX4_NUTTX - // expected directory layout only valid on nuttx - char response2[] = "Ddev|Detc|Dfs|Dobj"; -#endif /* __PX4_NUTTX */ - struct _testCase { const char *dir; ///< Directory to run List command on - char *response; ///< Expected response entries from List command + const char *response; ///< Expected response entries from List command int response_count; ///< Number of directories that should be returned bool success; ///< true: List command should succeed, false: List command should fail }; struct _testCase rgTestCases[] = { - { "/bogus", nullptr, 0, false }, - { PX4_MAVLINK_TEST_DATA_DIR "/unit_test_data/mavlink_tests", response1, 4, true }, + { "/bogus", nullptr, 0, false }, #ifdef __PX4_NUTTX - // expected directory layout only valid on nuttx - { "/", response2, 4, true }, -#endif /* __PX4_NUTTX */ + { PX4_MAVLINK_TEST_DATA_DIR, "Dempty_dir|Ftest_238.data\t238|Ftest_239.data\t239|Ftest_240.data\t240", 4, true }, +#else + { PX4_MAVLINK_TEST_DATA_DIR, "Dempty_dir|Ftest_238.data\t238|Ftest_239.data\t239|Ftest_240.data\t240|S|S", 6, true }, // readdir on Linux adds . and .. +#endif }; for (size_t i = 0; i < sizeof(rgTestCases) / sizeof(rgTestCases[0]); i++) { @@ -235,8 +287,8 @@ bool MavlinkFtpTest::_list_test() } else { ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak); - ut_compare("Incorrect payload size", reply->size, 2); - ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFailErrno); + ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFileNotFound); + ut_compare("Incorrect payload size", reply->size, 1); } } @@ -249,10 +301,14 @@ bool MavlinkFtpTest::_list_eof_test() { MavlinkFTP::PayloadHeader payload; const MavlinkFTP::PayloadHeader *reply; - const char *dir = "/"; + const char *dir = PX4_MAVLINK_TEST_DATA_DIR; payload.opcode = MavlinkFTP::kCmdListDirectory; - payload.offset = 4; // offset past top level dirs +#ifdef __PX4_NUTTX + payload.offset = 4; // (3 test files, 1 test folder) +#else + payload.offset = 6; // (3 test files, 1 test folder, two skipped ./..) +#endif bool success = _send_receive_msg(&payload, // FTP payload header strlen(dir) + 1, // size in bytes of data @@ -290,8 +346,8 @@ bool MavlinkFtpTest::_open_badfile_test() } ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak); - ut_compare("Incorrect payload size", reply->size, 2); - ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFailErrno); + ut_compare("Incorrect payload size", reply->size, 1); + ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFileNotFound); return true; } @@ -647,13 +703,14 @@ bool MavlinkFtpTest::_removedirectory_test() const char *dir; bool success; bool deleteFile; + uint8_t reply_size; + uint8_t error_code; }; static const struct _testCase rgTestCases[] = { - { "/bogus", false, false }, - { PX4_MAVLINK_TEST_DATA_DIR "/unit_test_data/mavlink_tests/empty_dir", false, false }, - { _unittest_microsd_dir, false, false }, - { _unittest_microsd_file, false, false }, - { _unittest_microsd_dir, true, true }, + { "/bogus", false, false, 1, MavlinkFTP::kErrFileNotFound }, + { _unittest_microsd_dir, false, false, 2, MavlinkFTP::kErrFailErrno }, + { _unittest_microsd_file, false, false, 2, MavlinkFTP::kErrFailErrno }, + { _unittest_microsd_dir, true, true, 0, MavlinkFTP::kErrNone }, }; ut_compare("mkdir failed", ::mkdir(_unittest_microsd_dir, S_IRWXU | S_IRWXG | S_IRWXO), 0); @@ -681,12 +738,12 @@ bool MavlinkFtpTest::_removedirectory_test() if (test->success) { ut_compare("Didn't get Ack back", reply->opcode, MavlinkFTP::kRspAck); - ut_compare("Incorrect payload size", reply->size, 0); + ut_compare("Incorrect payload size", reply->size, test->reply_size); } else { ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak); - ut_compare("Incorrect payload size", reply->size, 2); - ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFailErrno); + ut_compare("Incorrect payload size", reply->size, test->reply_size); + ut_compare("Incorrect error code", reply->data[0], test->error_code); } } @@ -701,13 +758,17 @@ bool MavlinkFtpTest::_createdirectory_test() struct _testCase { const char *dir; bool success; - bool fail_exists; + uint8_t reply_size; + uint8_t error_code; }; static const struct _testCase rgTestCases[] = { - { "/etc/bogus", false, false }, - { _unittest_microsd_dir, true, false }, - { _unittest_microsd_dir, false, true }, - { "/fs/microsd/bogus/bogus", false, false }, + { _unittest_microsd_dir, true, 0, MavlinkFTP::kErrNone}, + { _unittest_microsd_dir, false, 1, MavlinkFTP::kErrFailFileExists}, +#ifdef __PX4_NUTTX + { PX4_MAVLINK_TEST_DATA_DIR "/bogus/bogus", false, 2, MavlinkFTP::kErrFailErrno} // on NuttX missing folders is EIO +#else + { PX4_MAVLINK_TEST_DATA_DIR "/bogus/bogus", false, 1, MavlinkFTP::kErrFileNotFound} // on Linux it is ENOENT +#endif }; for (size_t i = 0; i < sizeof(rgTestCases) / sizeof(rgTestCases[0]); i++) { @@ -727,17 +788,12 @@ bool MavlinkFtpTest::_createdirectory_test() if (test->success) { ut_compare("Didn't get Ack back", reply->opcode, MavlinkFTP::kRspAck); - ut_compare("Incorrect payload size", reply->size, 0); - - } else if (test->fail_exists) { - ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak); - ut_compare("Incorrect payload size", reply->size, 1); - ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFailFileExists); + ut_compare("Incorrect payload size", reply->size, test->reply_size); } else { ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak); - ut_compare("Incorrect payload size", reply->size, 2); - ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFailErrno); + ut_compare("Incorrect error code", reply->data[0], test->error_code); + ut_compare("Incorrect payload size", reply->size, test->reply_size); } } @@ -753,16 +809,14 @@ bool MavlinkFtpTest::_removefile_test() struct _testCase { const char *file; bool success; + uint8_t reply_size; + uint8_t error_code; }; static const struct _testCase rgTestCases[] = { - { "/bogus", false }, -#ifdef __PX4_NUTTX - // file can actually be deleted on linux - { _rgDownloadTestCases[0].file, false }, -#endif /* __PX4_NUTTX */ - { _unittest_microsd_dir, false }, - { _unittest_microsd_file, true }, - { _unittest_microsd_file, false }, + { "/bogus", false, 1, MavlinkFTP::kErrFileNotFound }, + { _unittest_microsd_dir, false, 2, MavlinkFTP::kErrFailErrno }, + { _unittest_microsd_file, true, 0, MavlinkFTP::kErrNone }, + { _unittest_microsd_file, false, 1, MavlinkFTP::kErrFileNotFound }, }; ut_compare("mkdir failed", ::mkdir(_unittest_microsd_dir, S_IRWXU | S_IRWXG | S_IRWXO), 0); @@ -786,12 +840,12 @@ bool MavlinkFtpTest::_removefile_test() if (test->success) { ut_compare("Didn't get Ack back", reply->opcode, MavlinkFTP::kRspAck); - ut_compare("Incorrect payload size", reply->size, 0); + ut_compare("Incorrect payload size", reply->size, test->reply_size); } else { ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak); - ut_compare("Incorrect payload size", reply->size, 2); - ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrFailErrno); + ut_compare("Incorrect payload size", reply->size, test->reply_size); + ut_compare("Incorrect error code", reply->data[0], test->error_code); } } @@ -950,13 +1004,8 @@ bool MavlinkFtpTest::run_tests() ut_run_test(_ack_test); ut_run_test(_bad_opcode_test); ut_run_test(_bad_datasize_test); - - // TODO FIX: Incorrect payload size - (reply->size:1) (2:2) (../src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp:243) - //ut_run_test(_list_test); - - // TODO FIX: Didn't get Nak back - (reply->opcode:128) (MavlinkFTP::kRspNak:129) (../src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp:271) - //ut_run_test(_list_eof_test); - + ut_run_test(_list_test); + ut_run_test(_list_eof_test); ut_run_test(_open_badfile_test); ut_run_test(_open_terminate_test); ut_run_test(_terminate_badsession_test); @@ -964,9 +1013,7 @@ bool MavlinkFtpTest::run_tests() ut_run_test(_read_badsession_test); ut_run_test(_burst_test); ut_run_test(_removedirectory_test); - - // TODO FIX: Didn't get Nak back - (reply->opcode:128) (MavlinkFTP::kRspNak:129) (../../src/modules/mavlink/mavlink_tests/mavlink_ftp_test.cpp:730) - //ut_run_test(_createdirectory_test); + ut_run_test(_createdirectory_test); ut_run_test(_removefile_test); return (_tests_failed == 0); diff --git a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h b/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h index 8af982f41c..8d2868af76 100644 --- a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h +++ b/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h @@ -37,7 +37,11 @@ #pragma once #include +#ifndef MAVLINK_FTP_UNIT_TEST #include "../mavlink_bridge_header.h" +#else +#include +#endif #include "../mavlink_ftp.h" class MavlinkFtpTest : public UnitTest @@ -76,6 +80,8 @@ 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); diff --git a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test_data.py b/src/modules/mavlink/mavlink_tests/mavlink_ftp_test_data.py deleted file mode 100755 index 9c5580a9b7..0000000000 --- a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test_data.py +++ /dev/null @@ -1,8 +0,0 @@ -from __future__ import print_function -import sys -print('Arguments: file - ' + sys.argv[1] + ', length - ' + sys.argv[2]) -file = open(sys.argv[1], 'w') -for i in range(int(sys.argv[2])): - b = bytearray([i & 0xFF]) - file.write(b) -file.close() \ No newline at end of file diff --git a/src/systemcmds/tests/tests_main.c b/src/systemcmds/tests/tests_main.c index 9906a635ff..2f59e20f87 100644 --- a/src/systemcmds/tests/tests_main.c +++ b/src/systemcmds/tests/tests_main.c @@ -120,9 +120,8 @@ const struct { /* external tests */ {"commander", commander_tests_main, 0}, {"controllib", controllib_test_main, 0}, -#ifndef __PX4_NUTTX {"mavlink", mavlink_tests_main, 0}, -#else +#ifdef __PX4_NUTTX {"sf0x", sf0x_tests_main, 0}, #endif {"uorb", uorb_tests_main, 0},